[U-Boot] U-Boot Relocation (all sections, not just .text)

Hi All,
I am trying to fully relocate U-Boot out of the Boot Flash into RAM on my i386 (AMD sc520) board in order to allow the Boot Flash to be flashed from within U-Boot itself (upgrade in place)
I have added code to patch the command table so all the code can be relocated. Further investigation revealed that the code has absolute references into the Boot Flash - printf() format strings are a prime example, but I'm sure there are others
After a bit of searching around the 'net I discovered gcc's -fpie and ld's -pie flags which generation a Position Independent Executable.
This looks like it will do the trick - .text is (practically) identical for varying values of TEXT_BASE and ld produces a .got section as expected. However, ld creates a lot more sections than just .got
Before I go down the path of dissecting all this new and wonderful information, I thought I would quickly ask:
- Am I looking at the problem the wrong way? - Has anyone here looked into making U-Boot 100% relocatable before? - Is U-Boot already 100% relocatable (not just code) for any other platforms? - Has anyone here used pie before and had to write code to adjust the offset tables? - Does anyone know of a good reference for pie / .got / elf (I have found bits and pieces here and there, but no definitive reference)
And lastly - Is it worth the effort, or I should I just set TEXT_BASE to a known memory location and not bother with the relocation at all?
tia
Graeme

"Graeme Russ" graeme.russ@gmail.com wrote:
- Am I looking at the problem the wrong way?
No, I think you're on the right track.
- Has anyone here looked into making U-Boot 100% relocatable before?
I've looked at it briefly and come to the conclusion that -pie is probably the way to go. But I haven't written any code to confirm this.
- Is U-Boot already 100% relocatable (not just code) for any other platforms?
I think there are patches for PowerPC somewhere.
- Has anyone here used pie before and had to write code to adjust the offset tables?
I haven't, but it's on my TODO list for AVR32. I suspect the code will be very similar to the relocation code in the dynamic linker.
That said, the current AVR32 code does relocate the GOT. The only remaining piece is relocating statically initialized pointers.
- Does anyone know of a good reference for pie / .got / elf (I have found bits and pieces here and there, but no definitive reference)
Perhaps the i386 ABI spec will provide some hints. The dynamic linker code in glibc or uClibc might also be worth a look.
Haavard

On Fri, Oct 10, 2008 at 6:55 AM, Haavard Skinnemoen haavard.skinnemoen@atmel.com wrote:
"Graeme Russ" graeme.russ@gmail.com wrote:
- Am I looking at the problem the wrong way?
No, I think you're on the right track.
- Has anyone here looked into making U-Boot 100% relocatable before?
I've looked at it briefly and come to the conclusion that -pie is probably the way to go. But I haven't written any code to confirm this.
There was a long thread about this a while ago (and others longer ago)
http://news.gmane.org/find-root.php?message_id=%3cf608b67d0807231039i434e96d...
I think the upshot was that the behavior of different versions of gcc was varied enough that it was hit or miss whether things would work depending on architecture, and versions of gcc, linker, etc, but I confess I didn't wade through all the details
participants (3)
-
Andrew Dyer
-
Graeme Russ
-
Haavard Skinnemoen