[U-Boot] [RFC PATCH 4/7] reboard: arm: Add relocation function

Simon Glass sjg at chromium.org
Tue Nov 22 00:57:57 CET 2011


Add a function to process a single ELF relocation.

Signed-off-by: Simon Glass <sjg at chromium.org>
---
 arch/arm/lib/Makefile     |    4 +++
 arch/arm/lib/arch_reloc.c |   47 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/lib/arch_reloc.c

diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 300c8fa..ca2802a 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -48,6 +48,10 @@ SOBJS-$(CONFIG_USE_ARCH_MEMSET) += memset.o
 SOBJS-$(CONFIG_USE_ARCH_MEMCPY) += memcpy.o
 endif
 
+ifndef CONFIG_SYS_LEGACY_BOARD
+COBJS-y += arch_reloc.o
+endif
+
 SRCS	:= $(GLSOBJS:.o=.S) $(GLCOBJS:.o=.c) \
 	   $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c)
 OBJS	:= $(addprefix $(obj),$(SOBJS-y) $(COBJS-y))
diff --git a/arch/arm/lib/arch_reloc.c b/arch/arm/lib/arch_reloc.c
new file mode 100644
index 0000000..80cf5a0
--- /dev/null
+++ b/arch/arm/lib/arch_reloc.c
@@ -0,0 +1,47 @@
+/*
+ * 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>
+
+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;
+}
-- 
1.7.3.1



More information about the U-Boot mailing list