[U-Boot] armv8 relocation questions

Darwin Rambo drambo at broadcom.com
Tue May 13 23:38:59 CEST 2014


I'm hoping someone can help answer these questions about armv8 relocation.

The CONFIG_SYS_TEXT_BASE seems to be be usually setup to a decent amount 
of alignment. For the purposes of this discussion, let's say it would 
normally be 0x88000000 and all is well. The relocation address moves to 
near the end of memory, to say, 0xfffa8000. So far so good.

Now let's say I want to shift the image a bit so that I can add a small 
32-byte header required by a previous bootloader. So I set 
CONFIG_SYS_TEXT_BASE to 0x88000020, and the relocated address is still 
0xfffa8000 and the relocated vectors should be at 0xfffa9000. The image 
crashes so after some debugging, I find that the code appears to be 
relocated fine, but some sections have symbols that are not relocated 
properly. The vectors try to relocate to 0xfffa8fe0 and rodata.str1.1 
printf format strings are also 0x20 off. There are likely other offset 
sections with issues as well.

The relocation offset is 0x77fa7fe0 due to the calculations in 
arch/arm/lib/board.c. Simplifying, they look like this:

         addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;

         /* round down to next 4 kB limit */
         addr &= ~(4096 - 1);
         debug("Top of RAM usable for U-Boot at: %08lx\n", addr);

         /*
          * reserve memory for U-Boot code, data & bss
          * round down to next 4 kB limit
          */
         addr -= gd->mon_len;
         addr &= ~(4096 - 1);

         addr += 0x20; // hack to adjust relocaddr to aligned address...

<snip>

gd->relocaddr = addr;
         gd->start_addr_sp = addr_sp;
         gd->reloc_off = addr - _TEXT_BASE;
         debug("relocation Offset is: %08lx\n", gd->reloc_off);


Since _TEXT_BASE is 0x88000020 and addr is 0xfffa8000, the reloc_off is 
a number like 0x77fa7fe0.

Now if I add 0x20 to 'addr' above just before the <snip>, relocaddr 
becomes 0x77fa8000 and the relocation works perfectly and no more 
crashes happen.

So my question - is the CONFIG_SYS_TEXT_BASE alignment requirement 
related to to any assumptions in the linker itself about image base 
alignment, specifically referring to creation of the rela.dyn sections 
and their use for image relocation?

A related question is if CONFIG_SYS_TEXT_BASE needs to be at a specific 
alignment. The maximum alignment in the armv8 code base is ".align 11" 
which I believe means 0x800 or 2048.

Note that an armv7 target appears to relocate properly with smaller 
offsets such as 0x20.

Thanks.

Best Regards,
Darwin Rambo




More information about the U-Boot mailing list