flush rx buffer when bad crc and fix frame payload length
This commit is contained in:
parent
d62ef38c4b
commit
ebdc38fc91
|
@ -122,6 +122,7 @@ int serialboot(void)
|
|||
printf("Booting from serial...\n");
|
||||
printf("Press Q or ESC to abort boot completely.\n");
|
||||
|
||||
// send the "magic" request to host for a firmware download
|
||||
c = str;
|
||||
while(*c) {
|
||||
uart_write(*c);
|
||||
|
@ -145,18 +146,22 @@ int serialboot(void)
|
|||
int goodcrc;
|
||||
|
||||
/* Get one Frame */
|
||||
frame.length = uart_read();
|
||||
frame.payload_length = uart_read();
|
||||
frame.crc[0] = uart_read();
|
||||
frame.crc[1] = uart_read();
|
||||
frame.cmd = uart_read();
|
||||
for(i=0;i<frame.length;i++)
|
||||
for(i=0;i<frame.payload_length;i++)
|
||||
frame.payload[i] = uart_read();
|
||||
|
||||
/* Check Frame CRC (if CMD has a CRC) */
|
||||
if (frame.cmd != SFL_CMD_LOAD_NO_CRC) {
|
||||
actualcrc = ((int)frame.crc[0] << 8)|(int)frame.crc[1];
|
||||
goodcrc = crc16(&frame.cmd, frame.length+1);
|
||||
goodcrc = crc16(&frame.cmd, frame.payload_length+1);
|
||||
if(actualcrc != goodcrc) {
|
||||
// clear out the RX buffer
|
||||
while (uart_read_nonblock()) {
|
||||
uart_read();
|
||||
}
|
||||
failed++;
|
||||
if(failed == MAX_FAILED) {
|
||||
printf("Too many consecutive errors, aborting");
|
||||
|
@ -179,7 +184,7 @@ int serialboot(void)
|
|||
|
||||
failed = 0;
|
||||
writepointer = (char *) get_uint32(&frame.payload[0]);
|
||||
for(i=4;i<frame.length;i++)
|
||||
for(i=4;i<frame.payload_length;i++)
|
||||
*(writepointer++) = frame.payload[i];
|
||||
if (frame.cmd == SFL_CMD_LOAD)
|
||||
uart_write(SFL_ACK_SUCCESS);
|
||||
|
@ -201,7 +206,7 @@ int serialboot(void)
|
|||
failed = 0;
|
||||
addr = get_uint32(&frame.payload[0]);
|
||||
|
||||
for (i = 4; i < frame.length; i++) {
|
||||
for (i = 4; i < frame.payload_length; i++) {
|
||||
// erase page at sector boundaries before writing
|
||||
if ((addr & (SPIFLASH_SECTOR_SIZE - 1)) == 0) {
|
||||
erase_flash_sector(addr);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#define SFL_MAGIC_ACK "z6IHG7cYDID6o\n"
|
||||
|
||||
struct sfl_frame {
|
||||
unsigned char length;
|
||||
unsigned char payload_length;
|
||||
unsigned char crc[2];
|
||||
unsigned char cmd;
|
||||
unsigned char payload[255];
|
||||
|
|
|
@ -52,7 +52,7 @@ sfl_prompt_ack = b"\x06"
|
|||
sfl_magic_req = b"sL5DdSMmkekro\n"
|
||||
sfl_magic_ack = b"z6IHG7cYDID6o\n"
|
||||
|
||||
sfl_payload_length = 251
|
||||
sfl_payload_length = 64#251
|
||||
|
||||
# General commands
|
||||
sfl_cmd_abort = b"\x00"
|
||||
|
@ -212,7 +212,7 @@ class LiteXTerm:
|
|||
100*position//length))
|
||||
sys.stdout.flush()
|
||||
frame = SFLFrame()
|
||||
frame_data = f.read(min(remaining, sfl_payload_length))
|
||||
frame_data = f.read(min(remaining, sfl_payload_length-4))
|
||||
if self.flash:
|
||||
frame.cmd = sfl_cmd_flash
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue