Skip to content

Commit 01d4ec6

Browse files
3djcpfeerick
authored andcommitted
fix(uf2): prevent being unable to flash when corrupted firmware present (#6814)
1 parent 5fc7d72 commit 01d4ec6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

radio/src/drivers/uf2_ghostfat.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,12 @@ static FAT_BootBlock const BootBlock = {
223223
.ReservedSectors = RESERVED_SECTORS,
224224
.FATCopies = 2,
225225
.RootDirectoryEntries = (ROOT_DIR_SECTORS * DIRENTRIES_PER_SECTOR),
226-
.TotalSectors16 = NUM_FAT_BLOCKS - 2,
226+
.TotalSectors16 = 0,
227227
.MediaDescriptor = 0xF8,
228228
.SectorsPerFAT = SECTORS_PER_FAT,
229229
.SectorsPerTrack = 1,
230230
.Heads = 1,
231+
.TotalSectors32 = NUM_FAT_BLOCKS - 2,
231232
.PhysicalDriveNum = 0x80, // to match MediaDescriptor of 0xF8
232233
.ExtendedBootSig = 0x29,
233234
.VolumeSerialNumber = 0x00000000,
@@ -284,6 +285,9 @@ static uint32_t current_flash_size(void)
284285
if (is_firmware_valid(fw_desc)) {
285286
// round up to 256 bytes
286287
result = (fw_desc->length + BOOTLOADER_SIZE + 255U) & (~255U);
288+
// Sometime corrupted firmware return very large size, leave not enough space to flash a fix
289+
if (result >= UF2_MAX_FW_SIZE)
290+
result = UF2_MAX_FW_SIZE;
287291
} else {
288292
result = UF2_MAX_FW_SIZE;
289293
}

radio/src/drivers/uf2_ghostfat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include <stdint.h>
2525

26-
#define UF2_NUM_BLOCKS 32768 // at least 16MB
26+
#define UF2_NUM_BLOCKS 65536 // at least 32MB
2727
#define UF2_INVALID_NUM_BLOCKS 0xFFFFFFFF
2828

2929
typedef struct {

0 commit comments

Comments
 (0)