I am writing firmware for an ARM platform in which I want to have the main bootloader relocatable in memory rather than always loaded at a fixed address during boot. This means that I need a relocatable format stored in Flash, like ELF.

If ELF is used then I need an ELF loader stored in the ROM code that first gets execution after reset. While this is okay, I also need that same relocation code in the bootloader .. so I will have a lot of code duplication and loss of Flash space if. My intent for the ROM is to just load the bootloader from Flash, so it really is going to be very simple.

I toyed around with creating simple ROM stub that jumped into the text section of the stored ELF image (linked at the address it is stored at in Flash). While this sort of works, I think it might be overkill for my intent.

tl;dr: All I want/need is a relocatable format to store my binary in Flash. Are there other options that are perhaps simpler than ELF that retain relocation tables?

  • \$\begingroup\$ Can you compile your main bootloader as position-indepedent code? \$\endgroup\$ – Dave Tweed May 1 at 1:00
  • \$\begingroup\$ @DaveTweed, I had not considered PIE without any image format. While I like the idea, the page you link has that it only works on aarch32. Why might that be? \$\endgroup\$ – sherrellbc May 1 at 1:11
  • \$\begingroup\$ I don't know. I'm just learning this ARM stuff myself. I just did a quick search to see whether the techniques I've used on other processors also applied to ARM, at least in general. \$\endgroup\$ – Dave Tweed May 1 at 1:53
  • \$\begingroup\$ I'm pretty sure I used '-fPIC' on Arm GCC years ago for more or less the exact same purpose, and it just worked straight out of the box. \$\endgroup\$ – Timo May 1 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.