-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Delay relocation of data/bss init after MEMC init is completed #68888
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?
Conversation
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
I guess this would fix #43555 |
@talih0 Can you fix compliance issue reported by automated checks ? |
depends on ARCH_HAS_CODE_DATA_RELOCATION | ||
depends on CODE_DATA_RELOCATION |
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.
CODE_DATA_RELOCATION
already depends on ARCH_HAS_CODE_DATA_RELOCATION
, no need to add it again.
depends on ARCH_HAS_CODE_DATA_RELOCATION | |
depends on CODE_DATA_RELOCATION | |
depends on CODE_DATA_RELOCATION |
I wonder if we should have some form of The reason I ask is that if we simply blindly copy data into memory regions that may be set up by MEMC devices, we run the risk of crashing the chip. I have seen this with iMX.RT parts (which use external SDRAM setup by the bootloader). In this case, the chip will simply crash at initialization since the SRAM region is not accessible. I'm not sure how we would best handle this (perhaps simply triggering a fault). I just would like to avoid the case where an external memory device fails to initialize, and the application simply crashes rather than printing some form of error message |
Is cache handled at this point? I see most of cache enables are in the level of |
There is another issue I just thought about. Since stimer init call is in |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
I transition my memc driver to use In my opinion, this should be the policy across all the memc drivers. I can't think of anything useful the system could do with the time, because there's not going to be any other thread the memc initialization could yield to. In which case your PR would be a welcome improvement to Zephyr IMO. |
if os.path.isfile(args.edt_pickle): | ||
with open(args.edt_pickle, 'rb') as f: | ||
edt = pickle.load(f) | ||
for node in edt.compat2nodes["zephyr,memory-region"]: | ||
delayed_relocate[node.props["zephyr,memory-region"].val] = node.props["delay-relocation"].val | ||
|
||
else: | ||
edt = None |
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 really want to handle the file not existing, it would be better instead to handle FileNotFoundError
exceptions from open()
so that there is no change of a race condition between the check and the use of the file.
But I think it's wrong to set edt = None
if the file is not found. It should be set to None
only if the args.edt_pickle is not None
.
If the --edt_pickle
option is given but the file fails to open, then it would probably best to just let the exception go out unhandled.
I did some work on amending the patch yesterday, and it does indeed solve the problem now. I have an SDRAM that is initialized The main issue outstanding with the patch from my perspective is the way it reads from the EDT pickle. This design seems a little ugly to me. I would expect the information to have to somehow feed through Kconfig and CMake instead. |
One issue I encountered doing relocations |
Happy to take it over, though it will be a few weeks before I have time to finish it off |
Same problem applies to |
Looking forward to this 👍 |
I'll publish my latest attempt at the patch, but I'm not sure how we get around some of these issues. In the current version we can delay relocation until after memc device initialization. In practice though, the developer needs to ensure that none of the relocated memory is used before relocation occurs otherwise there will be early-boot crashes - this includes many device drivers, memory allocators and other system initialization code. In the current structure of Zephyr, this is extremely difficult and error-prone to ensure, and makes the patch rather useless. So for my project, I abandoned the approach and instead divided my application into a Zephyr-powered bootloader which loads a main Zephyr application into RAM. |
Note I've been doing some other work on the relocation code: |
Having the ability to delay the relocation is enough and not useless at all, it enables using the memc-setup memory for main app code at least, and other things as well if the user setups their priorities correctly, it's a very important capability. |
Here is my current version of the patch: b3df801 The main complaint about it is that parsing the EDT pickle in
It's certainly a capability many would like to have. |
Currently, when relocating to external SRAM regions via MEMC drivers, the relocation/zero initialization is done before the MEMC drivers are initialized.
See issue #68884
This patch delays initialization after PRE_KERNEL_1 level.
The initialization is only delayed on devicetree memory regions with delay-relocation property set.
Note, MEMC drivers (i.e. Atmel SAM SMC) use POST_KERNEL level, so their initialization levels would have to be updated.