cancel
Showing results for 
Search instead for 
Did you mean: 

End of program code address

diego ambroggi
Associate III

Hello everyone,

I'm tring to implement a calculation of firmware CRC in run time mode.

Is there inker command method to acquire last address where code is written?

I'm quite confident there is a specific command like __text_end__, for example.

Best regrds

1 ACCEPTED SOLUTION

Accepted Solutions
diego ambroggi
Associate III

Great!

It works fine.

I compute CRC from 0x08000000 to &_etext address.

/* User defines */

#define START_FLASH_ADDR   0x08000000

extern int _etext;

#define END_FLASH_ADDR   (uint32_t) (& _etext)

Thanks for your help.

Best regards

View solution in original post

8 REPLIES 8
S.Ma
Principal

The memory allocation and used segments typically are optionnally generated by the linker's MAP file.

Check the projet settings options. And remember that in some cases, the flash area might not be contiguous.

Look in the linker file (with *.ld extension). The symbols are defined there for each section, for example _etext here is the end of the code section (.text):

.text :
  {
    . = ALIGN(8);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
    *(.eh_frame)
 
    KEEP (*(.init))
    KEEP (*(.fini))
 
    . = ALIGN(8);
    _etext = .;        /* define a global symbols at end of code */
  } >FLASH
 

The startup code uses those symbols for copying the data segment from flash into RAM, for filling the bss segment with zeros, for configuring the stack, etc.

Yes, I saw Linker file, but i don't know how is possible to recall this command?

I tried:

 EndOfCodePtr = KEEP (*(.fini));

and

#define END_FLASH_ADDR      KEEP (*(.fini))

but is not correct :(

You see that "_etext = .;" ?

"." means this address. You can then use the defined symbol from your C code, just define it as extern before using it:

extern unsigned char _etext;
...
unsigned char *end_of_text = &_etext;

If it doesn't work try using PROVIDE in the linker file, for example:

PROVIDE (_etext = .);

The symbol is _etext

extern void *_etext;

printf("%x\n", (uint32_t)&_etext);

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

This likely does not include the statics placed beyond the text section, and copied into RAM by the code in startup.s

Find the last symbol in the >RAM >FLASH section, or create one if need be.

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

Review also .MAP file, should break down currently available symbolic data, and what the point too.

#WhatLinkersDo

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

Great!

It works fine.

I compute CRC from 0x08000000 to &_etext address.

/* User defines */

#define START_FLASH_ADDR   0x08000000

extern int _etext;

#define END_FLASH_ADDR   (uint32_t) (& _etext)

Thanks for your help.

Best regards