[U-Boot] [PATCH] [x86] Don't relocate symbols which point to things that aren't relocated

Gabe Black gabeblack at chromium.org
Tue Nov 8 08:02:23 CET 2011


This and my previous patch are quite related and could have been combined
into a series or even a single patch. I didn't see this one until I'd
already sent the other one, though. Even though keeping them separate was
unintentional, these are doing slightly different things. The first one
fixes a bug and is important to get in, while the second improves the
mechanism to avoid the bug all together.

Gabe

On Mon, Nov 7, 2011 at 10:58 PM, Gabe Black <gabeblack at chromium.org> wrote:

> This change adds an upper bound for symbols which are fixed up after u-boot
> is relocated into RAM. This way portions that are left at their original
> location can be referred to without having to manually fix up any pointers.
>
> Signed-off-by: Gabe Black <gabeblack at chromium.org>
> ---
>  arch/x86/lib/bios_setup.c |    7 ++-----
>  arch/x86/lib/board.c      |   14 +++++++++++---
>  arch/x86/lib/realmode.c   |    7 ++-----
>  3 files changed, 15 insertions(+), 13 deletions(-)
>
> diff --git a/arch/x86/lib/bios_setup.c b/arch/x86/lib/bios_setup.c
> index 6c6b0fe..8112f33 100644
> --- a/arch/x86/lib/bios_setup.c
> +++ b/arch/x86/lib/bios_setup.c
> @@ -140,11 +140,8 @@ static void setvector(int vector, u16 segment, void
> *handler)
>
>  int bios_setup(void)
>  {
> -       /*
> -        * The BIOS section is not relocated and still in the ROM. The
> -        * __bios_start symbol was adjusted, though, so adjust it back.
> -        */
> -       ulong bios_start = (ulong)&__bios_start - gd->reloc_off;
> +       /* The BIOS section is not relocated and still in the ROM. */
> +       ulong bios_start = (ulong)&__bios_start;
>        ulong bios_size = (ulong)&__bios_size;
>
>        static int done=0;
> diff --git a/arch/x86/lib/board.c b/arch/x86/lib/board.c
> index 8963580..ac135b7 100644
> --- a/arch/x86/lib/board.c
> +++ b/arch/x86/lib/board.c
> @@ -227,10 +227,18 @@ static int do_elf_reloc_fixups(void)
>        Elf32_Rel *re_src = (Elf32_Rel *)(&__rel_dyn_start);
>        Elf32_Rel *re_end = (Elf32_Rel *)(&__rel_dyn_end);
>
> +       /* The size of the region of u-boot that runs out of RAM. */
> +       uintptr_t size = &__bss_end - &__text_start;
> +
>        do {
> -               if (re_src->r_offset >= CONFIG_SYS_TEXT_BASE)
> -                       if (*(Elf32_Addr *)(re_src->r_offset +
> gd->reloc_off) >= CONFIG_SYS_TEXT_BASE)
> -                               *(Elf32_Addr *)(re_src->r_offset +
> gd->reloc_off) += gd->reloc_off;
> +               if (re_src->r_offset >= CONFIG_SYS_TEXT_BASE) {
> +                       Elf32_Addr *addr = (Elf32_Addr *)
> +                               (re_src->r_offset + gd->reloc_off);
> +                       if (*addr >= CONFIG_SYS_TEXT_BASE &&
> +                               *addr < (CONFIG_SYS_TEXT_BASE + size)) {
> +                               *addr += gd->reloc_off;
> +                       }
> +               }
>        } while (re_src++ < re_end);
>
>        return 0;
> diff --git a/arch/x86/lib/realmode.c b/arch/x86/lib/realmode.c
> index f8f2251..7637e2c 100644
> --- a/arch/x86/lib/realmode.c
> +++ b/arch/x86/lib/realmode.c
> @@ -34,11 +34,8 @@ extern char realmode_enter;
>
>  int realmode_setup(void)
>  {
> -       /*
> -        * The realmode section is not relocated and still in the ROM. The
> -        * __realmode_start symbol was adjusted, though, so adjust it back.
> -        */
> -       ulong realmode_start = (ulong)&__realmode_start - gd->reloc_off;
> +       /* The realmode section is not relocated and still in the ROM. */
> +       ulong realmode_start = (ulong)&__realmode_start;
>        ulong realmode_size = (ulong)&__realmode_size;
>
>        /* copy the realmode switch code */
> --
> 1.7.3.1
>
>


More information about the U-Boot mailing list