diff options
-rw-r--r-- | bootloader/bootloader.asm | 86 | ||||
-rwxr-xr-x | downloader/downloader.py | 18 | ||||
-rw-r--r-- | downloader/proto.txt | 74 |
3 files changed, 68 insertions, 110 deletions
diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm index 02b9105..bbf88b8 100644 --- a/bootloader/bootloader.asm +++ b/bootloader/bootloader.asm @@ -54,42 +54,26 @@ E_ADDR_PROHIB EQU .6 E_VALUE_OOB EQU .7 ;; CMD codes -CCMD_IDENTIFY EQU 'i' -CMD_IDENTIFY EQU .0 +CMD_INVALID EQU .0 -CCMD_BOOT EQU 'b' -CMD_BOOT EQU .1 +CMD_IDENTIFY EQU .1 +CMD_BOOT EQU .2 +CMD_RESET EQU .3 +CMD_R_FLASH EQU .4 +CMD_W_FLASH EQU .5 +CMD_R_EEPROM EQU .6 +CMD_W_EEPROM EQU .7 +CMD_R_CONFIG EQU .8 +CMD_W_CONFIG EQU .9 -CCMD_RESET EQU 'r' -CMD_RESET EQU .2 - -CCMD_R_FLASH EQU 'f' -CMD_R_FLASH EQU .3 - -CCMD_W_FLASH EQU 'F' -CMD_W_FLASH EQU .4 - -CCMD_R_EEPROM EQU 'e' -CMD_R_EEPROM EQU .5 - -CCMD_W_EEPROM EQU 'E' -CMD_W_EEPROM EQU .6 - -CCMD_R_CONFIG EQU 'c' -CMD_R_CONFIG EQU .7 - -CCMD_W_CONFIG EQU 'C' -CMD_W_CONFIG EQU .8 - -CMD_INVALID EQU H'FF' +CMD_MAX EQU .9 ;; Variables combuff EQU H'0020' combuff_end EQU H'006F' -current_cmd EQU H'0070' -current_cmdlen EQU H'0071' -csum EQU H'0072' +current_cmdlen EQU H'0070' +csum EQU H'0071' flags EQU H'007D' weep EQU .0 @@ -135,38 +119,12 @@ send_answer_next call uart_tx_byte return -translate_cmd_codes - xorlw CCMD_IDENTIFY - btfsc STATUS,Z - retlw CMD_IDENTIFY - xorlw CCMD_BOOT ^ CCMD_IDENTIFY - btfsc STATUS,Z - retlw CMD_BOOT - xorlw CCMD_RESET ^ CCMD_BOOT - btfsc STATUS,Z - retlw CMD_RESET - xorlw CCMD_R_FLASH ^ CCMD_RESET - btfsc STATUS,Z - retlw CMD_R_FLASH - xorlw CCMD_W_FLASH ^ CCMD_R_FLASH - btfsc STATUS,Z - retlw CMD_W_FLASH - xorlw CCMD_R_EEPROM ^ CCMD_W_FLASH - btfsc STATUS,Z - retlw CMD_R_EEPROM - xorlw CCMD_W_EEPROM ^ CCMD_R_EEPROM - btfsc STATUS,Z - retlw CMD_W_EEPROM - xorlw CCMD_R_CONFIG ^ CCMD_W_EEPROM - btfsc STATUS,Z - retlw CMD_R_CONFIG - xorlw CCMD_W_CONFIG ^ CCMD_R_CONFIG - btfsc STATUS,Z - retlw CMD_W_CONFIG +check_cmd_code retlw CMD_INVALID get_cmdlen addwf PCL,f + retlw .0 ; invalid retlw .1 ; identify: <csum> retlw .1 ; boot: <csum> retlw .1 ; reset: <csum> @@ -220,8 +178,7 @@ boot wait_new_cmd movlw combuff movwf FSR - movlw CMD_INVALID - movwf current_cmd + clrf combuff clrf current_cmdlen clrf flags @@ -255,12 +212,10 @@ uart_rx_fe ; recover from framing error goto wait_new_cmd new_cmd ; got new command code - call translate_cmd_codes - movwf current_cmd - xorlw CMD_INVALID + call check_cmd_code + movf combuff,w btfsc STATUS,Z goto invalid_cmd - movf current_cmd,w ; initializing cmdlen call get_cmdlen movwf current_cmdlen goto wait_cmd @@ -275,8 +230,9 @@ invalid_cmd ; received command code is not known exec_cmd ; command is correct and complete ;; TODO: check csum -> csum for write eeprom will not be correct because ;; it isn't finished yet....??? - movf current_cmd,w ; dispatch commands + movf combuff,w ; dispatch commands addwf PCL,f + nop goto cmd_identify goto cmd_boot goto cmd_reset @@ -292,7 +248,7 @@ exec_cmd ; command is correct and complete ;; ** identify ******* cmd_identify clrf csum - movlw CCMD_IDENTIFY + movf combuff,w call uart_tx_byte movlw E_OK diff --git a/downloader/downloader.py b/downloader/downloader.py index 3a66f3b..b332271 100755 --- a/downloader/downloader.py +++ b/downloader/downloader.py @@ -160,7 +160,7 @@ def exec_command(dev, cmd, answer): ### Commands def identify(dev): - data = exec_command(dev, 'i', '<BB10sHBHH') + data = exec_command(dev, struct.pack('<B', 1), '<BB10sHBHH') id = { 'ver_min': data[0], 'ver_maj': data[1], 'name': data[2], 'devid': data[3], 'fss': data[4], 'mess': data[5], 'supported': data[6] } @@ -175,34 +175,34 @@ def identify(dev): return id def boot(dev): - exec_command(dev, 'b', '<') + exec_command(dev, struct.pack('<B', 2), '<') def reset(dev, id): - exec_command(dev, 'r', '<') + exec_command(dev, struct.pack('<B', 3), '<') def read_flash_segment(dev, id, addr): - cmd = struct.pack('<cH', 'f', addr) + cmd = struct.pack('<BH', 4, addr) return exec_command(dev, cmd, '<%dH' % id['fss']) def write_flash_segment(dev, id, addr, data): - cmd = struct.pack('<cH%dH' % id['fss'], 'F', addr, *data) + cmd = struct.pack('<BH%dH' % id['fss'], 5, addr, *data) return exec_command(dev, cmd, '<') def read_eeprom(dev, id, addr, len): - cmd = struct.pack('<cHH', 'e', addr, len) + cmd = struct.pack('<BHH', 6, addr, len) return exec_command(dev, cmd, '<%dB' % len) def write_eeprom(dev, id, addr, data): - cmd = struct.pack('<cHH%dB' % len(data), 'E', addr, len(data), *data) + cmd = struct.pack('<BHH%dB' % len(data), 7, addr, len(data), *data) return exec_command(dev, cmd, '<') def read_config(dev, id, nr): - cmd = struct.pack('<cB', 'c', nr) + cmd = struct.pack('<BB', 8, nr) data = exec_command(dev, cmd, '<H') return data[0] def write_config(dev, id, nr, word): - cmd = struct.pack('<cBH', 'C', nr, word) + cmd = struct.pack('<BBH', 9, nr, word) return exec_command(dev, cmd, '<') diff --git a/downloader/proto.txt b/downloader/proto.txt index 71b0774..f4f32c8 100644 --- a/downloader/proto.txt +++ b/downloader/proto.txt @@ -1,15 +1,17 @@ Command List: ============= -'i' ... identify -'b' ... boot -'r' ... reset -'f' ... read flash -'F' ... write flash -'e' ... read eeprom -'E' ... write eeprom -'c' ... read config -'C' ... write config + code | command + ------+------------ + 1 | identify + 2 | boot + 3 | reset + 4 | read flash + 5 | write flash + 6 | read eeprom + 7 | write eeprom + 8 | read config + 9 | write config Description: @@ -36,10 +38,10 @@ The return codes have the following meaning: identify: ~~~~~~~~~ command: - 'i' | <csum> (in this case <csum> will always be 'i') + 1 | <csum> (in this case <csum> will always be 1) answer: - 'i' | <ret> | version | name | devid | fss | mess | supported | <csum> + 1 | <ret> | version | name | devid | fss | mess | supported | <csum> version: 2bytes, protocol version @@ -53,7 +55,7 @@ identify: devid: 2bytes, device id of the PIC - The downlaoder may use this id to check if it talks to the right bootloader + The downlaoder may use this id to check if it talks to the right bootloader fss: 1byte, flash segment size @@ -87,10 +89,10 @@ boot: ~~~~~ command: - 'b' | <csum> (in this case <csum> will always be 'b') + 2 | <csum> (in this case <csum> will always be 2) answer: - 'b' | <ret> | <csum> + 2 | <ret> | <csum> This instucts the bootloader to boot to the user application directly (no reset) @@ -99,10 +101,10 @@ reset: ~~~~~~ command: - 'r' | <csum> (in this case <csum> will always be 'r') + 3 | <csum> (in this case <csum> will always be 3) answer: - 'r' | <ret> | <csum> + 3 | <ret> | <csum> The device performs a reboot. If the boot condition (i.e.: port pin) is not met this instructs the device to boot to the user application. @@ -112,10 +114,10 @@ read flash: ~~~~~~~~~~~ command: - 'f' | addr | <csum> + 4 | addr | <csum> answer: - 'f' | <ret> | data | <csum> + 4 | <ret> | data | <csum> The bootloader reads <fss> words from flash address <addr> and returns it as <data>. @@ -125,10 +127,10 @@ write flash: ~~~~~~~~~~~~ command: - 'F' | addr | data | <csum> + 5 | addr | data | <csum> answer: - 'F' | <ret> | <csum> + 5 | <ret> | <csum> The bootloader writes <data> (which has to contain exactly <fss> words) to address <addr> inside the flash. @@ -138,10 +140,10 @@ read eeprom: ~~~~~~~~~~~~ command: - 'e' | addr | len | <csum> + 6 | addr | len | <csum> answer: - 'e' | <ret> | data | <csum> + 6 | <ret> | data | <csum> The bootloader reads <len> bytes from eeprom at address <addr> and returns it as <data>. len is 2bytes long. @@ -151,10 +153,10 @@ write eeprom: ~~~~~~~~~~~~~ command: - 'E' | addr | len | data | <csum> + 7 | addr | len | data | <csum> answer: - 'E' | <ret> | <csum> + 7 | <ret> | <csum> The bootloader writes <data> (which has to contain exactly <len> bytes) to address <addr> inside the eeprom. len is 2bytes long and the value must not exceed <mess> bytes. @@ -163,24 +165,24 @@ write eeprom: read config: ~~~~~~~~~~~~ - command: - 'c' | nr | <csum> + command: + 8 | nr | <csum> - answer: - 'c' | <ret> | word | <csum> + answer: + 8 | <ret> | word | <csum> - The bootloader reads and returns the configuration word number <nr>. <nr> is one - byte long. + The bootloader reads and returns the configuration word number <nr>. <nr> is one + byte long. write config: ~~~~~~~~~~~~~ - command: - 'C' | nr | word | <csum> + command: + 9 | nr | word | <csum> - answer: - 'C' | <ret> | <csum> + answer: + 9 | <ret> | <csum> - The bootloader writes <word> onto configuration word number <nr>. <nr> is one - byte long + The bootloader writes <word> onto configuration word number <nr>. <nr> is one + byte long. |