diff mbox

[U-Boot,v3,29/62] x86: Add support for 64-bit relocation

Message ID 20170116140427.29283-30-sjg@chromium.org
State Accepted
Delegated to: Bin Meng
Headers show

Commit Message

Simon Glass Jan. 16, 2017, 2:03 p.m. UTC
Add a 64-bit relocation function. SPL loads U-Boot into RAM at a fixed
address and runs it. U-Boot then relocates itself to the top of RAM using
this relocation function.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v3: None
Changes in v2: None

 arch/x86/lib/relocate.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

Comments

Bin Meng Jan. 17, 2017, 2:58 a.m. UTC | #1
On Mon, Jan 16, 2017 at 10:03 PM, Simon Glass <sjg@chromium.org> wrote:
> Add a 64-bit relocation function. SPL loads U-Boot into RAM at a fixed
> address and runs it. U-Boot then relocates itself to the top of RAM using
> this relocation function.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
>  arch/x86/lib/relocate.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>

applied to u-boot-x86, thanks!
diff mbox

Patch

diff --git a/arch/x86/lib/relocate.c b/arch/x86/lib/relocate.c
index 861e6675b3b..d207fddb756 100644
--- a/arch/x86/lib/relocate.c
+++ b/arch/x86/lib/relocate.c
@@ -47,6 +47,46 @@  int clear_bss(void)
 	return 0;
 }
 
+#if CONFIG_IS_ENABLED(X86_64)
+static void do_elf_reloc_fixups64(unsigned int text_base, uintptr_t size,
+				  Elf64_Rela *re_src, Elf64_Rela *re_end)
+{
+	Elf64_Addr *offset_ptr_rom, *last_offset = NULL;
+	Elf64_Addr *offset_ptr_ram;
+
+	do {
+		/* Get the location from the relocation entry */
+		offset_ptr_rom = (Elf64_Addr *)(uintptr_t)re_src->r_offset;
+
+		/* Check that the location of the relocation is in .text */
+		if (offset_ptr_rom >= (Elf64_Addr *)(uintptr_t)text_base &&
+		    offset_ptr_rom > last_offset) {
+			/* Switch to the in-RAM version */
+			offset_ptr_ram = (Elf64_Addr *)((ulong)offset_ptr_rom +
+							gd->reloc_off);
+
+			/* Check that the target points into .text */
+			if (*offset_ptr_ram >= text_base &&
+			    *offset_ptr_ram <= text_base + size) {
+				*offset_ptr_ram = gd->reloc_off +
+							re_src->r_addend;
+			} else {
+				debug("   %p: %lx: rom reloc %lx, ram %p, value %lx, limit %"
+				      PRIXPTR "\n",
+				      re_src, (ulong)re_src->r_info,
+				      (ulong)re_src->r_offset, offset_ptr_ram,
+				      (ulong)*offset_ptr_ram, text_base + size);
+			}
+		} else {
+			debug("   %p: %lx: rom reloc %lx, last %p\n", re_src,
+			      (ulong)re_src->r_info, (ulong)re_src->r_offset,
+			      last_offset);
+		}
+		last_offset = offset_ptr_rom;
+
+	} while (++re_src < re_end);
+}
+#else
 static void do_elf_reloc_fixups32(unsigned int text_base, uintptr_t size,
 				  Elf32_Rel *re_src, Elf32_Rel *re_end)
 {
@@ -84,6 +124,7 @@  static void do_elf_reloc_fixups32(unsigned int text_base, uintptr_t size,
 
 	} while (++re_src < re_end);
 }
+#endif
 
 /*
  * This function has more error checking than you might expect. Please see
@@ -109,7 +150,11 @@  int do_elf_reloc_fixups(void)
 #else
 	panic("No CONFIG_SYS_TEXT_BASE");
 #endif
+#if CONFIG_IS_ENABLED(X86_64)
+	do_elf_reloc_fixups64(text_base, size, re_src, re_end);
+#else
 	do_elf_reloc_fixups32(text_base, size, re_src, re_end);
+#endif
 
 	return 0;
 }