- 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.2k
 
Description
When using data relocation to store variables in external SDRAM the kernel will initialize the data section from ROM and clear the bss section. But this is done before the SDRAM is initialized, so the data will not be retained. In my application I see that all variables that are stored in SDRAM have wrong initialization values.
I'm seeing this with an stm32f7, using driver memc_stm32_sdram.c. This driver has the initialization level POST_KERNEL. I have verified that kernel/init.c and kernel/xip.c correctly initialize the relocated data, and also that the data is lost during memc_stm32_sdram_init().
As a workaround I'm calling bss_zeroing_relocation() and data_copy_xip_relocation() at the end of memc_stm32_sdram_init(). This fixes the problem for me, but it is not a general solution because it may overwrite any other data relocated to internal RAM.
One possible solution to this is to initialize the SDRAM a lot earlier, but that will probably require a rewrite of the driver (to not depend on kernel, clock initalization, etc)
Environment
- OS: Linux
 - Toolchain: Zephyr SDK 0.13.1
 - Zephyr v2.7.0