cancel
Showing results for 
Search instead for 
Did you mean: 

how do I get image end address from linker?

HZaib.1
Associate III

MCU : STM32F411CEU6

 

Hello everyone. I have an application in which I want to get image end address from linker. 

Here is a full context of what I want to do, I have a struct living in start of my image, which basically tells the bootloader usefull info, if bootloader want to inspect the image, the struct looks like this (BTW this struct is not yet implemented and this feature I made for when working with TI CC series so I am trying to replicate it for STM as well)

 

 

const imgHdr_t _imgHdr __attribute__((section( ".image_header"))) =
{
    .imgID = OAD_IMG_ID_VAL,
    .crc32 = DEFAULT_CRC,
    .imgCpStat = DEFAULT_STATE,            //!< Image copy status bytes */
    .crcStat = DEFAULT_STATE,              //!< CRC status */
    .imgNo = 0x1,                          //!< Image number of 'image type' */
    .imgVld = 0xFFFFFFFF,                  //!< In indicates if the current image in valid 0xff - valid, 0x00 invalid image */
    .len = INVALID_LEN,                     //!< Image length in bytes. */
    .softVer = SOFTWARE_VER,               //!< Software version of the image */
    .prgEntry = (uint32_t)&prgEntryAddr,   //vector table entry
    .imgEndAddr = (uint32_t)&flashEndAddr, 

}

 

 

Now what I want to do is to give this struct the flashEndAddr when I compile my code.

And I am also interested in getting vector table size, so I can put this struct exactly after the vector table. Right now I am thinking of putting it before vector table and vector table will be placed with offset of this struct, but I am not sure if this is the right way. In TI it was after the vector table so I am bit confused in this as well. 

 

you help or any suggestion is appreciated 

thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Place or use a symbol in the last output to the >FLASH section in the linker script, and then import that as an extern void * pointer.

The linker script is processed in a linear fashion, with the statics for RAM placed in FLASH to be copied to RAM via the code in startup.s, see it's use of symbols and the copy/zero code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

5 REPLIES 5

Place or use a symbol in the last output to the >FLASH section in the linker script, and then import that as an extern void * pointer.

The linker script is processed in a linear fashion, with the statics for RAM placed in FLASH to be copied to RAM via the code in startup.s, see it's use of symbols and the copy/zero code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks alot. It did the trick, I actually had no idea about it. 

Thanks I was able to get the img_final_addr. 

Also I need to ask can I assign the address to some section from c file ? 

For example I have a variable or directive in which I have given the address and that address be shared in linker script ?

extern uint32_t *g_pfnVectors[];

printf("%p : sp= %p, pc= %p\n",&g_pfnVectors[0], g_pfnVectors[0], g_pfnVectors[1]);

 

You can also put symbols in empty vectors, say defining an image length, or expressing linker symbols

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

The linker can calculate expressions, so you can make your exported symbol the image size (end - start) rather than the end address. This value can be used to initialize static C variable or structure.

This is true, however it can't do complex math, similarly the assembler with multiple symbols, where the linker has to fix things at bind time.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..