0

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!

artless noise
  • 21,212
  • 6
  • 68
  • 105
Bil_Bomba
  • 183
  • 1
  • 8

1 Answers1

0

My Version of arm-none-eabi-gdb is obviously broken, even

arm-none-eabi-gdb --version

gives no response. I installed it via pacman from the msys2 shell.

But I figured I dont need an ARM version of GDB to edit the elf file. So I just use

gdb --write "program.elf" -batch -ex "set { unsigned long} 0x8040000 = 2269382981"

which sets the value correctly.

Edit: Bug reported to: https://github.com/msys2/MINGW-packages/issues/16387

Bil_Bomba
  • 183
  • 1
  • 8