From b5fc7f10f3015d2d265d4421f813d32fa1ead5f6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 25 Jun 2018 10:28:40 +1000 Subject: [PATCH] AP_Bootloader: added flash size limiting on old CPUs --- Tools/AP_Bootloader/AP_Bootloader.cpp | 3 +++ Tools/AP_Bootloader/bl_protocol.cpp | 3 +++ Tools/AP_Bootloader/mcu_f4.h | 10 +++++----- Tools/AP_Bootloader/support.cpp | 20 ++++++++++++++++++++ Tools/AP_Bootloader/support.h | 3 +++ 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Tools/AP_Bootloader/AP_Bootloader.cpp b/Tools/AP_Bootloader/AP_Bootloader.cpp index 63e6385bdc..d3b3ac2eea 100644 --- a/Tools/AP_Bootloader/AP_Bootloader.cpp +++ b/Tools/AP_Bootloader/AP_Bootloader.cpp @@ -48,6 +48,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; + if (BOARD_FLASH_SIZE > 1024 && check_limit_flash_1M()) { + board_info.fw_size = (1024 - FLASH_BOOTLOADER_LOAD_KB)*1024; + } flash_init(); diff --git a/Tools/AP_Bootloader/bl_protocol.cpp b/Tools/AP_Bootloader/bl_protocol.cpp index cef0b5a2c8..148e7ad60f 100644 --- a/Tools/AP_Bootloader/bl_protocol.cpp +++ b/Tools/AP_Bootloader/bl_protocol.cpp @@ -740,6 +740,9 @@ bootloader(unsigned timeout) continue; } + // we got a good command on this port, lock to the port + lock_bl_port(); + // we got a command worth syncing, so kill the timeout because // we are probably talking to the uploader timeout = 0; diff --git a/Tools/AP_Bootloader/mcu_f4.h b/Tools/AP_Bootloader/mcu_f4.h index c3ebe061e1..e189942568 100644 --- a/Tools/AP_Bootloader/mcu_f4.h +++ b/Tools/AP_Bootloader/mcu_f4.h @@ -29,12 +29,12 @@ const mcu_des_t mcu_descriptions[] = { }; const mcu_rev_t silicon_revs[] = { - {MCU_REV_STM32F4_REV_3, '3'}, /* Revision 3 */ + {MCU_REV_STM32F4_REV_3, '3', false}, /* Revision 3 */ - {MCU_REV_STM32F4_REV_A, 'A'}, /* Revision A */ // FIRST_BAD_SILICON_OFFSET (place good ones above this line and update the FIRST_BAD_SILICON_OFFSET accordingly) - {MCU_REV_STM32F4_REV_Z, 'Z'}, /* Revision Z */ - {MCU_REV_STM32F4_REV_Y, 'Y'}, /* Revision Y */ - {MCU_REV_STM32F4_REV_1, '1'}, /* Revision 1 */ + {MCU_REV_STM32F4_REV_A, 'A', true}, /* Revision A */ + {MCU_REV_STM32F4_REV_Z, 'Z', true}, /* Revision Z */ + {MCU_REV_STM32F4_REV_Y, 'Y', true}, /* Revision Y */ + {MCU_REV_STM32F4_REV_1, '1', true}, /* Revision 1 */ }; #endif // STM32F4 diff --git a/Tools/AP_Bootloader/support.cpp b/Tools/AP_Bootloader/support.cpp index 86772257df..064ae19113 100644 --- a/Tools/AP_Bootloader/support.cpp +++ b/Tools/AP_Bootloader/support.cpp @@ -159,6 +159,22 @@ uint32_t get_mcu_desc(uint32_t max, uint8_t *revstr) return strp - revstr; } +/* + see if we should limit flash to 1M on devices with older revisions + */ +bool check_limit_flash_1M(void) +{ + uint32_t idcode = (*(uint32_t *)DBGMCU_BASE); + uint16_t revid = ((idcode & REVID_MASK) >> 16); + + for (int i = 0; i < ARRAY_SIZE_SIMPLE(silicon_revs); i++) { + if (silicon_revs[i].revid == revid) { + return silicon_revs[i].limit_flash_size_1M; + } + } + return false; +} + void led_on(unsigned led) { #ifdef HAL_GPIO_PIN_LED_BOOTLOADER @@ -251,3 +267,7 @@ int strcmp(const char *s1, const char *s2) } return (*s1 - *s2); } + +void lock_bl_port(void) +{ +} diff --git a/Tools/AP_Bootloader/support.h b/Tools/AP_Bootloader/support.h index be153bde2e..1e422c5c81 100644 --- a/Tools/AP_Bootloader/support.h +++ b/Tools/AP_Bootloader/support.h @@ -26,9 +26,11 @@ void flash_func_erase_sector(uint32_t sector); uint32_t flash_func_read_otp(uint32_t idx); uint32_t flash_func_read_sn(uint32_t idx); void flash_set_keep_unlocked(bool); +void lock_bl_port(void); uint32_t get_mcu_id(void); uint32_t get_mcu_desc(uint32_t len, uint8_t *buf); +bool check_limit_flash_1M(void); void led_on(unsigned led); void led_off(unsigned led); @@ -49,4 +51,5 @@ typedef struct mcu_des_t { typedef struct mcu_rev_t { uint16_t revid; char rev; + bool limit_flash_size_1M; } mcu_rev_t;