linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* v7-M: Fixing XIP when the kernel is in ROM
@ 2015-10-26  1:27 Ezequiel Garcia
  2015-10-26  8:05 ` Uwe Kleine-König
  2015-10-27 20:21 ` Uwe Kleine-König
  0 siblings, 2 replies; 20+ messages in thread
From: Ezequiel Garcia @ 2015-10-26  1:27 UTC (permalink / raw)
  To: linux-arm-kernel

I've been trying to make my ARM v7-M LPC43xx board
boot a XIP kernel from flash. Currently, this seems
to be broken in mainline due to this:

arch/arm/mm/proc-v7m.S
[..]
        @ SVC to run the kernel in this mode
        badr    r1, 1f
        ldr     r5, [r12, #11 * 4]      @ read the SVC vector entry
        str     r1, [r12, #11 * 4]      @ write the temporary SVC vector entry
        mov     r6, lr                  @ save LR
        mov     r7, sp                  @ save SP
	ldr     sp, =__v7m_setup_stack_top @ <<< Breaks XIP!
        cpsie   i
        svc     #0
1:      cpsid   i
        str     r5, [r12, #11 * 4]      @ restore the original SVC vector entry
        mov     lr, r6                  @ restore LR
        mov     sp, r7                  @ restore SP

Here, a temporary stack is prepared before making a
supervisor call (SVC) to switch to handler mode.

The temporary stack is allocated in the .text.init section
and so this doesn't work when the kernel is executing from ROM.

A similar problem has been reported for v7:

http://lists.infradead.org/pipermail/linux-arm-kernel/2015-July/357106.html

While trying to come up with a proper fix, I've noticed how
the stack doesn't seem to be used.

So, I've been trying to understand why the need for the temporary
stack@all, but I still can't get it. 

The below patch seems to work just fine, and allows to boot a
LPC43xx kernel either as XIP from ROM or non-XIP from RAM.

However, I'm still wondering if the stack is really unused or not,
so any lights that can be shed here will be appreciated.

Thanks!

>From a7c880c73b8ad2e4c4b07f4d11809ea541a65e1d Mon Sep 17 00:00:00 2001
From: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Date: Sat, 24 Oct 2015 13:27:27 -0300
Subject: [PATCH] ARM: Don't prepare any temporary stack in __v7m_setup

Since __v7m_setup() is implemented as the PROCINFO_INITFUNC
called in head-nommu.S it's called at the very beggining to
do some very basic setup.

The function prepares a temporary stack in the .text.init
section before calling SVC. However, this stack seems to
be completely unused and hence is not needed.

Moreover, this breaks on XIP kernels, when the text is in ROM.
Hence, this commit simply removes the temporary stack setup.

Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
---
 arch/arm/mm/proc-v7m.S | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/arch/arm/mm/proc-v7m.S b/arch/arm/mm/proc-v7m.S
index 67d9209077c6..6a383e619a0c 100644
--- a/arch/arm/mm/proc-v7m.S
+++ b/arch/arm/mm/proc-v7m.S
@@ -103,7 +103,6 @@ __v7m_setup:
 	str	r1, [r12, #11 * 4]	@ write the temporary SVC vector entry
 	mov	r6, lr			@ save LR
 	mov	r7, sp			@ save SP
-	ldr	sp, =__v7m_setup_stack_top
 	cpsie	i
 	svc	#0
 1:	cpsid	i
@@ -123,11 +122,6 @@ __v7m_setup:
 	ret	lr
 ENDPROC(__v7m_setup)
 
-	.align 2
-__v7m_setup_stack:
-	.space	4 * 8				@ 8 registers
-__v7m_setup_stack_top:
-
 	define_processor_functions v7m, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
 
 	.section ".rodata"
-- 
2.5.2

-- 
Ezequiel Garcia, VanguardiaSur
www.vanguardiasur.com.ar

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2015-11-03 20:30 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-26  1:27 v7-M: Fixing XIP when the kernel is in ROM Ezequiel Garcia
2015-10-26  8:05 ` Uwe Kleine-König
2015-10-26 13:12   ` Ezequiel Garcia
2015-10-27 15:35     ` Ezequiel Garcia
2015-10-27 16:03       ` Maxime Coquelin
2015-10-27 20:25         ` Maxime Coquelin
2015-10-27 20:33           ` Stefan Agner
2015-10-27 21:33             ` Maxime Coquelin
2015-10-27 21:46               ` Ezequiel Garcia
2015-10-27 21:52                 ` Maxime Coquelin
2015-10-27 22:08                   ` Ezequiel Garcia
2015-10-28  7:43                     ` Uwe Kleine-König
2015-11-03 17:52                       ` Chris Brandt
2015-11-03 20:09                         ` Uwe Kleine-König
2015-11-03 20:30                           ` Russell King - ARM Linux
2015-10-27 20:21 ` Uwe Kleine-König
2015-10-27 20:57   ` Ezequiel Garcia
2015-10-27 21:20     ` Uwe Kleine-König
2015-10-27 22:40       ` Russell King - ARM Linux
2015-10-28  7:34         ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).