fix(fatfs): Calculate max_pos in wl_fatfsgen.py safe mode correctly

This commit is contained in:
Adam Múdry
2026-01-28 14:07:41 +01:00
parent 857cbacbc7
commit 1ec2776034
+15 -7
View File
@@ -119,9 +119,11 @@ class WLFATFS:
# determine the number of required sectors (roundup to sector size)
self.wl_state_sectors = (self.wl_state_size + FATDefaults.WL_SECTOR_SIZE - 1) // FATDefaults.WL_SECTOR_SIZE
wl_sectors = (WLFATFS.WL_DUMMY_SECTORS_COUNT + WLFATFS.WL_CFG_SECTORS_COUNT +
self.wl_state_sectors * WLFATFS.WL_STATE_COPY_COUNT)
wl_sectors = (
WLFATFS.WL_DUMMY_SECTORS_COUNT
+ WLFATFS.WL_CFG_SECTORS_COUNT
+ self.wl_state_sectors * WLFATFS.WL_STATE_COPY_COUNT
)
if self.wl_mode is not None and self.wl_mode == 'safe':
wl_sectors += WLFATFS.WL_SAFE_MODE_DUMP_SECTORS
@@ -188,7 +190,11 @@ class WLFATFS:
wl_state_data = WLFATFS.WL_STATE_T_DATA.build(
dict(
pos=0,
max_pos=self.plain_fat_sectors + WLFATFS.WL_DUMMY_SECTORS_COUNT,
max_pos=(
self.plain_fat_sectors
+ WLFATFS.WL_DUMMY_SECTORS_COUNT
+ (WLFATFS.WL_SAFE_MODE_DUMP_SECTORS if self.wl_mode == 'safe' else 0)
),
move_count=0,
access_count=0,
max_count=FATDefaults.UPDATE_RATE,
@@ -201,14 +207,16 @@ class WLFATFS:
wl_state_crc = Int32ul.build(crc)
wl_state = wl_state_data + wl_state_crc
wl_state_sector_padding: bytes = (FATDefaults.WL_SECTOR_SIZE - WLFATFS.WL_STATE_HEADER_SIZE) * FULL_BYTE
wl_state_sectors: bytes = (wl_state + wl_state_sector_padding + (self.wl_state_sectors - 1) * FATDefaults.WL_SECTOR_SIZE * FULL_BYTE)
wl_state_sectors: bytes = (
wl_state + wl_state_sector_padding + (self.wl_state_sectors - 1) * FATDefaults.WL_SECTOR_SIZE * FULL_BYTE
)
# add 2 extra state-preservation sectors in 'Safe' mode
if self.wl_mode is not None and self.wl_mode == 'safe':
wl_safe_dummy_sec: bytes = (WLFATFS.WL_SAFE_MODE_DUMP_SECTORS * FATDefaults.WL_SECTOR_SIZE * FULL_BYTE)
wl_safe_dummy_sec: bytes = WLFATFS.WL_SAFE_MODE_DUMP_SECTORS * FATDefaults.WL_SECTOR_SIZE * FULL_BYTE
self.fatfs_binary_image += wl_safe_dummy_sec
self.fatfs_binary_image += (WLFATFS.WL_STATE_COPY_COUNT * wl_state_sectors)
self.fatfs_binary_image += WLFATFS.WL_STATE_COPY_COUNT * wl_state_sectors
def wl_write_filesystem(self, output_path: str) -> None:
if not self._initialized: