[ion/device] Fix Flash::SectorAtAddress to handle random values

This commit is contained in:
Romain Goyet
2018-10-19 10:42:58 +02:00
committed by LeaNumworks
parent fc80180d46
commit c934531ced

View File

@@ -54,13 +54,14 @@ static void typed_memcpy(uint8_t * source, uint8_t * destination, size_t length)
}
int SectorAtAddress(uint32_t address) {
uint32_t sectorAddresses[NumberOfSectors] = {
uint32_t sectorAddresses[NumberOfSectors+1] = {
0x08000000, 0x08004000, 0x08008000, 0x0800C000,
0x08010000, 0x08020000, 0x08040000, 0x08060000,
0x08080000, 0x080A0000, 0x080C0000, 0x080E0000
0x08080000, 0x080A0000, 0x080C0000, 0x080E0000,
0x08100000
};
for (int i=0; i<NumberOfSectors; i++) {
if (sectorAddresses[i] == address) {
if (address >= sectorAddresses[i] && address < sectorAddresses[i+1]) {
return i;
}
}