mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-27 11:31:13 +00:00
Review changes
* subtract WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT after getting last_sector * don't pass value beyond desc->sectors_count to flashGetSectorOffset * add checks if not enough flash sectors are available
This commit is contained in:
parent
3f0b5d3fd1
commit
d0002d3f24
@ -83,13 +83,21 @@ bool backing_store_init(void) {
|
||||
#else // defined(WEAR_LEVELING_EFL_FIRST_SECTOR)
|
||||
|
||||
// Work out how many sectors we want to use, working backwards from the end of the flash
|
||||
flash_sector_t last_sector = desc->sectors_count - WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT;
|
||||
flash_sector_t last_sector = desc->sectors_count;
|
||||
|
||||
// skip sectors that are past the actual flash size
|
||||
while (flashGetSectorOffset(flash, last_sector) >= flash_size) {
|
||||
last_sector--;
|
||||
while (flashGetSectorOffset(flash, last_sector - 1) >= flash_size) {
|
||||
if (--last_sector == 0) {
|
||||
chSysHalt("No sector in available flash range");
|
||||
}
|
||||
}
|
||||
|
||||
if (WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT >= last_sector) {
|
||||
chSysHalt("Last sector intended to be used with wear_leveling is beyond available flash descriptor range");
|
||||
}
|
||||
|
||||
last_sector -= WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT;
|
||||
|
||||
for (flash_sector_t i = 0; i < last_sector; ++i) {
|
||||
first_sector = last_sector - i - 1;
|
||||
counter += flashGetSectorSize(flash, first_sector);
|
||||
@ -100,6 +108,10 @@ bool backing_store_init(void) {
|
||||
}
|
||||
}
|
||||
|
||||
if (counter < WEAR_LEVELING_BACKING_SIZE) {
|
||||
chSysHalt("Not enough flash is available for the requested wear_leveling size");
|
||||
}
|
||||
|
||||
#endif // defined(WEAR_LEVELING_EFL_FIRST_SECTOR)
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user