STM32

stm32 gcc 将常量保存在指定的Flash地址上

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}

demo:

/* Specify the memory areas */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8008000, LENGTH = 1024K
BOOTINFO(rx) : ORIGIN = 0x8007C00, LENGTH = 1K
}

_versioninfo_start_address = ORIGIN(BOOTINFO);

/* Define output sections */
SECTIONS
{
/* The startup code goes first into FLASH */
.isr_vector :
{
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} >FLASH

...

.versioninfo _versioninfo_start_address :
{
KEEP(*(.versioninfo)) ;
} >BOOTINFO


/* Remove information from the standard libraries */
/DISCARD/ :
{
libc.a ( * )
libm.a ( * )
libgcc.a ( * )
}

.ARM.attributes 0 : { *(.ARM.attributes) }
}

main.c:

const char __attribute__((section (".versioninfo"))) bootloader_info[4] = {0x01,0x02,0x03,0x04};