-
Notifications
You must be signed in to change notification settings - Fork 8k
arch: Allow to specify memory for S2RAM resume #95914
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
base: main
Are you sure you want to change the base?
arch: Allow to specify memory for S2RAM resume #95914
Conversation
7c1b650
to
1dbc200
Compare
Could you provide more details? |
1dbc200
to
4e4d6f2
Compare
The current solution assumes that the value of
|
Do you mean that what MCUboot sees as |
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 needs to be documentation somewhere about these special regions or it will get out of hand. While at it, please document pm_s2ram_context
too - I think it was introduced without docs either.
Correct. The placement of |
Do you have any specific area in the Zephyr documentation that you'd find suitable for such page? |
4e4d6f2
to
773f71f
Compare
Extended the |
There was a suggestion made here for a different issue to use a new stack for initialization flow. The issue is still open and creating a new stack could be an option but if it does then with this PR we would be stuck with 2 different options for init stack. So something like below:
and you might also want to add The only thing to consider here is that with my suggestion you would need a slightly bigger memory carved out for the init stack compared to the 16B allocate right now so let me know if you all would still like to go with the current solution. |
@tomchy btw, could you provide some steps to reproduce the issue this is trying to fix? I just wanted to try the build steps to see the mapfile and if the issue could be solved in any different way without changing this file. |
I do not think I fully understand your suggestion. The other issue is about the value of the
That said, if the S2RAM is disabled, the I am also new to the It is fairly easy to reproduce the different values of the
This should bring you two, different values, i.e.:
It is however hard to provide a recipe to see the faults, because:
In the builds that I had, even changing things like optimization level made the issue disappear, so I think it is better to understand the root cause than try to consistently reproduce the exact failure. |
Hi @tomchy, without going into details of which SP the other issue is talking about, what I wanted to highlight was that it talks about using a custom stack for initialization and so my suggestion was, instead of having the custom stack only for the CONFIG_PM_S2RAM path, have it in general. And thanks for the steps, IIUC as per the description, the image that wakes up from resume is mcuboot and loads z_interrupt_stacks into MSP. MSP of mcuboot overlaps with one of smp_svr/zephyr's memory regions causing a corruption. I don't have any experience with mcuboot so please help me to understand this, once mcuboot resumes its context in arch_pm_s2ram_resume it goes back to using z_interrupt_stacks as MSP and z_main_stack as PSP so, what is stopping it from causing any more corruption in the next zephyr image? |
I think @tomchy's scenario works because it also makes use of the "pinned context" feature, though I'll let @tomchy confirm. If my understanding is correct, the following happens:
TL;DR: MCUboot is able to pivot to a stack of the Zephyr image because Another solution would be to increase the size of zephyr/include/zephyr/arch/arm/cortex_m/cpu.h Lines 89 to 107 in 9d10d67
struct __cpu_context {
/* GPRs are saved onto the stack */
uint32_t msp;
uint32_t psp;
uint32_t primask;
uint32_t control;
#if defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE)
/* Registers present only on ARMv7-M and ARMv8-M Mainline */
uint32_t faultmask;
uint32_t basepri;
#endif /* CONFIG_ARMV7_M_ARMV8_M_MAINLINE */
#if defined(CONFIG_CPU_CORTEX_M_HAS_SPLIM)
/* Registers present only on certain ARMv8-M implementations */
uint32_t msplim;
uint32_t psplim;
#endif /* CONFIG_CPU_CORTEX_M_HAS_SPLIM */
+ uint8_t scratch_stack_space[CONFIG_ARM_PM_S2RAM_RESUME_STACK_SIZE];
}; Yet another other solution would be to bring back the constraints about |
The flow @mathieuchopstm mentioned looks similar to what was mentioned in #96290 (comment). If that's the case then maybe a new
and |
#96290's approach has the advantage that it runs through the bootloader again which may be required in certain use-cases (e.g., XIP from external flash/RAM? are there even S2RAM platforms where this exists?); the disadvantage is that it runs through the bootloader again which may be inappropriate due to shared resource overwriting... but it is gated behind a Kconfig. (but I guess the idea would be that |
@wearyzen, @mathieuchopstm You're correct. This change alone does not solve the problem of resuming from S2RAM if bootloader is enabled - it must be combined with one of the other changes:
@wearyzen: regarding the custom stack, I agree that we may name this "small" stack a --edit-- |
Considering both the PRs, I think changing MSP to use to small stack can just be done inside the soc_resume_hook() and there is no change needed here at arch level. |
Do you propose to create a new I cannot find a reference for the existing |
Yes a new hook suggested to be added in the other PR (#96290 (comment)) |
Regarding the new hook - note that the What I'm more concerned about - the issue is not specific to the SoC, but rather to the combination of having both bootloader and a sleepy application on the same core, started through chain-loading. That said, are you sure that a fix for it should be hidden inside nRF-specific files? This kind of issues are not easy to debug, so before we remove it from the generic scope, I would like to confirm that the solution on other platforms is not desired. |
I agree that there would be an issue is such a scenario and might not be easy to debug but for such a design where mcuboot resumes just to load the next images context won't they still need the soc_resume_hook? and if they do then with the right documentation they may chose to either change the msp to something like this PR does or not use the the stack at all and avoid the issue in soc_resume_hook 🤷. |
Considering that (additionally, |
Please rebase and resolve conflicts. |
If the area, dedicated for the interrupt stack is not available, allow to specify a memory region that will be used as the stack for the S2RAM resume logic. Signed-off-by: Tomasz Chyrowicz <[email protected]>
Add the definition of pm_s2ram_stack memory region for nRF54H20. Signed-off-by: Tomasz Chyrowicz <[email protected]>
74e6b66
0cb2901
to
74e6b66
Compare
PR rebased, docs removed due to: 4626f6b To my understanding - if possible, the solution should be move into the board-specific files and there is an agreement on adding a platform-specific hook. |
|
If the area, dedicated for the interrupt stack is not available, allow to specify a memory region that will be used as the stack for the S2RAM resume logic.