mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ARM: fix setup_c when runtime offset is != 0
@ 2018-12-13  6:40 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2018-12-13  6:40 UTC (permalink / raw)
  To: Barebox List

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-12-13  6:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13  6:40 [PATCH] ARM: fix setup_c when runtime offset is != 0 Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox