Reputation: 43
I have an embedded application that also has a bootloader, my goal is to be able to get the version of the bootloader and other information within the application, all information is constant, and thus I thought of placing them at the beginning of the bootloader code section, so the application can easily read the data which is allways going to be at the same address.
So far I have defined something like
const char bootloader_info[4] = {0x01,0x02,0x03,0x04};
and defining in the linker script
__bootloader_info = 0xD000 /*Where exactly should this line be placed?*/
However the variable ends placed in the data section...
What I have done now is to define a new section in the linker script and place it before the init code, although it works I think it is not the right way
const char __attribute__((section (".versioninfo"))) bootloader_info[4] = {0x01,0x02,0x03,0x04};
.
versioninfo (rx) : ORIGIN = 0xD000, LENGTH = 0x0000
rom (rx) : ORIGIN = 0xD000, LENGTH = 0x27B0
-------
.text :
{
. = ALIGN(2);
KEEP(*(.versioninfo)) /*info gets added at the beginning of .text*/
KEEP(*(.init .init.*))
KEEP...
What should be the right way of achieving this using a gcc toolchain, and why did the first method didn't work?
EDIT
I was not defining a section, I actually don't know what was that. To define a section it goes like this:
.versioninfo :
{
KEEP(*(.versioninfo))
} > versioninfo
Now it complains if the data is bigger than the section, so I guess it is better than before, I still would like to hear another aproaches or why the first method didn't work, thanks
Upvotes: 2
Views: 2920
Reputation: 16243
You must define your section as follow:
_versioninfo_start_address = 0x0000D000;
.versioninfo _versioninfo_start_address :
{
KEEP(*(.versioninfo)) ;
} > // place here the region where to this section has to be stored
Then you can define your variable:
const char __attribute__((section (".versioninfo"))) bootloader_info[4] = {0x01,0x02,0x03,0x04}
Upvotes: 2