From aac0081929eea88ca0e2889c424422a25982cd53 Mon Sep 17 00:00:00 2001 From: Alex Dolzhenkov Date: Tue, 29 Nov 2022 21:28:28 +1300 Subject: [PATCH 1/8] Fix linker script to prevent using not available flash memory --- gcc_nrf52-mcuboot.ld | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/gcc_nrf52-mcuboot.ld b/gcc_nrf52-mcuboot.ld index 81b318c5..c18875b6 100644 --- a/gcc_nrf52-mcuboot.ld +++ b/gcc_nrf52-mcuboot.ld @@ -1,11 +1,39 @@ -/* Linker script to configure memory regions. */ +/**************************************************************** + * Memory map configuration for using application with MCU-boot * + ****************************************************************/ +/* + * Internal nRF52 flash memory: + * 0x00000000: MCUBoot(28 kB) + * 0x00007000: Reboot logs (4 kB) + * 0x00008000: MCUBoot header (0x20 bytes) + * 0x00008020: Application (463+ kB) + * 0x0007be50: MCUBoot image trailer (432 bytes) + * 0x0007c000: MCUBoot Scratch partition (4 kB) + * 0x0007d000: unused (12 kB) + * + * SPI flash: + * 0x00000000: Bootloader Assets, like Boot Graphic (256 kB) + * 0x00040000: Application 2 (including MCUBoot header) (464 kB) + * 0x000b4000: User files - littlefs (3376 kB) + */ SEARCH_DIR(.) GROUP(-lgcc -lc -lnosys) +MCUBOOT_SIZE = 0x8000; +MCUBOOT_APP_IMAGE_HEADER_SIZE = 0x20; +MCUBOOT_APP_IMAGE_TRAILER_SIZE = 432; +APP_OFFSET = MCUBOOT_SIZE + MCUBOOT_APP_IMAGE_HEADER_SIZE; +APP_SIZE = 464K - MCUBOOT_APP_IMAGE_HEADER_SIZE - MCUBOOT_APP_IMAGE_TRAILER_SIZE; +SCRATCH_OFFSET = 0x7c000; +SCRATCH_SIZE = 4K; + MEMORY { - FLASH (rx) : ORIGIN = 0x08020, LENGTH = 0x78000 + /* MCUBOOT (r) : ORIGIN = 0x0, LENGTH = MCUBOOT_SIZE */ + FLASH (rx) : ORIGIN = APP_OFFSET, LENGTH = APP_SIZE + /* SCRATCH (r) : ORIGIN = SCRATCH_OFFSET, LENGTH = SCRATCH_SIZE */ + SPARE_SPACE (r) : ORIGIN = SCRATCH_OFFSET + SCRATCH_SIZE, LENGTH = 12K RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K } From fe32af1ce9c44db6a37a58d07579b5b37200778e Mon Sep 17 00:00:00 2001 From: Alex Dolzhenkov Date: Sat, 3 Dec 2022 20:42:55 +1300 Subject: [PATCH 2/8] #1463 Update mcuboot-app linker file to be more consistent --- gcc_nrf52-mcuboot.ld | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gcc_nrf52-mcuboot.ld b/gcc_nrf52-mcuboot.ld index c18875b6..204c414d 100644 --- a/gcc_nrf52-mcuboot.ld +++ b/gcc_nrf52-mcuboot.ld @@ -5,7 +5,7 @@ * Internal nRF52 flash memory: * 0x00000000: MCUBoot(28 kB) * 0x00007000: Reboot logs (4 kB) - * 0x00008000: MCUBoot header (0x20 bytes) + * 0x00008000: MCUBoot header (32 bytes) * 0x00008020: Application (463+ kB) * 0x0007be50: MCUBoot image trailer (432 bytes) * 0x0007c000: MCUBoot Scratch partition (4 kB) @@ -21,12 +21,12 @@ SEARCH_DIR(.) GROUP(-lgcc -lc -lnosys) MCUBOOT_SIZE = 0x8000; -MCUBOOT_APP_IMAGE_HEADER_SIZE = 0x20; +MCUBOOT_APP_IMAGE_HEADER_SIZE = 32; MCUBOOT_APP_IMAGE_TRAILER_SIZE = 432; APP_OFFSET = MCUBOOT_SIZE + MCUBOOT_APP_IMAGE_HEADER_SIZE; -APP_SIZE = 464K - MCUBOOT_APP_IMAGE_HEADER_SIZE - MCUBOOT_APP_IMAGE_TRAILER_SIZE; +APP_SIZE = SCRATCH_OFFSET - MCUBOOT_SIZE - MCUBOOT_APP_IMAGE_HEADER_SIZE - MCUBOOT_APP_IMAGE_TRAILER_SIZE; SCRATCH_OFFSET = 0x7c000; -SCRATCH_SIZE = 4K; +SCRATCH_SIZE = 0x1000; MEMORY { From a356113d0ca36180ab55384bd232bb60d40d06f2 Mon Sep 17 00:00:00 2001 From: Alex Dolzhenkov Date: Sun, 4 Dec 2022 08:14:10 +1300 Subject: [PATCH 3/8] #1463 Fixed linker script syntax --- gcc_nrf52-mcuboot.ld | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc_nrf52-mcuboot.ld b/gcc_nrf52-mcuboot.ld index 204c414d..8bee1de4 100644 --- a/gcc_nrf52-mcuboot.ld +++ b/gcc_nrf52-mcuboot.ld @@ -21,12 +21,12 @@ SEARCH_DIR(.) GROUP(-lgcc -lc -lnosys) MCUBOOT_SIZE = 0x8000; +SCRATCH_SIZE = 0x1000; +SCRATCH_OFFSET = 0x7c000; MCUBOOT_APP_IMAGE_HEADER_SIZE = 32; MCUBOOT_APP_IMAGE_TRAILER_SIZE = 432; APP_OFFSET = MCUBOOT_SIZE + MCUBOOT_APP_IMAGE_HEADER_SIZE; APP_SIZE = SCRATCH_OFFSET - MCUBOOT_SIZE - MCUBOOT_APP_IMAGE_HEADER_SIZE - MCUBOOT_APP_IMAGE_TRAILER_SIZE; -SCRATCH_OFFSET = 0x7c000; -SCRATCH_SIZE = 0x1000; MEMORY { From 4f6a9571f3783f52eb00bd359f864ab05f62471a Mon Sep 17 00:00:00 2001 From: Alex Dolzhenkov Date: Mon, 5 Dec 2022 22:04:14 +1300 Subject: [PATCH 4/8] #1463 Replaced decimal numbers with hex --- gcc_nrf52-mcuboot.ld | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc_nrf52-mcuboot.ld b/gcc_nrf52-mcuboot.ld index 8bee1de4..8337099e 100644 --- a/gcc_nrf52-mcuboot.ld +++ b/gcc_nrf52-mcuboot.ld @@ -23,8 +23,8 @@ GROUP(-lgcc -lc -lnosys) MCUBOOT_SIZE = 0x8000; SCRATCH_SIZE = 0x1000; SCRATCH_OFFSET = 0x7c000; -MCUBOOT_APP_IMAGE_HEADER_SIZE = 32; -MCUBOOT_APP_IMAGE_TRAILER_SIZE = 432; +MCUBOOT_APP_IMAGE_HEADER_SIZE = 0x20; +MCUBOOT_APP_IMAGE_TRAILER_SIZE = 0x1b0; APP_OFFSET = MCUBOOT_SIZE + MCUBOOT_APP_IMAGE_HEADER_SIZE; APP_SIZE = SCRATCH_OFFSET - MCUBOOT_SIZE - MCUBOOT_APP_IMAGE_HEADER_SIZE - MCUBOOT_APP_IMAGE_TRAILER_SIZE; From 71e9a97e7c87e33ece6ddc85584c9b0e245db516 Mon Sep 17 00:00:00 2001 From: Alex Dolzhenkov Date: Tue, 27 Dec 2022 09:57:50 +1300 Subject: [PATCH 5/8] Update gcc_nrf52-mcuboot.ld Co-authored-by: JF --- gcc_nrf52-mcuboot.ld | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc_nrf52-mcuboot.ld b/gcc_nrf52-mcuboot.ld index 8337099e..4c4b83d9 100644 --- a/gcc_nrf52-mcuboot.ld +++ b/gcc_nrf52-mcuboot.ld @@ -22,6 +22,7 @@ GROUP(-lgcc -lc -lnosys) MCUBOOT_SIZE = 0x8000; SCRATCH_SIZE = 0x1000; +TLV_SIZE = 0x28; /* Metadata added by imgtool at the end of the image */ SCRATCH_OFFSET = 0x7c000; MCUBOOT_APP_IMAGE_HEADER_SIZE = 0x20; MCUBOOT_APP_IMAGE_TRAILER_SIZE = 0x1b0; From 1e8ed181ea4b4825ffe5671453c07af06ad36faa Mon Sep 17 00:00:00 2001 From: Alex Dolzhenkov Date: Tue, 27 Dec 2022 09:58:51 +1300 Subject: [PATCH 6/8] Update gcc_nrf52-mcuboot.ld Co-authored-by: JF --- gcc_nrf52-mcuboot.ld | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc_nrf52-mcuboot.ld b/gcc_nrf52-mcuboot.ld index 4c4b83d9..6c3a769b 100644 --- a/gcc_nrf52-mcuboot.ld +++ b/gcc_nrf52-mcuboot.ld @@ -27,7 +27,8 @@ SCRATCH_OFFSET = 0x7c000; MCUBOOT_APP_IMAGE_HEADER_SIZE = 0x20; MCUBOOT_APP_IMAGE_TRAILER_SIZE = 0x1b0; APP_OFFSET = MCUBOOT_SIZE + MCUBOOT_APP_IMAGE_HEADER_SIZE; -APP_SIZE = SCRATCH_OFFSET - MCUBOOT_SIZE - MCUBOOT_APP_IMAGE_HEADER_SIZE - MCUBOOT_APP_IMAGE_TRAILER_SIZE; +APP_SIZE = SCRATCH_OFFSET - MCUBOOT_SIZE - MCUBOOT_APP_IMAGE_HEADER_SIZE - MCUBOOT_APP_IMAGE_TRAILER_SIZE - TLV_SIZE; + MEMORY { From cfc86d7d85167b1340740bbf4ec319d62c1513cf Mon Sep 17 00:00:00 2001 From: Alex Dolzhenkov Date: Thu, 29 Dec 2022 18:11:24 +1300 Subject: [PATCH 7/8] #1463 Updated CMakeLists.txt for building images with expected alignment --- src/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e59c0d81..ce365dd1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -976,8 +976,8 @@ add_custom_command(TARGET ${EXECUTABLE_MCUBOOT_NAME} COMMAND ${CMAKE_SIZE_UTIL} ${EXECUTABLE_MCUBOOT_FILE_NAME}.out COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE_MCUBOOT_FILE_NAME}.out "${EXECUTABLE_MCUBOOT_FILE_NAME}.bin" COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_MCUBOOT_FILE_NAME}.out "${EXECUTABLE_MCUBOOT_FILE_NAME}.hex" - COMMAND ${CMAKE_SOURCE_DIR}/tools/mcuboot/imgtool.py create --align 4 --version 1.0.0 --header-size 32 --slot-size 475136 --pad-header ${EXECUTABLE_MCUBOOT_FILE_NAME}.hex ${IMAGE_MCUBOOT_FILE_NAME_HEX} - COMMAND ${CMAKE_SOURCE_DIR}/tools/mcuboot/imgtool.py create --align 4 --version 1.0.0 --header-size 32 --slot-size 475136 --pad-header ${EXECUTABLE_MCUBOOT_FILE_NAME}.bin ${IMAGE_MCUBOOT_FILE_NAME_BIN} + COMMAND ${CMAKE_SOURCE_DIR}/tools/mcuboot/imgtool.py create --align 1 --version 1.0.0 --header-size 32 --slot-size 475136 --pad-header ${EXECUTABLE_MCUBOOT_FILE_NAME}.hex ${IMAGE_MCUBOOT_FILE_NAME_HEX} + COMMAND ${CMAKE_SOURCE_DIR}/tools/mcuboot/imgtool.py create --align 1 --version 1.0.0 --header-size 32 --slot-size 475136 --pad-header ${EXECUTABLE_MCUBOOT_FILE_NAME}.bin ${IMAGE_MCUBOOT_FILE_NAME_BIN} COMMENT "post build steps for ${EXECUTABLE_MCUBOOT_FILE_NAME}" ) @@ -1049,7 +1049,7 @@ add_custom_command(TARGET ${EXECUTABLE_RECOVERY_MCUBOOT_NAME} COMMAND ${CMAKE_SIZE_UTIL} ${EXECUTABLE_RECOVERY_MCUBOOT_FILE_NAME}.out COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE_RECOVERY_MCUBOOT_FILE_NAME}.out "${EXECUTABLE_RECOVERY_MCUBOOT_FILE_NAME}.bin" COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_RECOVERY_MCUBOOT_FILE_NAME}.out "${EXECUTABLE_RECOVERY_MCUBOOT_FILE_NAME}.hex" - COMMAND ${CMAKE_SOURCE_DIR}/tools/mcuboot/imgtool.py create --align 4 --version 1.0.0 --header-size 32 --slot-size 475136 --pad-header ${EXECUTABLE_RECOVERY_MCUBOOT_FILE_NAME}.hex ${IMAGE_RECOVERY_MCUBOOT_FILE_NAME_HEX} + COMMAND ${CMAKE_SOURCE_DIR}/tools/mcuboot/imgtool.py create --align 1 --version 1.0.0 --header-size 32 --slot-size 475136 --pad-header ${EXECUTABLE_RECOVERY_MCUBOOT_FILE_NAME}.hex ${IMAGE_RECOVERY_MCUBOOT_FILE_NAME_HEX} COMMAND ${CMAKE_OBJCOPY} -I ihex -O binary ${IMAGE_RECOVERY_MCUBOOT_FILE_NAME_HEX} "${IMAGE_RECOVERY_MCUBOOT_FILE_NAME}.bin" COMMAND python3 ${CMAKE_SOURCE_DIR}/tools/bin2c.py ${IMAGE_RECOVERY_MCUBOOT_FILE_NAME}.bin recoveryImage > recoveryImage.h COMMENT "post build steps for ${EXECUTABLE_RECOVERY_MCUBOOT_FILE_NAME}" @@ -1125,7 +1125,7 @@ add_custom_command(TARGET ${EXECUTABLE_MCUBOOT_RECOVERYLOADER_NAME} COMMAND ${CMAKE_SIZE_UTIL} ${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.out COMMAND ${CMAKE_OBJCOPY} -O binary ${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.out "${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.bin" COMMAND ${CMAKE_OBJCOPY} -O ihex ${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.out "${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.hex" - COMMAND ${CMAKE_SOURCE_DIR}/tools/mcuboot/imgtool.py create --align 4 --version 1.0.0 --header-size 32 --slot-size 475136 --pad-header ${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.hex ${IMAGE_MCUBOOT_RECOVERYLOADER_FILE_NAME_HEX} + COMMAND ${CMAKE_SOURCE_DIR}/tools/mcuboot/imgtool.py create --align 1 --version 1.0.0 --header-size 32 --slot-size 475136 --pad-header ${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.hex ${IMAGE_MCUBOOT_RECOVERYLOADER_FILE_NAME_HEX} COMMAND ${CMAKE_OBJCOPY} -I ihex -O binary ${IMAGE_MCUBOOT_RECOVERYLOADER_FILE_NAME_HEX} "${IMAGE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.bin" COMMAND python3 ${CMAKE_SOURCE_DIR}/tools/bin2c.py ${IMAGE_MCUBOOT_RECOVERYLOADER_FILE_NAME}.bin recoveryLoaderImage > recoveryLoaderImage.h COMMENT "post build steps for ${EXECUTABLE_MCUBOOT_RECOVERYLOADER_FILE_NAME}" From 98d1de070a316a8714b32c42fa35084bc8e0431f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 29 Jan 2023 12:38:05 +0100 Subject: [PATCH 8/8] Linker script: Update gcc_nrf52.ld to reflect changes done in gcc_nrf52-mcuboot.ld. The only change between the 2 linker scripts is the ORIGIN address of the flash memory allocated to InfiniTime. The MCUBoot one starts at 0x8000, which is the address that will be loaded by MCUBoot after the boot process. This linker script allow to run the application without MCUBoot by setting the origin address to 0x00. The APP_SIZE is the same for both linker scripts, but it could be set to a higher value in this one for development purposes. --- gcc_nrf52.ld | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/gcc_nrf52.ld b/gcc_nrf52.ld index f9bc5b68..1bd5e821 100644 --- a/gcc_nrf52.ld +++ b/gcc_nrf52.ld @@ -1,11 +1,46 @@ -/* Linker script to configure memory regions. */ +/**************************************************************** + * Memory map configuration for using application with MCU-boot * + ****************************************************************/ +/* + * Internal nRF52 flash memory: + * 0x00000000: MCUBoot(28 kB) + * 0x00007000: Reboot logs (4 kB) + * 0x00008000: MCUBoot header (32 bytes) + * 0x00008020: Application (463+ kB) + * 0x0007be50: MCUBoot image trailer (432 bytes) + * 0x0007c000: MCUBoot Scratch partition (4 kB) + * 0x0007d000: unused (12 kB) + * + * SPI flash: + * 0x00000000: Bootloader Assets, like Boot Graphic (256 kB) + * 0x00040000: Application 2 (including MCUBoot header) (464 kB) + * 0x000b4000: User files - littlefs (3376 kB) + * + * This linker script sets the origin of the application at 0x00 + * which means that the application must be linked with a start + * address at 0x00 and that it'll overwrite the bootloader. + * This is very practical when debugging and testing on + * the hardware with a SWD probe. + */ SEARCH_DIR(.) GROUP(-lgcc -lc -lnosys) +MCUBOOT_SIZE = 0x8000; +SCRATCH_SIZE = 0x1000; +TLV_SIZE = 0x28; /* Metadata added by imgtool at the end of the image */ +SCRATCH_OFFSET = 0x7c000; +MCUBOOT_APP_IMAGE_HEADER_SIZE = 0x20; +MCUBOOT_APP_IMAGE_TRAILER_SIZE = 0x1b0; +APP_OFFSET = 0x00; +APP_SIZE = SCRATCH_OFFSET - MCUBOOT_SIZE - MCUBOOT_APP_IMAGE_HEADER_SIZE - MCUBOOT_APP_IMAGE_TRAILER_SIZE - TLV_SIZE; + MEMORY { - FLASH (rx) : ORIGIN = 0x00000, LENGTH = 0x78000 + /* MCUBOOT (r) : ORIGIN = 0x0, LENGTH = MCUBOOT_SIZE */ + FLASH (rx) : ORIGIN = APP_OFFSET, LENGTH = APP_SIZE + /* SCRATCH (r) : ORIGIN = SCRATCH_OFFSET, LENGTH = SCRATCH_SIZE */ + SPARE_SPACE (r) : ORIGIN = SCRATCH_OFFSET + SCRATCH_SIZE, LENGTH = 12K RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K }