HAL_ChibiOS: ensure we don't overflow bootloader area

this modifies the ld script to use the maximum size available for the
bootloader, so we can't accidentially grow the bootloader beyond its
max size
This commit is contained in:
Andrew Tridgell 2019-05-06 10:14:18 +10:00
parent 3cbbc33766
commit 2b0a30a2c5
33 changed files with 39 additions and 33 deletions

View File

@ -24,7 +24,7 @@ FLASH_SIZE_KB 2048
FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 32
FLASH_BOOTLOADER_LOAD_KB 32
# start with PE3 low
undef PE3

View File

@ -24,7 +24,7 @@ FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
# the H743 has 128k sectors
define FLASH_BOOTLOADER_LOAD_KB 128
FLASH_BOOTLOADER_LOAD_KB 128
define HAL_LED_ON 0

View File

@ -63,7 +63,7 @@ PA14 JTCK-SWCLK SWD
FLASH_RESERVE_START_KB 0
# start on 4th sector (1st sector for bootloader, 2 for extra storage)
define FLASH_BOOTLOADER_LOAD_KB 96
FLASH_BOOTLOADER_LOAD_KB 96
define HAL_USE_EMPTY_STORAGE 1
define HAL_STORAGE_SIZE 16384

View File

@ -20,7 +20,7 @@ STM32_ST_USE_TIMER 5
FLASH_SIZE_KB 2048
# location of application code
define FLASH_BOOTLOADER_LOAD_KB 16
FLASH_BOOTLOADER_LOAD_KB 16
# bootloader loads at start of flash
FLASH_RESERVE_START_KB 0

View File

@ -17,7 +17,7 @@ FLASH_RESERVE_START_KB 0
FLASH_SIZE_KB 1024
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
define HAL_STORAGE_SIZE 15360
define STORAGE_FLASH_PAGE 1

View File

@ -42,4 +42,4 @@ define HAL_USE_EMPTY_STORAGE 1
define HAL_STORAGE_SIZE 16384
# location of application code
define FLASH_BOOTLOADER_LOAD_KB 16
FLASH_BOOTLOADER_LOAD_KB 16

View File

@ -20,7 +20,7 @@ PB5 LED_BOOTLOADER OUTPUT LOW
define HAL_LED_ON 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
# board voltage
STM32_VDD 330U

View File

@ -25,7 +25,7 @@ FLASH_SIZE_KB 1024
FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 96
FLASH_BOOTLOADER_LOAD_KB 96
# board voltage
STM32_VDD 330U

View File

@ -17,7 +17,7 @@ FLASH_RESERVE_START_KB 0
FLASH_SIZE_KB 1024
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
define HAL_STORAGE_SIZE 15360
define STORAGE_FLASH_PAGE 1

View File

@ -22,7 +22,7 @@ PA14 LED_ACTIVITY OUTPUT LOW
define HAL_LED_ON 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
# board voltage
STM32_VDD 330U

View File

@ -20,7 +20,7 @@ FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
# the H743 has 128k sectors
define FLASH_BOOTLOADER_LOAD_KB 128
FLASH_BOOTLOADER_LOAD_KB 128
# board voltage
STM32_VDD 330U

View File

@ -25,7 +25,7 @@ FLASH_SIZE_KB 1024
FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 96
FLASH_BOOTLOADER_LOAD_KB 96
# board voltage
STM32_VDD 330U

View File

@ -24,7 +24,7 @@ PA8 LED_BOOTLOADER OUTPUT LOW
define HAL_LED_ON 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
# board voltage
STM32_VDD 330U

View File

@ -24,7 +24,7 @@ FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
# the H743 has 128k sectors
define FLASH_BOOTLOADER_LOAD_KB 128
FLASH_BOOTLOADER_LOAD_KB 128
PB1 LED_RED OUTPUT LOW # red
PC6 LED_ACTIVITY OUTPUT LOW # green

View File

@ -24,7 +24,7 @@ FLASH_SIZE_KB 2048
FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 32
FLASH_BOOTLOADER_LOAD_KB 32
# enabling PE3 on the Colibri causes it to reset on startup
undef PE3

View File

@ -31,7 +31,7 @@ FLASH_USE_MAX_KB 16
FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 16
FLASH_BOOTLOADER_LOAD_KB 16
# ChibiOS system timer
STM32_ST_USE_TIMER 5

View File

@ -31,7 +31,7 @@ FLASH_USE_MAX_KB 16
FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 16
FLASH_BOOTLOADER_LOAD_KB 16
# ChibiOS system timer
STM32_ST_USE_TIMER 5

View File

@ -31,7 +31,7 @@ FLASH_USE_MAX_KB 16
FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 16
FLASH_BOOTLOADER_LOAD_KB 16
# ChibiOS system timer
STM32_ST_USE_TIMER 5

