diff --git a/cpu/stm32/Makefile.include b/cpu/stm32/Makefile.include index 86bc23bcfd..27f528be1e 100644 --- a/cpu/stm32/Makefile.include +++ b/cpu/stm32/Makefile.include @@ -4,7 +4,7 @@ CFLAGS += -DCPU_FAM_$(call uppercase_and_underscore,$(CPU_FAM)) LINKER_SCRIPT ?= stm32.ld # Include riotboot specific variables --include $(RIOTCPU)/stm32/$(CPU_FAM)_riotboot.mk +include $(RIOTCPU)/stm32/stm32_riotboot.mk # Compute ROM_LEN and RAM_LEN include $(RIOTCPU)/stm32/stm32_mem_lengths.mk diff --git a/cpu/stm32/stm32_riotboot.mk b/cpu/stm32/stm32_riotboot.mk new file mode 100644 index 0000000000..b04d8f9a75 --- /dev/null +++ b/cpu/stm32/stm32_riotboot.mk @@ -0,0 +1,45 @@ +ifneq (,$(filter $(CPU_FAM),stm32f2 stm32f4 stm32f7)) + # STM32F2/4/7 uses sectors instead of pages, where the minimum sector length is 16KB + # or 32KB (the first sector), depending on the CPU_MODEL. Therefore RIOTBOOT_LEN must + # be 16KB or 32kB to cover a whole sector. + ifneq (,$(filter $(CPU_FAM),stm32f2 stm32f4)) + RIOTBOOT_LEN ?= 0x4000 + else ifneq (,$(filter stm32f722ze,$(CPU_MODEL))) + RIOTBOOT_LEN ?= 0x4000 + else # others stm32f7 + RIOTBOOT_LEN ?= 0x8000 + endif + + # CPU_IRQ_NUMOF for STM32F2 boards is < 81+16 so (97*4 bytes = 388 bytes ~= 0x200) + # CPU_IRQ_NUMOF for STM32F4 boards is < 102+16 so (118*4 bytes = 472 bytes ~= 0x200) + # CPU_IRQ_NUMOF for STM32F7 boards is < 110+16 so (126*4 bytes = 504 bytes ~= 0x200) + # RIOTBOOT_HDR_LEN can be set to 0x200. + # Details on alignment requirements for M3 in `cpu/cortexm_common/Makefile.include`. + RIOTBOOT_HDR_LEN ?= 0x200 + + # Sectors don't have the same length. Per bank there can be up to 12 sectors. The + # first 4 sectors are 16kB long, the 5th is 64kB and the remaining 7 are 128kB. + # Since flash can only be erased by sector, slots can't overlap over sectors. + # The most efficient layout comes from removing RIOTBOOT_LEN twice, once at the + # start of the flash for the bootloader, and a second time at the end of the + # flash, to get evenly sized and distributed slots. + SLOT0_LEN ?= $(shell printf "0x%x" $$((($(ROM_LEN:%K=%*1024)-2*$(RIOTBOOT_LEN)) / $(NUM_SLOTS)))) + SLOT1_LEN ?= $(SLOT0_LEN) +else ifeq (stm32l4,$(CPU_FAM)) + # "The Vector table must be naturally aligned to a power of two whose alignment + # value is greater than or equal to number of Exceptions supported x 4" + # CPU_IRQ_NUMOFF for stm32l4 boards is < 91+16 so (107*4 bytes = 428 bytes ~= 0x200) + # RIOTBOOT_HDR_LEN can be set to 0x200 + RIOTBOOT_HDR_LEN ?= 0x200 +else ifeq (stm32wb,$(CPU_FAM)) + # "The Vector table must be naturally aligned to a power of two whose alignment + # value is greater than or equal to number of Exceptions supported x 4" + # CPU_IRQ_NUMOFF for stm32l4 boards is < 91+16 so (107*4 bytes = 428 bytes ~= 0x200) + # RIOTBOOT_HDR_LEN can be set to 0x200 + RIOTBOOT_HDR_LEN ?= 0x200 + + # Slot size is determined by "((total_flash_size - RIOTBOOT_LEN) / 2)". + # If RIOTBOOT_LEN uses an odd number of flashpages, the remainder of the + # flash cannot be divided by two slots while staying FLASHPAGE_SIZE aligned. + RIOTBOOT_LEN ?= 0x2000 +endif diff --git a/cpu/stm32/stm32f2_riotboot.mk b/cpu/stm32/stm32f2_riotboot.mk deleted file mode 100644 index 60cde2e60c..0000000000 --- a/cpu/stm32/stm32f2_riotboot.mk +++ /dev/null @@ -1,17 +0,0 @@ -# STM32F2 uses sectors instead of pages, where the minimum sector length is 16KB -# (the first sector), therefore RIOTBOOT_LEN must be 16KB to cover a whole sector. -RIOTBOOT_LEN ?= 0x4000 - -# CPU_IRQ_NUMOF for STM32F2 boards is < 81+16 so (97*4 bytes = 388 bytes ~= 0x200) -# RIOTBOOT_HDR_LEN can be set to 0x200. -# Details on alignment requirements for M3 in `cpu/cortexm_common/Makefile.include`. -RIOTBOOT_HDR_LEN ?= 0x200 - -# Sectors don't have the same length. Per bank there can be up to 12 sectors. The -# first 4 sectors are 16kB long, the 5th is 64kB and the remaining 7 are 128kB. -# Since flash can only be erased by sector, slots can't overlap over sectors. -# The most efficient layout comes from removing RIOTBOOT_LEN twice, once at the -# start of the flash for the bootloader, and a second time at the end of the -# flash, to get evenly sized and distributed slots. -SLOT0_LEN ?= $(shell printf "0x%x" $$((($(ROM_LEN:%K=%*1024)-2*$(RIOTBOOT_LEN)) / $(NUM_SLOTS)))) -SLOT1_LEN ?= $(SLOT0_LEN) diff --git a/cpu/stm32/stm32f4_riotboot.mk b/cpu/stm32/stm32f4_riotboot.mk deleted file mode 100644 index 792613e75d..0000000000 --- a/cpu/stm32/stm32f4_riotboot.mk +++ /dev/null @@ -1,16 +0,0 @@ -# STM32F4 uses sectors instead of pages, where the minimum sector length is 16KB -# (the first sector), therefore RIOTBOOT_LEN must be 16KB to cover a whole sector. -RIOTBOOT_LEN ?= 0x4000 - -# CPU_IRQ_NUMOF for STM32F4 boards is < 102+16 so (118*4 bytes = 472 bytes ~= 0x200) -# RIOTBOOT_HDR_LEN can be set to 0x200. -# Details on alignment requirements for M4 in `cpu/cortexm_common/Makefile.include`. -RIOTBOOT_HDR_LEN ?= 0x200 - -# Sectors don't have the same length. Per bank there can be up to 12 sectors. The -# first 4 sectors are 16kB long, the 5th is 64kB and the remaining 7 are 128kB. -# Since flash can only be erased by sector, slots can't overlap over sectors. -# RIOTBOOT_LEN is removed twice, once at the start of the flash for the bootloader, -# and a second time at the end of the flash, to get evenly sized and distributed slots. -SLOT0_LEN ?= $(shell printf "0x%x" $$((($(ROM_LEN:%K=%*1024)-2*$(RIOTBOOT_LEN)) / $(NUM_SLOTS)))) -SLOT1_LEN ?= $(SLOT0_LEN) diff --git a/cpu/stm32/stm32f7_riotboot.mk b/cpu/stm32/stm32f7_riotboot.mk deleted file mode 100644 index 3ff6b483d2..0000000000 --- a/cpu/stm32/stm32f7_riotboot.mk +++ /dev/null @@ -1,22 +0,0 @@ -# STM32F7 uses sectors instead of pages, where the minimum sector length is 16KB or -# 32kB (the first sector), depending on the CPU_MODEL. Therefore RIOTBOOT_LEN must -# be 16KB or 32kB to cover a whole sector. -ifneq (,$(filter stm32f722ze ,$(CPU_MODEL))) - RIOTBOOT_LEN ?= 0x4000 -else - RIOTBOOT_LEN ?= 0x8000 -endif - -# CPU_IRQ_NUMOF for STM32F7 boards is < 110+16 so (126*4 bytes = 504 bytes ~= 0x200) -# RIOTBOOT_HDR_LEN can be set to 0x200. -# Details on alignment requirements for M4 in `cpu/cortexm_common/Makefile.include`. -RIOTBOOT_HDR_LEN ?= 0x200 - -# Sectors don't have the same length. Per bank there can be up to 12 sectors. If -# the smallest sector size is 16kb the first 4 sectors are 16kB long, the 5th is -# 64kB and the remaining 7 are 128kB. Since flash can only be erased by sector, -# slots can't overlap over sectors. -# RIOTBOOT_LEN is removed twice, once at the start of the flash for the bootloader, -# and a second time at the end of the flash, to get evenly sized and distributed slots. -SLOT0_LEN ?= $(shell printf "0x%x" $$((($(ROM_LEN:%K=%*1024)-2*$(RIOTBOOT_LEN)) / $(NUM_SLOTS)))) -SLOT1_LEN ?= $(SLOT0_LEN) diff --git a/cpu/stm32/stm32l4_riotboot.mk b/cpu/stm32/stm32l4_riotboot.mk deleted file mode 100644 index 53122c6354..0000000000 --- a/cpu/stm32/stm32l4_riotboot.mk +++ /dev/null @@ -1,5 +0,0 @@ -# "The Vector table must be naturally aligned to a power of two whose alignment -# value is greater than or equal to number of Exceptions supported x 4" -# CPU_IRQ_NUMOFF for stm32l4 boards is < 91+16 so (107*4 bytes = 428 bytes ~= 0x200) -# RIOTBOOT_HDR_LEN can be set to 0x200 -RIOTBOOT_HDR_LEN ?= 0x200 diff --git a/cpu/stm32/stm32wb_riotboot.mk b/cpu/stm32/stm32wb_riotboot.mk deleted file mode 100644 index b35c78ffb3..0000000000 --- a/cpu/stm32/stm32wb_riotboot.mk +++ /dev/null @@ -1,10 +0,0 @@ -# "The Vector table must be naturally aligned to a power of two whose alignment -# value is greater than or equal to number of Exceptions supported x 4" -# CPU_IRQ_NUMOFF for stm32l4 boards is < 91+16 so (107*4 bytes = 428 bytes ~= 0x200) -# RIOTBOOT_HDR_LEN can be set to 0x200 -RIOTBOOT_HDR_LEN ?= 0x200 - -# Slot size is determined by "((total_flash_size - RIOTBOOT_LEN) / 2)". -# If RIOTBOOT_LEN uses an odd number of flashpages, the remainder of the -# flash cannot be divided by two slots while staying FLASHPAGE_SIZE aligned. -RIOTBOOT_LEN ?= 0x2000