X-Git-Url: http://git.linex4red.de/pub/lufa.git/blobdiff_plain/06f53eed83b4ad639698aeb9bcc1a3702e2ac7c4..refs/heads/ProMicro:/Bootloaders/MassStorage/BootloaderAPI.c?ds=inline diff --git a/Bootloaders/MassStorage/BootloaderAPI.c b/Bootloaders/MassStorage/BootloaderAPI.c index 5198ea7f0..d1fb62585 100644 --- a/Bootloaders/MassStorage/BootloaderAPI.c +++ b/Bootloaders/MassStorage/BootloaderAPI.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2017. + Copyright (C) Dean Camera, 2021. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2017 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2021 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -35,8 +35,25 @@ #include "BootloaderAPI.h" +bool IsPageAddressValid(const uint32_t Address) +{ + /* Determine if the given page address is correctly aligned to the + start of a flash page. + + Note that this is not static, as we need to force it into the + AUX_BOOT_SECTION on small flash devices to save space. + */ + + 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 +64,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);