From 2882dab78c43d7f7189a583b302e21de561bb70f Mon Sep 17 00:00:00 2001 From: Kesavan Yogeswaran Date: Mon, 31 Mar 2025 20:10:05 +0000 Subject: [PATCH] soc: nxp: Fix boot header placement when using lld As well described in a previous PR [1], the GNU ld and LLVM lld linkers treat the location counter (`.`) differently. lld always inteprets the location counter as an absolute address whereas ld interprets it as an offset from the start of the current object. The NXP boot header linker script files use `.` assignment to specify an offset within the rom_start region (ld-style). This causes lld to error out since it interprets this as the location counter moving backwards. To fix this, re-use the idea from the previous PR [1]: replace `. = FOO` with `. += FOO - (. - __rom_start_address)` This sets the location counter in a way that works with both ld and lld. [1] https://github.com/zephyrproject-rtos/zephyr/pull/58315 Signed-off-by: Kesavan Yogeswaran --- soc/nxp/imxrt/boot_header.ld | 12 ++++++------ soc/nxp/rw/boot_header.ld | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/soc/nxp/imxrt/boot_header.ld b/soc/nxp/imxrt/boot_header.ld index b61487c4819..e52e64506f4 100644 --- a/soc/nxp/imxrt/boot_header.ld +++ b/soc/nxp/imxrt/boot_header.ld @@ -10,9 +10,9 @@ __Vectors = __VECTOR_TABLE; #endif #if defined(CONFIG_BOOT_XSPI_NOR) -. = CONFIG_XSPI_CONFIG_BLOCK_OFFSET; +. += CONFIG_XSPI_CONFIG_BLOCK_OFFSET - (. - __rom_start_address); #else -. = CONFIG_FLEXSPI_CONFIG_BLOCK_OFFSET; +. += CONFIG_FLEXSPI_CONFIG_BLOCK_OFFSET - (. - __rom_start_address); #endif #if defined(CONFIG_SOC_SERIES_IMXRT11XX) || defined(CONFIG_SOC_SERIES_IMXRT10XX) || defined(CONFIG_SOC_SERIES_IMXRT118X) KEEP(*(.boot_hdr.conf)) @@ -22,13 +22,13 @@ KEEP(*(.flash_conf)) #endif #if defined(CONFIG_SOC_SERIES_IMXRT118X) #ifdef CONFIG_EXTERNAL_MEM_CONFIG_DATA - . = CONFIG_EXTERNAL_MEM_CONFIG_OFFSET; + . += CONFIG_EXTERNAL_MEM_CONFIG_OFFSET - (. - __rom_start_address); KEEP(*(.boot_hdr.xmcd_data)) #endif -. = CONFIG_IMAGE_CONTAINER_OFFSET; +. += CONFIG_IMAGE_CONTAINER_OFFSET - (. - __rom_start_address); KEEP(*(.boot_hdr.container)) #else -. = CONFIG_IMAGE_VECTOR_TABLE_OFFSET; +. += CONFIG_IMAGE_VECTOR_TABLE_OFFSET - (. - __rom_start_address); KEEP(*(.boot_hdr.ivt)) #endif #if defined(CONFIG_SOC_SERIES_IMXRT11XX) || defined(CONFIG_SOC_SERIES_IMXRT10XX) @@ -37,7 +37,7 @@ KEEP(*(.boot_hdr.data)) KEEP(*(.boot_hdr.dcd_data)) #endif /* CONFIG_DEVICE_CONFIGURATION_DATA */ #ifdef CONFIG_EXTERNAL_MEM_CONFIG_DATA - . = CONFIG_EXTERNAL_MEM_CONFIG_OFFSET; + . += CONFIG_EXTERNAL_MEM_CONFIG_OFFSET - (. - __rom_start_address); KEEP(*(.boot_hdr.xmcd_data)) #endif #endif /* CONFIG_SOC_SERIES_IMXRT10XX || CONFIG_SOC_SERIES_IMXRT11XX */ diff --git a/soc/nxp/rw/boot_header.ld b/soc/nxp/rw/boot_header.ld index ee0be5b4753..eadc03a4035 100644 --- a/soc/nxp/rw/boot_header.ld +++ b/soc/nxp/rw/boot_header.ld @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -. = CONFIG_FLASH_CONFIG_OFFSET; +. += CONFIG_FLASH_CONFIG_OFFSET - (. - __rom_start_address); KEEP(*(.flash_conf)) -. = CONFIG_IMAGE_VECTOR_TABLE_OFFSET; +. += CONFIG_IMAGE_VECTOR_TABLE_OFFSET - (. - __rom_start_address); KEEP(*(.boot_hdr.ivt))