| 1241 | return size; |
| 1242 | } |
| 1243 | bool load() |
| 1244 | { |
| 1245 | const uint8_t *flashEnd = reinterpret_cast<const uint8_t *>(EEPROM_ADDRESS_START) + EEPROM_SIZE_BYTES; |
| 1246 | const ConfigFooter &footer = *reinterpret_cast<const ConfigFooter *>(flashEnd - sizeof(ConfigFooter)); |
| 1247 | |
| 1248 | // Check for presence of magic value |
| 1249 | if (footer.magic != FOOTER_MAGIC) |
| 1250 | { |
| 1251 | printf("footer wrong %x != %x\r\n", footer.magic, FOOTER_MAGIC); |
| 1252 | return false; |
| 1253 | } |
| 1254 | |
| 1255 | // Check if dataSize exceeds the reserved space |
| 1256 | if (footer.dataSize + sizeof(ConfigFooter) > EEPROM_SIZE_BYTES) |
| 1257 | { |
| 1258 | return false; |
| 1259 | } |
| 1260 | |
| 1261 | const uint8_t *dataPtr = flashEnd - sizeof(ConfigFooter) - footer.dataSize; |
| 1262 | |
| 1263 | // Verify CRC32 hash |
| 1264 | if (CRC32::calculate(dataPtr, footer.dataSize) != footer.dataCrc) |
| 1265 | { |
| 1266 | return false; |
| 1267 | } |
| 1268 | |
| 1269 | return inner_load(footer.currentProfile, dataPtr, footer.dataSize, footer.mainSize, footer.auxSize); |
| 1270 | } |
| 1271 | |
| 1272 | void first_load() |
| 1273 | { |
no test coverage detected