Skip to main content
AP_040
Senior
June 12, 2019
Solved

Generated binary file size in STM32L4

  • June 12, 2019
  • 16 replies
  • 12693 views

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.

This topic has been closed for replies.
Best answer by Tesla DeLorean

If that doesn't work try

 .word _limit_flash - g_pfnVectors /* compute size */

16 replies

AP_040
AP_040Author
Senior
July 3, 2019

@Community member​  Can you provide the feedback on this? We specify the "_limit_flash" as ".word" in startup file. So, Why it is store the 0x0802 (two bytes) every time in flash instead of storing the 4 bytes length of binary?

Tesla DeLorean
Guru
July 3, 2019

It is storing the end address, or limit, of the firmware image, for the length you'll clearly need to deference it from the base address of the image.

You can probably use existing symbols to do the math, the base of the vector table for instance.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
AP_040
AP_040Author
Senior
July 3, 2019

@Community member​ I tried it with de referencing it. But not got the success. Please help me to do this. How it is end address storing? 0x0802 is not an address of any location.

Tesla DeLorean
Guru
July 3, 2019

All your other vector addresses are in the 0x08020000+ range, it is within the FLASH memory region.

/* 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_size = _limit_flash - g_pfnVectors; /* compute length based on beginning and ending points */

 } >FLASH

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
AP_040
AP_040Author
Senior
July 4, 2019

@Community member​  As per your given above solution, I added "_flash_size = _limit_flash - g_pfnVectors;" this specific line into linker file but still it is not working. Is it require to configure some other things which I have missed? What should require to do here?

Tesla DeLorean
Guru
July 4, 2019

>> Is it require to configure some other things which I have missed?

Are you using the _flash_size symbol?

.endof 0x080086fc 0x0
 0x080086fc _limit_flash = .
 0x000086fc _flash_size = (_limit_flash - g_pfnVectors)
...
 .word	UsageFault_Handler
 .word	_flash_size /* symbol you define in .ld linker script */
 .word	0
 .word	0
...
 

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
July 4, 2019

If that doesn't work try

 .word _limit_flash - g_pfnVectors /* compute size */

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
AP_040
AP_040Author
Senior
July 4, 2019

0690X000009YO8cQAG.png@Community member​ Yes, I have already used _flash_size symbol in the startup file.

.word I2C4_EV_IRQHandler

.word I2C4_ER_IRQHandler

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

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

In the linker file, symbol is used as per your suggestion. But not working.

YHass.14
Associate III
August 1, 2019

Hello,

@Community member​: If you use the Flash size for calculating and checking Flash CRC: can you please advise how to do it?

Thanks in advance.

Yacob Hassidim.

Tesla DeLorean
Guru
August 1, 2019

Expand to end answers on this thread.

https://community.st.com/s/question/0D50X00009Xkhp1SAB/flash-crc-integrity

But basically uses C 101 File-IO functions like fopen,fread, etc to read and navigate the binary data. If you have the size recorded at a fixed location in the image you could use that, but would swear objcopy can just output .BIN or .HEX, the former being size appropriately for the data contained in the .ELF

I've got tools that can work with .HEX or .ELF directly, but I'd really like to get paid for that amount of effort.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
YHass.14
Associate III
August 4, 2019

Hello @Community member​,

Thank you for your reply.

How can I use objcopy to calculate CRC and save it in a known address?

Sincerely,

Yacob Hassidim.

Pavel A.
Super User
August 5, 2019

@Community member​ 

The binary file is so large because you've chosen wrong start address (probably 0).

The start address of the flash is 0x08000000 and from there you need to copy the binary data.

If you start from 0, the size of course will be huge.

For manipulations on binary data, Python is very good and easy. No other linuxy stuff is needed on Windows.

And on Linux or Mac Python is great too.

-- pa

YHass.14
Associate III
August 5, 2019

Hello @Pavel A.​ 

Thank you for your answer.

As I know the start address set in the linker file (*.ld) in the Flash region.

The Flash region started from 0x8000000.

I attached my linker file.

Can you please check if there is a wrong value?

Yacob Hassidim.

Tesla DeLorean
Guru
August 5, 2019

You're describing SDRAM, and not storing the content you initialize there in FLASH.

You will need to make it a NOLOAD/NOINIT type section,

Or use the >EXTRAM_REGION AT> FLASH

along with the code in startup.s to copy the data after you have brought up the external memory interface.

/* Memories definition */

MEMORY

{

  CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K

  RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192K

  FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K

  EXTRAM_REGION (xrw) : ORIGIN = 0xD0000000, LENGTH = _Extram_Length /*CNT-32*/

}

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