-
Notifications
You must be signed in to change notification settings - Fork 3k
Cortex M33: set DOMAIN_NS to 0 when TZ is not used #10514
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
Conversation
This looks plausible, and might be sufficient, but I'm not familiar enough with where else assumptions occur in the tools. I guess the "TFM" check will do - "TrustZone iff TFM" seems a sounder assumption than "TrustZone iff ARMv8" at least. Does |
tools/toolchains/iar.py
Outdated
@@ -55,7 +55,7 @@ def __init__(self, target, notify=None, macros=None, build_profile=None, | |||
build_profile=build_profile | |||
) | |||
core = target.core | |||
if CORE_ARCH[target.core] == 8: | |||
if CORE_ARCH[target.core] == 8 and "TFM" in target.labels: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If testing TFM, I would take out the CORE_ARCH
test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please consider following approach:
if CORE_ARCH[target.core] == 8 and "TFM" in target.labels: | |
if CORE_ARCH[target.core] == 8 and target.is_PSA_secure_target: |
We are only injecting this define to a linker script. Please consider adding this macro also for compile flags for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'd like to see is a core-independent "we're making a TrustZone/CMSE-type split image" test here.
If I understand correctly, is_PSA_secure_target
covers TrustZone and dual-core solutions, and there's no fundamental reason why someone might not end up making a dual-M33 device.
So "TFM" is closer to the meaning we want. In #9460 I suggested adding Target.is_TZ_secure_target
and Target.is_TZ_nonsecure_target
for this bit of code.
If not changing anything else, those could be defined as 'TFM' in self.labels and [not] self.core.ends_with('-NS')
Although for all of the three possibilities suggested here, we're not covering "NUMAKER_PFM_M2351", which doesn't have TFM/PSA.
But then that's why @bridadan was looking at adding a separate explicit tz
flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alzix proposition is fine for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
if CORE_ARCH[target.core] == 8 and (target.is_PSA_secure_target or "MBED_TZ_DEFAULT_ACCESS=1" in target.macros):
would be fine for all ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't want CORE_ARCH
in there, on principle. The tying of security to core version is the whole problem we're trying to fix, so even if this is a temporary "heuristic" until a more explicit flag is added for targets.json, I want that to be an architecture-free heuristic if at all possible.
We can cover M2351's use of NS by just detecting the "-NS" suffix on the core, without caring about any other settings.
I believe it should be flattened out, a bit like my initial comment on #9460, so it's something like
if `TFM` in target.labels:
if not target.core.endswith("-NS"):
# XXX Why is this conditional? Don't we always create secure library
# if setting secure build flag?
if (kwargs.get('build_dir', False)):
# Create Secure library
# Add secure build flag
# No else? No special handling for TFM NS images, I think?
if target.core.ends_with('-NS'):
# Add linking time preprocessor macro DOMAIN_NS
I didn't quite get @alzix's objection to looking at label TFM
rather than SPE_Target
or NSPE_Target
.
I think the above makes sense as a heuristic for now, as the only secure image we support building is a TFM one, but we don't really care why anyone might choose to make a NS image. They're free to use whatever secure library they want, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and I still don't think there's any need to be explicitly setting DOMAIN_NS to 0, but let me know if I'm wrong.
@jeromecoutant, thank you for your changes. |
Let's use this PR to have a "quick" workaround, |
"Quick" certainly implies limiting it to just modifying the heuristic in this code block. But given that I'm not sure when any progress is going to be made on wider tool changes, I want to get whatever heuristic is placed here as solid as possible, so we hopefully don't have to mess with it again (and maybe cope without any further tool changes for a prolonged time). |
This PR is all about injecting a define to a linker script, right? regardless of SPM implementation this can be useful piece of configuration for the SW developer.
Am i missing something? This discussion got too lengthy :) So i'm suggesting: self.flags["ld"].append(self.make_ld_define("DOMAIN_NS", "0x0" if target.is_PSA_secure_target else "0x1")) |
No, So when using TFM it's 0/unset for secure side and 1 for non-secure side. If this was PSOC6 PSA, it's 0/unset on both chips. The DOMAIN_NS option is actually being set for the assembler and compiler elsewhere, based on the core's -NS suffix - this code fragment is just doing the same for the linker. Code is a bit out-of-place. The PR is really about changing the CMSE options - it's not actually changing DOMAIN_NS behaviour. I'm making a replacement PR myself as it's going to be easier than continuing to discuss changing this one. |
Description
This could fix #9460 ?
If TFM is not used for a V8M target:
Pull request type
Reviewers
@ARMmbed/mbed-os-psa
@LMESTM
@kjbracey-arm