Browse Source

AP_Bootloader: added flash size limiting on old CPUs

master
Andrew Tridgell 7 years ago
parent
commit
b5fc7f10f3
  1. 3
      Tools/AP_Bootloader/AP_Bootloader.cpp
  2. 3
      Tools/AP_Bootloader/bl_protocol.cpp
  3. 10
      Tools/AP_Bootloader/mcu_f4.h
  4. 20
      Tools/AP_Bootloader/support.cpp
  5. 3
      Tools/AP_Bootloader/support.h

3
Tools/AP_Bootloader/AP_Bootloader.cpp

@ -48,6 +48,9 @@ int main(void) @@ -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();

3
Tools/AP_Bootloader/bl_protocol.cpp

@ -740,6 +740,9 @@ bootloader(unsigned timeout) @@ -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;

10
Tools/AP_Bootloader/mcu_f4.h

@ -29,12 +29,12 @@ const mcu_des_t mcu_descriptions[] = { @@ -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

20
Tools/AP_Bootloader/support.cpp

@ -159,6 +159,22 @@ uint32_t get_mcu_desc(uint32_t max, uint8_t *revstr) @@ -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) @@ -251,3 +267,7 @@ int strcmp(const char *s1, const char *s2)
}
return (*s1 - *s2);
}
void lock_bl_port(void)
{
}

3
Tools/AP_Bootloader/support.h

@ -26,9 +26,11 @@ void flash_func_erase_sector(uint32_t sector); @@ -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 { @@ -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;

Loading…
Cancel
Save