Skip to content

Add Cortex-R support #2261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

m-braunschweig
Copy link

This PR adds support for Booting on a Cortex-R core. It has been tested with the following branch which also includes some instructions what Kconfig options need to be set: https://github.com/siemens/zephyr/tree/mika/ti/ti-am2434-native-boot

@@ -1,6 +1,7 @@
# Copyright (c) 2017-2020 Linaro Limited
# Copyright (c) 2020 Arm Limited
# Copyright (c) 2023 Nordic Semiconductor ASA
# Copyright (c) 2025 Siemens Mobility GmbH
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think half a line addition gives this

Comment on lines +74 to +97
uint8_t i;
uint8_t num_regions;
uint32_t mpu_type_register;

// disable MPU
__asm__(
" mrc p15, 0, r0, c1, c0, 0\n"
" bic r0, #1\n"
" mcr p15, 0, r0, c1, c0, 0\n"
" isb\n"
::: "r0");

// the number of MPU regions is stored in bits 15:8 of the MPU type register
__asm__ volatile("mrc p15, 0, %0, c0, c0, 4\n" : "=r" (mpu_type_register) ::);
num_regions = (uint8_t) ((mpu_type_register >> 8) & BIT_MASK(8));

for (i = 0; i < num_regions; ++i) {
// select region in the MPU and clear the region size field
__asm__ volatile(
" mov r0, #0\n"
" mcr p15, 0, %0, c6, c2, 0\n"
" mcr p15, 0, r0, c6, c1, 2\n"
:: "r" (i) : "r0");
}
Copy link
Collaborator

@nordicjm nordicjm Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be using zephyr APIs, should not be adding code, let alone assembly, here to do this (applies to clearing MPU, the boot assembly code is fine)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the inline assmebly isn't really good here. I was also thinking about using Zephyr functions but then noticed that arm_core_mpu_disable is not public (as in: Not in any header) and only interally used, meaning it could change.

For disabling (clearing) the individual regions Zephyr has a non-public header that provides ARM_MPU_ClrRegion (link), which is the same name CMSIS provides only for Cortex-M cores.

@@ -1,6 +1,7 @@

/*
* Copyright (c) 2020 Nordic Semiconductor ASA
* Copyright (c) 2025 Siemens Mobility GmbH
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

__set_CONTROL(0x00); /* application will configures core on its own */
__ISB();
#else
/* set mode to supervisor and A, I and F bit as described in the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capital first letter of comments

((void (*)(void))vt->reset)();
#else
// some architectures like the Cortex-R run in thumb mode but reset into ARM
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use /* */ style comments

@@ -0,0 +1 @@
- Add support for cleaning up the Cortex-R core before final jumping (interrupt controller, MPU and setting the CPSR to the reset state)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80 char line width

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>
Add code to cleanup the Cortex-R processor state to the reset
configuration and disable + acknowledge all interrupts before entering
the booted application.

Signed-off-by: Mika Braunschweig <mika.braunschweig@siemens.com>
Add notes about the additions made in order to support Cortex-R booting.

Signed-off-by: Mika Braunschweig <mika.braunschweig@siemens.com>
@m-braunschweig m-braunschweig force-pushed the mika/upstream/add-cortex-r-support branch from 604b494 to d4a3922 Compare April 10, 2025 14:56
@m-braunschweig
Copy link
Author

Thanks for the review. I addressed the changes in the last force-push and added a comment to the MPU

@m-braunschweig m-braunschweig requested a review from nordicjm April 10, 2025 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants