Solved
I am struggling trying to locate a library header in a specific address. Header has a limited size Error is: ld.exe: DiscoL496_07.elf section `CLIENT_HDR' will not fit in region `CLIENT_ROM' ld.exe: region `CLIENT_ROM' overflowed by 269730352 bytes
The structure of the code is:
- A library called "clientManiobra.a" to be placed in "CLIENT_ROM" memory region. Library requires to place a struct constant in the very first position in "CLIENT_ROM" memory
- The above library to be linked with main application.
Application's memory map ("memory_map.ld"):
/* Common memory definition */
MEMORY
{
SHARED_RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256
RAM (xrw) : ORIGIN = 0x20000100, LENGTH = 320K - LENGTH(SHARED_RAM)
BOOT_FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 32K
SLOT1_ROM (rx) : ORIGIN = 0x08008000, LENGTH = 360k
SLOT2_ROM (rx) : ORIGIN = 0x08062000, LENGTH = 360k
CLIENT_ROM (rx) : ORIGIN = 0x080BC000, LENGTH = 240k
SHARED_CFG (rx) : ORIGIN = 0x080F8000, LENGTH = 32k
}
/* SHARED_RAM is memory to pass messages between firmwares. Needs to hold data while MCU is not unpowered */
SECTIONS
{
.SHARED_RAM(NOLOAD) : {
KEEP(*(.SHARED_RAM))
} > SHARED_RAM
}
__sharedram_start__ = ORIGIN(SHARED_RAM);
__sharedram_size__ = LENGTH(SHARED_RAM);
__bootrom_start__ = ORIGIN(BOOT_FLASH);
__bootrom_size__ = LENGTH(BOOT_FLASH);
__slot1rom_start__ = ORIGIN(SLOT1_ROM);
__slot1rom_size__ = LENGTH(SLOT1_ROM);
__slot2rom_start__ = ORIGIN(SLOT2_ROM);
__slot2rom_size__ = LENGTH(SLOT2_ROM);
__clientrom_start__ = ORIGIN(CLIENT_ROM);
__clientrom_size__ = LENGTH(CLIENT_ROM);
/* offset to be used for locating the image header from start image address */
__fw_header_offset = 0x200;
/* offset to be used for locating firmware code (".text") after image header */
__fw_codestart_offset = 0x30;
/* bootloader configuration, stored at the last page of SHARED_CFG section */
__bootloader_cfg_addr = 0x080FF800;Application's Flash linker scatter file:
INCLUDE memory_map.ld
/* Entry Point */
ENTRY(Reset_Handler)
/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
_Min_Heap_Size = 0x200 ; /* required amount of heap */
_Min_Stack_Size = 0x400 ; /* required amount of stack */
/* Sections */
SECTIONS
{
/* The Vector table into SLOT1_ROM Rom type memory */
.isr_vector : {
. = ALIGN(4);
KEEP(*(.isr_vector)) /* Startup code */
. = ALIGN(4);
} > SLOT1_ROM
/* The application image header */
.image_hdr : ALIGN(4) {
FILL(0xFF)
. = ORIGIN(SLOT1_ROM) + __fw_header_offset;
KEEP (*(.image_hdr))
} > SLOT1_ROM
/* The clientManiobra library image header */
CLIENT_HDR : ALIGN(4) {
FILL(0xFF)
. = __clientrom_start__;
KEEP (*(CLIENT_HDR))
} > CLIENT_ROM
/* The Client Library program code and other data into "CLIENT_ROM" slot in flash */
.text2 :
{
FILL(0xFF)
. = __clientrom_start__ + __fw_header_offset + __fw_codestart_offset;
. = ALIGN(4);
*clientManiobra.a:* (.text .text*) /* .text sections from Client Library (code) */
} > CLIENT_ROM
/* The program code and other data into "FLASH" Rom type memory */
.text : {
FILL(0xFF)
. = ORIGIN(SLOT1_ROM) + __fw_header_offset + __fw_codestart_offset;
. = ALIGN(4);
/* Before was: *(.text) */
/* Before was: *(.text*) */
*(EXCLUDE_FILE (*clientManiobra.a) .text .text*) /* .text sections (code) */
*(.glue_7)
*(.glue_7t)
*(.eh_frame) /* exception handling tables */
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
_etext = .; /* define a global symbols at end of code */
} > SLOT1_ROM
... (continues)...Withing "clientManiobra" library code, the following code snippets are implemented:
- Structure definition:
typedef struct __attribute__((packed)) {
uint32_t magicWord;
uint16_t imageFormatVersion;
uint32_t crc;
uint32_t data_size;
uint8_t imageType;
uint16_t clientFamily;
uint8_t clientVersion;
f_init_TypeDef func_init; /* callbacks */
f_checkEndOfMsgCallback_TypeDef func_EndOfMsgCbk;
f_getCmdTypeDef func_getCmd;
f_getErrorTypeDef func_getError;
f_getRspTypeDef func_getRsp;
f_getUrcTypeDef func_getUrc;
f_extractElemTypeDef func_extractElem;
f_analyzeCmdTypeDef func_analyzeCmd;
f_analyzeParamTypeDef func_analyzeParam;
f_terminateCmdTypedef func_terminateCmd;
uint32_t reserved;
} client_image_hdr_t;- In above structure definition every "func_xxxx" type is a function signature typedef. As example:
typedef void (*f_init_TypeDef)(uart_parser_context_t *p_upCtxt);- Code snippet creating the constant variable holding the structure content to be placed at the very beginning of "CLIENT_ROM" memory region:
/* Global variables of clientManiobra */
static const client_image_hdr_t client_hdr __attribute__((section("CLIENT_HDR"))) = {
.magicWord = CLIENT_IMAGE_MAGIC,
.imageFormatVersion = CLIENT_IMAGE_CURRENT_VERSION,
.crc = 0, /* to be parsed in post-processing */
.data_size = 0x0000, /* to be parsed in post-processing */
.imageType = IMAGE_TYPE_CLIENT_LIBRARY,
.clientFamily = CLIENT_FAMILY_ORONA_ARCA,
.clientVersion = CLIENT_ORONA_FW_VERSION,
.func_init = &libInit,
.func_EndOfMsgCbk = &lib_checkEndOfMsgCallback,
.func_getCmd = &lib_getCmd,
.func_getError = &lib_getError,
.func_getRsp = &lib_getRsp,
.func_getUrc = &lib_getUrc,
.func_extractElem = &lib_extractElem,
.func_analyzeCmd = &lib_analyzeCmd,
.func_analyzeParam = &lib_analyzeParam,
.func_terminateCmd = &lib_terminateCmd,
.reserved = 0
};All compiles perfect but linking is raising error.
It's already 3 days reviewing where may I be mistaken but no progress. Any help/suggestion will be highly appreciated.
Pol