X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/ad9225bdd34230e13333be5d4c29e4f96abc9b2b..1e9e7bc8b88af32f466f7438a06fb8dc96b3035d:/Bootloaders/Printer/BootloaderAPI.c diff --git a/Bootloaders/Printer/BootloaderAPI.c b/Bootloaders/Printer/BootloaderAPI.c index 5e8083ed3..c1e76d3bd 100644 --- a/Bootloaders/Printer/BootloaderAPI.c +++ b/Bootloaders/Printer/BootloaderAPI.c @@ -35,8 +35,20 @@ #include "BootloaderAPI.h" +static bool IsPageAddressValid(const uint32_t Address) +{ + /* Determine if the given page address is correctly aligned to the + start of a flash page. */ + bool PageAddressIsAligned = !(Address & (SPM_PAGESIZE - 1)); + + return (Address < BOOT_START_ADDR) && PageAddressIsAligned; +} + void BootloaderAPI_ErasePage(const uint32_t Address) { + if (! IsPageAddressValid(Address)) + return; + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { boot_page_erase_safe(Address); @@ -47,6 +59,9 @@ void BootloaderAPI_ErasePage(const uint32_t Address) void BootloaderAPI_WritePage(const uint32_t Address) { + if (! IsPageAddressValid(Address)) + return; + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { boot_page_write_safe(Address);