[U-Boot] [PATCH 12/13] Conditionally perform common relocation fixups

Peter Tyser ptyser at xes-inc.com
Mon Sep 21 18:20:36 CEST 2009


Add #ifdefs where necessary to not perform relocation fixups.  This
allows boards/architectures which support relocation to trim a decent
chunk of code.

Note that this patch doesn't add #ifdefs to architecture-specific code
which does not support relocation.

Signed-off-by: Peter Tyser <ptyser at xes-inc.com>
---
 common/cmd_bootm.c      |    4 +++-
 common/cmd_date.c       |    4 ++++
 common/dlmalloc.c       |    2 ++
 common/env_common.c     |    4 ++++
 common/hush.c           |    4 ++++
 common/image.c          |    6 +++++-
 common/serial.c         |    2 ++
 common/stdio.c          |    5 +++--
 disk/part.c             |    5 ++++-
 drivers/mtd/nand/nand.c |    2 ++
 fs/ubifs/ubifs.c        |    4 ++++
 include/post.h          |    2 ++
 post/post.c             |    2 ++
 13 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 365ceeb..8f83598 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -561,7 +561,6 @@ int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 /*******************************************************************/
 /* bootm - boot application image from image in memory */
 /*******************************************************************/
-static int relocated = 0;
 
 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
@@ -569,6 +568,8 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	ulong		load_end = 0;
 	int		ret;
 	boot_os_fn	*boot_fn;
+#ifndef CONFIG_RELOC_FIXUP_WORKS
+	static int relocated = 0;
 
 	/* relocate boot function table */
 	if (!relocated) {
@@ -578,6 +579,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 				boot_os[i] += gd->reloc_off;
 		relocated = 1;
 	}
+#endif
 
 	/* determine if we have a sub command */
 	if (argc > 1) {
diff --git a/common/cmd_date.c b/common/cmd_date.c
index b69e935..9f50f89 100644
--- a/common/cmd_date.c
+++ b/common/cmd_date.c
@@ -35,7 +35,11 @@ const char *weekdays[] = {
 	"Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur",
 };
 
+#ifdef CONFIG_RELOC_FIXUP_WORKS
+#define RELOC(a)	a
+#else
 #define RELOC(a)	((typeof(a))((unsigned long)(a) + gd->reloc_off))
+#endif
 
 int mk_date (char *, struct rtc_time *);
 
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 241db8c..ca088a1 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -1494,6 +1494,7 @@ static mbinptr av_[NAV * 2 + 2] = {
  IAV(120), IAV(121), IAV(122), IAV(123), IAV(124), IAV(125), IAV(126), IAV(127)
 };
 
+#ifndef CONFIG_RELOC_FIXUP_WORKS
 void malloc_bin_reloc (void)
 {
 	unsigned long *p = (unsigned long *)(&av_[2]);
@@ -1502,6 +1503,7 @@ void malloc_bin_reloc (void)
 		*p++ += gd->reloc_off;
 	}
 }
+#endif
 
 ulong mem_malloc_start = 0;
 ulong mem_malloc_end = 0;
diff --git a/common/env_common.c b/common/env_common.c
index be64d13..439a4a9 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -224,8 +224,10 @@ void set_default_env(void)
 
 void env_relocate (void)
 {
+#ifndef CONFIG_RELOC_FIXUP_WORKS
 	DEBUGF ("%s[%d] offset = 0x%lx\n", __FUNCTION__,__LINE__,
 		gd->reloc_off);
+#endif
 
 #ifdef CONFIG_AMIGAONEG3SE
 	enable_nvram();
@@ -236,7 +238,9 @@ void env_relocate (void)
 	 * The environment buffer is embedded with the text segment,
 	 * just relocate the environment pointer
 	 */
+#ifndef CONFIG_RELOC_FIXUP_WORKS
 	env_ptr = (env_t *)((ulong)env_ptr + gd->reloc_off);
+#endif
 	DEBUGF ("%s[%d] embedded ENV at %p\n", __FUNCTION__,__LINE__,env_ptr);
 #else
 	/*
diff --git a/common/hush.c b/common/hush.c
index 528dd25..06c5ff8 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -3270,6 +3270,7 @@ int parse_file_outer(void)
 }
 
 #ifdef __U_BOOT__
+#ifndef CONFIG_RELOC_FIXUP_WORKS
 static void u_boot_hush_reloc(void)
 {
 	unsigned long addr;
@@ -3280,6 +3281,7 @@ static void u_boot_hush_reloc(void)
 		r->literal = (char *)addr;
 	}
 }
+#endif
 
 int u_boot_hush_start(void)
 {
@@ -3290,7 +3292,9 @@ int u_boot_hush_start(void)
 		top_vars->next = 0;
 		top_vars->flg_export = 0;
 		top_vars->flg_read_only = 1;
+#ifndef CONFIG_RELOC_FIXUP_WORKS
 		u_boot_hush_reloc();
+#endif
 	}
 	return 0;
 }
diff --git a/common/image.c b/common/image.c
index d0f169d..6eaf41e 100644
--- a/common/image.c
+++ b/common/image.c
@@ -513,7 +513,7 @@ char *get_table_entry_name (table_entry_t *table, char *msg, int id)
 {
 	for (; table->id >= 0; ++table) {
 		if (table->id == id)
-#ifdef USE_HOSTCC
+#if defined(USE_HOSTCC) || defined(CONFIG_RELOC_FIXUP_WORKS)
 			return table->lname;
 #else
 			return table->lname + gd->reloc_off;
@@ -578,7 +578,11 @@ int get_table_entry_id (table_entry_t *table,
 	fprintf (stderr, "\n");
 #else
 	for (t = table; t->id >= 0; ++t) {
+#ifdef CONFIG_RELOC_FIXUP_WORKS
+		if (t->sname && strcmp(t->sname, name) == 0)
+#else
 		if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
+#endif
 			return (t->id);
 	}
 	debug ("Invalid %s Type: %s\n", table_name, name);
diff --git a/common/serial.c b/common/serial.c
index 41a24c2..b4db46b 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -81,12 +81,14 @@ struct serial_device *default_serial_console(void) __attribute__((weak, alias("_
 
 int serial_register (struct serial_device *dev)
 {
+#ifndef CONFIG_RELOC_FIXUP_WORKS
 	dev->init += gd->reloc_off;
 	dev->setbrg += gd->reloc_off;
 	dev->getc += gd->reloc_off;
 	dev->tstc += gd->reloc_off;
 	dev->putc += gd->reloc_off;
 	dev->puts += gd->reloc_off;
+#endif
 
 	dev->next = serial_devices;
 	serial_devices = dev;
diff --git a/common/stdio.c b/common/stdio.c
index 697df5a..5e58dbe 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -201,7 +201,8 @@ int stdio_deregister(char *devname)
 
 int stdio_init (void)
 {
-#ifndef CONFIG_ARM	/* already relocated for current ARM implementation */
+#if !defined(CONFIG_ARM) && !defined(CONFIG_RELOC_FIXUP_WORKS)
+	/* already relocated for current ARM implementation */
 	ulong relocation_offset = gd->reloc_off;
 	int i;
 
@@ -210,7 +211,7 @@ int stdio_init (void)
 		stdio_names[i] = (char *) (((ulong) stdio_names[i]) +
 						relocation_offset);
 	}
