-
Notifications
You must be signed in to change notification settings - Fork 3k
Add framework for configuring boot stack size #8039
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
Add the target config option "boot-stack-size" which is passed to the linker as the define "MBED_BOOT_STACK_SIZE" so the linker can adjust the stack accordingly. On mbed 2 the boot stack becomes the main stack after boot. On mbed 5 the boot stack becomes the ISR stack after boot. Because of these different uses the stack size for mbed 2 is set to 4K by default while on mbed 5 it is set to 1k. Additionally, the NRF5X family requires a larger interrupt stack size due to the softdevice so the size is increased to 2k on mbed 5 builds.
Update the K64F linker scripts to make use of the newly added stack size target config.
define symbol MBED_BOOT_STACK_SIZE = 0x400; | ||
} | ||
|
||
define symbol __stack_size__=MBED_BOOT_STACK_SIZE; |
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.
@theotherjimmy does the name MBED_BOOT_STACK_SIZE seems reasonable to you? Alternatively I could set this to the target define that is set - MBED_CONF_TARGET_BOOT_STACK_SIZE. Let me know what you think.
if stack_param in params: | ||
define_string = self.make_ld_define("MBED_BOOT_STACK_SIZE", int(params[stack_param].value, 0)) | ||
self.ld.append(define_string) | ||
self.flags["ld"].append(define_string) |
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.
@theotherjimmy this is how the target define is getting passed to the linker script. Is this the right way to do it or would you like any changes made 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.
That looks fine.
This should unblock #7238 as this mechanism allows the boot stack size to be correctly configured for all 3 toolchains in both mbed 2 and mbed 5. |
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.
This is great. Well done :-)
@@ -3,5 +3,22 @@ | |||
"config": { | |||
"present": 1 | |||
}, | |||
"macros": ["_RTE_"] | |||
"macros": ["_RTE_"], | |||
"target_overrides": { |
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.
In targets/targets.json
file boot-stack-size
is set to 4kB and here is modified and set to 1kB with some exceptions (like for NRF boards).
Is this done to distinguish stack size for builds with and without RTOS (4kB for non RTOS and typically 1kB for builds with RTOS)?
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.
Yep, by default stack sizes are 4K and they are overridden to 1K when the RTOS is present. Targets with special requirements on stack size, such as the nrf51, can further override for both the RTOS and non-RTOS configuration.
* the stack where main runs is determined via the RTOS. */ | ||
__stack_size__ = MBED_BOOT_STACK_SIZE; | ||
|
||
__heap_size__ = 0x6000; |
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.
It looks like __heap_size__
and HEAP_SIZE
symbols now are unused and can be removed.
It would be enough to define STACK_SIZE = MBED_BOOT_STACK_SIZE
or even remove also STACK_SIZE
and use MBED_BOOT_STACK_SIZE
instead.
"target.boot-stack-size": "0x400" | ||
}, | ||
"MCU_NRF51": { | ||
"target.boot-stack-size": "0x800" |
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.
Will it be good to move these overrides in targets.json instead?
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.
The size in targets.json is the size for mbed 2 - 0x1000
, while rtos/mbed_lib.json is for mbed 5 - 0x400
. In the case of the nrf5x the interrupt stack needs to be customized for mbed 5 only so it is set to 0x800
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.
Tools and config changes look fine.
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.
LGTM would be good to add some info to the porting guide.
/morph build |
Build : SUCCESSBuild number : 3223 Triggering tests/morph test |
Test : FAILUREBuild number : 3026 |
/morph test |
Exporter Build : FAILUREBuild number : 2880 |
Test : SUCCESSBuild number : 3071 |
/morph export-build |
Exporter Build : SUCCESSBuild number : 2885 |
@cmonr Why only for target K64F? I think that same kind changes are needed other target e.g. K66F. |
Yes, I think so. |
@JaniSuonpera the rest of the targets were going to be updated in #7238. I think @mprse is making a new PR for this. |
Now this PR has been closed, who is in charge to update all the targets ? |
@mprse Can you review? |
I'm working on it. PR should be ready today or tomorrow. |
The following commits: ARMmbed#8039, ARMmbed#9092 added Boot/ISR stack definition to all scatter files (ARM_LIB_STACK). This has changed memory model for RTOS-less builds to 2-region memory model and caused failure in case of rtos less builds. This PR defines valid heap/stack regions for rtos-less builds.
The following commits: ARMmbed#8039, ARMmbed#9092 added Boot/ISR stack definition to all scatter files (ARM_LIB_STACK). This has changed memory model for RTOS-less builds to 2-region memory model and caused failure in case of rtos less builds. This PR defines valid heap/stack regions for rtos-less builds.
The following commits: ARMmbed#8039, ARMmbed#9092 added Boot/ISR stack definition to all scatter files (ARM_LIB_STACK). This has changed memory model for RTOS-less builds to 2-region memory model and caused failure in case of rtos less builds. This PR defines valid heap/stack regions for rtos-less builds.
Description
Add the target config option "boot-stack-size" which is passed to the linker as the define "MBED_BOOT_STACK_SIZE" so the linker can adjust the stack accordingly. On mbed 2 the boot stack becomes the main stack after boot. On mbed 5 the boot stack becomes the ISR stack after boot. Because of these different uses the stack size for mbed 2 is set to 4K by default while on mbed 5 it is set to 1k.
Additionally, the NRF5X family requires a larger interrupt stack sizedue to the softdevice so the size is increased to 2k on mbed 5 builds.
Pull request type