From 32f2120ec6de33a277c1084f08cf47871fd85a82 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Fri, 18 Dec 2020 14:09:54 -0600 Subject: [PATCH] fix timeout when firmware size is 10x packet size When the firmware blob is exactly a multiple of 10 times the packet size, the last checksum request causes the reply to the last program request to be missed (there is only a response from the hub to the very last program request). The program response is received, then the checksum response is received. Since the saga is waiting for the checksum response first, the program response is discarded. Fix by breaking out of the loop when the firmware has been fully transferred before making the checksum request. Fixes: pybricks/support#178 --- src/sagas/flash-firmware.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sagas/flash-firmware.ts b/src/sagas/flash-firmware.ts index 158d7f934..3e101a79f 100644 --- a/src/sagas/flash-firmware.ts +++ b/src/sagas/flash-firmware.ts @@ -280,7 +280,7 @@ function* flashFirmware(action: FlashFirmwareFlashAction): Generator { throw Error('Missing hub type in MaxProgramFlashSize'); } - for (let offset = 0; offset < firmware.length; offset += maxDataSize) { + for (let offset = 0; ; ) { const payload = firmware.slice(offset, offset + maxDataSize); const programAction = (yield put( programRequest(info[0].startAddress + offset, payload.buffer), @@ -289,6 +289,13 @@ function* flashFirmware(action: FlashFirmwareFlashAction): Generator { yield put(progress(offset, firmware.length)); + // we don't want to request checksum if this is the last packet since + // the bootloader will send a response to the program request already. + offset += maxDataSize; + if (offset >= firmware.length) { + break; + } + if (connectResult.canWriteWithoutResponse) { // Request checksum every 10 packets to prevent buffer overrun on // the hub because of sending too much data at once. The actual