I have a project for a cortex M4 microcontroller, which compiles and runs fine. I'd like to add the checksum of the file to the file itself, so I can check the correctness of the binary at runtime.
The address where the checksum needs to be in the flash memory is set to a fixed address (0x08040000) in the linker configuration. At compile time the value is set to 0. After linking i calculate the checksum of the binary and store it at this fixed address in the elf file. That's the idea.
The debugger needs an elf file for debugging, so I need to set the value in the elf file. Setting it in the bin would be rather easy.
From an old source (which I suppose worked years ago) I found:
arm-none-eabi-gdb --write "program.elf" -batch -ex "set { unsigned long} 0x8040000 = 2269382981"
Where 2269382981 ist the calculated checksum. There is no output if I execute the line above from the powershell.
However it does not work with msys2 Packet mingw-w64-x86_64-arm-none-eabi-gdb 9.2-6
as
readelf shows.
c:\>readelf -x.BinaryInfo .\program.elf
Hex dump of section '.BinaryInfo':
0x08040000 00000000 04000408 47770508 ........Gw..
How can I set a value in an elf file?
How can I get gdb to give gd to give some kind of error message?
Thanks!