fix spiffs downloads >= 64K, and stop losing flash errors
CMD_SPIFFS_DOWNLOAD read the whole file into BigBuf first. BigBuf_calloc() takes a uint16_t while the size is a uint32_t, so a 64K file allocated zero bytes and anything larger wrapped to a short buffer the file was then read straight past the end of. rdv40_spiffs_read_stream() opens the file once and hands out one frame at a time, so the size never reaches the allocator, and the SPIFFS path now honours start_index. Verified with an 80K round trip: upload, download, byte identical. The same BigBuf_calloc(filesize) wrap was in copy_in_spiffs(); it now copies in SPIFFS_WRITE_CHUNK_SIZE chunks. Separately, every flash failure was invisible. SPIFFS_CHECK_RES() only treats a negative result as an error and the HAL hooks returned 128/129/130, so SPIFFS saw success. The erase path was worst: Flash_Erase4k() only reports that the command was sent, both Flash_CheckBusy() results were discarded, and 'return (SPIFFS_OK == erased)' yields 1 on failure. A flash dump from a device that hit this showed one block written without being erased - its object index header held '0x14000 & 0x10000', and the filename ANDed away to empty. Erases are now read back and retried, and the HAL returns real SPIFFS error codes. Flash_Write() returned len unconditionally even after a rejected page, which also defeated the 'res == payload->len' check in CMD_FLASHMEM_WRITE. Feedback, so none of this is silent again: CMD_SPIFFS_WRITE answers with the SPIFFS result, the client aborts on the first refusal and names the byte it stopped at, dl_it() checks the terminator status, and both transfer directions print inline progress. Co-Authored-By: Claude Opus 5 (1M context)
This commit is contained in:
1 parent
a967560335
commit
9a8e179266
6 files changed
+345
-50
No files matched your search
@@ -106,12 +106,15 @@ uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) {
|
||||
|
||||
// assumes valid start 256 based 00 address
|
||||
// Start writing flash from the specified location.
|
||||
// Write FLASH_MEM_BLOCK_SIZE bytes at most each time. If the writing is nearly complete, write it as bytes_remaining bytes.
|
||||
// Write FLASH_MEM_BLOCK_SIZE bytes at most each time.
|
||||
// If the writing is nearly complete, write it as bytes_remaining bytes.
|
||||
uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len) {
|
||||
|
||||
bool isok;
|
||||
uint16_t res, bytes_sent = 0, bytes_remaining = len;
|
||||
uint8_t buf[FLASH_MEM_BLOCK_SIZE];
|
||||
uint16_t res;
|
||||
uint16_t bytes_sent = 0;
|
||||
uint16_t bytes_remaining = len;
|
||||
uint8_t buf[FLASH_MEM_BLOCK_SIZE] = {0};
|
||||
|
||||
while (bytes_remaining > 0) {
|
||||
|
||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||
@@ -123,18 +126,19 @@ uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len) {
|
||||
|
||||
res = Flash_WriteDataCont(address + bytes_sent, buf, bytes_in_packet);
|
||||
|
||||
// a rejected page stops here, so bytes_sent stays at what really landed
|
||||
if (res != bytes_in_packet) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
bytes_remaining -= bytes_in_packet;
|
||||
bytes_sent += bytes_in_packet;
|
||||
|
||||
isok = (res == bytes_in_packet);
|
||||
|
||||
if (!isok)
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
FlashStop();
|
||||
return len;
|
||||
// bytes actually programmed, callers compare this against len
|
||||
return bytes_sent;
|
||||
}
|
||||
|
||||
void Flashmem_print_status(void) {
|
||||
|
||||
Reference in new issue
Block a user