Skip to content

Commit 420a2f9

Browse files
boot: zephyr: Add Cortex-R support
Add Cortex-R support by using ifdefs to change the vector table, remove CORTEX_M only code and do an explicit bx instruction to switch from Thumb to ARM mode on exit of the MCUboot application. Signed-off-by: Mika Braunschweig <mika.braunschweig@siemens.com>
1 parent 547ac60 commit 420a2f9

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

boot/zephyr/main.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2020 Arm Limited
44
* Copyright (c) 2021-2023 Nordic Semiconductor ASA
55
* Copyright (c) 2025 Aerlync Labs Inc.
6+
* Copyright (c) 2025 Siemens Mobility GmbH
67
*
78
* Licensed under the Apache License, Version 2.0 (the "License");
89
* you may not use this file except in compliance with the License.
@@ -32,7 +33,7 @@
3233
#include <zephyr/cache.h>
3334
#endif
3435

35-
#if defined(CONFIG_ARM)
36+
#if defined(CONFIG_CPU_CORTEX_M)
3637
#include <cmsis_core.h>
3738
#endif
3839

@@ -142,8 +143,19 @@ extern void *_vector_table_pointer;
142143
#endif
143144

144145
struct arm_vector_table {
146+
#ifdef CONFIG_CPU_CORTEX_M
145147
uint32_t msp;
146148
uint32_t reset;
149+
#else
150+
uint32_t reset;
151+
uint32_t undef_instruction;
152+
uint32_t svc;
153+
uint32_t abort_prefetch;
154+
uint32_t abort_data;
155+
uint32_t reserved;
156+
uint32_t irq;
157+
uint32_t fiq;
158+
#endif
147159
};
148160

149161
static void do_boot(struct boot_rsp *rsp)
@@ -226,7 +238,10 @@ static void do_boot(struct boot_rsp *rsp)
226238
#endif
227239
#endif /* CONFIG_BOOT_INTR_VEC_RELOC */
228240

241+
#ifdef CONFIG_CPU_CORTEX_M
229242
__set_MSP(vt->msp);
243+
#endif
244+
230245
#if CONFIG_MCUBOOT_CLEANUP_ARM_CORE
231246
__set_CONTROL(0x00); /* application will configures core on its own */
232247
__ISB();
@@ -257,7 +272,18 @@ static void do_boot(struct boot_rsp *rsp)
257272
: "r0", "r1", "r2", "r3", "memory"
258273
);
259274
#else
275+
276+
#ifdef CONFIG_CPU_CORTEX_M
260277
((void (*)(void))vt->reset)();
278+
#else
279+
/* Some ARM CPUs like the Cortex-R5 can run in thumb mode but reset into ARM
280+
* mode (depending on a CPU signal configurations). To do the switch into ARM
281+
* mode, if needed, an explicit branch with exchange instruction set
282+
* instruction is needed
283+
*/
284+
__asm__("bx %0\n" : : "r" (&vt->reset));
285+
#endif
286+
261287
#endif
262288
}
263289

0 commit comments

Comments
 (0)