From d9db2584115055cf1b6f0797dcdb8c22c58838b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 13 Jun 2018 13:50:42 +0200 Subject: [PATCH 01/11] cortexm_common/ldscript: re-use _rom_offset variable name Inspired by kaspar030 version to removing the new _boot_offset variable. https://github.com/kaspar030/RIOT/blob/cbf324a66d0c925dd02eca290e17c350945e97b2/cpu/cortexm_common/ldscripts/cortexm.ld --- cpu/cortexm_common/ldscripts/cortexm.ld | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cpu/cortexm_common/ldscripts/cortexm.ld b/cpu/cortexm_common/ldscripts/cortexm.ld index cb19c10935..1c65d9f6d5 100644 --- a/cpu/cortexm_common/ldscripts/cortexm.ld +++ b/cpu/cortexm_common/ldscripts/cortexm.ld @@ -1,5 +1,6 @@ /* * Copyright (C) 2017 Inria + * 2018 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -14,16 +15,17 @@ * @brief Memory definitions for the Cortex-M family * * @author Francisco Acosta + * Gaëtan Harter * * @} */ -_boot_offset = DEFINED( _rom_offset ) ? _rom_offset : 0x0 ; +_rom_offset = DEFINED( _rom_offset ) ? _rom_offset : 0x0; MEMORY { - rom (rx) : ORIGIN = _rom_start_addr + _boot_offset, LENGTH = _rom_length - _boot_offset - ram (w!rx) : ORIGIN = _ram_start_addr, LENGTH = _ram_length + rom (rx) : ORIGIN = _rom_start_addr + _rom_offset, LENGTH = _rom_length - _rom_offset + ram (w!rx) : ORIGIN = _ram_start_addr, LENGTH = _ram_length } INCLUDE cortexm_base.ld From bbb1fbe0e3d3596afd0b7be98716743f023228d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Mon, 16 Jul 2018 08:54:01 +0200 Subject: [PATCH 02/11] cortexm_common_ldscript: add a test that checks if ROM_LEN is used Trigger an overflow by 1 byte to detect in ROM_LEN is indeed used. --- tests/cortexm_common_ldscript/Makefile | 37 ++++++++++++++++++++++++++ tests/cortexm_common_ldscript/main.c | 25 +++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 tests/cortexm_common_ldscript/Makefile create mode 100644 tests/cortexm_common_ldscript/main.c diff --git a/tests/cortexm_common_ldscript/Makefile b/tests/cortexm_common_ldscript/Makefile new file mode 100644 index 0000000000..e4a7c7c9f4 --- /dev/null +++ b/tests/cortexm_common_ldscript/Makefile @@ -0,0 +1,37 @@ +BOARD ?= samr21-xpro +include ../Makefile.tests_common + + +# Normally all boards using `cortexm_common/ldscripts/cortexm.ld` linkerscript +# Only tested on these ones for the moment +BOARD_WHITELIST += iotlab-a8-m3 +BOARD_WHITELIST += iotlab-m3 +BOARD_WHITELIST += samr21-xpro + +include $(RIOTBASE)/Makefile.include + + +# # # # # # # # # # # # # # # # # # # +# Compile time tests for ROM_OFFSET # +# # # # # # # # # # # # # # # # # # # + +COMPILE_TESTS = test-elffile-overflow + +all: compile-tests + +compile-tests: $(COMPILE_TESTS) +.PHONY: compile-tests $(COMPILE_TESTS) + + +# test-elffile-overflow depends on $(BINFILE) to prevent: +# * ROM_LEN to be passed to $(ELFFILE) generation +# * dummy error message of wc not finding the .bin file (ELFFILE is not enough) +test-elffile-overflow: $(BINFILE) _test-elffile-overflow-runtest + +.PHONY: _test-elffile-overflow-runtest +_test-elffile-overflow-runtest: ROM_LEN=$(firstword $(shell wc -c $(BINFILE)))-1+$(if $(ROM_OFFSET),$(ROM_OFFSET),0) +_test-elffile-overflow-runtest: $(BINFILE) + $(Q)echo -n "Test rom offset 1 byte overflow detection: " + $(Q)\ + { $(_LINK) -o /dev/null 2>&1 | grep -q "region \`rom' overflowed by 1 byte" ; } \ + && echo [OK] || { echo [ERROR] Compilation should have failed >&2; exit 1; } diff --git a/tests/cortexm_common_ldscript/main.c b/tests/cortexm_common_ldscript/main.c new file mode 100644 index 0000000000..59d2d4dcce --- /dev/null +++ b/tests/cortexm_common_ldscript/main.c @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2018 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for more + * details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Empty main file + * + * @author Gaëtan Harter + * + * @} + */ + +int main(void) +{ + /* The important rules are in the Makefile */ + return 0; +} From 83a617261a02bedeee47f7f58f8a02300219af38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Mon, 16 Jul 2018 14:13:04 +0200 Subject: [PATCH 03/11] cortexm_common/ldscript: add _fw_rom_length variable It will help testing if it is taken into account and for defining for outside after. --- cpu/cortexm_common/ldscripts/cortexm.ld | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpu/cortexm_common/ldscripts/cortexm.ld b/cpu/cortexm_common/ldscripts/cortexm.ld index 1c65d9f6d5..eb849a9602 100644 --- a/cpu/cortexm_common/ldscripts/cortexm.ld +++ b/cpu/cortexm_common/ldscripts/cortexm.ld @@ -21,10 +21,11 @@ */ _rom_offset = DEFINED( _rom_offset ) ? _rom_offset : 0x0; +_fw_rom_length = _rom_length - _rom_offset; MEMORY { - rom (rx) : ORIGIN = _rom_start_addr + _rom_offset, LENGTH = _rom_length - _rom_offset + rom (rx) : ORIGIN = _rom_start_addr + _rom_offset, LENGTH = _fw_rom_length ram (w!rx) : ORIGIN = _ram_start_addr, LENGTH = _ram_length } From def2858af910703635f4796cb68f1f772d2b685f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 12 Jun 2018 19:32:17 +0200 Subject: [PATCH 04/11] cortexm_common_ldscript: test _rom_offfset taken into account Test that _rom_offfset is removed from the available _rom_length. --- tests/cortexm_common_ldscript/Makefile | 32 +++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/cortexm_common_ldscript/Makefile b/tests/cortexm_common_ldscript/Makefile index e4a7c7c9f4..10b58ab291 100644 --- a/tests/cortexm_common_ldscript/Makefile +++ b/tests/cortexm_common_ldscript/Makefile @@ -7,6 +7,15 @@ include ../Makefile.tests_common BOARD_WHITELIST += iotlab-a8-m3 BOARD_WHITELIST += iotlab-m3 BOARD_WHITELIST += samr21-xpro +# Boards using a bootloader and ROM_OFFSET by default +BOARD_WHITELIST += arduino-mkr1000 +BOARD_WHITELIST += arduino-mkrfox1200 +BOARD_WHITELIST += arduino-mkrzero +BOARD_WHITELIST += bluepill +BOARD_WHITELIST += feather-m0 +BOARD_WHITELIST += opencm904 +BOARD_WHITELIST += spark-core +BOARD_WHITELIST += stm32mindev include $(RIOTBASE)/Makefile.include @@ -15,7 +24,7 @@ include $(RIOTBASE)/Makefile.include # Compile time tests for ROM_OFFSET # # # # # # # # # # # # # # # # # # # # -COMPILE_TESTS = test-elffile-overflow +COMPILE_TESTS = test-elffile-overflow test-elffile-fw_rom_length all: compile-tests @@ -23,6 +32,10 @@ compile-tests: $(COMPILE_TESTS) .PHONY: compile-tests $(COMPILE_TESTS) +# iotlab-m3 defines ROM_LEN as 512K which is not handled by bash math operations +ROM_LEN_BYTES = $(shell printf "0x%x\n" $$(($(ROM_LEN:%K=%*1024)))) + + # test-elffile-overflow depends on $(BINFILE) to prevent: # * ROM_LEN to be passed to $(ELFFILE) generation # * dummy error message of wc not finding the .bin file (ELFFILE is not enough) @@ -35,3 +48,20 @@ _test-elffile-overflow-runtest: $(BINFILE) $(Q)\ { $(_LINK) -o /dev/null 2>&1 | grep -q "region \`rom' overflowed by 1 byte" ; } \ && echo [OK] || { echo [ERROR] Compilation should have failed >&2; exit 1; } + + +# Test `ROM_OFFSET` is removed from firmware rom length if the board defines it +test-elffile-fw_rom_length: $(ELFFILE) + $(Q)echo -n "Test rom offset substracted from rom length in elffile: " + $(Q)\ + if test -n "$(ROM_OFFSET)"; then \ + TEST_FW_LEN=$$($(PREFIX)readelf --symbols $^ 2>/dev/null | awk '/_fw_rom_length/{printf "0x%s\n", $$2}'); \ + EXPECT_FW_LEN=$$(printf "0x%08x" $$(( $(ROM_LEN_BYTES) - $(ROM_OFFSET) ))); \ + if test $${TEST_FW_LEN} != $${EXPECT_FW_LEN}; then \ + echo "[ERROR] Rom offset not taken into account for firmware length $${TEST_FW_LEN} != $${EXPECT_FW_LEN}" >&2; \ + exit 1;\ + fi ;\ + echo [OK] ; \ + else \ + echo "[SKIP](Reason: board does not have a ROM_OFFSET configured)" ;\ + fi From 9103dcaeda7b10b2a8cdda318aeb0de7c29e9897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 5 Jun 2018 13:32:51 +0200 Subject: [PATCH 05/11] cortexm_common: refactor the definition test The variables should all always be defined. --- cpu/cortexm_common/Makefile.include | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cpu/cortexm_common/Makefile.include b/cpu/cortexm_common/Makefile.include index 65463a1859..d7150d2cdb 100644 --- a/cpu/cortexm_common/Makefile.include +++ b/cpu/cortexm_common/Makefile.include @@ -6,7 +6,13 @@ ifneq (,$(ROM_OFFSET)) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_offset=$(ROM_OFFSET) endif +# All variables must be defined in the CPU configuration when using the common +# `ldscripts/cortexm.ld` ifneq (,$(ROM_START_ADDR)$(RAM_START_ADDR)$(ROM_LEN)$(RAM_LEN)) + $(if $(ROM_START_ADDR),,$(error ROM_START_ADDR is not defined)) + $(if $(RAM_START_ADDR),,$(error RAM_START_ADDR is not defined)) + $(if $(ROM_LEN),,$(error ROM_LEN is not defined)) + $(if $(RAM_LEN),,$(error RAM_LEN is not defined)) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_start_addr=$(ROM_START_ADDR) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_ram_start_addr=$(RAM_START_ADDR) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_length=$(ROM_LEN) From c84539fdb33247154cf4fd1b0aa0cd1acab32a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 5 Jun 2018 13:43:40 +0200 Subject: [PATCH 06/11] cortexm_common: allow defining ROM_OFFFSET in a compilation rule Define _rom_offset with a conditional evaluated at execution time to allow setting it in compilation rules and generate in the same make instance different elf files with different configurations. --- cpu/cortexm_common/Makefile.include | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cpu/cortexm_common/Makefile.include b/cpu/cortexm_common/Makefile.include index d7150d2cdb..0cf0926b48 100644 --- a/cpu/cortexm_common/Makefile.include +++ b/cpu/cortexm_common/Makefile.include @@ -2,10 +2,6 @@ INCLUDES += -I$(RIOTCPU)/cortexm_common/include INCLUDES += -I$(RIOTCPU)/cortexm_common/include/vendor -ifneq (,$(ROM_OFFSET)) - LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_offset=$(ROM_OFFSET) -endif - # All variables must be defined in the CPU configuration when using the common # `ldscripts/cortexm.ld` ifneq (,$(ROM_START_ADDR)$(RAM_START_ADDR)$(ROM_LEN)$(RAM_LEN)) @@ -18,3 +14,10 @@ ifneq (,$(ROM_START_ADDR)$(RAM_START_ADDR)$(ROM_LEN)$(RAM_LEN)) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_length=$(ROM_LEN) LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_ram_length=$(RAM_LEN) endif + + +# Only define the linker symbol if the variable is set +# The variable can be set using target specific variable thanks to lazy evaluation + +# ROM_OFFSET: offset in rom to start linking, allows supporting a bootloader +LINKFLAGS += $(if $(ROM_OFFSET),$(LINKFLAGPREFIX)--defsym=_rom_offset=$(ROM_OFFSET)) From 642f5f24142703e4b557acc3c5485b6f1e3a8927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 12 Jun 2018 19:32:17 +0200 Subject: [PATCH 07/11] cortexm_common_ldscript: add test for linker script offset Compile two elf files with different offset and verify the linked file offset. I only enabled samr21-xpro and iotlab nodes for the moment. --- tests/cortexm_common_ldscript/Makefile | 35 +++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/cortexm_common_ldscript/Makefile b/tests/cortexm_common_ldscript/Makefile index 10b58ab291..49973d3f29 100644 --- a/tests/cortexm_common_ldscript/Makefile +++ b/tests/cortexm_common_ldscript/Makefile @@ -24,7 +24,8 @@ include $(RIOTBASE)/Makefile.include # Compile time tests for ROM_OFFSET # # # # # # # # # # # # # # # # # # # # -COMPILE_TESTS = test-elffile-overflow test-elffile-fw_rom_length +COMPILE_TESTS = test-elffile-overflow test-elffile-fw_rom_length +COMPILE_TESTS += tests-offsets all: compile-tests @@ -65,3 +66,35 @@ test-elffile-fw_rom_length: $(ELFFILE) else \ echo "[SKIP](Reason: board does not have a ROM_OFFSET configured)" ;\ fi + + +# Test elffiles must not have $(ELFFILE) prerequisite as target specific +# variables are used for configuration and they also apply to prerequisites. +# +# https://www.gnu.org/software/make/manual/make.html#Target_002dspecific + +ELFFILES_DEPS = $(BASELIBS) FORCE + + +# Compile elf files with different ROM_OFFSET +# and verify the offset is taken into account + +OFFSETS_TESTS = 0x1000 0x2000 +tests-offsets: $(OFFSETS_TESTS:%=test-offset_%) + +.PHONY: test-offset_% +test-offset_%: $(BINDIR)/$(APPLICATION)_offset_%.elf + $(Q)echo -n "Test compilation with offset $*: " + $(Q)\ + TEST_START_ADDR=$$($(PREFIX)readelf --section-headers $^ 2>/dev/null | awk '/.text/{printf "0x%s\n", $$5}'); \ + EXPECT_START_ADDR=$$(printf "0x%08x" $$(( $(ROM_START_ADDR) + $* ))); \ + if test $${TEST_START_ADDR} != $${EXPECT_START_ADDR}; then \ + echo "[ERROR] Linker offset not used $${TEST_START_ADDR} != $${EXPECT_START_ADDR}" >&2; \ + exit 1;\ + fi + $(Q)echo [OK] + +$(BINDIR)/$(APPLICATION)_offset_%.elf: ROM_OFFSET=$* +$(BINDIR)/$(APPLICATION)_offset_%.elf: $(ELFFILES_DEPS) + $(Q)$(_LINK) -o $@ +.PRECIOUS: $(BINDIR)/$(APPLICATION)_offset_%.elf From 7dad2e7096bd5d61d5a085a3c6d6d4041a35210e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 13 Jun 2018 17:31:32 +0200 Subject: [PATCH 08/11] cortexm_common/ldscript: allow defining FW_ROM_SIZE Allow defining a specific rom length to use for linking the firmware, _fw_rom_length, instead of the default configuration to use the whole rom from _rom_offset to the end. * Add cortexm_common/Makefile.include FW_ROM_SIZE configuration * Add an assertion that _fw_rom_length still respects _rom_length --- cpu/cortexm_common/Makefile.include | 2 ++ cpu/cortexm_common/ldscripts/cortexm.ld | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cpu/cortexm_common/Makefile.include b/cpu/cortexm_common/Makefile.include index 0cf0926b48..b1be7aff71 100644 --- a/cpu/cortexm_common/Makefile.include +++ b/cpu/cortexm_common/Makefile.include @@ -21,3 +21,5 @@ endif # ROM_OFFSET: offset in rom to start linking, allows supporting a bootloader LINKFLAGS += $(if $(ROM_OFFSET),$(LINKFLAGPREFIX)--defsym=_rom_offset=$(ROM_OFFSET)) +# FW_ROM_LEN: rom length to use for firmware linking. Allows linking only in a section of the rom. +LINKFLAGS += $(if $(FW_ROM_LEN),$(LINKFLAGPREFIX)--defsym=_fw_rom_length=$(FW_ROM_LEN)) diff --git a/cpu/cortexm_common/ldscripts/cortexm.ld b/cpu/cortexm_common/ldscripts/cortexm.ld index eb849a9602..1ce1024595 100644 --- a/cpu/cortexm_common/ldscripts/cortexm.ld +++ b/cpu/cortexm_common/ldscripts/cortexm.ld @@ -21,7 +21,9 @@ */ _rom_offset = DEFINED( _rom_offset ) ? _rom_offset : 0x0; -_fw_rom_length = _rom_length - _rom_offset; +_fw_rom_length = DEFINED( _fw_rom_length ) ? _fw_rom_length : _rom_length - _rom_offset; + +ASSERT((_fw_rom_length <= _rom_length - _rom_offset), "Specified firmware size does not fit in ROM"); MEMORY { From 6768763601e332b60eb2452a7d5dd6053192de75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 13 Jun 2018 18:02:14 +0200 Subject: [PATCH 09/11] cortexm_common_ldscript: add test for linker FW_ROM_LEN Compile an elf file with a length equals to half the rom length. --- tests/cortexm_common_ldscript/Makefile | 31 ++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tests/cortexm_common_ldscript/Makefile b/tests/cortexm_common_ldscript/Makefile index 49973d3f29..337462fdea 100644 --- a/tests/cortexm_common_ldscript/Makefile +++ b/tests/cortexm_common_ldscript/Makefile @@ -20,12 +20,12 @@ BOARD_WHITELIST += stm32mindev include $(RIOTBASE)/Makefile.include -# # # # # # # # # # # # # # # # # # # -# Compile time tests for ROM_OFFSET # -# # # # # # # # # # # # # # # # # # # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # +# Compile time tests for ROM_OFFSET and FW_ROM_LENGTH # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # COMPILE_TESTS = test-elffile-overflow test-elffile-fw_rom_length -COMPILE_TESTS += tests-offsets +COMPILE_TESTS += tests-offsets tests-fw_rom_len all: compile-tests @@ -98,3 +98,26 @@ $(BINDIR)/$(APPLICATION)_offset_%.elf: ROM_OFFSET=$* $(BINDIR)/$(APPLICATION)_offset_%.elf: $(ELFFILES_DEPS) $(Q)$(_LINK) -o $@ .PRECIOUS: $(BINDIR)/$(APPLICATION)_offset_%.elf + + +# Compile elf files with FW_ROM_LEN and verify the length is taken into account +# I arbitrarily do 'half' size because I needed to take a value and +# that it is similar to what is required for doing dual firmware in rom ota + +tests-fw_rom_len: test-fw_len_half_rom + +.PHONY: test-fw_len_half_rom +test-fw_len_half_rom: $(BINDIR)/$(APPLICATION)_fw_len_half_rom.elf + $(Q)echo -n "Test compilation with half ROM length: " + $(Q)\ + TEST_FW_LEN=$$($(PREFIX)readelf --symbols $^ 2>/dev/null | awk '/_fw_rom_length/{printf "0x%s\n", $$2}'); \ + EXPECT_FW_LEN=$$(printf "0x%08x" $$(( $(ROM_LEN_BYTES) / 2 ))); \ + if test $${TEST_FW_LEN} != $${EXPECT_FW_LEN}; then \ + echo "[ERROR] Linker firmware length not used $${TEST_FW_LEN} != $${EXPECT_FW_LEN}" >&2; \ + exit 1;\ + fi + $(Q)echo [OK] +$(BINDIR)/$(APPLICATION)_fw_len_half_rom.elf: FW_ROM_LEN=$$(($(ROM_LEN_BYTES)/2)) +$(BINDIR)/$(APPLICATION)_fw_len_half_rom.elf: $(ELFFILES_DEPS) + $(Q)$(_LINK) -o $@ +.PRECIOUS: $(BINDIR)/$(APPLICATION)_fw_len_half_rom.elf From 8ecc0ac652f765e52ae7dce719580a03f058492e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 13 Jun 2018 18:03:29 +0200 Subject: [PATCH 10/11] cortexm_common_ldscript: add test for _fw_rom_length overflow Verify that specifying a too big _fw_rom_length for the rom is detected and prevent compilation. --- tests/cortexm_common_ldscript/Makefile | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/cortexm_common_ldscript/Makefile b/tests/cortexm_common_ldscript/Makefile index 337462fdea..4db91761d1 100644 --- a/tests/cortexm_common_ldscript/Makefile +++ b/tests/cortexm_common_ldscript/Makefile @@ -25,7 +25,7 @@ include $(RIOTBASE)/Makefile.include # # # # # # # # # # # # # # # # # # # # # # # # # # # # COMPILE_TESTS = test-elffile-overflow test-elffile-fw_rom_length -COMPILE_TESTS += tests-offsets tests-fw_rom_len +COMPILE_TESTS += tests-offsets tests-fw_rom_len tests-rom-overflow all: compile-tests @@ -121,3 +121,24 @@ $(BINDIR)/$(APPLICATION)_fw_len_half_rom.elf: FW_ROM_LEN=$$(($(ROM_LEN_BYTES)/2) $(BINDIR)/$(APPLICATION)_fw_len_half_rom.elf: $(ELFFILES_DEPS) $(Q)$(_LINK) -o $@ .PRECIOUS: $(BINDIR)/$(APPLICATION)_fw_len_half_rom.elf + + +# Test FW_ROM_LEN overflow detection + +OVERFLOW_TESTS = too_big_for_rom offset_and_romlen +tests-rom-overflow: $(OVERFLOW_TESTS:%=test-assert_overflow_%) + + +# Simple FW_ROM_LEN overflow +test-assert_overflow_too_big_for_rom: FW_ROM_LEN=$$(($(ROM_LEN_BYTES) + 1)) + +# ROM_OFFSET and FW_ROM_LEN set ROM_LEN +test-assert_overflow_offset_and_romlen: ROM_OFFSET=0x1000 +test-assert_overflow_offset_and_romlen: FW_ROM_LEN=$(ROM_LEN_BYTES) + +.PHONY: test-assert_overflow_% +test-assert_overflow_%: $(ELFFILES_DEPS) + $(Q) echo -n "Test ROM overflow detection ($*): " + $(Q)\ + { $(_LINK) -o /dev/null 2>&1 | grep -q 'Specified firmware size does not fit in ROM' ; } \ + && echo [OK] || { echo [ERROR] Compilation should have failed >&2; exit 1; } From 6abcf2e015147c01136a05fb198f3f3819e8d2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 7 Aug 2018 15:39:39 +0200 Subject: [PATCH 11/11] cortexm_common_ldscript: add a README.md Explain the test and the output you should get. --- tests/cortexm_common_ldscript/README.md | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/cortexm_common_ldscript/README.md diff --git a/tests/cortexm_common_ldscript/README.md b/tests/cortexm_common_ldscript/README.md new file mode 100644 index 0000000000..5571d4adc4 --- /dev/null +++ b/tests/cortexm_common_ldscript/README.md @@ -0,0 +1,45 @@ +Cortexm-common ldscript +======================= + +This test checks the support for building firmwares with a rom offset and +specific sized firmwares using `cortexm-common` ldscript. + +When building `all`, the `compile-tests` target is also build and executes build +time compilation tests checking different firmwares configurations verified by +inspecting the result elf files. + + +Test output +----------- + +For a board that does not have a `ROM_OFFSET` variable configured by default +(== a board without bootloader installed), it produces the following output +after the normal compilation: + +``` +make all BOARD=iotlab-m3 +... +Test rom offset 1 byte overflow detection: [OK] +Test rom offset substracted from rom length in elffile: [SKIP](Reason: board does not have a ROM_OFFSET configured) +Test compilation with offset 0x1000: [OK] +Test compilation with offset 0x2000: [OK] +Test compilation with half ROM length: [OK] +Test ROM overflow detection (too_big_for_rom): [OK] +Test ROM overflow detection (offset_and_romlen): [OK] +``` + +For a bord that have a `ROM_OFFSET` variable configured by default (== a board +with bootloader installed), it produces the following output after the normal +compilation: + +``` +make BOARD=bluepill PROGRAMMER=dfu-util +... +Test rom offset 1 byte overflow detection: [OK] +Test rom offset substracted from rom length in elffile: [OK] +Test compilation with offset 0x1000: [OK] +Test compilation with offset 0x2000: [OK] +Test compilation with half ROM length: [OK] +Test ROM overflow detection (too_big_for_rom): [OK] +Test ROM overflow detection (offset_and_romlen): [OK] +```