fix(uf2): prevent being unable to flash when corrupted firmware present (#6814)

This commit is contained in:
3djc
2025-11-26 13:09:35 +10:00
committed by GitHub
parent 5c25f220b0
commit 851475ba03
2 changed files with 6 additions and 2 deletions
+5 -1
View File
@@ -223,11 +223,12 @@ static FAT_BootBlock const BootBlock = {
.ReservedSectors = RESERVED_SECTORS,
.FATCopies = 2,
.RootDirectoryEntries = (ROOT_DIR_SECTORS * DIRENTRIES_PER_SECTOR),
.TotalSectors16 = NUM_FAT_BLOCKS - 2,
.TotalSectors16 = 0,
.MediaDescriptor = 0xF8,
.SectorsPerFAT = SECTORS_PER_FAT,
.SectorsPerTrack = 1,
.Heads = 1,
.TotalSectors32 = NUM_FAT_BLOCKS - 2,
.PhysicalDriveNum = 0x80, // to match MediaDescriptor of 0xF8
.ExtendedBootSig = 0x29,
.VolumeSerialNumber = 0x00000000,
@@ -284,6 +285,9 @@ static uint32_t current_flash_size(void)
if (is_firmware_valid(fw_desc)) {
// round up to 256 bytes
result = (fw_desc->length + BOOTLOADER_SIZE + 255U) & (~255U);
// Sometime corrupted firmware return very large size, leave not enough space to flash a fix
if (result >= UF2_MAX_FW_SIZE)
result = UF2_MAX_FW_SIZE;
} else {
result = UF2_MAX_FW_SIZE;
}
+1 -1
View File
@@ -23,7 +23,7 @@
#include <stdint.h>
#define UF2_NUM_BLOCKS 32768 // at least 16MB
#define UF2_NUM_BLOCKS 65536 // at least 32MB
#define UF2_INVALID_NUM_BLOCKS 0xFFFFFFFF
typedef struct {