don't let openblt erase itself (#401)

This commit is contained in:
Matthew Kennedy 2024-04-14 13:31:39 -05:00 committed by GitHub
parent 5b23965152
commit 43d4f4f92b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 3 deletions

View File

@ -21,16 +21,32 @@ blt_addr FlashGetUserProgBaseAddress() {
}
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data) {
return (FLASH_RETURN_SUCCESS == intFlashWrite(addr, (const char*)data, len)) ? BLT_TRUE : BLT_FALSE;
// don't allow overwriting the bootloader
if (addr < FlashGetUserProgBaseAddress()) {
return BLT_FALSE;
}
return
(FLASH_RETURN_SUCCESS == intFlashWrite(addr, (const char*)data, len))
? BLT_TRUE
: BLT_FALSE;
}
blt_bool FlashErase(blt_addr addr, blt_int32u len) {
// don't allow erasing the bootloader
if (addr < FlashGetUserProgBaseAddress()) {
return BLT_FALSE;
}
if (intFlashIsErased(addr, len)) {
// Already blank, we can skip the expensive erase operation
return BLT_TRUE;
}
return (FLASH_RETURN_SUCCESS == intFlashErase(addr, len)) ? BLT_TRUE : BLT_FALSE;
return
(FLASH_RETURN_SUCCESS == intFlashErase(addr, len))
? BLT_TRUE
: BLT_FALSE;
}
blt_bool FlashDone() {
@ -66,5 +82,5 @@ blt_bool FlashVerifyChecksum() {
uint32_t storedChecksum = *reinterpret_cast<uint32_t*>(start + checksumOffset);
return calcChecksum == storedChecksum ? BLT_TRUE : BLT_FALSE;
return (calcChecksum == storedChecksum) ? BLT_TRUE : BLT_FALSE;
}