mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] ARM: fix setup_c when runtime offset is != 0
Date: Thu, 13 Dec 2018 07:40:26 +0100	[thread overview]
Message-ID: <20181213064026.15127-1-s.hauer@pengutronix.de> (raw)

The runtime offset has to be added to the memcpy source address and
substracted from the return address. This should have been changed in
a43e2bbc46 which changed from returning the negative runtime offset
into changing the positive runtime offset. Instead a43e2bbc46 only
changed a zero substraction ("subs r4, r0, #0") into a zero addition
("adds r4, r0, #0") which was used as a equal to zero test and changed
nothing. This part is reverted here.

Fixes wrong copy / return locations when setup_c is called with
different runtime and link addresses.

fixes: a43e2bbc46 ("ARM: return positive offset in get_runtime_offset()")

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/setupc.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/cpu/setupc.S b/arch/arm/cpu/setupc.S
index 717500cfff..a5f311b8ec 100644
--- a/arch/arm/cpu/setupc.S
+++ b/arch/arm/cpu/setupc.S
@@ -15,13 +15,13 @@ ENTRY(setup_c)
 	push	{r4, r5}
 	mov	r5, lr
 	bl	get_runtime_offset
-	adds	r4, r0, #0
+	subs	r4, r0, #0
 	beq	1f			/* skip memcpy if already at correct address */
 	ldr	r0,=_text
 	ldr	r2,=__bss_start
 	sub	r2, r2, r0
-	sub	r1, r0, r4
-	bl	memcpy			/* memcpy(_text, _text - offset, __bss_start - _text) */
+	add	r1, r0, r4
+	bl	memcpy			/* memcpy(_text, _text + offset, __bss_start - _text) */
 1:	ldr	r0, =__bss_start
 	mov	r1, #0
 	ldr	r2, =__bss_stop
@@ -32,7 +32,7 @@ ENTRY(setup_c)
 #endif
 	mov	r0, #0
 	mcr	p15, 0, r0, c7, c5, 0	/* flush icache */
-	add	lr, r5, r4		/* adjust return address to new location */
+	sub	lr, r5, r4		/* adjust return address to new location */
 	pop	{r4, r5}
 	mov	pc, lr
 ENDPROC(setup_c)
-- 
2.19.1


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

                 reply	other threads:[~2018-12-13  6:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20181213064026.15127-1-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