View File

@ -31,7 +31,7 @@ FLASH_USE_MAX_KB 16
FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 16
FLASH_BOOTLOADER_LOAD_KB 16
# ChibiOS system timer
STM32_ST_USE_TIMER 5

View File

@ -31,7 +31,7 @@ FLASH_USE_MAX_KB 16
FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
# ChibiOS system timer
STM32_ST_USE_TIMER 5

View File

@ -24,7 +24,7 @@ PB5 LED_BOOTLOADER OUTPUT LOW
define HAL_LED_ON 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
# board voltage
STM32_VDD 330U

View File

@ -20,7 +20,7 @@ STM32_ST_USE_TIMER 5
FLASH_SIZE_KB 2048
# location of application code
define FLASH_BOOTLOADER_LOAD_KB 16
FLASH_BOOTLOADER_LOAD_KB 16
# bootloader loads at start of flash
FLASH_RESERVE_START_KB 0

View File

@ -43,7 +43,7 @@ PD6 USART2_RX USART2
define HAL_STORAGE_SIZE 16384
# location of application code
define FLASH_BOOTLOADER_LOAD_KB 16
FLASH_BOOTLOADER_LOAD_KB 16
# bootloader loads at start of flash
FLASH_RESERVE_START_KB 0

View File

@ -24,7 +24,7 @@ FLASH_SIZE_KB 2048
FLASH_RESERVE_START_KB 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 32
FLASH_BOOTLOADER_LOAD_KB 32
PC6 LED_BOOTLOADER OUTPUT HIGH
PC7 LED_ACTIVITY OUTPUT HIGH

View File

@ -70,7 +70,7 @@ PA14 JTCK-SWCLK SWD
FLASH_RESERVE_START_KB 0
# start on 4th sector (1st sector for bootloader, 2 for extra storage)
define FLASH_BOOTLOADER_LOAD_KB 96
FLASH_BOOTLOADER_LOAD_KB 96
define HAL_USE_EMPTY_STORAGE 1
define HAL_STORAGE_SIZE 16384

View File

@ -23,7 +23,7 @@ STM32_VDD 330U
FLASH_SIZE_KB 2048
# location of application code
define FLASH_BOOTLOADER_LOAD_KB 16
FLASH_BOOTLOADER_LOAD_KB 16
# bootloader loads at start of flash
FLASH_RESERVE_START_KB 0

View File

@ -25,7 +25,7 @@ PE12 LED_ACTIVITY OUTPUT LOW
define HAL_LED_ON 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 16
FLASH_BOOTLOADER_LOAD_KB 16
# board voltage
STM32_VDD 330U

View File

@ -24,7 +24,7 @@ PB5 LED_BOOTLOADER OUTPUT LOW
define HAL_LED_ON 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
# board voltage
STM32_VDD 330U

View File

@ -24,7 +24,7 @@ PA8 LED_BOOTLOADER OUTPUT LOW
define HAL_LED_ON 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
# board voltage
STM32_VDD 330U

View File

@ -25,7 +25,7 @@ PB4 LED_ACTIVITY OUTPUT LOW
define HAL_LED_ON 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
# board voltage
STM32_VDD 330U

View File

@ -573,6 +573,8 @@ def write_mcu_config(f):
'FLASH_RESERVE_START_KB', default=16, type=int)
f.write('\n// location of loaded firmware\n')
f.write('#define FLASH_LOAD_ADDRESS 0x%08x\n' % (0x08000000 + flash_reserve_start*1024))
if args.bootloader:
f.write('#define FLASH_BOOTLOADER_LOAD_KB %u\n' % get_config('FLASH_BOOTLOADER_LOAD_KB', type=int))
f.write('\n')
ram_map = get_mcu_config('RAM_MAP', True)
@ -657,7 +659,11 @@ def write_ldscript(fname):
ram_map = get_mcu_config('RAM_MAP', True)
flash_base = 0x08000000 + flash_reserve_start * 1024
flash_length = flash_size - (flash_reserve_start + flash_reserve_end)
if not args.bootloader:
flash_length = flash_size - (flash_reserve_start + flash_reserve_end)
else:
flash_length = get_config('FLASH_BOOTLOADER_LOAD_KB', type=int)
print("Generating ldscript.ld")
f = open(fname, 'w')

View File

@ -25,7 +25,7 @@ PB4 LED_ACTIVITY OUTPUT LOW
define HAL_LED_ON 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
# board voltage
STM32_VDD 330U

View File

@ -24,7 +24,7 @@ PB5 LED_BOOTLOADER OUTPUT LOW
define HAL_LED_ON 0
# the location where the bootloader will put the firmware
define FLASH_BOOTLOADER_LOAD_KB 64
FLASH_BOOTLOADER_LOAD_KB 64
# board voltage
STM32_VDD 330U