X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/8802907ce274489690f8edf169454f750c8efe57..ba6d9c1a971db3c42bf0b054ebb64f72b3e3ddba:/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);