Skip to main content
diego ambroggi
Associate III
April 2, 2019
Solved

End of program code address

  • April 2, 2019
  • 3 replies
  • 2715 views

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

This topic has been closed for replies.
Best answer by diego ambroggi

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

3 replies

S.Ma
Principal
April 2, 2019

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.

After Forever
Senior III
April 2, 2019

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.

diego ambroggi
Associate III
April 2, 2019

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 :(

After Forever
Senior III
April 2, 2019

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 = .);

diego ambroggi
diego ambroggiAuthorBest answer
Associate III
April 2, 2019

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