summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2011-11-27 17:51:22 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2011-11-29 20:59:56 +0100
commit351058fa51dbc010c37906b46ecf67a41dbbad8d (patch)
treed7618117468f050f94ce05cbf0079826b0cb6eac
parentec4ee82ca96a6a4867cd3f2e58fed4afd816d14a (diff)
downloadbarebox-351058fa51dbc010c37906b46ecf67a41dbbad8d.tar.gz
barebox-351058fa51dbc010c37906b46ecf67a41dbbad8d.tar.xz
bootm: push relocate_image up to the generic command
All handlers used to just relocate the image without any checks, so we are doomed if we write outside of SDRAM or will overwrite ourselves. Move the relocation up to the generic part where we have a chance of catching these issues. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--arch/arm/lib/bootm.c7
-rw-r--r--arch/blackfin/lib/blackfin_linux.c3
-rw-r--r--arch/nios2/lib/bootm.c3
-rw-r--r--arch/ppc/lib/ppclinux.c3
-rw-r--r--commands/bootm.c17
5 files changed, 17 insertions, 16 deletions
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index a104aaa371..5b85ba9d31 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -29,13 +29,6 @@ static int do_bootm_linux(struct image_data *data)
debug("## Transferring control to Linux (at address 0x%p) ...\n",
theKernel);
- if (relocate_image(data->os, (void *)image_get_load(os_header)))
- return -1;
-
- if (data->initrd)
- if (relocate_image(data->initrd, (void *)image_get_load(&data->initrd->header)))
- return -1;
-
/* we assume that the kernel is in place */
printf("\nStarting kernel %s...\n\n", data->initrd ? "with initrd " : "");
diff --git a/arch/blackfin/lib/blackfin_linux.c b/arch/blackfin/lib/blackfin_linux.c
index a20cf55748..9da9ec4e58 100644
--- a/arch/blackfin/lib/blackfin_linux.c
+++ b/arch/blackfin/lib/blackfin_linux.c
@@ -50,9 +50,6 @@ static int do_bootm_linux(struct image_data *idata)
appl = (int (*)(char *))image_get_ep(os_header);
printf("Starting Kernel at 0x%p\n", appl);
- if (relocate_image(os_handle, (void *)image_get_load(os_header)))
- return -1;
-
icache_disable();
strncpy(cmdlinedest, cmdline, 0x1000);
diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c
index c38243f9a3..b5b344f499 100644
--- a/arch/nios2/lib/bootm.c
+++ b/arch/nios2/lib/bootm.c
@@ -43,9 +43,6 @@ static int do_bootm_linux(struct image_data *idata)
kernel = (void (*)(int, int, int, const char *))ntohl(os_header->ih_ep);
- if (relocate_image(idata->os, (void *)ntohl(os_header->ih_load)))
- return -1;
-
/* kernel parameters passing
* r4 : NIOS magic
* r5 : initrd start
diff --git a/arch/ppc/lib/ppclinux.c b/arch/ppc/lib/ppclinux.c
index 531c215817..471b3037fe 100644
--- a/arch/ppc/lib/ppclinux.c
+++ b/arch/ppc/lib/ppclinux.c
@@ -200,9 +200,6 @@ static int do_bootm_linux(struct image_data *idata)
kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep(os_header); /* FIXME */
- if (relocate_image(idata->os, (void *)image_get_load(os_header)))
- return -1;
-
#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
unlock_ram_in_cache();
#endif
diff --git a/commands/bootm.c b/commands/bootm.c
index ff9b18520f..cad7b21261 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -210,6 +210,23 @@ static int do_bootm(struct command *cmdtp, int argc, char *argv[])
puts ("OK\n");
+ /*
+ * FIXME: we do not check at all whether
+ * - we will write the image to sdram
+ * - we overwrite ourselves
+ * - kernel and initrd overlap
+ */
+ ret = relocate_image(data.os, (void *)image_get_load(os_header));
+ if (ret)
+ goto err_out;
+
+ if (data.initrd) {
+ ret = relocate_image(data.initrd,
+ (void *)image_get_load(&data.initrd->header));
+ if (ret)
+ goto err_out;
+ }
+
/* loop through the registered handlers */
list_for_each_entry(handler, &handler_list, list) {
if (image_get_os(os_header) == handler->image_type) {