Ethan
Ethan

Reputation: 313

Questions about u-boot relocation feature

I am using the u-boot-2011.12 on my OMAP3 target, the cross tool chain is CodeSourcery arm-none-linux-gnueabi, I compiled u-boot, downloaded it onto the target and booted it, everything went fine,but I have some questions about the u-boot relocation feature, we know that this feature is base on PIC(position independent code), position independent code is generated by setting the -fpic flag to gcc, but I don't find fpic in the compile flags. Without the PIC, how can u-boot implement the relocation feature?

Upvotes: 0

Views: 2636

Answers (2)

ey3ball
ey3ball

Reputation: 11

I found this troubling too, and banged my head around this question for a few hours.

Luckily I stumbled upon the following thread on the u-boot mailing list :

http://lists.denx.de/pipermail/u-boot/2010-October/078297.html

What this says, is that at least on ARM, using -fPIC/-fPIE at COMPILE TIME is not necessary to generate position independent binaries. It eases the task of the runtime loader by doing as most work up-front as possible, but that's all.

Whether you use fPIC or not, you can always use -pic / -pie at LINK TIME, which will move all position-dependent references to a relocation section. Since no processing was performed at COMPILE TIME to add helpers, expect this section to be larger than when using -fPIC.

They conclude that for their purposes using -fPIC does not have any significant advantage over a link-time only solution.

[edit] See commit u-boot 92d5ecba for reference

arm: implement ELF relocations http://git.denx.de/cgi-bin/gitweb.cgi?p=u-boot.git;a=commit;h=92d5ecba47feb9961c3b7525e947866c5f0d2de5

Upvotes: 1

sessyargc.jp
sessyargc.jp

Reputation: 573

Remember when u-boot is running there is no OS yet. It doesn't really need the 'pic' feature used in most user applications. What I'll describe below is for the PowerPC architecture.

u-boot is initially running in NV memory (NAND or NOR). After u-boot initializes most of the peripherals (specially the RAM) it locates the top of the RAM, reserves some area for the global data, then copies itself to RAM. u-boot will then branch to the code in RAM and modify the fixups. u-boot is now relocated in RAM.

Look at the start.S file for your architecture and find the relocate_code() function. Then study, study, study...

Upvotes: 3

Related Questions