[U-Boot] [PATCH v2 5/6] reboard: arm: Move over to generic relocation

Simon Glass sjg at chromium.org
Sat Dec 10 20:16:15 CET 2011


Add a function to process a single ELF relocation and switch ARM over
to use generic relocation.

Unfortunately a few boards need to be modified to make this work
(mostly adding link symbols to the .lds files).

Signed-off-by: Simon Glass <sjg at chromium.org>
---
Changes in v2:
- Use an inline relocation function to reduce code size

 arch/arm/config.mk                          |    3 -
 arch/arm/include/asm/reloc.h                |   56 +++++++++++++++++++++++++++
 nand_spl/board/freescale/mx31pdk/Makefile   |    8 +++-
 nand_spl/board/freescale/mx31pdk/u-boot.lds |    1 +
 nand_spl/board/karo/tx25/Makefile           |    8 +++-
 nand_spl/board/karo/tx25/u-boot.lds         |    1 +
 6 files changed, 72 insertions(+), 5 deletions(-)
 create mode 100644 arch/arm/include/asm/reloc.h

diff --git a/arch/arm/config.mk b/arch/arm/config.mk
index f47d4f7..45f9dca 100644
--- a/arch/arm/config.mk
+++ b/arch/arm/config.mk
@@ -81,6 +81,3 @@ endif
 ifndef CONFIG_NAND_SPL
 LDFLAGS_u-boot += -pie
 endif
-
-# We use legacy relocation for now
-CONFIG_SYS_SKIP_RELOC := y
diff --git a/arch/arm/include/asm/reloc.h b/arch/arm/include/asm/reloc.h
new file mode 100644
index 0000000..3b6491d
--- /dev/null
+++ b/arch/arm/include/asm/reloc.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <elf.h>
+
+/**
+ * Process a single ELF relocation entry
+ *
+ * @param addr		Pointer to address of intruction/data to relocate
+ * @param info		The ELF information word / flags
+ * @param symtab	The ELF relocation symbol table
+ * @param reloc_off	Offset of relocated U-Boot relative to load address
+ * @return 0 if ok, -1 on error
+ */
+static inline int arch_elf_relocate_entry(Elf32_Addr *addr, Elf32_Word info,
+			    Elf32_Sym *symtab, ulong reloc_off)
+{
+	int sym;
+
+	switch (ELF32_R_TYPE(info)) {
+	/* relative fix: increase location by offset */
+	case 23: /* TODO: add R_ARM_... defines to elf.h */
+		*addr += reloc_off;
+		break;
+
+	/* absolute fix: set location to (offset) symbol value */
+	case 2:
+		sym = ELF32_R_SYM(info);
+		*addr = symtab[sym].st_value + reloc_off;
+		break;
+
+	default:
+		debug("*** Invalid relocation\n");
+		return -1;
+	}
+	return 0;
+}
diff --git a/nand_spl/board/freescale/mx31pdk/Makefile b/nand_spl/board/freescale/mx31pdk/Makefile
index 87784d2..470e320 100644
--- a/nand_spl/board/freescale/mx31pdk/Makefile
+++ b/nand_spl/board/freescale/mx31pdk/Makefile
@@ -11,7 +11,7 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o lowlevel_init.o proc.o reloc.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
@@ -50,6 +50,12 @@ $(obj)%.o:	$(SRCTREE)/board/freescale/mx31pdk/%.S
 $(obj)%.o:	$(SRCTREE)/nand_spl/%.c
 	$(CC) $(CFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/common/%.c
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 # defines $(obj).depend target
 include $(SRCTREE)/rules.mk
 
diff --git a/nand_spl/board/freescale/mx31pdk/u-boot.lds b/nand_spl/board/freescale/mx31pdk/u-boot.lds
index d2b08f6..2273e9b 100644
--- a/nand_spl/board/freescale/mx31pdk/u-boot.lds
+++ b/nand_spl/board/freescale/mx31pdk/u-boot.lds
@@ -51,6 +51,7 @@ SECTIONS
 	__u_boot_cmd_end = .;
 
 	. = ALIGN(4);
+	__image_copy_end = .;
 
 	.rel.dyn : {
 		__rel_dyn_start = .;
diff --git a/nand_spl/board/karo/tx25/Makefile b/nand_spl/board/karo/tx25/Makefile
index 0336346..cac5600 100644
--- a/nand_spl/board/karo/tx25/Makefile
+++ b/nand_spl/board/karo/tx25/Makefile
@@ -32,7 +32,7 @@ LDFLAGS := -T $(nandobj)u-boot.lds -Ttext $(CONFIG_SYS_TEXT_BASE) $(LDFLAGS) \
 AFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 CFLAGS	+= -DCONFIG_SPL_BUILD -DCONFIG_NAND_SPL
 
-SOBJS	= start.o lowlevel_init.o
+SOBJS	= start.o lowlevel_init.o proc.o reloc.o
 COBJS	= nand_boot_fsl_nfc.o
 
 SRCS	:= $(SRCTREE)/nand_spl/nand_boot_fsl_nfc.c
@@ -71,6 +71,12 @@ $(obj)%.o:	$(SRCTREE)/board/karo/tx25/%.S
 $(obj)%.o:	$(SRCTREE)/nand_spl/%.c
 	$(CC) $(CFLAGS) -c -o $@ $<
 
+$(obj)%.o:	$(SRCTREE)/common/%.c
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+$(obj)%.o:	$(SRCTREE)/arch/arm/lib/%.S
+	$(CC) $(AFLAGS) -c -o $@ $<
+
 # defines $(obj).depend target
 include $(SRCTREE)/rules.mk
 
diff --git a/nand_spl/board/karo/tx25/u-boot.lds b/nand_spl/board/karo/tx25/u-boot.lds
index d2b08f6..2273e9b 100644
--- a/nand_spl/board/karo/tx25/u-boot.lds
+++ b/nand_spl/board/karo/tx25/u-boot.lds
@@ -51,6 +51,7 @@ SECTIONS
 	__u_boot_cmd_end = .;
 
 	. = ALIGN(4);
+	__image_copy_end = .;
 
 	.rel.dyn : {
 		__rel_dyn_start = .;
-- 
1.7.3.1



More information about the U-Boot mailing list