diff --git a/Tools/AP_Bootloader/AP_Bootloader.cpp b/Tools/AP_Bootloader/AP_Bootloader.cpp index 41a1c4ad7b..78eeff4ac9 100644 --- a/Tools/AP_Bootloader/AP_Bootloader.cpp +++ b/Tools/AP_Bootloader/AP_Bootloader.cpp @@ -51,9 +51,9 @@ int main(void) { board_info.board_type = APJ_BOARD_ID; board_info.board_rev = 0; - board_info.fw_size = (BOARD_FLASH_SIZE - FLASH_BOOTLOADER_LOAD_KB)*1024; + board_info.fw_size = (BOARD_FLASH_SIZE - (FLASH_BOOTLOADER_LOAD_KB + FLASH_RESERVE_END_KB))*1024; if (BOARD_FLASH_SIZE > 1024 && check_limit_flash_1M()) { - board_info.fw_size = (1024 - FLASH_BOOTLOADER_LOAD_KB)*1024; + board_info.fw_size = (1024 - FLASH_BOOTLOADER_LOAD_KB)*1024; } bool try_boot = false; diff --git a/Tools/AP_Bootloader/support.cpp b/Tools/AP_Bootloader/support.cpp index eef6cb941e..f37b413b77 100644 --- a/Tools/AP_Bootloader/support.cpp +++ b/Tools/AP_Bootloader/support.cpp @@ -80,11 +80,22 @@ void flash_init(void) { uint32_t reserved = 0; num_pages = stm32_flash_getnumpages(); + /* + advance flash_base_page to account for FLASH_BOOTLOADER_LOAD_KB + */ while (reserved < FLASH_BOOTLOADER_LOAD_KB * 1024U && flash_base_page < num_pages) { reserved += stm32_flash_getpagesize(flash_base_page); flash_base_page++; } + /* + reduce num_pages to account for FLASH_RESERVE_END_KB + */ + reserved = 0; + while (reserved < FLASH_RESERVE_END_KB * 1024U) { + reserved += stm32_flash_getpagesize(num_pages-1); + num_pages--; + } } void flash_set_keep_unlocked(bool set)