1
votes

I use OpenOcd to flash the Elf image of a STM32 ARM Cmake project.

In the mem.ld script the origin address of the FLASH sector is assigned with an address offset to 0x08020200.

If the Elf file is written to the Flash using OpenOCD and the write_image command it seems like the ELF header is written to the FLASH at 0x08020000.

enter image description here

The application binary is correctly written to the flash at 0x08020200 (the first four bytes at 0x08020200 reflect the stack pointer value)

Since 0x08020200 is a address within the flash sector 5 (0x08020000 - 0x0803FFFF) i would expect the auto erase feature of the OpenOcd write_image command to erase the entire sector 5 (because only full sectors can be erased)

What could cause the ELF header to be written to flash at address 0x08020000 ?

I performed the following steps:

  • Manually erased the entire flash memory
  • Dumped the entire flash content with the OpenOcd dump_image command
  • Checked the dumped image represents a clear flash (all bytes 0xFF)
  • Flashed the test.elf file with the OpenOcd write_image command
  • Dumped the entire flash content with the OpenOcd dump_image command again
  • Checked the first four bytes at 0x08020200 reflect the stack pointer value
  • Checked content of flash at 0x08020000 -> ELF header was written to flash
1
I edited your question to make it clear this is a CLion configuration/usage issue - I found the original wording, 'Flashing of ELF file causes ELF header to be written to Flash' a bit confusing. By the way, can you only see the ELF header in the flash, or the whole ELF file ? - Frant
openocd knows how to read and use elf files properly, how are you using the tool? - old_timer
@old_timer: my undestanding is that he is not using openocd directly, but through Jetbrain's CLion IDE. This is thefore likely a Clion configuration issue, not an openocd one, since, as you were pointing out, openocd does speak ELF. - Frant
I did some further testing today and my question was not correct at many points. Therefore i edited the original question. I also removed the CLion topic because i was able to reproduce the problem by just using OpenOcd directly. - Y. Wilkening
How exactly are you using write_image command? Do you use type argument? - domen

1 Answers

-1
votes

I have the same problem when ELF header is programmed at the start of flash, but I have this problem with "stm32 programmer CLI" (not openOCD) and I fixed it by means HEX. If I use hex file instead ELF beginning of flash isn't corrupted.