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 1/5] ARM: uncompress.c: copy executable to SDRAM if necessary
Date: Thu, 12 Jun 2014 08:53:39 +0200	[thread overview]
Message-ID: <1402556023-1811-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1402556023-1811-1-git-send-email-s.hauer@pengutronix.de>

We used to relocate the executable to the current address. This does
not work when the executable runs from a readonly location like for
example NOR Flash. Test if we run from inside the available memory and
if we do, relocate to the current address as before. Otherwise copy
the executable to the start of memory and relocate to that address.
While at it add some comments to the code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/uncompress.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index 74a4286..d64706d 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -47,15 +47,27 @@ static void __noreturn noinline uncompress_start_payload(unsigned long membase,
 	void __noreturn (*barebox)(unsigned long, unsigned long, void *);
 	uint32_t endmem = membase + memsize;
 	unsigned long barebox_base;
-	uint32_t *ptr;
+	uint32_t *image_end;
 	void *pg_start;
+	unsigned long pc = get_pc();
 
 	arm_early_mmu_cache_invalidate();
 
 	endmem -= STACK_SIZE; /* stack */
 
-	if (IS_ENABLED(CONFIG_PBL_RELOCATABLE))
-		relocate_to_current_adr();
+	image_end = (void *)ld_var(__image_end) - get_runtime_offset();
+
+	if (IS_ENABLED(CONFIG_PBL_RELOCATABLE)) {
+		/*
+		 * If we run from inside the memory just relocate the binary
+		 * to the current address. Otherwise it may be a readonly location.
+		 * Copy and relocate to the start of the memory in this case.
+		 */
+		if (pc > membase && pc < membase + memsize)
+			relocate_to_current_adr();
+		else
+			relocate_to_adr(membase);
+	}
 
 	if (IS_ENABLED(CONFIG_RELOCATABLE))
 		barebox_base = arm_barebox_image_place(membase + memsize);
@@ -74,9 +86,12 @@ static void __noreturn noinline uncompress_start_payload(unsigned long membase,
 	free_mem_ptr = endmem;
 	free_mem_end_ptr = free_mem_ptr + SZ_128K;
 
-	ptr = (void *)__image_end;
-	pg_start = ptr + 1;
-	pg_len = *(ptr);
+	/*
+	 * image_end is the first location after the executable. It contains
+	 * the size of the appended compressed binary followed by the binary.
+	 */
+	pg_start = image_end + 1;
+	pg_len = *(image_end);
 
 	pbl_barebox_uncompress((void*)barebox_base, pg_start, pg_len);
 
-- 
2.0.0.rc2


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

  reply	other threads:[~2014-06-12  6:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-12  6:53 phyCORE-imx27 updates Sascha Hauer
2014-06-12  6:53 ` Sascha Hauer [this message]
2014-06-12  6:53 ` [PATCH 2/5] ARM: Phytec-phyCORE-imx27: Register board env during runtime Sascha Hauer
2014-06-12  6:53 ` [PATCH 3/5] ARM: i.MX bbu: Add update handler for external NOR boot Sascha Hauer
2014-06-12  6:53 ` [PATCH 4/5] ARM: Phytec-phyCORE-imx27: Register NOR/NAND update handlers Sascha Hauer
2014-06-12  6:53 ` [PATCH 5/5] ARM: Phytec-phyCORE-imx27: Switch to multiimage support 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=1402556023-1811-2-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