cancel
Showing results for 
Search instead for 
Did you mean: 

Generated binary file size in STM32L4

AP_040
Senior

Is there any specific address location in generated binary file so we can know the size of that binary file?

Using this, in the firmware to read the size of binary file from that location and use it in our application.

1 ACCEPTED SOLUTION

Accepted Solutions

If that doesn't work try

  .word  _limit_flash - g_pfnVectors /* compute size */

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

65 REPLIES 65

One typically has linker symbols, and you can refer to them within the code. For fixed location stuff people typically refer to the symbol via an empty/unused vector in the vector table at the front of the image.​

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

@Community member​ 

Yes, can you give example for this?

Not from my phone.

These​ aren't complicated concepts.

In the GNU tools the symbols are often defined in the linker script, see .LD and .MAP files. In Keil there are $$Limit$$ type symbols.​

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

@Community member​ 

If some constant value needs to be defined it will be okay but how can I store the binary size? How to calculate the size of .bin file?

Please provide some example to do it?

Which symbol is for Atollic TrueStudio?

I accept PayPal and Amazon Gift cards

https://community.st.com/s/question/0D70X000006Srs3SAC/end-of-program

extern uint32_t Load$$LR$$LR_IROM1$$Limit;

 printf("Limit %08X\n", (uint32_t)&Load$$LR$$LR_IROM1$$Limit);

extern uint32_t Load$$LR$$LR_IROM1$$Length;

 printf("Length %08X\n", (uint32_t)&Load$$LR$$LR_IROM1$$Length);

; In your starup.s file, could be placed at known offset in vector table

 IMPORT ||Load$$LR$$LR_IROM1$$Length||

 DCD ||Load$$LR$$LR_IROM1$$Length||

In GNU define a variable marking the end of text+code sections

Equivalent to

  _etext = .;    /* define a global symbols at end of code */

but including the initialization by placing beyond that.

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

@Community member​ 

I tried but it will give errors.

Here I attached the startup and linker file. So, can you suggest me where I can add those symbol to add binary size?

AP_040
Senior

For example, binary start at 0x8000000 location and if I read 4bytes from the 0x8000004, i will have the total length of this binary. How I do it?

Yeah, because that's for Keil, something like this? Perhaps review how your tools function

startup.s

...

g_pfnVectors:

.word _estack

.word Reset_Handler

.word NMI_Handler

.word HardFault_Handler

.word MemManage_Handler

.word BusFault_Handler

.word UsageFault_Handler

.word _limit_flash /* symbol you define in .ld linker script */

.word 0

.word 0

.word 0

.word SVC_Handler

.word DebugMon_Handler

.word 0

...

script.ld

...

 /* User_heap_stack section, used to check that there is enough RAM left */

 ._user_heap_stack :

 {

  . = ALIGN(4);

  PROVIDE ( end = . );

  PROVIDE ( _end = . );

  . = . + _Min_Heap_Size;

  . = . + _Min_Stack_Size;

  . = ALIGN(4);

 } >RAM

 /* End section */

 . = ALIGN(4);

 .endof :

 {

  /* This is used by the startup in order to find the end */

  _limit_flash = .;     /* define a global symbol at the end of flash */

 } >FLASH

 /* Remove information from the standard libraries */

 /DISCARD/ :

 {

  libc.a ( * )

  libm.a ( * )

  libgcc.a ( * )

 }

...

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

Thanks, @Community member​ 

Now, I am able to get the size of binary from the specific location. But when we load binary into the MCU, it is not working.

So, I put the ".word _limit_flash" at last in the startup file then location of the size is changed and load .bin file into the MCU, it is working.