[U-Boot] linker question u-boot - setting armv8 mem_map struct at runtime
mbrugger at suse.com
Tue Oct 22 14:17:39 UTC 2019
I'm trying to support one binary that can boot from RPi3 and RPi4 .
For this I need to set mem_map at runtime .
Up to now, mem_map is defined in lowlevel_init.S which pushes it to section
But as Alex noted in the thread, much cleaner would be to define mem_map as an
external variable which is put into .data
So the logical solution would be something like
struct mm_region *mem_map = bcm283x_mem_map;
But that takes the value at compile time and does not update mem_map afterwards
mach_cpu_ini(). Which leads to a binary that can only boot on RPi3.
If instead I define:
struct mm_region __attribute__ ((section (".data"))) *mem_map;
Then U-boot updates the variable at run-time and boots as expected on RPi3 and RPi4.
I'm banging my head against this for the last few days, but don't really grok
why this happens. I suppose that it has something to do with the relocation of
U-Boot after boot_init_f sequence is finished, but I'm not sure.
The only difference I can see when using assignment at compile time is, that
mem_map get's put into .data.mem_map section  and in the relocation section
 we can see extra entries in section '.rela.text.mach_cpu_init', .data.mem_map
Apart from that a nwe section .rela.data.mem_map is created which holds one
To be honest I don't really understand what's going on and if just pushing
mem_map to .data through a GCC attribute is the correct thing to do or not.
Any help would be appreciated.
 objdump --disassemble-all arch/arm/mach-bcm283x/built-in.o
 readelf --relocs arch/arm/mach-bcm283x/built-in.o
More information about the U-Boot