diff --git a/firmware/bootloader/openblt_chibios/openblt_flash.cpp b/firmware/bootloader/openblt_chibios/openblt_flash.cpp index 4a498f9e38..1e6084bf62 100644 --- a/firmware/bootloader/openblt_chibios/openblt_flash.cpp +++ b/firmware/bootloader/openblt_chibios/openblt_flash.cpp @@ -19,12 +19,22 @@ blt_addr FlashGetUserProgBaseAddress() { } blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data) { + // 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; return BLT_TRUE; } 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)) { return (FLASH_RETURN_SUCCESS == intFlashErase(addr, len)) ? BLT_TRUE : BLT_FALSE; }