-
Notifications
You must be signed in to change notification settings - Fork 3k
Support secure/non-secure flash IAP for Cortex-M23/M33 #6630
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
Support secure/non-secure flash IAP for Cortex-M23/M33 #6630
Conversation
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.
Would split be more readable ? to have cmsis flash algo nonsecure ? Because looking at the diff it's lot of ifdef in the implementation here now
|
||
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) | ||
__attribute__((cmse_nonsecure_entry)) | ||
#endif |
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.
Isn't this somehow in CMSIS as one line macro that could say (NON SECURE FUNCTION or similar) ? This is in the entire file.
is attribute valid for all 3 toolchains?
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.
Attribute is valid for all three toolchains, and it to specify which function is entry point to secure world.
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.
Its not a macro in CMSIS, but its good idea to have this in macro like below:
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
#define SECURE_ENTRY_FNC __attribute__((cmse_nonsecure_entry))
#else
#define SECURE_ENTRY_FNC
#endif
Will look neat if code below is changed
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
__attribute__((cmse_nonsecure_entry))
#endif
int32_t flash_init(flash_t *obj)
{
flash_set_target_config(obj);
return 0;
}
to
SECURE_ENTRY_FNC int32_t flash_init(flash_t *obj)
{
flash_set_target_config(obj);
return 0;
}
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.
@0xc0170 @deepikabhavnani I add MBED_NONSECURE_ENTRY
for defining all-toolchain secure gateway functions in 1b7b94e and 92d937d.
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.
Would split be more readable ?
@0xc0170 To split into multiple files, what's the suggested folder structure?
mbed-os
/hal
/TARGET_FLASH_CMSIS_ALGO
/TARGET_CORTEX_M4
/flash_common_algo.c
mbed-os
/hal
/TARGET_FLASH_CMSIS_ALGO
/TARGET_CORTEX_M23
/flash_common_algo.c
mbed-os
/hal
/TARGET_FLASH_CMSIS_ALGO
/TARGET_CORTEX_M33
/flash_common_algo.c
Or other approach?
@deepikabhavnani
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 you can create a commit that we could review? I would like to compare _S version to regular one
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.
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.
@0xc0170 - We are avoiding directory creation for S/NS as it will be difficult to remove later. With these folders in place, it might give false impression that Mbed OS supports both secure / non-secure world.. Current secure library generation is not fully secure and will change with PSA in place. I would suggest to go back to old version with defines, as it will be easier to change them.
@ccli8 Sorry for delayed response here.
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.
OK, sounds good
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.
@0xc0170 @deepikabhavnani OK. I cancel the commit of creating new flash algorithm folder.
int32_t flash_erase_sector(flash_t *obj, uint32_t address) | ||
{ | ||
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) | ||
if (cmse_nonsecure_caller()) { | ||
// Confine non-secure access to non-secure flash |
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.
Can we have a common static function/macro to check range of non-secure flash, which can be called ftom all API's?
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.
@deepikabhavnani I refactored the code in 00147b5.
@@ -50,6 +50,9 @@ typedef struct { | |||
*/ | |||
struct flash_s { | |||
const flash_target_config_t *target_config; | |||
#if defined(__CORTEX_M23) || defined(__CORTEX_M33) | |||
const flash_target_config_t *target_config_ns; |
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.
Condition everywhere for access of target_config_ns
is (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
,
But here we always have pointer irrespective of secure/non-secure build.. Shouldn't it be confined to secure build where we have complete flash info.. But non-secure world does not know anything about secure flash and it will access flash using target_config?
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.
@deepikabhavnani I expect the following behavior:
flash_t
is initialized through secure gateway functionflash_init
for both secure/non-secure worlds, so alltarget_config
/target_config_ns
/flash_algo
structs are initialized in secure-onlyflash_set_target_config
(flash_api.c
).struct flash_s { const flash_target_config_t *target_config; #if defined(__CORTEX_M23) || defined(__CORTEX_M33) const flash_target_config_t *target_config_ns; #endif const flash_algo_t *flash_algo; };
- For non-secure world,
flash_t
should be seen as an opaque struct. It can be accessed only through secure gateway functionsflash_init
/flash_free
/flash_erase_sector
etc.flashIAP.h
/flashIAP.cpp
follows this rule.
|
||
MBED_NONSECURE_ENTRY |
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 would place this on the same line, any attribute it is like that MBED_WEAK function()
, etc
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.
1c51eee
to
7a7b634
Compare
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.
Can you describe what config_ns brings ? as a comment there? With this update, we have two target configs (how they differ, when to use which one).
The rest looks good to me
/morph build |
@deepikabhavnani Approve/request changes? |
Build : SUCCESSBuild number : 1786 Triggering tests/morph test |
Test : SUCCESSBuild number : 1596 |
Exporter Build : SUCCESSBuild number : 1432 |
@c1728p9 @deepikabhavnani Please approve/request changes. |
Description
This PR tries to support secure/non-secure flash IAP for Cortex-M23/M33 targets. It has the following behavior:
flash_target_config_t
,target_config
andtarget_config_ns
for secure/non-secure flash respectively.flash_erase_sector
/flash_program_page
, but cannot erase/program secure flash, which is guarded in secure flash IAP functions.Pull request type
[ ] Fix
[ ] Refactor
[ ] New target
[X] Feature
[ ] Breaking change
@cyliangtw @deepikabhavnani