Skip to content

soc: nxp: mcxn: configure CPU1 TrustZone access level #88975

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 2 commits into
base: main
Choose a base branch
from

Conversation

DerekSnell
Copy link
Collaborator

Configures AHBSC MASTER_SEC_LEVEL register for the cpu1 before cpu1 is enabled. By default, this gives CPU1 secure and privileged access to the rest of the SOC, same as CPU0.

This also reverts feb966d. Configuring the GPIO access permissions is no longer required for CPU1 to access the GPIO.

Resolves #88965 .

Tested using the blinky sample running on CPU1 using the following commands:

west build -b frdm_mcxn947//cpu1 samples/basic/blinky -d blinky_cpu1 -p -- -DCONFIG_SECOND_CORE_MCUX=y
west flash -d blinky_cpu1
west build -b frdm_mcxn947//cpu0 samples/hello_world/  -d hello_cpu0_loader -p -- -DCONFIG_SECOND_CORE_MCUX=y
west flash -d hello_cpu0_loader

GPIO also accessible from CPU0, tested with sample blinky and button.

This reverts commit feb966d.  That
change makes GPIO registers inaccessible from cpu0.

Signed-off-by: Derek Snell <[email protected]>
Configures AHBSC MASTER_SEC_LEVEL register for the cpu1 before cpu1 is
enabled.  By default, this gives CPU1 secure and privileged access to
the rest of the SOC, same as CPU0.

Signed-off-by: Derek Snell <[email protected]>
@DerekSnell
Copy link
Collaborator Author

@alxrey and @ubieda , FYI

Copy link
Member

@ubieda ubieda left a comment

Choose a reason for hiding this comment

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

I just tested and confirmed it fixes the regression. Thanks!

/* Configure CPU1 TrustZone access level before CPU1 is enabled */
AHBSC->MASTER_SEC_LEVEL |=
AHBSC_MASTER_SEC_LEVEL_CPU1(CONFIG_SECOND_CORE_MCUX_ACCESS_LEVEL);
AHBSC->MASTER_SEC_ANTI_POL_REG = (~AHBSC->MASTER_SEC_LEVEL & 0x3FFFFFF3U) | 0x80000000U;
Copy link
Contributor

Choose a reason for hiding this comment

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

Bits 3-2 (CPU1 field) are cleared by the mask & 0x3FFFFFF3U, which doesn't seem to be the intended behavior.

If COP1 in MASTER_SEC_LEVEL is set to 1 or 2 (Non-secure and privileged Master, respectively Secure and non-privileged Master), MASTER_SEC_ANTI_POL_REG will not have the inverse polarity of MASTER_SEC_LEVEL as specified.

IMHO, the mask should be set to 0x3FFFFFFFU.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't macros be used instead of hard-coded values?

Concretely:

AHBSC->MASTER_SEC_ANTI_POL_REG = (~AHBSC->MASTER_SEC_LEVEL & ~AHBSC_MASTER_SEC_ANTI_POL_REG_MASTER_SEC_LEVEL_ANTIPOL_LOCK_MASK) | AHBSC_MASTER_SEC_ANTI_POL_REG_MASTER_SEC_LEVEL_ANTIPOL_LOCK(2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

regression: NXP: GPIO inaccessible on frdm_mcxn947//cpu0
7 participants