When building a gcc based bare metal mcu project you need to take care of the initialization of the .data and .bss sections during startup.
The .bss section is quite easy since I just fill the entire section to 0. But variables in the .data section needs to have their initialization data in rom/flash and copied during startup.
How do I know where the data with the initialization values can be found?
Let's take a example.
Let's say that I create two global variables in main.c
unsigned int my_global_variable_one = 1;
unsigned int my_global_variable_two = 2;
Then I can use objdump on the object file to see in what section they will be in, but I can't find anything in the objdump out put where the init data should be placed.
$ arm-none-eabi-objdump --syms main.o | grep my_global_variable
00000000 g O .data 00000004 my_global_variable_one
00000004 g O .data 00000004 my_global_variable_two
Then I can look at the resulting elf for the entire system, in this case main.elf.
$ arm-none-eabi-nm -n main.elf | grep my_global_variable
20000000 D my_global_variable_one
20000004 D my_global_variable_two
Where can I find where they are so I can do copy the data? What do I need to put into my linker script?
It should be in something like .text or .rodata, but how do I know?
How can I check where the init data for my_global_variable_one is?
Can I find where this data is with any of the binutils commands like readelf or objdump?
/Thanks
This is on a stm32 (Cortex M3) mcu, and the CodeBench version of gcc is used.