2019-04-02 05:04 AM
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
Solved! Go to Solution.
2019-04-02 06:51 AM
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
2019-04-02 05:09 AM
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.
2019-04-02 05:13 AM
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.
2019-04-02 05:27 AM
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 :(
2019-04-02 05:47 AM
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 = .);
2019-04-02 05:48 AM
The symbol is _etext
extern void *_etext;
printf("%x\n", (uint32_t)&_etext);
2019-04-02 05:51 AM
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.
2019-04-02 05:54 AM
Review also .MAP file, should break down currently available symbolic data, and what the point too.
#WhatLinkersDo
2019-04-02 06:51 AM
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