mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 13/14] bootm: push relocate_image up to the generic command
Date: Mon, 28 Nov 2011 09:02:19 +0100	[thread overview]
Message-ID: <1322467340-10596-14-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1322467340-10596-1-git-send-email-s.hauer@pengutronix.de>

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>
---
 arch/arm/lib/bootm.c               |    7 -------
 arch/blackfin/lib/blackfin_linux.c |    3 ---
 arch/nios2/lib/bootm.c             |    3 ---
 arch/ppc/lib/ppclinux.c            |    3 ---
 commands/bootm.c                   |   17 +++++++++++++++++
 5 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index a104aaa..5b85ba9 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 a20cf55..9da9ec4 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 c38243f..b5b344f 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 531c215..471b303 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 c400ab5..027dd37 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -207,6 +207,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) {
-- 
1.7.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2011-11-28  8:02 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-28  8:02 bootm work Sascha Hauer
2011-11-28  8:02 ` [PATCH 01/14] bootm: remove dead code Sascha Hauer
2011-11-28  8:02 ` [PATCH 02/14] factor out iminfo command Sascha Hauer
2011-11-28  8:02 ` [PATCH 03/14] compile in simple_strtoull Sascha Hauer
2011-11-28  8:02 ` [PATCH 04/14] introduce some env helpers Sascha Hauer
2011-11-28  8:02 ` [PATCH 05/14] armlinux: cleanup linux vars Sascha Hauer
2011-11-28 11:03   ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-28 11:12     ` Sascha Hauer
2011-11-29  4:38       ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-29  7:23         ` Robert Schwebel
2011-11-29  8:13           ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-29 10:09             ` Sascha Hauer
2011-11-28  8:02 ` [PATCH 06/14] ARM bootm: remove now obsolete args Sascha Hauer
2011-11-28  8:02 ` [PATCH 07/14] bootm: handle initrds inline Sascha Hauer
2011-12-06 15:08   ` Jean-Christophe PLAGNIOL-VILLARD
2011-12-07  9:19     ` Sascha Hauer
2011-12-07 13:26       ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-28  8:02 ` [PATCH 08/14] bootm: remove image handler options Sascha Hauer
2011-11-28  8:02 ` [PATCH 09/14] bootm: fix various memory leaks Sascha Hauer
2011-11-28  8:02 ` [PATCH 10/14] bootm: do not require -L after -r Sascha Hauer
2011-11-28  8:02 ` [PATCH 11/14] bootm: fix typo, update help str Sascha Hauer
2011-11-28 11:00   ` Jean-Christophe PLAGNIOL-VILLARD
2011-11-28  8:02 ` [PATCH 12/14] bootm relocate_image: honour load_address Sascha Hauer
2011-11-28  8:02 ` Sascha Hauer [this message]
2011-11-28  8:02 ` [PATCH 14/14] bootm: use initrd_address and initrd_size Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1322467340-10596-14-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox