projects
/
pub
/
USBasp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed bootloaders accepting flash writes to the bootloader region (thanks to NicoHood).
[pub/USBasp.git]
/
Bootloaders
/
HID
/
BootloaderHID.c
diff --git
a/Bootloaders/HID/BootloaderHID.c
b/Bootloaders/HID/BootloaderHID.c
index
c21bf56
..
e5b7d32
100644
(file)
--- a/
Bootloaders/HID/BootloaderHID.c
+++ b/
Bootloaders/HID/BootloaderHID.c
@@
-152,6
+152,10
@@
void EVENT_USB_Device_ControlRequest(void)
uint16_t PageAddress = Endpoint_Read_16_LE();
#endif
uint16_t PageAddress = Endpoint_Read_16_LE();
#endif
+ /* Determine if the given page address is correctly aligned to the
+ start of a flash page. */
+ bool PageAddressIsAligned = !(PageAddress & (SPM_PAGESIZE - 1));
+
/* Check if the command is a program page command, or a start application command */
#if (FLASHEND > 0xFFFF)
if ((uint16_t)(PageAddress >> 8) == COMMAND_STARTAPPLICATION)
/* Check if the command is a program page command, or a start application command */
#if (FLASHEND > 0xFFFF)
if ((uint16_t)(PageAddress >> 8) == COMMAND_STARTAPPLICATION)
@@
-161,7
+165,7
@@
void EVENT_USB_Device_ControlRequest(void)
{
RunBootloader = false;
}
{
RunBootloader = false;
}
- else if (
PageAddress < BOOT_START_ADDR
)
+ else if (
(PageAddress < BOOT_START_ADDR) && PageAddressIsAligned
)
{
/* Erase the given FLASH page, ready to be programmed */
ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
{
/* Erase the given FLASH page, ready to be programmed */
ATOMIC_BLOCK(ATOMIC_RESTORESTATE)