[En-Nut-Discussion] NutOS relocatable?

Harald Kipp harald.kipp at egnite.de
Thu Apr 7 10:52:26 CEST 2011

Hi Ulrich,

On 4/5/2011 11:32 PM, Ulrich Prinz wrote:

> How difficult would it be to make Nut/OS relocatable to have the
> firmware at two different places in the system? As the firmware is
> compiled once it needs to be dynamic in the way that it might be started
> from two different flash sections.

AFAIK, you cannot force the compiler to avoid absolute locations. 
Therefore the linker will create a binary, which can only run at a fixed 
memory location on targets without MMU. In order to create relocatable 
code, you need to use assembly language.

By default the compiler generates relocatable code. The resulting object 
files contain additional information about absolute addressing, that is 
used by the linker when creating the final binary for a specific memory 

It might be possible to instruct the linker to create a relocatable elf 
file. And it won't be too hard for the boot loader to read the binary 
code from such an elf file and "fix" the absolute addresses. I remember, 
that relocatable elf files had been available on some platforms. No 
idea, if this is the case for ARM.

As you would need only 2 or 3 different binaries, a funny idea pops up. 
You may create a basic binary for the default location and use some kind 
of patching mechanism to modify this code to run at a different 
location. Your custom binary would then consist of 2 parts, the patch 
location table and the unpatched, default binary. In the most simple 
case you'd only need to add/subtract a fixed offset to all patch locations.

Well...unfortunately the linker may do more than just fixing absolute 
addresses. It may be smart enough to do some additional optimization, 
which will require more advanced patches by the boot loader.



More information about the En-Nut-Discussion mailing list