-#endif
+#endif /* !ARM && !CONFIG_RELOC_FIXUP_WORKS */
 
 	/* Initialize the list */
 	INIT_LIST_HEAD(&(devs.list));
diff --git a/disk/part.c b/disk/part.c
index b92fb45..9ced452 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -80,7 +80,10 @@ block_dev_desc_t *get_dev(char* ifname, int dev)
 	block_dev_desc_t* (*reloc_get_dev)(int dev);
 
 	while (drvr->name) {
-		reloc_get_dev = drvr->get_dev + gd->reloc_off;
+		reloc_get_dev = drvr->get_dev;
+#ifndef CONFIG_RELOC_FIXUP_WORKS
+		reloc_get_dev += gd->reloc_off;
+#endif
 		if (strncmp(ifname, drvr->name, strlen(drvr->name)) == 0)
 			return reloc_get_dev(dev);
 		drvr++;
diff --git a/drivers/mtd/nand/nand.c b/drivers/mtd/nand/nand.c
index 9065fa9..47d6872 100644
--- a/drivers/mtd/nand/nand.c
+++ b/drivers/mtd/nand/nand.c
@@ -54,8 +54,10 @@ static void nand_init_chip(struct mtd_info *mtd, struct nand_chip *nand,
 		if (nand_scan(mtd, maxchips) == 0) {
 			if (!mtd->name)
 				mtd->name = (char *)default_nand_name;
+#ifndef CONFIG_RELOC_FIXUP_WORKS
 			else
 				mtd->name += gd->reloc_off;
+#endif
 
 #ifdef CONFIG_MTD_DEVICE
 			/*
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 8ede188..5b7abad 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -124,9 +124,13 @@ int ubifs_decompress(const void *in_buf, int in_len, void *out_buf,
 static int __init compr_init(struct ubifs_compressor *compr)
 {
 	ubifs_compressors[compr->compr_type] = compr;
+
+#ifndef CONFIG_RELOC_FIXUP_WORKS
 	ubifs_compressors[compr->compr_type]->name += gd->reloc_off;
 	ubifs_compressors[compr->compr_type]->capi_name += gd->reloc_off;
 	ubifs_compressors[compr->compr_type]->decompress += gd->reloc_off;
+#endif
+
 	return 0;
 }
 
diff --git a/include/post.h b/include/post.h
index fe96312..9fcd3ce 100644
--- a/include/post.h
+++ b/include/post.h
@@ -73,7 +73,9 @@ void post_output_backlog ( void );
 int post_run (char *name, int flags);
 int post_info (char *name);
 int post_log (char *format, ...);
+#ifndef CONFIG_RELOC_FIXUP_WORKS
 void post_reloc (void);
+#endif
 unsigned long post_time_ms (unsigned long base);
 
 extern struct post_test post_list[];
diff --git a/post/post.c b/post/post.c
index bc8114e..b74e762 100644
--- a/post/post.c
+++ b/post/post.c
@@ -393,6 +393,7 @@ int post_log (char *format, ...)
 	return 0;
 }
 
+#ifndef CONFIG_RELOC_FIXUP_WORKS
 void post_reloc (void)
 {
 	unsigned int i;
@@ -437,6 +438,7 @@ void post_reloc (void)
 		}
 	}
 }
+#endif
 
 
 /*
-- 
1.6.2.1



More information about the U-Boot mailing list