Skip to content

Commit 36c5e26

Browse files
soc: nxp: s32k3: gate IVT emission when chain-loaded by MCUboot
Emit the IVT section and IVT header only when XIP and the image is either a standalone XIP app or MCUboot itself. Do not emit the IVT when the Zephyr image is chain-loaded by MCUboot (BOOTLOADER_MCUBOOT=y). - linker.ld/sections.ld: place .ivt_header at IVT_HEADER only under XIP && (!BOOTLOADER_MCUBOOT || MCUBOOT). Provide __ivt_region_start/end symbols. - soc.c: guard IVT struct under the same condition and mark it 'used' so the linker keeps it when needed. - Kconfig.defconfig - Make the bootloader and the sign tool compatible with the vector table. This avoids populating 0x400000 IVT from the app image while retaining it for MCUboot or standalone XIP use-cases. Signed-off-by: Sumit Batra <sumit.batra@nxp.com>
1 parent 006f5ad commit 36c5e26

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

soc/nxp/s32/s32k3/Kconfig.defconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ endif # ETH_DRIVER && NET_L2_ETHERNET
2828
config CACHE_MANAGEMENT
2929
default y
3030

31+
# S32K3 places the vector table at +0x400
32+
# This makes the bootloader and the sign tool compatible with that.
33+
config ROM_START_OFFSET
34+
default 0x400 if BOOTLOADER_MCUBOOT
35+
3136
endif # SOC_SERIES_S32K3

soc/nxp/s32/s32k3/linker.ld

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#ifdef CONFIG_XIP
7+
/* Emit IVT section only when XIP and (standalone app OR MCUboot itself) */
8+
#if defined(CONFIG_XIP) && (!defined(CONFIG_BOOTLOADER_MCUBOOT) || defined(CONFIG_MCUBOOT))
9+
810
MEMORY
911
{
10-
IVT_HEADER (r) : ORIGIN = CONFIG_FLASH_BASE_ADDRESS + CONFIG_IVT_HEADER_OFFSET,
12+
IVT_HEADER (r) : ORIGIN = (CONFIG_FLASH_BASE_ADDRESS + CONFIG_IVT_HEADER_OFFSET),
1113
LENGTH = CONFIG_IVT_HEADER_SIZE
1214
}
15+
16+
/* Symbols for IVT */
17+
PROVIDE(__ivt_region_start = ORIGIN(IVT_HEADER));
18+
PROVIDE(__ivt_region_end = ORIGIN(IVT_HEADER) + LENGTH(IVT_HEADER));
19+
1320
#endif
1421

22+
/* Include standard Zephyr ARM script */
1523
#include <zephyr/arch/arm/cortex_m/scripts/linker.ld>

soc/nxp/s32/s32k3/sections.ld

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#ifdef CONFIG_XIP
7+
/* Emit IVT section only when XIP and (standalone app OR MCUboot itself) */
8+
#if defined(CONFIG_XIP) && (!defined(CONFIG_BOOTLOADER_MCUBOOT) || defined(CONFIG_MCUBOOT))
89

9-
.ivt_header : {
10-
KEEP(*(.ivt_header));
10+
/* IVT at flash base */
11+
.ivt_header ORIGIN(IVT_HEADER) : ALIGN(4)
12+
{
13+
/* Using a wildcard makes it more robust */
14+
KEEP(*(.ivt_header*));
1115
} > IVT_HEADER
1216

1317
#else

soc/nxp/s32/s32k3/soc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
#include <OsIf.h>
1414

1515
#ifdef CONFIG_XIP
16+
/*
17+
* Emit IVT only for standalone XIP or MCUboot itself
18+
* But not for the cases where Zephyr Image is loaded by MCUboot
19+
*/
20+
#if !defined(CONFIG_BOOTLOADER_MCUBOOT) || defined(CONFIG_MCUBOOT)
1621
/* Image Vector Table structure definition for S32K3XX */
1722
struct ivt {
1823
uint32_t header;
@@ -33,20 +38,23 @@ struct ivt {
3338
extern char _vector_start[];
3439

3540
/*
41+
* Attribute 'used' forces the compiler to emit ivt_header
42+
* even if nothing references it.
3643
* IVT for SoC S32K344, the minimal boot configuration is:
3744
* - Watchdog (SWT0) is disabled (default value).
3845
* - Non-Secure Boot is used (default value).
3946
* - Ungate clock for Cortex-M7_0 after boot.
4047
* - Application start address of Cortex-M7_0 is application's vector table.
4148
*/
42-
const struct ivt ivt_header __attribute__((section(".ivt_header"))) = {
49+
const struct ivt ivt_header __attribute__((section(".ivt_header"), used)) = {
4350
.header = IVT_MAGIC_MARKER,
4451
.boot_configure = 1,
4552
.cm7_0_start_address = (const void *)_vector_start,
4653
.cm7_1_start_address = NULL,
4754
.cm7_2_start_address = NULL,
4855
.lc_configure = NULL,
4956
};
57+
#endif
5058
#endif /* CONFIG_XIP */
5159

5260
void soc_early_init_hook(void)

0 commit comments

Comments
 (0)