├── BPv1a-firmware ├── BPv1a-Bootloader-v4.4.hex ├── BPv1a-Firmware-v5.10.hex ├── BPv1a-Firmware-v5.9-extras.hex ├── BPv1a-STK500v2-v0b-hiz.hex ├── BPv1a-STK500v2-v0b.hex ├── README.TXT ├── STK500v2-gpl.txt ├── old-versions │ ├── BPv1a-Bootloader-v4.2.hex │ ├── BPv1a-Firmware-v5.4.hex │ ├── BPv1a-Firmware-v5.5.hex │ ├── BPv1a-Firmware-v5.6.hex │ ├── BPv1a-Firmware-v5.7.hex │ ├── BPv1a-Firmware-v5.8.hex │ └── BPv1a-Firmware-v5.9.hex ├── v1a-REAME.TXT ├── v4UPGRADES!!!.txt ├── v4UPGRADES!!.txt └── v4UPGRADES!.txt ├── BPv3-firmware ├── BPv3-STK500v2-v0b-hiz.hex ├── BPv3-STK500v2-v0b.hex ├── BPv3-frimware-v6.1.hex ├── BPv3-update-v6.1.bat ├── GHelper.dll ├── README.TXT ├── STK500v2-gpl.txt ├── bpv3-xsvf-vb.hex ├── ds30 Loader GUI.exe ├── ds30 Loader.dll ├── old-versions │ ├── BPv3-Firmware-v5.10.hex │ ├── BPv3-Firmware-v5.9-extras.hex │ ├── BPv3-Firmware-v5.9.hex │ ├── BPv3-STK500v2-v0b-hiz.hex │ ├── BPv3-STK500v2-v0b.hex │ ├── BPv3-frimware-v6.hex │ ├── BPv3-update-v6.bat │ ├── README.TXT │ ├── STK500v2-gpl.txt │ ├── bpv3-BL44FW510-DUMP.hex │ ├── v4UPGRADES!!!.txt │ ├── v4UPGRADES!!.txt │ └── v4UPGRADES!.txt ├── pirate-loader-source │ ├── build-unix.sh │ ├── build-win32.bat │ ├── makefile │ └── source │ │ └── pirate-loader.c ├── pirate-loader.exe ├── pirate-loader_lnx ├── pirate-loader_mac ├── settings.xml └── v4UPGRADES!!!.txt ├── BPv4-firmware ├── BPv4-frimware-v6.1.hex ├── BPv4-update-v6.1.bat ├── pirate-loader-v4-source │ ├── build-unix.sh │ ├── build-win32.bat │ ├── makefile │ ├── makefile.bak │ ├── pirate-loader.c │ ├── pirate-loader.cbp │ ├── pirate-loader.depend │ ├── pirate-loader.layout │ └── pirate-loader_mac └── pirate-loader.exe ├── BPv4-inf-driver ├── mchpcdc.cat └── mchpcdc.inf ├── README.md ├── bootloader ├── BPv3-Bootloader-v4.4.hex └── BPv4-bootloader-v1.hex └── hardware ├── BPv3-LCDadapter-v2c.brd ├── BPv3-LCDadapter-v2c.sch ├── BPv3-PICprogrammer-v1c.brd ├── BPv3-PICprogrammer-v1c.sch ├── BusPirate-v3.5c-SSOP.brd ├── BusPirate-v3.5c-SSOP.sch ├── BusPirate-v3a-final.brd ├── BusPirate-v3a-final.sch ├── BusPirate-v4.brd └── BusPirate-v4.sch /BPv1a-firmware/README.TXT: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------ 2 | STOP! If you are upgrading from v2 you must install the v4 bootloader first: 3 | http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/ 4 | v4 BOOTLOADER ONLY!!! 5 | DO NOT TRY TO LOAD THE BOOTLOADER FROM THIS ARCHIVE!!!! 6 | DO NOT TRY TO LOAD THE V4 FIRMWARE WITH p24QP!!! 7 | ------------------------------------------------------------------ 8 | Firmware upgrades: 9 | 10 | http://dangerousprototypes.com/docs/Bus_Pirate#Firmware_upgrades 11 | 12 | 1) Enter the bootloader: 13 | 14 | Connect PGC and PGD pins of the ICSP header and plug in the USB cable 15 | 16 | --+OR+-- 17 | 18 | Type $ in the Bus Pirate terminal. 19 | 20 | With both methods the MODE LED should light. 21 | 22 | 2) Load the new firmware: 23 | 24 | * ds30Loader: just use the GUI (.net/Mono required) 25 | * Pirate-loader (console app for Windows, Linux, Mac) firmware upgrades: 26 | 27 | C:\pl>pirate-loader --dev=COM10 --hex=BPv3-Firmware-v1.0.hex 28 | 29 | 3) re-plug the USB cable to reset the Bus Pirate. The upgrade is complete. 30 | 31 | ------------------------------------------------------------------ 32 | BPv3-Bootloader-v4.4.hex is the same as v4.3 installed with the updater. This file is only for programming the bootlaoder to a new PIC. Use the upgrade package to upgrade: 33 | 34 | http://dangerousprototypes.com/docs/Bus_Pirate#Bootloader_upgrades 35 | 36 | ------------------------------------------------------------------ 37 | vX-Firmware-vY(.z_Z).hex 38 | 39 | Normal Bus Pirate firmware. 40 | vX - Bus Pirate hardware version. 41 | vY - The Bus Pirate firmware version. 42 | z_Z - The .z_Z versions are translated compiles (currently Spanish and Italian). 43 | 44 | vX-STK500v2-vY(-hiz).hex 45 | 46 | ATMEL AVR programmer clone for the Bus Pirate hardware. An STK500 v2 protocol compatible firmware for the Bus Pirate, works with AVRDude, AVR Studio v4.11+, etc. 47 | vX - Bus Pirate hardware version (v2go and v3 use the same firmware). 48 | vY - THe STK500v2 clone firmware version. 49 | hiz - The -hiz version of the fimware uses open drain/high impedance outputs. On-board pull-up resistors are enabled (where applicable). The non -hiz version uses normal 3.3volt outputs. 50 | 51 | vX-PIC Bootloader-vY.hex 52 | 53 | Bootloader to program in a new PIC microcontroller. This is usually only programmed once. 54 | vX - Bus Pirate hardware version. 55 | vY - The Bus Pirate bootloader version. 56 | 57 | BPvX-Firmware-vX.X-extras.hex 58 | 59 | The BPv3-Firmware-vX.X-extras.hex has a few modes and new stuff we couldn't fit in the main firmware. 60 | -------------------------------------------------------------------------------- /BPv1a-firmware/STK500v2-gpl.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv1a-firmware/STK500v2-gpl.txt -------------------------------------------------------------------------------- /BPv1a-firmware/v1a-REAME.TXT: -------------------------------------------------------------------------------- 1 | Firmware v5.10 is the last official release for hardware v1a. Code has drifed so far from the humble v1a beginnings that we are no longer making releases. 2 | 3 | Firmware v5.10 requires bootloader v4.x. The v1a hardware shipped with v2. You will need to upgrade bootloaders with a PIC programmer, no auto-update package was released. 4 | 5 | For more see: 6 | http://dangerousprototypes.com/docs/Bus_Pirate#Firmware_upgrades -------------------------------------------------------------------------------- /BPv1a-firmware/v4UPGRADES!!!.txt: -------------------------------------------------------------------------------- 1 | STOP! If you are upgrading from v2 you must install the v4 bootloader first: 2 | http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/ 3 | v4 BOOTLOADER ONLY!!! 4 | DO NOT TRY TO LOAD THE BOOTLOADER FROM THIS ARCHIVE!!!! 5 | DO NOT TRY TO LOAD THE V4 FIRMWARE WITH p24QP!!! -------------------------------------------------------------------------------- /BPv1a-firmware/v4UPGRADES!!.txt: -------------------------------------------------------------------------------- 1 | STOP! If you are upgrading from v2 you must install the v4 bootloader first: 2 | http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/ 3 | v4 BOOTLOADER ONLY!!! 4 | DO NOT TRY TO LOAD THE BOOTLOADER FROM THIS ARCHIVE!!!! 5 | DO NOT TRY TO LOAD THE V4 FIRMWARE WITH p24QP!!! -------------------------------------------------------------------------------- /BPv1a-firmware/v4UPGRADES!.txt: -------------------------------------------------------------------------------- 1 | STOP! If you are upgrading from v2 you must install the v4 bootloader first: 2 | http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/ 3 | v4 BOOTLOADER ONLY!!! 4 | DO NOT TRY TO LOAD THE BOOTLOADER FROM THIS ARCHIVE!!!! 5 | DO NOT TRY TO LOAD THE V4 FIRMWARE WITH p24QP!!! -------------------------------------------------------------------------------- /BPv3-firmware/BPv3-update-v6.1.bat: -------------------------------------------------------------------------------- 1 | pause 2 | pirate-loader.exe --dev=COM43 --hex=BPv3-frimware-v6.1.hex 3 | pause 4 | -------------------------------------------------------------------------------- /BPv3-firmware/GHelper.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv3-firmware/GHelper.dll -------------------------------------------------------------------------------- /BPv3-firmware/README.TXT: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------ 2 | STOP! If you are upgrading from v2 you must install the v4 bootloader first: 3 | http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/ 4 | v4 BOOTLOADER ONLY!!! 5 | DO NOT TRY TO LOAD THE BOOTLOADER FROM THIS ARCHIVE!!!! 6 | DO NOT TRY TO LOAD THE V4 FIRMWARE WITH p24QP!!! 7 | ------------------------------------------------------------------ 8 | Firmware upgrades: 9 | 10 | http://dangerousprototypes.com/docs/Bus_Pirate#Firmware_upgrades 11 | 12 | 1) Enter the bootloader: 13 | 14 | Connect PGC and PGD pins of the ICSP header and plug in the USB cable 15 | 16 | --+OR+-- 17 | 18 | Type $ in the Bus Pirate terminal. 19 | 20 | With both methods the MODE LED should light. 21 | 22 | 2) Load the new firmware: 23 | 24 | * ds30Loader: just use the GUI (.net/Mono required) 25 | * Pirate-loader (console app for Windows, Linux, Mac) firmware upgrades: 26 | 27 | C:\pl>pirate-loader --dev=COM10 --hex=BPv3-Firmware-v1.0.hex 28 | 29 | 3) re-plug the USB cable to reset the Bus Pirate. The upgrade is complete. 30 | 31 | ------------------------------------------------------------------ 32 | BPv3-Bootloader-v4.4.hex is the same as v4.3 installed with the updater. This file is only for programming the bootlaoder to a new PIC. Use the upgrade package to upgrade: 33 | 34 | http://dangerousprototypes.com/docs/Bus_Pirate#Bootloader_upgrades 35 | 36 | ------------------------------------------------------------------ 37 | vX-Firmware-vY(.z_Z).hex 38 | 39 | Normal Bus Pirate firmware. 40 | vX - Bus Pirate hardware version. 41 | vY - The Bus Pirate firmware version. 42 | z_Z - The .z_Z versions are translated compiles (currently Spanish and Italian). 43 | 44 | vX-STK500v2-vY(-hiz).hex 45 | 46 | ATMEL AVR programmer clone for the Bus Pirate hardware. An STK500 v2 protocol compatible firmware for the Bus Pirate, works with AVRDude, AVR Studio v4.11+, etc. 47 | vX - Bus Pirate hardware version (v2go and v3 use the same firmware). 48 | vY - THe STK500v2 clone firmware version. 49 | hiz - The -hiz version of the fimware uses open drain/high impedance outputs. On-board pull-up resistors are enabled (where applicable). The non -hiz version uses normal 3.3volt outputs. 50 | 51 | vX-PIC Bootloader-vY.hex 52 | 53 | Bootloader to program in a new PIC microcontroller. This is usually only programmed once. 54 | vX - Bus Pirate hardware version. 55 | vY - The Bus Pirate bootloader version. 56 | 57 | BPvX-Firmware-vX.X-extras.hex 58 | 59 | The BPv3-Firmware-vX.X-extras.hex has a few modes and new stuff we couldn't fit in the main firmware. 60 | -------------------------------------------------------------------------------- /BPv3-firmware/STK500v2-gpl.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv3-firmware/STK500v2-gpl.txt -------------------------------------------------------------------------------- /BPv3-firmware/ds30 Loader GUI.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv3-firmware/ds30 Loader GUI.exe -------------------------------------------------------------------------------- /BPv3-firmware/ds30 Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv3-firmware/ds30 Loader.dll -------------------------------------------------------------------------------- /BPv3-firmware/old-versions/BPv3-update-v6.bat: -------------------------------------------------------------------------------- 1 | pause 2 | pirate-loader.exe --dev=COM43 --hex=BPv3-frimware-v6.hex 3 | pause 4 | -------------------------------------------------------------------------------- /BPv3-firmware/old-versions/README.TXT: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------ 2 | STOP! If you are upgrading from v2 you must install the v4 bootloader first: 3 | http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/ 4 | v4 BOOTLOADER ONLY!!! 5 | DO NOT TRY TO LOAD THE BOOTLOADER FROM THIS ARCHIVE!!!! 6 | DO NOT TRY TO LOAD THE V4 FIRMWARE WITH p24QP!!! 7 | ------------------------------------------------------------------ 8 | Firmware upgrades: 9 | 10 | http://dangerousprototypes.com/docs/Bus_Pirate#Firmware_upgrades 11 | 12 | 1) Enter the bootloader: 13 | 14 | Connect PGC and PGD pins of the ICSP header and plug in the USB cable 15 | 16 | --+OR+-- 17 | 18 | Type $ in the Bus Pirate terminal. 19 | 20 | With both methods the MODE LED should light. 21 | 22 | 2) Load the new firmware: 23 | 24 | * ds30Loader: just use the GUI (.net/Mono required) 25 | * Pirate-loader (console app for Windows, Linux, Mac) firmware upgrades: 26 | 27 | C:\pl>pirate-loader --dev=COM10 --hex=BPv3-Firmware-v1.0.hex 28 | 29 | 3) re-plug the USB cable to reset the Bus Pirate. The upgrade is complete. 30 | 31 | ------------------------------------------------------------------ 32 | BPv3-Bootloader-v4.4.hex is the same as v4.3 installed with the updater. This file is only for programming the bootlaoder to a new PIC. Use the upgrade package to upgrade: 33 | 34 | http://dangerousprototypes.com/docs/Bus_Pirate#Bootloader_upgrades 35 | 36 | ------------------------------------------------------------------ 37 | vX-Firmware-vY(.z_Z).hex 38 | 39 | Normal Bus Pirate firmware. 40 | vX - Bus Pirate hardware version. 41 | vY - The Bus Pirate firmware version. 42 | z_Z - The .z_Z versions are translated compiles (currently Spanish and Italian). 43 | 44 | vX-STK500v2-vY(-hiz).hex 45 | 46 | ATMEL AVR programmer clone for the Bus Pirate hardware. An STK500 v2 protocol compatible firmware for the Bus Pirate, works with AVRDude, AVR Studio v4.11+, etc. 47 | vX - Bus Pirate hardware version (v2go and v3 use the same firmware). 48 | vY - THe STK500v2 clone firmware version. 49 | hiz - The -hiz version of the fimware uses open drain/high impedance outputs. On-board pull-up resistors are enabled (where applicable). The non -hiz version uses normal 3.3volt outputs. 50 | 51 | vX-PIC Bootloader-vY.hex 52 | 53 | Bootloader to program in a new PIC microcontroller. This is usually only programmed once. 54 | vX - Bus Pirate hardware version. 55 | vY - The Bus Pirate bootloader version. 56 | 57 | BPvX-Firmware-vX.X-extras.hex 58 | 59 | The BPv3-Firmware-vX.X-extras.hex has a few modes and new stuff we couldn't fit in the main firmware. 60 | -------------------------------------------------------------------------------- /BPv3-firmware/old-versions/STK500v2-gpl.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv3-firmware/old-versions/STK500v2-gpl.txt -------------------------------------------------------------------------------- /BPv3-firmware/old-versions/v4UPGRADES!!!.txt: -------------------------------------------------------------------------------- 1 | STOP! If you are upgrading from v2 you must install the v4 bootloader first: 2 | http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/ 3 | v4 BOOTLOADER ONLY!!! 4 | DO NOT TRY TO LOAD THE BOOTLOADER FROM THIS ARCHIVE!!!! 5 | DO NOT TRY TO LOAD THE V4 FIRMWARE WITH p24QP!!! -------------------------------------------------------------------------------- /BPv3-firmware/old-versions/v4UPGRADES!!.txt: -------------------------------------------------------------------------------- 1 | STOP! If you are upgrading from v2 you must install the v4 bootloader first: 2 | http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/ 3 | v4 BOOTLOADER ONLY!!! 4 | DO NOT TRY TO LOAD THE BOOTLOADER FROM THIS ARCHIVE!!!! 5 | DO NOT TRY TO LOAD THE V4 FIRMWARE WITH p24QP!!! -------------------------------------------------------------------------------- /BPv3-firmware/old-versions/v4UPGRADES!.txt: -------------------------------------------------------------------------------- 1 | STOP! If you are upgrading from v2 you must install the v4 bootloader first: 2 | http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/ 3 | v4 BOOTLOADER ONLY!!! 4 | DO NOT TRY TO LOAD THE BOOTLOADER FROM THIS ARCHIVE!!!! 5 | DO NOT TRY TO LOAD THE V4 FIRMWARE WITH p24QP!!! -------------------------------------------------------------------------------- /BPv3-firmware/pirate-loader-source/build-unix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | OS=`uname` 4 | 5 | echo -n "Building for $OS..." 6 | 7 | case $OS in 8 | 9 | Darwin ) 10 | gcc -O2 -Wall -force_cpusubtype_ALL -arch i386 -arch ppc source/pirate-loader.c -DOS=$OS -o pirate-loader_mac || exit -1 11 | ;; 12 | Linux ) 13 | gcc -O2 -Wall source/pirate-loader.c -DOS=$OS -o pirate-loader_lnx || exit -1 14 | ;; 15 | FreeBSD ) 16 | gcc -O2 -Wall source/pirate-loader.c -DOS=$OS -o pirate-loader_fbsd || exit -1 17 | ;; 18 | *) 19 | echo "ERROR" 20 | echo "Unsupported operating system $OS" 21 | exit -1 22 | ;; 23 | esac 24 | 25 | echo "DONE" 26 | exit 0 27 | -------------------------------------------------------------------------------- /BPv3-firmware/pirate-loader-source/build-win32.bat: -------------------------------------------------------------------------------- 1 | @echo "Building for WINDOWS" 2 | 3 | @cl source/pirate-loader.c /DWIN32=1 /DNDEBUG=1 /D_CRT_SECURE_NO_DEPRECATE=1 >out.log 2>err.log || exit 4 | 5 | @del pirate-loader.obj 6 | @del out.log 7 | @del err.log -------------------------------------------------------------------------------- /BPv3-firmware/pirate-loader-source/makefile: -------------------------------------------------------------------------------- 1 | OS := $(shell uname) 2 | SOURCEPATH=. 3 | CC=gcc 4 | CFLAGS=-O2 -Wall 5 | OSFLAGS= -DOS=$OS 6 | SOURCES=$(SOURCEPATH)/pirate-loader.c 7 | 8 | ifeq ($(OS),Linux) 9 | SUFFIX=lnx 10 | endif 11 | ifeq ($(OS),Darwin) 12 | SUFFIX=mac 13 | CFLAGS=$(CFLAGS) -force_cpusubtype_ALL -arch i386 -arch ppc 14 | endif 15 | ifeq ($(OS),FreeBSD) 16 | SUFFIX=fbsd 17 | endif 18 | 19 | all: pirate-loader 20 | 21 | pirate-loader: $(SOURCES) 22 | $(CC) $(CFLAGS) $(<) $(OSFLAGS) -o $(@)_${SUFFIX} 23 | 24 | .PHONY: clean 25 | 26 | clean: 27 | rm -f *.o *~ core 28 | -------------------------------------------------------------------------------- /BPv3-firmware/pirate-loader-source/source/pirate-loader.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Pirate-Loader for Bootloader v4 4 | 5 | Version : 1.0.2 6 | 7 | Changelog: 8 | +2010-06-28 - Made HEX parser case-insensative 9 | 10 | + 2010-02-04 - Changed polling interval to 10ms on Windows select wrapper, suggested by Michal (robots) 11 | 12 | + 2010-02-04 - Added sleep(0) between write instructions, patch submitted by kbulgrien 13 | 14 | + 2010-01-22 - Added loader version number to the console output and source code 15 | 16 | + 2010-01-19 - Fixed BigEndian incompatibility 17 | - Added programming simulate switch ( --simulate ) for data verification 18 | 19 | + 2010-01-18 - Initial release 20 | 21 | 22 | Building: 23 | 24 | UNIX family systems: 25 | 26 | gcc pirate-loader.c -o pirate-loader 27 | 28 | WINDOWS: 29 | 30 | cl pirate-loader.c /DWIN32=1 31 | 32 | 33 | Usage: 34 | 35 | Run ./pirate-loader --help for more information on usage and possible switches 36 | 37 | */ 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #define PIRATE_LOADER_VERSION "1.0.2" 46 | 47 | #define STR_EXPAND(tok) #tok 48 | #define OS_NAME(tok) STR_EXPAND(tok) 49 | 50 | 51 | #ifdef WIN32 52 | #include 53 | #include 54 | 55 | #define O_NOCTTY 0 56 | #define O_NDELAY 0 57 | #define B115200 115200 58 | 59 | #define OS WINDOWS 60 | 61 | int write(int fd, const void* buf, int len) 62 | { 63 | HANDLE hCom = (HANDLE)fd; 64 | int res = 0; 65 | unsigned long bwritten = 0; 66 | 67 | 68 | res = WriteFile(hCom, buf, len, &bwritten, NULL); 69 | 70 | if( res == FALSE ) { 71 | return -1; 72 | } else { 73 | return bwritten; 74 | } 75 | } 76 | 77 | int read(int fd, void* buf, int len) 78 | { 79 | HANDLE hCom = (HANDLE)fd; 80 | int res = 0; 81 | unsigned long bread = 0; 82 | 83 | res = ReadFile(hCom, buf, len, &bread, NULL); 84 | 85 | if( res == FALSE ) { 86 | return -1; 87 | } else { 88 | return bread; 89 | } 90 | } 91 | 92 | int close(int fd) 93 | { 94 | HANDLE hCom = (HANDLE)fd; 95 | 96 | CloseHandle(hCom); 97 | return 0; 98 | } 99 | 100 | int open(const char* path, unsigned long flags) 101 | { 102 | static char full_path[32] = {0}; 103 | 104 | HANDLE hCom = NULL; 105 | 106 | if( path[0] != '\\' ) { 107 | _snprintf(full_path, sizeof(full_path) - 1, "\\\\.\\%s", path); 108 | path = full_path; 109 | } 110 | 111 | hCom = CreateFileA(path, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 112 | 113 | if( !hCom || hCom == INVALID_HANDLE_VALUE ) { 114 | return -1; 115 | } else { 116 | return (int)hCom; 117 | } 118 | } 119 | 120 | int __stdcall select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfs, const struct timeval* timeout) 121 | { 122 | time_t maxtc = time(0) + (timeout->tv_sec); 123 | COMSTAT cs = {0}; 124 | unsigned long dwErrors = 0; 125 | 126 | if( readfds->fd_count != 1 ) { 127 | return -1; 128 | } 129 | 130 | while( time(0) <= maxtc ) 131 | { //only one file supported 132 | if( ClearCommError( (HANDLE)readfds->fd_array[0], 0, &cs) != TRUE ){ 133 | return -1; 134 | } 135 | 136 | if( cs.cbInQue > 0 ) { 137 | return 1; 138 | } 139 | 140 | Sleep(10); 141 | } 142 | return 0; 143 | } 144 | 145 | unsigned int sleep(unsigned int sec) 146 | { 147 | Sleep(sec * 1000); 148 | 149 | return 0; 150 | } 151 | 152 | #else 153 | #include 154 | #include 155 | #include 156 | #include 157 | #include 158 | #endif 159 | 160 | /* macro definitions */ 161 | 162 | #if !defined OS 163 | #define OS UNKNOWN 164 | #endif 165 | 166 | #define BOOTLOADER_HELLO_STR "\xC1" 167 | #define BOOTLOADER_OK 0x4B 168 | #define BOOTLOADER_PLACEMENT 1 169 | 170 | #define PIC_FLASHSIZE 0xAC00 171 | 172 | #define PIC_NUM_PAGES 512 173 | #define PIC_NUM_ROWS_IN_PAGE 8 174 | #define PIC_NUM_WORDS_IN_ROW 64 175 | 176 | #define PIC_WORD_SIZE (3) 177 | #define PIC_ROW_SIZE (PIC_NUM_WORDS_IN_ROW * PIC_WORD_SIZE) 178 | #define PIC_PAGE_SIZE (PIC_NUM_ROWS_IN_PAGE * PIC_ROW_SIZE) 179 | 180 | 181 | #define PIC_ROW_ADDR(p,r) (((p) * PIC_PAGE_SIZE) + ((r) * PIC_ROW_SIZE)) 182 | #define PIC_WORD_ADDR(p,r,w) (PIC_ROW_ADDR(p,r) + ((w) * PIC_WORD_SIZE)) 183 | #define PIC_PAGE_ADDR(p) (PIC_PAGE_SIZE * (p)) 184 | 185 | #define PAYLOAD_OFFSET 5 186 | #define HEADER_LENGTH PAYLOAD_OFFSET 187 | #define LENGTH_OFFSET 4 188 | #define COMMAND_OFFSET 3 189 | 190 | /* type definitions */ 191 | 192 | typedef unsigned char uint8; 193 | typedef unsigned short uint16; 194 | typedef unsigned long uint32; 195 | 196 | /* global settings, command line arguments */ 197 | 198 | uint8 g_verbose = 0; 199 | uint8 g_hello_only = 0; 200 | uint8 g_simulate = 0; 201 | const char* g_device_path = NULL; 202 | const char* g_hexfile_path = NULL; 203 | 204 | /* functions */ 205 | 206 | int readWithTimeout(int fd, uint8* out, int length, int timeout) 207 | { 208 | fd_set fds; 209 | struct timeval tv = {timeout, 0}; 210 | int res = -1; 211 | int got = 0; 212 | 213 | do { 214 | 215 | FD_ZERO(&fds); 216 | FD_SET(fd, &fds); 217 | 218 | res = select(fd + 1, &fds, NULL, NULL, &tv); 219 | 220 | if( res > 0 ) { 221 | res = read(fd, out, length); 222 | if( res > 0 ) { 223 | length -= res; 224 | got += res; 225 | out += res; 226 | } else { 227 | break; 228 | } 229 | } else { 230 | return res; 231 | } 232 | } while( length > 0); 233 | 234 | return got; 235 | } 236 | 237 | unsigned char hexdec(const char* pc) 238 | { unsigned char temp; 239 | 240 | if(pc[0]>='a'){ 241 | temp=pc[0]-'a'+10; 242 | }else if(pc[0] >= 'A'){ 243 | temp=pc[0]-'A'+10; 244 | }else{ 245 | temp=pc[0] - '0'; 246 | } 247 | temp=temp<<4; 248 | 249 | if(pc[1]>='a'){ 250 | temp|=pc[1]-'a'+10; 251 | }else if(pc[1] >= 'A'){ 252 | temp|=pc[1]-'A'+10; 253 | }else{ 254 | temp|=pc[1] - '0'; 255 | } 256 | 257 | return(temp & 0x0FF); 258 | 259 | 260 | //return (((pc[0] >= 'A') ? ( pc[0] - 'A' + 10 ) : ( pc[0] - '0' ) ) << 4 | 261 | // ((pc[1] >= 'A') ? ( pc[1] - 'A' + 10 ) : ( pc[1] - '0' ) )) & 0x0FF; 262 | 263 | } 264 | 265 | void dumpHex(uint8* buf, uint32 len) 266 | { 267 | uint32 i=0; 268 | 269 | for(i=0; i pline && *pc <= ' ' ) { 316 | *pc-- = 0; 317 | res--; 318 | } 319 | 320 | if( res & 0x01 || res > 512 || res < 10) { 321 | fprintf(stderr, "Incorrect number of characters on line %d:%d\n", line_no, res); 322 | return -1; 323 | } 324 | 325 | hex_crc = 0; 326 | 327 | for( pc = pline, i = 0; i> 1] = hexdec(pc); 329 | hex_crc += linebin[i >> 1]; 330 | } 331 | 332 | binlen = res / 2; 333 | 334 | if( hex_crc != 0 ) { 335 | fprintf(stderr, "Checksum does not match, line %d\n", line_no); 336 | return -1; 337 | } 338 | 339 | hex_addr = (linebin[1] << 8) | linebin[2]; 340 | hex_len = linebin[0]; 341 | hex_type = linebin[3]; 342 | 343 | if( binlen - (1 + 2 + 1 + hex_len + 1) != 0 ) { 344 | fprintf(stderr, "Incorrect number of bytes, line %d\n", line_no); 345 | return -1; 346 | } 347 | 348 | if( hex_type == 0x00 ) 349 | { 350 | f_addr = (hex_base_addr | (hex_addr)) / 2; //PCU 351 | 352 | if( hex_len % 4 ) { 353 | fprintf(stderr, "Misaligned data, line %d\n", line_no); 354 | return -1; 355 | } else if( f_addr >= PIC_FLASHSIZE ) { 356 | fprintf(stderr, "Current record address is higher than maximum allowed, line %d\n", line_no); 357 | return -1; 358 | } 359 | 360 | hex_words = hex_len / 4; 361 | o_addr = (f_addr / 2) * PIC_WORD_SIZE; //BYTES 362 | 363 | for( i=0; i= PIC_FLASHSIZE ) { 450 | fprintf(stderr, "Address out of flash\n"); 451 | return -1; 452 | } 453 | 454 | //erase page 455 | command[0] = (u_addr & 0x00FF0000) >> 16; 456 | command[1] = (u_addr & 0x0000FF00) >> 8; 457 | command[2] = (u_addr & 0x000000FF) >> 0; 458 | command[COMMAND_OFFSET] = 0x01; //erase command 459 | command[LENGTH_OFFSET ] = 0x01; //1 byte, CRC 460 | command[PAYLOAD_OFFSET] = makeCrc(command, 5); 461 | 462 | if( g_verbose ) { 463 | dumpHex(command, HEADER_LENGTH + command[LENGTH_OFFSET]); 464 | } 465 | 466 | printf("Erasing page %ld, %04lx...", page, u_addr); 467 | 468 | if( g_simulate == 0 && sendCommandAndWaitForResponse(fd, command) < 0 ) { 469 | return -1; 470 | } 471 | 472 | puts("OK"); 473 | 474 | //write 8 rows 475 | for( row = 0; row < PIC_NUM_ROWS_IN_PAGE; row ++, u_addr += (PIC_NUM_WORDS_IN_ROW * 2)) 476 | { 477 | command[0] = (u_addr & 0x00FF0000) >> 16; 478 | command[1] = (u_addr & 0x0000FF00) >> 8; 479 | command[2] = (u_addr & 0x000000FF) >> 0; 480 | command[COMMAND_OFFSET] = 0x02; //write command 481 | command[LENGTH_OFFSET ] = PIC_ROW_SIZE + 0x01; //DATA_LENGTH + CRC 482 | 483 | memcpy(&command[PAYLOAD_OFFSET], &data[PIC_ROW_ADDR(page, row)], PIC_ROW_SIZE); 484 | 485 | command[PAYLOAD_OFFSET + PIC_ROW_SIZE] = makeCrc(command, HEADER_LENGTH + PIC_ROW_SIZE); 486 | 487 | printf("Writing page %ld row %ld, %04lx...", page, row + page*PIC_NUM_ROWS_IN_PAGE, u_addr); 488 | 489 | if( g_simulate == 0 && sendCommandAndWaitForResponse(fd, command) < 0 ) { 490 | return -1; 491 | } 492 | 493 | puts("OK"); 494 | 495 | sleep(0); 496 | 497 | if( g_verbose ) { 498 | dumpHex(command, HEADER_LENGTH + command[LENGTH_OFFSET]); 499 | } 500 | done += PIC_ROW_SIZE; 501 | } 502 | } 503 | 504 | return done; 505 | } 506 | 507 | void fixJumps(uint8* bin_buff, uint8* pages_used) 508 | { 509 | uint32 iGotoUserAppAdress = 0; 510 | uint32 iGotoUserAppAdressB3 = 0, iIter = 0; 511 | uint32 iBLAddress = 0; 512 | 513 | iBLAddress = ( PIC_FLASHSIZE - (BOOTLOADER_PLACEMENT * PIC_NUM_ROWS_IN_PAGE * PIC_NUM_WORDS_IN_ROW * 2)); //PCU 514 | iGotoUserAppAdress = iBLAddress - 4; 515 | iGotoUserAppAdressB3 = (iGotoUserAppAdress / 2) * 3; 516 | 517 | for ( iIter = 0; iIter < 6; iIter++ ) { 518 | bin_buff[ iGotoUserAppAdressB3 + iIter ] = bin_buff[ iIter ]; 519 | } 520 | 521 | pages_used[ (iGotoUserAppAdressB3 / PIC_PAGE_SIZE) ] = 1; 522 | 523 | bin_buff[0] = 0x04; 524 | bin_buff[1] = ( (iBLAddress & 0x0000FE) ); 525 | bin_buff[2] = ( (iBLAddress & 0x00FF00) >> 8 ); 526 | bin_buff[3] = 0x00; 527 | bin_buff[4] = ( (iBLAddress & 0x7F0000) >> 16 ); 528 | bin_buff[5] = 0x00; 529 | } 530 | 531 | /* non-firmware functions */ 532 | 533 | int configurePort(int fd, unsigned long baudrate) 534 | { 535 | #ifdef WIN32 536 | DCB dcb = {0}; 537 | HANDLE hCom = (HANDLE)fd; 538 | 539 | dcb.DCBlength = sizeof(dcb); 540 | 541 | dcb.BaudRate = baudrate; 542 | dcb.ByteSize = 8; 543 | dcb.Parity = NOPARITY; 544 | dcb.StopBits = ONESTOPBIT; 545 | 546 | if( !SetCommState(hCom, &dcb) ){ 547 | return -1; 548 | } 549 | 550 | return (int)hCom; 551 | #else 552 | struct termios g_new_tio; 553 | 554 | memset(&g_new_tio, 0x00 , sizeof(g_new_tio)); 555 | cfmakeraw(&g_new_tio); 556 | 557 | g_new_tio.c_cflag |= (CS8 | CLOCAL | CREAD); 558 | g_new_tio.c_cflag &= ~(PARENB | CSTOPB | CSIZE); 559 | g_new_tio.c_oflag = 0; 560 | g_new_tio.c_lflag = 0; 561 | 562 | 563 | g_new_tio.c_cc[VTIME] = 0; 564 | g_new_tio.c_cc[VMIN] = 1; 565 | 566 | cfsetispeed (&g_new_tio, baudrate); 567 | cfsetospeed (&g_new_tio, baudrate); 568 | 569 | tcflush(fd, TCIOFLUSH); 570 | 571 | return tcsetattr(fd, TCSANOW, &g_new_tio); 572 | #endif 573 | } 574 | 575 | int openPort(const char* dev, unsigned long flags) 576 | { 577 | return open(dev, O_RDWR | O_NOCTTY | O_NDELAY | flags); 578 | } 579 | 580 | int parseCommandLine(int argc, const char** argv) 581 | { 582 | int i = 0; 583 | 584 | for(i=1; i PIC_FLASHSIZE ) { 662 | fprintf(stderr, "Could not load HEX file, result=%d\n", res); 663 | goto Error; 664 | } 665 | 666 | printf("Found %d words (%d bytes)\n", res, res * 3); 667 | 668 | printf("Fixing bootloader/userprogram jumps\n"); 669 | fixJumps(bin_buff, pages_used); 670 | } 671 | 672 | if( g_simulate ) { 673 | sendFirmware(dev_fd, bin_buff, pages_used); 674 | goto Finished; 675 | } 676 | 677 | if( !g_device_path ) { 678 | fprintf(stderr, "Please specify serial device path --dev=/dev/...\n"); 679 | return -1; 680 | } 681 | 682 | printf("Opening serial device %s...", g_device_path); 683 | 684 | dev_fd = openPort(g_device_path, 0); 685 | 686 | if( dev_fd < 0 ) { 687 | puts("ERROR"); 688 | fprintf(stderr, "Could not open %s\n", g_device_path); 689 | goto Error; 690 | } 691 | puts("OK"); 692 | 693 | printf("Configuring serial port settings..."); 694 | 695 | if( configurePort(dev_fd, B115200) < 0 ) { 696 | puts("ERROR"); 697 | fprintf(stderr, "Could not configure device, errno=%d\n", errno); 698 | goto Error; 699 | } 700 | puts("OK"); 701 | 702 | printf("Sending Hello to the Bootloader..."); 703 | 704 | //send HELLO 705 | res = write(dev_fd, BOOTLOADER_HELLO_STR, 1); 706 | 707 | res = readWithTimeout(dev_fd, buffer, 4, 3); 708 | 709 | if( res != 4 || buffer[3] != BOOTLOADER_OK ) { 710 | puts("ERROR"); 711 | fprintf(stderr, "No reply from the bootloader, or invalid reply received: %d\n", res); 712 | fprintf(stderr, "Please make sure that PGND and PGC are connected, replug the devide and try again\n"); 713 | goto Error; 714 | } 715 | puts("OK\n"); //extra LF for spacing 716 | 717 | printf("Device ID: %s [%02x]\n", (buffer[0] == 0xD4) ? "PIC24FJ64GA002" : "UNKNOWN", buffer[0]); 718 | printf("Bootloader version: %d,%02d\n", buffer[1], buffer[2]); 719 | 720 | if( buffer[0] != 0xD4 ) { 721 | fprintf(stderr, "Unsupported device (%02x:UNKNOWN), only 0xD4 PIC24FJ64GA002 is supported\n", buffer[0]); 722 | goto Error; 723 | } 724 | 725 | if( !g_hello_only ) { 726 | 727 | res = sendFirmware(dev_fd, bin_buff, pages_used); 728 | 729 | if( res > 0 ) { 730 | puts("\nFirmware updated successfully :)!"); 731 | printf("Use screen %s 115200 to verify\n", g_device_path); 732 | } else { 733 | puts("\nError updating firmware :("); 734 | goto Error; 735 | } 736 | 737 | } 738 | 739 | Finished: 740 | if( bin_buff ) { 741 | free( bin_buff ); 742 | } 743 | close(dev_fd); 744 | return 0; 745 | 746 | Error: 747 | if( bin_buff ) { 748 | free( bin_buff ); 749 | } 750 | if( dev_fd >= 0 ) { 751 | close(dev_fd); 752 | } 753 | return -1; 754 | } 755 | -------------------------------------------------------------------------------- /BPv3-firmware/pirate-loader.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv3-firmware/pirate-loader.exe -------------------------------------------------------------------------------- /BPv3-firmware/pirate-loader_lnx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv3-firmware/pirate-loader_lnx -------------------------------------------------------------------------------- /BPv3-firmware/pirate-loader_mac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv3-firmware/pirate-loader_mac -------------------------------------------------------------------------------- /BPv3-firmware/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | false 4 | false 5 | false 6 | 346 7 | 538 8 | E:\Work\bus-pirate\trunk\firmware\v4-nightly\BPv3&v2go\BPv3-Firmware-v4.1.hex 9 | 10 | true 11 | false 12 | true 13 | 14 | true 15 | 115200 16 | false 17 | PIC24FJ 18 | false 19 | 64GA002 20 | false 21 | true 22 | false 23 | false 24 | false 25 | false 26 | false 27 | false 28 | false 29 | false 30 | false 31 | true 32 | false 33 | 1 34 | false 35 | 1 36 | false 37 | 250 38 | true 39 | 5000 40 | true 41 | false 42 | true 43 | 44 | true 45 | 9600 46 | true 47 | false 48 | true 49 | true 50 | true 51 | false 52 | true 53 | 250 54 | true 55 | false 56 | true 57 | false 58 | true 59 | false 60 | 115200 61 | 0 62 | 0 63 | 64 | 65 | -------------------------------------------------------------------------------- /BPv3-firmware/v4UPGRADES!!!.txt: -------------------------------------------------------------------------------- 1 | STOP! If you are upgrading from v2 you must install the v4 bootloader first: 2 | http://dangerousprototypes.com/2010/01/18/how-to-bus-pirate-bootloader-v4-upgrade/ 3 | v4 BOOTLOADER ONLY!!! 4 | DO NOT TRY TO LOAD THE BOOTLOADER FROM THIS ARCHIVE!!!! 5 | DO NOT TRY TO LOAD THE V4 FIRMWARE WITH p24QP!!! -------------------------------------------------------------------------------- /BPv4-firmware/BPv4-update-v6.1.bat: -------------------------------------------------------------------------------- 1 | pirate-loader.exe --dev=COM3 --hex=BPv4-frimware-v6.1.hex 2 | pause 3 | -------------------------------------------------------------------------------- /BPv4-firmware/pirate-loader-v4-source/build-unix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | OS=`uname` 4 | 5 | echo -n "Building for $OS..." 6 | 7 | case $OS in 8 | 9 | Darwin ) 10 | gcc -O2 -Wall -force_cpusubtype_ALL -arch i386 -arch ppc source/pirate-loader.c -DOS=$OS -o pirate-loader_mac || exit -1 11 | ;; 12 | Linux ) 13 | gcc -O2 -Wall source/pirate-loader.c -DOS=$OS -o pirate-loader_lnx || exit -1 14 | ;; 15 | FreeBSD ) 16 | gcc -O2 -Wall source/pirate-loader.c -DOS=$OS -o pirate-loader_fbsd || exit -1 17 | ;; 18 | *) 19 | echo "ERROR" 20 | echo "Unsupported operating system $OS" 21 | exit -1 22 | ;; 23 | esac 24 | 25 | echo "DONE" 26 | exit 0 27 | -------------------------------------------------------------------------------- /BPv4-firmware/pirate-loader-v4-source/build-win32.bat: -------------------------------------------------------------------------------- 1 | @echo "Building for WINDOWS" 2 | 3 | @cl source/pirate-loader.c /DWIN32=1 /DNDEBUG=1 /D_CRT_SECURE_NO_DEPRECATE=1 >out.log 2>err.log || exit 4 | 5 | @del pirate-loader.obj 6 | @del out.log 7 | @del err.log 8 | 9 | pause -------------------------------------------------------------------------------- /BPv4-firmware/pirate-loader-v4-source/makefile: -------------------------------------------------------------------------------- 1 | OS := $(shell uname) 2 | SOURCEPATH=. 3 | CC=gcc 4 | CFLAGS=-O2 -Wall 5 | OSFLAGS= -DOS=$OS 6 | SOURCES=$(SOURCEPATH)/pirate-loader.c 7 | 8 | ifeq ($(OS),Linux) 9 | SUFFIX=lnx 10 | endif 11 | ifeq ($(OS),Darwin) 12 | SUFFIX=mac 13 | CFLAGS=-O2 -Wall -force_cpusubtype_ALL -arch i386 -arch x86_64 14 | endif 15 | ifeq ($(OS),FreeBSD) 16 | SUFFIX=fbsd 17 | endif 18 | 19 | all: pirate-loader 20 | 21 | pirate-loader: $(SOURCES) 22 | $(CC) $(CFLAGS) $(<) $(OSFLAGS) -o $(@)_${SUFFIX} 23 | 24 | .PHONY: clean 25 | 26 | clean: 27 | rm -f *.o *~ core 28 | -------------------------------------------------------------------------------- /BPv4-firmware/pirate-loader-v4-source/makefile.bak: -------------------------------------------------------------------------------- 1 | OS := $(shell uname) 2 | SOURCEPATH=. 3 | CC=gcc 4 | CFLAGS=-O2 -Wall 5 | OSFLAGS= -DOS=$OS 6 | SOURCES=$(SOURCEPATH)/pirate-loader.c 7 | 8 | ifeq ($(OS),Linux) 9 | SUFFIX=lnx 10 | endif 11 | ifeq ($(OS),Darwin) 12 | SUFFIX=mac 13 | CFLAGS=$(CFLAGS) -force_cpusubtype_ALL -arch i386 -arch ppc 14 | endif 15 | ifeq ($(OS),FreeBSD) 16 | SUFFIX=fbsd 17 | endif 18 | 19 | all: pirate-loader 20 | 21 | pirate-loader: $(SOURCES) 22 | $(CC) $(CFLAGS) $(<) $(OSFLAGS) -o $(@)_${SUFFIX} 23 | 24 | .PHONY: clean 25 | 26 | clean: 27 | rm -f *.o *~ core 28 | -------------------------------------------------------------------------------- /BPv4-firmware/pirate-loader-v4-source/pirate-loader.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Pirate-Loader for Bootloader v4 4 | 5 | Version : 1.0.2 6 | 7 | Changelog: 8 | +2010-06-28 - Made HEX parser case-insensative 9 | 10 | + 2010-02-04 - Changed polling interval to 10ms on Windows select wrapper, suggested by Michal (robots) 11 | 12 | + 2010-02-04 - Added sleep(0) between write instructions, patch submitted by kbulgrien 13 | 14 | + 2010-01-22 - Added loader version number to the console output and source code 15 | 16 | + 2010-01-19 - Fixed BigEndian incompatibility 17 | - Added programming simulate switch ( --simulate ) for data verification 18 | 19 | + 2010-01-18 - Initial release 20 | 21 | 22 | Building: 23 | 24 | UNIX family systems: 25 | 26 | gcc pirate-loader.c -o pirate-loader 27 | 28 | WINDOWS: 29 | 30 | cl pirate-loader.c /DWIN32=1 31 | 32 | 33 | Usage: 34 | 35 | Run ./pirate-loader --help for more information on usage and possible switches 36 | 37 | */ 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #define PIRATE_LOADER_VERSION "1.0.2" 46 | 47 | #define STR_EXPAND(tok) #tok 48 | #define OS_NAME(tok) STR_EXPAND(tok) 49 | 50 | 51 | #ifdef WIN32 52 | #include 53 | #include 54 | 55 | #define O_NOCTTY 0 56 | #define O_NDELAY 0 57 | #define B115200 921600 58 | 59 | #define OS WINDOWS 60 | 61 | int write(int fd, const void* buf, int len) 62 | { 63 | HANDLE hCom = (HANDLE)fd; 64 | int res = 0; 65 | unsigned long bwritten = 0; 66 | 67 | 68 | res = WriteFile(hCom, buf, len, &bwritten, NULL); 69 | 70 | if( res == FALSE ) 71 | { 72 | return -1; 73 | } 74 | else 75 | { 76 | return bwritten; 77 | } 78 | } 79 | 80 | int read(int fd, void* buf, int len) 81 | { 82 | HANDLE hCom = (HANDLE)fd; 83 | int res = 0; 84 | unsigned long bread = 0; 85 | 86 | res = ReadFile(hCom, buf, len, &bread, NULL); 87 | 88 | if( res == FALSE ) 89 | { 90 | return -1; 91 | } 92 | else 93 | { 94 | return bread; 95 | } 96 | } 97 | 98 | int close(int fd) 99 | { 100 | HANDLE hCom = (HANDLE)fd; 101 | 102 | CloseHandle(hCom); 103 | return 0; 104 | } 105 | 106 | int open(const char* path, unsigned long flags) 107 | { 108 | static char full_path[32] = {0}; 109 | 110 | HANDLE hCom = NULL; 111 | 112 | if( path[0] != '\\' ) 113 | { 114 | _snprintf(full_path, sizeof(full_path) - 1, "\\\\.\\%s", path); 115 | path = full_path; 116 | } 117 | 118 | hCom = CreateFileA(path, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 119 | 120 | if( !hCom || hCom == INVALID_HANDLE_VALUE ) 121 | { 122 | return -1; 123 | } 124 | else 125 | { 126 | return (int)hCom; 127 | } 128 | } 129 | 130 | int __stdcall select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfs, const struct timeval* timeout) 131 | { 132 | time_t maxtc = time(0) + (timeout->tv_sec); 133 | COMSTAT cs = {0}; 134 | // JTR not used so get rig of warning unsigned long dwErrors = 0; 135 | 136 | if( readfds->fd_count != 1 ) 137 | { 138 | return -1; 139 | } 140 | 141 | while( time(0) <= maxtc ) 142 | { 143 | //only one file supported 144 | if( ClearCommError( (HANDLE)readfds->fd_array[0], 0, &cs) != TRUE ) 145 | { 146 | return -1; 147 | } 148 | 149 | if( cs.cbInQue > 0 ) 150 | { 151 | return 1; 152 | } 153 | 154 | Sleep(10); 155 | } 156 | return 0; 157 | } 158 | 159 | unsigned int sleep(unsigned int sec) 160 | { 161 | Sleep(sec * 1000); 162 | 163 | return 0; 164 | } 165 | 166 | #else 167 | #include 168 | #include 169 | #include 170 | #include 171 | #include 172 | #endif 173 | 174 | /* macro definitions */ 175 | 176 | /* type definitions */ 177 | 178 | typedef unsigned char uint8; 179 | typedef unsigned short uint16; 180 | typedef unsigned long uint32; 181 | 182 | #if !defined OS 183 | #define OS UNKNOWN 184 | #endif 185 | 186 | #define BOOTLOADER_HELLO_STR "\xC1" 187 | #define BOOTLOADER_OK 0x4B 188 | #define BOOTLOADER_PROT 'P' 189 | #define PIC_WORD_SIZE (3) 190 | #define PIC_NUM_ROWS_IN_PAGE 8 191 | #define PIC_NUM_WORDS_IN_ROW 64 192 | #define PIC_ROW_SIZE (PIC_NUM_WORDS_IN_ROW * PIC_WORD_SIZE) 193 | #define PIC_PAGE_SIZE (PIC_NUM_ROWS_IN_PAGE * PIC_ROW_SIZE) 194 | #define PIC_ROW_ADDR(p,r) (((p) * PIC_PAGE_SIZE) + ((r) * PIC_ROW_SIZE)) 195 | #define PIC_WORD_ADDR(p,r,w) (PIC_ROW_ADDR(p,r) + ((w) * PIC_WORD_SIZE)) 196 | #define PIC_PAGE_ADDR(p) (PIC_PAGE_SIZE * (p)) 197 | 198 | #define PAYLOAD_OFFSET 5 199 | #define HEADER_LENGTH PAYLOAD_OFFSET 200 | #define LENGTH_OFFSET 4 201 | #define COMMAND_OFFSET 3 202 | #define IS_24FJ 1 203 | #define PIC_NUM_PAGES 512 204 | 205 | //#define flashsize 0x2AC00 //was 0xac00 206 | //#define PIC_NUM_PAGES 512 207 | 208 | //unsigned short pic_num_pages; 209 | unsigned short family = IS_24FJ; 210 | unsigned long flashsize = 0x2AC00; 211 | unsigned short eesizeb = 0; 212 | unsigned long blstartaddr = 0x400L; // not currently used 213 | unsigned long blendaddr = 0x23FFL; // not currently used 214 | 215 | 216 | /* global settings, command line arguments */ 217 | 218 | uint8 g_verbose = 0; 219 | uint8 g_hello_only = 0; 220 | uint8 g_simulate = 0; 221 | const char* g_device_path = NULL; 222 | const char* g_hexfile_path = NULL; 223 | 224 | /* functions */ 225 | 226 | int readWithTimeout(int fd, uint8* out, int length, int timeout) 227 | { 228 | fd_set fds; 229 | struct timeval tv = {timeout, 0}; 230 | int res = -1; 231 | int got = 0; 232 | 233 | do 234 | { 235 | 236 | FD_ZERO(&fds); 237 | FD_SET(fd, &fds); 238 | 239 | res = select(fd + 1, &fds, NULL, NULL, &tv); 240 | 241 | if( res > 0 ) 242 | { 243 | res = read(fd, out, length); 244 | if( res > 0 ) 245 | { 246 | length -= res; 247 | got += res; 248 | out += res; 249 | } 250 | else 251 | { 252 | break; 253 | } 254 | } 255 | else 256 | { 257 | return res; 258 | } 259 | } 260 | while( length > 0); 261 | 262 | return got; 263 | } 264 | 265 | unsigned char hexdec(const char* pc) 266 | { 267 | unsigned char temp; 268 | 269 | if(pc[0]>='a') 270 | { 271 | temp=pc[0]-'a'+10; 272 | } 273 | else if(pc[0] >= 'A') 274 | { 275 | temp=pc[0]-'A'+10; 276 | } 277 | else 278 | { 279 | temp=pc[0] - '0'; 280 | } 281 | temp=temp<<4; 282 | 283 | if(pc[1]>='a') 284 | { 285 | temp|=pc[1]-'a'+10; 286 | } 287 | else if(pc[1] >= 'A') 288 | { 289 | temp|=pc[1]-'A'+10; 290 | } 291 | else 292 | { 293 | temp|=pc[1] - '0'; 294 | } 295 | 296 | return(temp & 0x0FF); 297 | 298 | 299 | //return (((pc[0] >= 'A') ? ( pc[0] - 'A' + 10 ) : ( pc[0] - '0' ) ) << 4 | 300 | // ((pc[1] >= 'A') ? ( pc[1] - 'A' + 10 ) : ( pc[1] - '0' ) )) & 0x0FF; 301 | 302 | } 303 | 304 | void dumpHex(uint8* buf, uint32 len) 305 | { 306 | uint32 i=0; 307 | 308 | for(i=0; i pline && *pc <= ' ' ) 358 | { 359 | *pc-- = 0; 360 | res--; 361 | } 362 | 363 | if( res & 0x01 || res > 512 || res < 10) 364 | { 365 | fprintf(stderr, "Incorrect number of characters on line %d:%d\n", line_no, res); 366 | return -1; 367 | } 368 | 369 | hex_crc = 0; 370 | 371 | for( pc = pline, i = 0; i> 1] = hexdec(pc); 374 | hex_crc += linebin[i >> 1]; 375 | } 376 | 377 | binlen = res / 2; 378 | 379 | if( hex_crc != 0 ) 380 | { 381 | fprintf(stderr, "Checksum does not match, line %d\n", line_no); 382 | return -1; 383 | } 384 | 385 | hex_addr = (linebin[1] << 8) | linebin[2]; 386 | hex_len = linebin[0]; 387 | hex_type = linebin[3]; 388 | 389 | if( binlen - (1 + 2 + 1 + hex_len + 1) != 0 ) 390 | { 391 | fprintf(stderr, "Incorrect number of bytes, line %d\n", line_no); 392 | return -1; 393 | } 394 | 395 | if( hex_type == 0x00 ) 396 | { 397 | f_addr = (hex_base_addr | (hex_addr)) / 2; //PCU 398 | 399 | if( hex_len % 4 ) 400 | { 401 | fprintf(stderr, "Misaligned data, line %d\n", line_no); 402 | return -1; 403 | } 404 | else if( f_addr >= flashsize ) 405 | { 406 | fprintf(stderr, "Current record address is higher than maximum allowed, line %d\n", line_no); 407 | return -1; 408 | } 409 | 410 | hex_words = hex_len / 4; 411 | o_addr = (f_addr / 2) * PIC_WORD_SIZE; //BYTES 412 | 413 | for( i=0; i= flashsize ) 521 | { 522 | fprintf(stderr, "Address out of flash\n"); 523 | return -1; 524 | } 525 | 526 | //erase page 527 | command[0] = (u_addr & 0x00FF0000) >> 16; 528 | command[1] = (u_addr & 0x0000FF00) >> 8; 529 | command[2] = (u_addr & 0x000000FF) >> 0; 530 | command[COMMAND_OFFSET] = 0x01; //erase command 531 | command[LENGTH_OFFSET ] = 0x01; //1 byte, CRC 532 | command[PAYLOAD_OFFSET] = makeCrc(command, 5); 533 | 534 | if( g_verbose ) 535 | { 536 | dumpHex(command, HEADER_LENGTH + command[LENGTH_OFFSET]); 537 | } 538 | 539 | printf("Erasing page %ld, %04lx...", page, u_addr); 540 | 541 | if( g_simulate == 0 && sendCommandAndWaitForResponse(fd, command) < 0 ) 542 | { 543 | return -1; 544 | } 545 | 546 | puts("OK"); 547 | 548 | //write 8 rows 549 | for( row = 0; row < PIC_NUM_ROWS_IN_PAGE; row ++, u_addr += (PIC_NUM_WORDS_IN_ROW * 2)) 550 | { 551 | command[0] = (u_addr & 0x00FF0000) >> 16; 552 | command[1] = (u_addr & 0x0000FF00) >> 8; 553 | command[2] = (u_addr & 0x000000FF) >> 0; 554 | command[COMMAND_OFFSET] = 0x02; //write command 555 | command[LENGTH_OFFSET ] = PIC_ROW_SIZE + 0x01; //DATA_LENGTH + CRC 556 | 557 | memcpy(&command[PAYLOAD_OFFSET], &data[PIC_ROW_ADDR(page, row)], PIC_ROW_SIZE); 558 | 559 | command[PAYLOAD_OFFSET + PIC_ROW_SIZE] = makeCrc(command, HEADER_LENGTH + PIC_ROW_SIZE); 560 | 561 | printf("Writing page %ld row %ld, %04lx...", page, row + page*PIC_NUM_ROWS_IN_PAGE, u_addr); 562 | 563 | if( g_verbose ) 564 | { 565 | dumpHex(command, HEADER_LENGTH + command[LENGTH_OFFSET]); 566 | } 567 | 568 | if( g_simulate == 0 && sendCommandAndWaitForResponse(fd, command) < 0 ) 569 | { 570 | return -1; 571 | } 572 | 573 | puts("OK"); 574 | 575 | sleep(0); 576 | 577 | 578 | done += PIC_ROW_SIZE; 579 | } 580 | } 581 | 582 | return done; 583 | } 584 | 585 | 586 | /* non-firmware functions */ 587 | 588 | int configurePort(int fd, unsigned long baudrate) 589 | { 590 | #ifdef WIN32 591 | DCB dcb = {0}; 592 | HANDLE hCom = (HANDLE)fd; 593 | 594 | dcb.DCBlength = sizeof(dcb); 595 | 596 | dcb.BaudRate = baudrate; 597 | dcb.ByteSize = 8; 598 | dcb.Parity = NOPARITY; 599 | dcb.StopBits = ONESTOPBIT; 600 | 601 | if( !SetCommState(hCom, &dcb) ) 602 | { 603 | return -1; 604 | } 605 | 606 | return (int)hCom; 607 | #else 608 | struct termios g_new_tio; 609 | 610 | memset(&g_new_tio, 0x00 , sizeof(g_new_tio)); 611 | cfmakeraw(&g_new_tio); 612 | 613 | g_new_tio.c_cflag |= (CS8 | CLOCAL | CREAD); 614 | g_new_tio.c_cflag &= ~(PARENB | CSTOPB | CSIZE); 615 | g_new_tio.c_oflag = 0; 616 | g_new_tio.c_lflag = 0; 617 | 618 | 619 | g_new_tio.c_cc[VTIME] = 0; 620 | g_new_tio.c_cc[VMIN] = 1; 621 | 622 | cfsetispeed (&g_new_tio, baudrate); 623 | cfsetospeed (&g_new_tio, baudrate); 624 | 625 | tcflush(fd, TCIOFLUSH); 626 | 627 | return tcsetattr(fd, TCSANOW, &g_new_tio); 628 | #endif 629 | } 630 | 631 | int openPort(const char* dev, unsigned long flags) 632 | { 633 | return open(dev, O_RDWR | O_NOCTTY | O_NDELAY | flags); 634 | } 635 | 636 | int parseCommandLine(int argc, const char** argv) 637 | { 638 | int i = 0; 639 | 640 | for(i=1; i flashsize ) 737 | { 738 | fprintf(stderr, "Could not load HEX file, result=%d\n", res); 739 | goto Error; 740 | } 741 | 742 | printf("Found %d words (%d bytes)\n", res, res * 3); 743 | 744 | //printf("Fixing bootloader/userprogram jumps\n"); 745 | //fixJumps(bin_buff, pages_used); 746 | } 747 | 748 | if( g_simulate ) 749 | { 750 | sendFirmware(dev_fd, bin_buff, pages_used); 751 | goto Finished; 752 | } 753 | 754 | if( !g_device_path ) 755 | { 756 | fprintf(stderr, "Please specify serial device path --dev=/dev/...\n"); 757 | return -1; 758 | } 759 | 760 | printf("Opening serial device %s...", g_device_path); 761 | 762 | dev_fd = openPort(g_device_path, 0); 763 | 764 | if( dev_fd < 0 ) 765 | { 766 | puts("ERROR"); 767 | fprintf(stderr, "Could not open %s\n", g_device_path); 768 | goto Error; 769 | } 770 | puts("OK"); 771 | 772 | printf("Configuring serial port settings..."); 773 | 774 | if( configurePort(dev_fd, B115200) < 0 ) 775 | { 776 | puts("ERROR"); 777 | fprintf(stderr, "Could not configure device, errno=%d\n", errno); 778 | goto Error; 779 | } 780 | puts("OK"); 781 | 782 | printf("Sending Hello to the Bootloader..."); 783 | 784 | //send HELLO 785 | res = write(dev_fd, BOOTLOADER_HELLO_STR, 1); 786 | 787 | res = readWithTimeout(dev_fd, buffer, 4, 3); 788 | 789 | if( res != 4 || buffer[3] != BOOTLOADER_OK ) 790 | { 791 | puts("ERROR"); 792 | fprintf(stderr, "No reply from the bootloader, or invalid reply received: %d\n", res); 793 | fprintf(stderr, "Please make sure that PGND and PGC are connected, replug the devide and try again\n"); 794 | goto Error; 795 | } 796 | puts("OK\n"); //extra LF for spacing 797 | 798 | printf("Bootloader version: %d,%02d\n", buffer[1], buffer[2]); 799 | 800 | printf("Device ID [%02x]:",buffer[0]); 801 | switch(buffer[0]) 802 | { 803 | // case 0xd4: 804 | // printf("PIC24FJ64GA002\n"); 805 | // break; 806 | case 9: 807 | printf("PIC24FJ128GB206\n"); 808 | // __PIC24FJ128GB206__ 809 | family = IS_24FJ; 810 | flashsize = 0x15800; 811 | eesizeb = 0; 812 | blstartaddr = 0x400L; 813 | blendaddr = 0x23FFL; 814 | break; 815 | case 17: 816 | printf("PIC24FJ128GB210\n"); 817 | // __PIC24FJ128GB210__ 818 | family = IS_24FJ; 819 | flashsize = 0x15800; 820 | eesizeb = 0; 821 | blstartaddr = 0x400L; 822 | blendaddr = 0x23FFL; 823 | 824 | break; 825 | case 18: 826 | printf("PIC24FJ256GB206\n"); 827 | // __PIC24FJ256GB206__ 828 | family = IS_24FJ; 829 | flashsize = 0x2AC00; 830 | eesizeb = 0; 831 | blstartaddr = 0x400L; 832 | blendaddr = 0x23FFL; 833 | break; 834 | case 19: 835 | printf("PIC24FJ256GB210\n"); 836 | // __PIC24FJ256GB210__ 837 | family = IS_24FJ; 838 | flashsize = 0x2AC00; 839 | eesizeb = 0; 840 | blstartaddr = 0x400L; 841 | blendaddr = 0x23FFL; 842 | break; 843 | case 191: 844 | printf("PIC24FJ256DA206\n"); 845 | // __PIC24FJ256DA206__ 846 | family = IS_24FJ; 847 | flashsize = 0x2AC00; 848 | eesizeb = 0; 849 | blstartaddr = 0x400L; 850 | blendaddr = 0x23FFL; 851 | break; 852 | case 192: 853 | printf("PIC24FJ256DA210\n"); 854 | // __PIC24FJ256DA210__ 855 | family = IS_24FJ; 856 | flashsize = 0x2AC00; 857 | eesizeb = 0; 858 | blstartaddr = 0x400L; 859 | blendaddr = 0x23FFL; 860 | break; 861 | case 217: 862 | printf("PIC24FJ64GB106\n"); 863 | // __PIC24FJ64GB106__ 864 | family = IS_24FJ; 865 | flashsize = 0xAC00; 866 | eesizeb = 0; 867 | blstartaddr = 0x400L; 868 | blendaddr = 0x23FFL; 869 | break; 870 | case 218: 871 | printf("PIC24FJ64GB108\n"); 872 | // __PIC24FJ64GB108__ 873 | family = IS_24FJ; 874 | flashsize = 0xAC00; 875 | eesizeb = 0; 876 | blstartaddr = 0x400L; 877 | blendaddr = 0x23FFL; 878 | break; 879 | case 219: 880 | printf("PIC24FJ64GB110\n"); 881 | // __PIC24FJ64GB110__ 882 | family = IS_24FJ; 883 | flashsize = 0xAC00; 884 | eesizeb = 0; 885 | blstartaddr = 0x400L; 886 | blendaddr = 0x23FFL; 887 | break; 888 | case 229: 889 | printf("PIC24FJ128GB106\n"); 890 | // __PIC24FJ128GB106__ 891 | family = IS_24FJ; 892 | flashsize = 0x15800; 893 | eesizeb = 0; 894 | blstartaddr = 0x400L; 895 | blendaddr = 0x23FFL; 896 | break; 897 | case 230: 898 | printf("PIC24FJ128GB108\n"); 899 | // __PIC24FJ128GB108__ 900 | family = IS_24FJ; 901 | flashsize = 0x15800; 902 | eesizeb = 0; 903 | blstartaddr = 0x400L; 904 | blendaddr = 0x23FFL; 905 | break; 906 | case 231: 907 | printf("PIC24FJ128GB110\n"); 908 | // __PIC24FJ128GB110__ 909 | family = IS_24FJ; 910 | flashsize = 0x15800; 911 | eesizeb = 0; 912 | blstartaddr = 0x400L; 913 | blendaddr = 0x23FFL; 914 | break; 915 | case 235: 916 | printf("PIC24FJ192GB106\n"); 917 | // __PIC24FJ192GB106__ 918 | family = IS_24FJ; 919 | flashsize = 0x20C00; 920 | eesizeb = 0; 921 | blstartaddr = 0x400L; 922 | blendaddr = 0x23FFL; 923 | break; 924 | case 236: 925 | printf("PIC24FJ192GB108\n"); 926 | // __PIC24FJ192GB108__ 927 | family = IS_24FJ; 928 | flashsize = 0x20C00; 929 | eesizeb = 0; 930 | blstartaddr = 0x400L; 931 | blendaddr = 0x23FFL; 932 | break; 933 | case 237: 934 | printf("PIC24FJ192GB110\n"); 935 | // __PIC24FJ192GB110__ 936 | family = IS_24FJ; 937 | flashsize = 0x20C00; 938 | eesizeb = 0; 939 | blstartaddr = 0x400L; 940 | blendaddr = 0x23FFL; 941 | break; 942 | case 241: 943 | printf("PIC24FJ256GB106\n"); 944 | // __PIC24FJ256GB106__ 945 | #define IS_24FJ 1 946 | flashsize = 0x2AC00; 947 | eesizeb = 0; 948 | blstartaddr = 0x400L; 949 | blendaddr = 0x23FFL; 950 | break; 951 | case 242: 952 | printf("PIC24FJ256GB108\n"); 953 | // __PIC24FJ256GB108__ 954 | family = IS_24FJ; 955 | flashsize = 0x2AC00; 956 | eesizeb = 0; 957 | blstartaddr = 0x400L; 958 | blendaddr = 0x23FFL; 959 | break; 960 | case 243: 961 | printf("PIC24FJ256GB110\n"); 962 | // __PIC24FJ256GB110__ 963 | family = IS_24FJ; 964 | flashsize = 0x2AC00; 965 | eesizeb = 0; 966 | blstartaddr = 0x400L; 967 | blendaddr = 0x23FFL; 968 | break; 969 | case 244: 970 | printf("PIC24FJ32GB002\n"); 971 | // __PIC24FJ32GB002__ 972 | family = IS_24FJ; 973 | flashsize = 0x5800; 974 | eesizeb = 0; 975 | blstartaddr = 0x400L; 976 | blendaddr = 0x23FFL; 977 | break; 978 | case 245: 979 | printf("PIC24FJ32GB004\n"); 980 | // __PIC24FJ32GB004__ 981 | family = IS_24FJ; 982 | flashsize = 0x5800; 983 | eesizeb = 0; 984 | blstartaddr = 0x400L; 985 | blendaddr = 0x23FFL; 986 | break; 987 | case 246: 988 | printf("PIC24FJ64GB002\n"); 989 | // __PIC24FJ64GB002__ 990 | family = IS_24FJ; 991 | flashsize = 0xAC00; 992 | eesizeb = 0; 993 | blstartaddr = 0x400L; 994 | blendaddr = 0x23FFL; 995 | break; 996 | case 247: 997 | printf("PIC24FJ64GB004\n"); 998 | // __PIC24FJ64GB004__ 999 | family = IS_24FJ; 1000 | flashsize = 0xAC00; 1001 | eesizeb = 0; 1002 | blstartaddr = 0x400L; 1003 | blendaddr = 0x23FFL; 1004 | break; 1005 | case 250: 1006 | printf("PIC24FJ128DA106\n");// __PIC24FJ128DA106__ 1007 | family = IS_24FJ; 1008 | flashsize = 0x15800; 1009 | eesizeb = 0; 1010 | blstartaddr = 0x400L; 1011 | blendaddr = 0x23FFL; 1012 | break; 1013 | case 251: 1014 | printf("PIC24FJ128DA110\n"); 1015 | // __PIC24FJ128DA110__ 1016 | family = IS_24FJ; 1017 | flashsize = 0x15800; 1018 | eesizeb = 0; 1019 | blstartaddr = 0x400L; 1020 | blendaddr = 0x23FFL; 1021 | break; 1022 | case 252: 1023 | printf("PIC24FJ128DA206\n"); 1024 | // __PIC24FJ128DA206__ 1025 | family = IS_24FJ; 1026 | flashsize = 0x15800; 1027 | eesizeb = 0; 1028 | blstartaddr = 0x400L; 1029 | blendaddr = 0x23FFL; 1030 | break; 1031 | case 253: 1032 | printf("PIC24FJ128DA210\n"); 1033 | // __PIC24FJ128DA210__ 1034 | family = IS_24FJ; 1035 | flashsize = 0x15800; 1036 | eesizeb = 0; 1037 | blstartaddr = 0x400L; 1038 | blendaddr = 0x23FFL; 1039 | break; 1040 | case 254: 1041 | printf("PIC24FJ256DA106\n"); 1042 | // __PIC24FJ256DA106__ 1043 | family = IS_24FJ; 1044 | flashsize = 0x2AC00; 1045 | eesizeb = 0; 1046 | blstartaddr = 0x400L; 1047 | blendaddr = 0x23FFL; 1048 | break; 1049 | case 255: 1050 | printf("PIC24FJ256DA110\n"); 1051 | // __PIC24FJ256DA110__ 1052 | family = IS_24FJ; 1053 | flashsize = 0x2AC00; 1054 | eesizeb = 0; 1055 | blstartaddr = 0x400L; 1056 | blendaddr = 0x23FFL; 1057 | break; 1058 | case 206: 1059 | printf("PIC24FJ16GA002\n"); 1060 | flashsize = 0x2C00; 1061 | 1062 | break; 1063 | 1064 | case 207: 1065 | printf("PIC24FJ16GA004\n"); 1066 | flashsize = 0x2C00; 1067 | 1068 | break; 1069 | 1070 | 1071 | case 208: 1072 | printf("PIC24FJ32GA002\n"); 1073 | flashsize = 0x5800; 1074 | 1075 | break; 1076 | 1077 | case 209: 1078 | printf("PIC24FJ32GA004\n"); 1079 | flashsize = 0x5800; 1080 | 1081 | break; 1082 | 1083 | case 210: 1084 | printf("PIC24FJ48GA002\n"); 1085 | flashsize = 0x8400; 1086 | 1087 | break; 1088 | 1089 | case 211: 1090 | printf("PIC24FJ48GA004\n"); 1091 | flashsize = 0x8400; 1092 | 1093 | break; 1094 | 1095 | 1096 | case 212: 1097 | printf("PIC24FJ64GA002\n"); 1098 | flashsize = 0xAC00; 1099 | 1100 | break; 1101 | 1102 | case 213: 1103 | printf("PIC24FJ64GA004\n"); 1104 | flashsize = 0xAC00; 1105 | 1106 | break; 1107 | 1108 | case 214: 1109 | printf("PIC24FJ64GA006\n"); 1110 | flashsize = 0xAC00; 1111 | 1112 | break; 1113 | 1114 | printf("PIC24FJ64GA008\n"); 1115 | flashsize = 0xAC00; 1116 | case 215: 1117 | break; 1118 | 1119 | case 216: 1120 | printf("PIC24FJ64GA010\n"); 1121 | flashsize = 0xAC00; 1122 | 1123 | break; 1124 | 1125 | case 220: 1126 | printf("PIC24FJ96GA006\n"); 1127 | flashsize = 0x10000; 1128 | 1129 | break; 1130 | 1131 | case 221: 1132 | printf("PIC24FJ96GA008\n"); 1133 | flashsize = 0x10000; 1134 | 1135 | break; 1136 | 1137 | case 222: 1138 | printf("PIC24FJ96GA010\n"); 1139 | flashsize = 0x10000; 1140 | 1141 | break; 1142 | 1143 | 1144 | case 223: 1145 | printf("PIC24FJ128GA006\n"); 1146 | flashsize = 0x15800; 1147 | 1148 | break; 1149 | 1150 | case 224: 1151 | printf("PIC24FJ128GA008\n"); 1152 | flashsize = 0x15800; 1153 | 1154 | break; 1155 | 1156 | case 225: 1157 | printf("PIC24FJ128GA010\n"); 1158 | flashsize = 0x15800; 1159 | 1160 | break; 1161 | 1162 | case 226: 1163 | printf("PIC24FJ128GA106\n"); 1164 | flashsize = 0x15800; 1165 | 1166 | break; 1167 | 1168 | case 227: 1169 | printf("PIC24FJ128GA108\n"); 1170 | flashsize = 0x15800; 1171 | break; 1172 | 1173 | case 228: 1174 | printf("PIC24FJ128GA110\n"); 1175 | flashsize = 0x15800; 1176 | break; 1177 | 1178 | case 232: 1179 | printf("PIC24FJ192GA106\n"); 1180 | flashsize = 0x20C00; 1181 | break; 1182 | 1183 | case 233: 1184 | printf("PIC24FJ192GA108\n"); 1185 | flashsize = 0x20C00; 1186 | break; 1187 | 1188 | case 234: 1189 | printf("PIC24FJ192GA110\n"); 1190 | flashsize = 0x20C00; 1191 | break; 1192 | 1193 | case 238: 1194 | printf("PIC24FJ256GA106\n"); 1195 | flashsize = 0x2AC00; 1196 | 1197 | break; 1198 | 1199 | case 239: 1200 | printf("PIC24FJ256GA108\n"); 1201 | flashsize = 0x2AC00; 1202 | break; 1203 | 1204 | case 240: 1205 | printf("PIC24FJ256GA110\n"); 1206 | flashsize = 0x2AC00; 1207 | break; 1208 | 1209 | 1210 | default: 1211 | printf("UNKNOWN"); 1212 | fprintf(stderr, "Unsupported device (%02x:UNKNOWN)\n", buffer[0]); 1213 | goto Error; 1214 | break; 1215 | } 1216 | 1217 | if( !g_hello_only ) 1218 | { 1219 | 1220 | res = sendFirmware(dev_fd, bin_buff, pages_used); 1221 | 1222 | if( res > 0 ) 1223 | { 1224 | puts("\nFirmware updated successfully :)!"); 1225 | //printf("Use screen %s 115200 to verify\n", g_device_path); 1226 | } 1227 | else 1228 | { 1229 | puts("\nError updating firmware :("); 1230 | goto Error; 1231 | } 1232 | 1233 | } 1234 | 1235 | Finished: 1236 | if( bin_buff ) 1237 | { 1238 | free( bin_buff ); 1239 | } 1240 | if( dev_fd >= 0 ) 1241 | { 1242 | close(dev_fd); 1243 | } 1244 | return 0; 1245 | 1246 | Error: 1247 | if( bin_buff ) 1248 | { 1249 | free( bin_buff ); 1250 | } 1251 | if( dev_fd >= 0 ) 1252 | { 1253 | close(dev_fd); 1254 | } 1255 | return -1; 1256 | } 1257 | -------------------------------------------------------------------------------- /BPv4-firmware/pirate-loader-v4-source/pirate-loader.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 43 | 44 | -------------------------------------------------------------------------------- /BPv4-firmware/pirate-loader-v4-source/pirate-loader.depend: -------------------------------------------------------------------------------- 1 | # depslib dependency file v1.0 2 | 1313065012 source:e:\work\dp\bus_pirate\pirate-loader-v4\source\pirate-loader.c 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 1313134078 source:e:\work\dp\bus_pirate\pirate-loader-v4\pirate-loader\pirate-loader.c 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /BPv4-firmware/pirate-loader-v4-source/pirate-loader.layout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /BPv4-firmware/pirate-loader-v4-source/pirate-loader_mac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv4-firmware/pirate-loader-v4-source/pirate-loader_mac -------------------------------------------------------------------------------- /BPv4-firmware/pirate-loader.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv4-firmware/pirate-loader.exe -------------------------------------------------------------------------------- /BPv4-inf-driver/mchpcdc.cat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/BPv4-inf-driver/mchpcdc.cat -------------------------------------------------------------------------------- /BPv4-inf-driver/mchpcdc.inf: -------------------------------------------------------------------------------- 1 | 2 | ; Windows USB CDC ACM Setup File 3 | ; Copyright (c) 2000 Microsoft Corporation 4 | ; Copyright (C) 2007 Microchip Technology Inc. 5 | 6 | [Version] 7 | Signature="$Windows NT$" 8 | Class=Ports 9 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 10 | Provider=%MFGNAME% 11 | LayoutFile=layout.inf 12 | CatalogFile=%MFGFILENAME%.cat 13 | DriverVer=11/15/2007,5.1.2600.0 14 | 15 | [Manufacturer] 16 | %MFGNAME%=DeviceList, NTamd64 17 | 18 | [DestinationDirs] 19 | DefaultDestDir=12 20 | 21 | 22 | ;------------------------------------------------------------------------------ 23 | ; Windows 2000/XP/Vista-32bit Sections 24 | ;------------------------------------------------------------------------------ 25 | 26 | [DriverInstall.nt] 27 | include=mdmcpq.inf 28 | CopyFiles=DriverCopyFiles.nt 29 | AddReg=DriverInstall.nt.AddReg 30 | 31 | [DriverCopyFiles.nt] 32 | usbser.sys,,,0x20 33 | 34 | [DriverInstall.nt.AddReg] 35 | HKR,,DevLoader,,*ntkern 36 | HKR,,NTMPDriver,,%DRIVERFILENAME%.sys 37 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 38 | 39 | [DriverInstall.nt.Services] 40 | AddService=usbser, 0x00000002, DriverService.nt 41 | 42 | [DriverService.nt] 43 | DisplayName=%SERVICE% 44 | ServiceType=1 45 | StartType=3 46 | ErrorControl=1 47 | ServiceBinary=%12%\%DRIVERFILENAME%.sys 48 | 49 | ;------------------------------------------------------------------------------ 50 | ; Vista-64bit Sections 51 | ;------------------------------------------------------------------------------ 52 | 53 | [DriverInstall.NTamd64] 54 | include=mdmcpq.inf 55 | CopyFiles=DriverCopyFiles.NTamd64 56 | AddReg=DriverInstall.NTamd64.AddReg 57 | 58 | [DriverCopyFiles.NTamd64] 59 | %DRIVERFILENAME%.sys,,,0x20 60 | 61 | [DriverInstall.NTamd64.AddReg] 62 | HKR,,DevLoader,,*ntkern 63 | HKR,,NTMPDriver,,%DRIVERFILENAME%.sys 64 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 65 | 66 | [DriverInstall.NTamd64.Services] 67 | AddService=usbser, 0x00000002, DriverService.NTamd64 68 | 69 | [DriverService.NTamd64] 70 | DisplayName=%SERVICE% 71 | ServiceType=1 72 | StartType=3 73 | ErrorControl=1 74 | ServiceBinary=%12%\%DRIVERFILENAME%.sys 75 | 76 | 77 | ;------------------------------------------------------------------------------ 78 | ; Vendor and Product ID Definitions 79 | ;------------------------------------------------------------------------------ 80 | ; When developing your USB device, the VID and PID used in the PC side 81 | ; application program and the firmware on the microcontroller must match. 82 | ; Modify the below line to use your VID and PID. Use the format as shown below. 83 | ; Note: One INF file can be used for multiple devices with different VID and PIDs. 84 | ; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. 85 | ;------------------------------------------------------------------------------ 86 | [SourceDisksFiles] 87 | [SourceDisksNames] 88 | [DeviceList] 89 | %DESCRIPTION%=DriverInstall, USB\VID_04D8&PID_FB00 90 | %DESLOADER%=DriverInstall, USB\VID_04D8&PID_000A 91 | 92 | [DeviceList.NTamd64] 93 | %DESCRIPTION%=DriverInstall, USB\VID_04D8&PID_FB00 94 | %DESLOADER%=DriverInstall, USB\VID_04D8&PID_000A 95 | 96 | 97 | ;------------------------------------------------------------------------------ 98 | ; String Definitions 99 | ;------------------------------------------------------------------------------ 100 | ;Modify these strings to customize your device 101 | ;------------------------------------------------------------------------------ 102 | [Strings] 103 | MFGFILENAME="mchpcdc" 104 | DRIVERFILENAME ="usbser" 105 | MFGNAME="Microchip Technology, Inc." 106 | INSTDISK="Microchip Technology, Inc. Installation Disc" 107 | DESCRIPTION="Bus Pirate v4" 108 | DESLOADER="Bus Pirate v4 Bootloader" 109 | SERVICE="USB RS-232 Emulation Driver" 110 | 111 | 112 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # buspirate v6.1 2 | Bus Pirate (cleaned up to run cleanly on OS X) 3 | 4 | Should be cleanly cross-platform, OS X binary included. 5 | 6 | ## Compiling 7 | 8 | cd BPv4-firmware/pirate-loader-v4-source && make clean && make 9 | 10 | ## Running 11 | 12 | ./pirate-loader_mac 13 | 14 | ## Moar 15 | 16 | Bus Pirate homepage, purchasing, etc: http://dangerousprototypes.com/docs/Bus_Pirate 17 | 18 | yarr -samy 19 | -------------------------------------------------------------------------------- /hardware/BPv3-LCDadapter-v2c.brd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/hardware/BPv3-LCDadapter-v2c.brd -------------------------------------------------------------------------------- /hardware/BPv3-LCDadapter-v2c.sch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/hardware/BPv3-LCDadapter-v2c.sch -------------------------------------------------------------------------------- /hardware/BPv3-PICprogrammer-v1c.brd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/hardware/BPv3-PICprogrammer-v1c.brd -------------------------------------------------------------------------------- /hardware/BPv3-PICprogrammer-v1c.sch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/hardware/BPv3-PICprogrammer-v1c.sch -------------------------------------------------------------------------------- /hardware/BusPirate-v3.5c-SSOP.brd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/hardware/BusPirate-v3.5c-SSOP.brd -------------------------------------------------------------------------------- /hardware/BusPirate-v3.5c-SSOP.sch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/hardware/BusPirate-v3.5c-SSOP.sch -------------------------------------------------------------------------------- /hardware/BusPirate-v3a-final.brd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/hardware/BusPirate-v3a-final.brd -------------------------------------------------------------------------------- /hardware/BusPirate-v3a-final.sch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/hardware/BusPirate-v3a-final.sch -------------------------------------------------------------------------------- /hardware/BusPirate-v4.brd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/hardware/BusPirate-v4.brd -------------------------------------------------------------------------------- /hardware/BusPirate-v4.sch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samyk/buspirate/084bccf317de71cc3dd7ed82480369a843abfa33/hardware/BusPirate-v4.sch --------------------------------------------------------------------------------