From ed9c1e9f9689c5364fe63742d17015b17bcaa265 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 7 Jul 2013 14:17:49 +0000 Subject: removed name for identify - now using userid git-svn-id: https://svn.spreadspace.org/pic/trunk@49 a09c6847-51d9-44de-8ef2-e725cf50f3c7 --- bootloader/bootloader.asm | 107 +++++++++++++++++++++++++++------------------- downloader/downloader.py | 8 ++-- downloader/proto.txt | 8 ++-- 3 files changed, 72 insertions(+), 51 deletions(-) diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm index 6df5906..164adb7 100644 --- a/bootloader/bootloader.asm +++ b/bootloader/bootloader.asm @@ -35,9 +35,15 @@ ISRVECT EQU USERVECT + H'4' VERSION_MAJ EQU .0 VERSION_MIN EQU .1 +USERID_L EQU H'fe' +USERID_H EQU H'ca' DEVID_H EQU H'20' DEVID_L EQU H'82' +FLASH_SIZE_L EQU H'00' +FLASH_SIZE_H EQU H'20' ; 0x2000 -> 8192 Words of Flash FSS EQU .16 ; writing is done 8 words at a time but 16 words get erased +EEPROM_SIZE_L EQU H'00' +EEPROM_SIZE_H EQU H'01' ; 0x0100 -> 256 Bytes of EEPROM MESS EQU .64 ; this limit is because of to combuff size and single byte len field for messages SUPPORTED_H EQU .0 SUPPORTED_L EQU b'00000110' ; only read/write flash is supported by now @@ -66,7 +72,10 @@ CMD_R_CONFIG EQU .8 CMD_W_CONFIG EQU .9 CMD_MAX EQU .9 + + ;; Sanity Checks CMD_MIN_LEN EQU .3 +FLASH_BOUNDARY EQU b'00001111' ; flash boundary is at 16 bytes boundaries ;; Variables combuff EQU H'0020' @@ -96,14 +105,15 @@ isr ;; ------------------------------------- ;; Bootloader (Subroutines) -uart_tx_byte +uart_tx_byte ;send one byte and add it to csum btfss PIR1,TXIF goto uart_tx_byte movwf TXREG xorwf csum,f return -send_answer + ;; ------------------ +send_answer ; generic answer message, leave len of data in W addlw .3 movwf combuff + .1 decf combuff + .1,w @@ -122,19 +132,13 @@ send_answer_next call uart_tx_byte return -get_name - addwf PCL,f - nop - retlw 'c' - retlw 'i' - retlw 'p' - retlw '-' - retlw 'd' - retlw 'a' - retlw 'e' - retlw 'r' - retlw 'p' - retlw 's' + ;; ------------------ +ack_cmd ; short answers which only contain return code + movwf combuff + .2 + movlw .1 + call send_answer + return + ;; ------------------------------------- ;; Bootloader (init) boot @@ -162,6 +166,8 @@ boot movlw b'10010000' ; enable Serial Port, 8bit, enable continues receive, disable address detection movwf RCSTA + ;; --------- end of init + wait_new_cmd movlw combuff movwf FSR @@ -169,7 +175,7 @@ wait_new_cmd clrf current_cmdlen clrf flags -wait_cmd +wait_cmd ; wait for new commands btfsc PIR1,RCIF goto uart_rx_byte btfsc RCSTA,OERR @@ -181,7 +187,7 @@ uart_rx_oe ; recover from overflow bsf RCSTA,CREN goto wait_new_cmd -uart_rx_byte ; process received command +uart_rx_byte ; process received byte btfsc RCSTA,FERR goto uart_rx_fe movf RCREG,w @@ -200,11 +206,11 @@ uart_rx_fe ; recover from framing error movf RCREG,w goto wait_new_cmd -wait_cmd_len +wait_cmd_len ; command code received, now wait for length bsf F_CMD_STARTED goto wait_cmd -new_cmd ; got new command code +new_cmd ; got new command code and length -> check it movf combuff,w sublw CMD_MAX btfss STATUS,C @@ -218,13 +224,6 @@ new_cmd ; got new command code movwf current_cmdlen goto wait_cmd -invalid_cmd ; received command code is not known or len is bogus - movlw E_INV_CMD - movwf combuff + .2 - movlw .1 - call send_answer - goto wait_new_cmd - exec_cmd ; command is complete -> check csum movlw combuff movwf FSR @@ -254,11 +253,25 @@ exec_cmd_check_csum goto cmd_not_impl ; read config goto cmd_not_impl ; write config + ;; ** error messages ******* +invalid_cmd ; received command code is not known or len is bogus + movlw E_INV_CMD + call ack_cmd + goto wait_new_cmd + csum_error ; received command has an invalid check sum movlw E_BAD_CSUM - movwf combuff + .2 - movlw .1 - call send_answer + call ack_cmd + goto wait_new_cmd + +address_invalid ; received command uses invalid address (i.e. not aligned to 16bytes) + movlw E_ADDR_INVALID + call ack_cmd + goto wait_new_cmd + +address_prohibited ; received command uses prohibited address (i.e. FLASH < 0x100) + movlw E_ADDR_PROHIB + call ack_cmd goto wait_new_cmd ;; ** Command Handlers ******************** @@ -279,22 +292,27 @@ cmd_identify movlw VERSION_MAJ call uart_tx_byte - movlw .10 - movwf cnt1 -cmd_identify_send_name - movf cnt1,w - call get_name + movlw USERID_L call uart_tx_byte - decfsz cnt1,f - goto cmd_identify_send_name - + movlw USERID_H + call uart_tx_byte + movlw DEVID_L call uart_tx_byte movlw DEVID_H call uart_tx_byte + movlw FLASH_SIZE_L + call uart_tx_byte + movlw FLASH_SIZE_H + call uart_tx_byte movlw FSS call uart_tx_byte + + movlw EEPROM_SIZE_L + call uart_tx_byte + movlw EEPROM_SIZE_H + call uart_tx_byte movlw MESS call uart_tx_byte @@ -310,9 +328,7 @@ cmd_identify_send_name ;; ** boot ******* cmd_boot movlw E_OK - movwf combuff + .2 - movlw .1 - call send_answer + call ack_cmd goto USERVECT ;; ** read flash ******* @@ -330,9 +346,7 @@ cmd_w_flash ;; ** not implemented commands ******* cmd_not_impl movlw E_NOT_IMPL - movwf combuff + .2 - movlw .1 - call send_answer + call ack_cmd goto wait_new_cmd ;; ------------------------------------- @@ -375,6 +389,13 @@ read_flash_segment_next ;; flash write -------- write_flash_segment + movlw FLASH_BOUNDARY ; addr on boundary? + andwf combuff + .2,w + btfss STATUS,Z + goto address_invalid + movf combuff + .3,f ; if addr[15:8] == 0 -> boot loader section + btfsc STATUS,Z + goto address_prohibited movlw FSS ; initialize EEADR:EEADRH and FSR movwf cnt1 movlw b'01011000' diff --git a/downloader/downloader.py b/downloader/downloader.py index f0407e9..c0ce34f 100755 --- a/downloader/downloader.py +++ b/downloader/downloader.py @@ -158,8 +158,8 @@ def exec_command(dev, cmd, param, answer): ### Commands def identify(dev): - data = exec_command(dev, 1, '', ' answer: - 1 | len=22 | | version | name | devid | fs | fss | es | mess | supported | + 1 | len=22 | | version | userid | devid | fs | fss | es | mess | supported | version: 2bytes, protocol version It is an error if the major version (MSB) is different (hence any protocol update must change the major version of the bootloader). - name: - 10bytes, a descriptive name of the device. - The downloader has to compare this name with the device name supplied + userid: + 2bytes, an id which determines the exact device + The downloader has to compare this with the device id supplied via commandline and stop in case they don't match devid: -- cgit v1.2.3