Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intel hex format and position independent code using gcc

Tags:

bootloader

arm

I'm not sure if this is specific to the processor I'm using, so for what it's worth I'm using a Cortex M0+. I was wondering: if I generate a hex file through gcc using -fPIC, I produce...Position Independent Code. However, the intel hex file format that I get out of objcopy always has address information on each line's header. If I'm trying to write a bootloader, do I just ignore that information, skip the bytes relating to it, and load the actual code into memory wherever I want, or do I have to keep track of it somehow?

like image 304
Michael Stachowsky Avatar asked May 04 '26 12:05

Michael Stachowsky


1 Answers

The intel-HEX format was specially designed to programm PROMs, EPROMS or processors with an internal EPROM and is normally used with programmers for theses devices. The addresses at the beginning of the records have not much to do with the program code directly. They indicate at which address of the PROM the data will be written. Remember also that the PROM can be mapped anywhere into the address space of the processor, thus the final address can change anyway.

As long as you don't want to program a PROM you must remove anything except the data from the records. (Don't forget the checksum at the end ;-)

As I understand the intel-HEX format the records must not be contiguous, there may be holes in between.

Some remarks:

The -f PIC parameter is not responsible for the intel-HEX format. I think that somewhere in your command lines you'll find -O ihex. If you want to have a file that could be executed, objcopy provides better suited output formats.

As long as you don't write earlier stages of the boot process by yourself, you don't load your bootloader - it will be loaded for you. The address at which this will happen is normally fixed and not changeable. So there is no need for position independent code, but it doesn't hurt either.

like image 99
Kitana Avatar answered May 06 '26 05:05

Kitana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!