diff mbox

[U-Boot] CONFIG_ARMV7_NONSEC on altera soc (alignment issues ?)

Message ID 5564506.u1KPOY9OcW@dabox
State Not Applicable
Delegated to: Albert ARIBAUD
Headers show

Commit Message

Tim Sander March 26, 2014, 2:25 p.m. UTC
Hi

I am currently trying to configure either Altera Soc and Xilinx Zynq to boot Linux in nonsecure-mode.
This mail focusses on the Altera SOC.

As soon as the u-boot switched to normal mode it seems there is a problem with code alignment handling? 
At least it seems the code which is running beforehand stops working in normal mode and stops in either
data_abort or prefetch handler. It stopps working when it hits the call to
stdio_devices[file]->puts(s); in console_puts (console.c:255).

print *stdio_devices[file]
$2 = {flags = 16978471, ext = 16978464, 
name = "$\022\003\001\202\022\003\001\360\031\003\001\020\060\220", <incomplete sequence \345>, 
  start = 0xe92d4070, stop = 0xe2806010, putc = 0xe1530006, puts = 0xe1a04000, tstc = 0xe1a05001, 
  getc = 0xe5810024, priv = 0x1a000007, list = { next = 0xe5831004, prev = 0xe5813000}}

As there are unaligned addresses (putc?) in these function calls i have the impression that this is not working in
normal mode but in secure mode.

Unfortunatly i was not able to get the mainline u-boot to boot on the altera soc so i patched the altera release:
git://git.rocketboards.org/u-boot-socfpga.git
with the 1740999a39ea4217bf926002d10869c0d925a5dc aka socfpga_v2013.01.01-rel branch.

As the altera u-boot release socfpga_v2013.01.01-rel is to old to have the CONFIG_ARMV7_NONSEC patches
i cherry-picked the following patches:
d4296887544ddf95808bfb62f312008f519efb7b	extend non-secure switch to also go into HYP mode
ba6a1698116da272f14c53a3ae41467cb7fc4372 	add SMP support for non-secure switch
bb975455650b1f36681de31a93ffe54952ed3a6b 	trigger non-secure state switch during bootm execution
1ef923851ab8ffcc4265fd991815b88d9c1f12d7 	add C function to switch to non-secure state
16212b594f385bd594d5d316bf11b13c1186e3d7 	add assembly routine to switch to non-secure state
45b940d6f9a9d4989452ea67480e299bfa51ee19 	add secure monitor handler to switch to non-secure state
d75ba503a972df09784f1a332ba356ef8b42a0a6 	ARM: prepare armv7.h to be included from assembly source

I also applied the attached hacked together patches to get the system running and fix up the stack pointer in 
normal mode as it pointed to 0. 

Best regards
Tim

Comments

Albert ARIBAUD April 7, 2014, 8:53 p.m. UTC | #1
Hi Tim,

On Wed, 26 Mar 2014 15:25:33 +0100, Tim Sander <tim@krieglstein.org>
wrote:

> Hi
> 
> I am currently trying to configure either Altera Soc and Xilinx Zynq to boot Linux in nonsecure-mode.
> This mail focusses on the Altera SOC.
> 
> As soon as the u-boot switched to normal mode it seems there is a problem with code alignment handling? 
> At least it seems the code which is running beforehand stops working in normal mode and stops in either
> data_abort or prefetch handler. It stopps working when it hits the call to
> stdio_devices[file]->puts(s); in console_puts (console.c:255).
> 
> print *stdio_devices[file]
> $2 = {flags = 16978471, ext = 16978464, 
> name = "$\022\003\001\202\022\003\001\360\031\003\001\020\060\220", <incomplete sequence \345>, 
>   start = 0xe92d4070, stop = 0xe2806010, putc = 0xe1530006, puts = 0xe1a04000, tstc = 0xe1a05001, 
>   getc = 0xe5810024, priv = 0x1a000007, list = { next = 0xe5831004, prev = 0xe5813000}}
> 
> As there are unaligned addresses (putc?) in these function calls i have the impression that this is not working in
> normal mode but in secure mode.
> 
> Unfortunatly i was not able to get the mainline u-boot to boot on the altera soc so i patched the altera release:
> git://git.rocketboards.org/u-boot-socfpga.git
> with the 1740999a39ea4217bf926002d10869c0d925a5dc aka socfpga_v2013.01.01-rel branch.
> 
> As the altera u-boot release socfpga_v2013.01.01-rel is to old to have the CONFIG_ARMV7_NONSEC patches
> i cherry-picked the following patches:
> d4296887544ddf95808bfb62f312008f519efb7b	extend non-secure switch to also go into HYP mode
> ba6a1698116da272f14c53a3ae41467cb7fc4372 	add SMP support for non-secure switch
> bb975455650b1f36681de31a93ffe54952ed3a6b 	trigger non-secure state switch during bootm execution
> 1ef923851ab8ffcc4265fd991815b88d9c1f12d7 	add C function to switch to non-secure state
> 16212b594f385bd594d5d316bf11b13c1186e3d7 	add assembly routine to switch to non-secure state
> 45b940d6f9a9d4989452ea67480e299bfa51ee19 	add secure monitor handler to switch to non-secure state
> d75ba503a972df09784f1a332ba356ef8b42a0a6 	ARM: prepare armv7.h to be included from assembly source
> 
> I also applied the attached hacked together patches to get the system running and fix up the stack pointer in 
> normal mode as it pointed to 0. 
> 
> Best regards
> Tim

So this is not a patch for mainline U-Boot, right?

Amicalement,
Tim Sander April 7, 2014, 10:41 p.m. UTC | #2
Hi Albert
> > I am currently trying to configure either Altera Soc and Xilinx Zynq to
> > boot Linux in nonsecure-mode. This mail focusses on the Altera SOC.
> > 
> > As soon as the u-boot switched to normal mode it seems there is a problem
> > with code alignment handling? At least it seems the code which is running
> > beforehand stops working in normal mode and stops in either data_abort or
> > prefetch handler. It stopps working when it hits the call to
> > stdio_devices[file]->puts(s); in console_puts (console.c:255).
> > 
> > print *stdio_devices[file]
> > $2 = {flags = 16978471, ext = 16978464,
> > name = "$\022\003\001\202\022\003\001\360\031\003\001\020\060\220",
> > <incomplete sequence \345>,> 
> >   start = 0xe92d4070, stop = 0xe2806010, putc = 0xe1530006, puts =
> >   0xe1a04000, tstc = 0xe1a05001, getc = 0xe5810024, priv = 0x1a000007,
> >   list = { next = 0xe5831004, prev = 0xe5813000}}> 
> > As there are unaligned addresses (putc?) in these function calls i have
> > the impression that this is not working in normal mode but in secure
> > mode.
> > 
> > Unfortunatly i was not able to get the mainline u-boot to boot on the
> > altera soc so i patched the altera release:
> > git://git.rocketboards.org/u-boot-socfpga.git
> > with the 1740999a39ea4217bf926002d10869c0d925a5dc aka
> > socfpga_v2013.01.01-rel branch.
> > 
> > As the altera u-boot release socfpga_v2013.01.01-rel is to old to have the
> > CONFIG_ARMV7_NONSEC patches i cherry-picked the following patches:
> > d4296887544ddf95808bfb62f312008f519efb7b	extend non-secure switch to also
> > go into HYP mode ba6a1698116da272f14c53a3ae41467cb7fc4372 	add SMP
> > support for non-secure switch bb975455650b1f36681de31a93ffe54952ed3a6b
> > 	trigger non-secure state switch during bootm execution
> > 1ef923851ab8ffcc4265fd991815b88d9c1f12d7 	add C function to switch to
> > non-secure state 16212b594f385bd594d5d316bf11b13c1186e3d7 	add assembly
> > routine to switch to non-secure state
> > 45b940d6f9a9d4989452ea67480e299bfa51ee19 	add secure monitor handler to
> > switch to non-secure state d75ba503a972df09784f1a332ba356ef8b42a0a6 	
ARM:
> > prepare armv7.h to be included from assembly source
> > 
> > I also applied the attached hacked together patches to get the system
> > running and fix up the stack pointer in normal mode as it pointed to 0.
> > 
> > Best regards
> > Tim
> 
> So this is not a patch for mainline U-Boot, right?
Unfortunatly not. The altera branch is from an older version and i had 
problems booting mainline. So i went the other way round and used the altera 
git release and cherry picked the patches of which i thought that would be 
needed for switching to normal world. This works but as soon as i print out 
something in u-boot ("Booting linux") or if thats commented out, booting linux
i get a access violation. So i either get in the prefetch or abort handler. As 
i don't know where the TrustZone registers are nor what they do, i have a hard 
time moving on with this. So these patches are just very experimental and got 
me as far as booting into early linux. I have the suscpicion that the serial 
port, and probably other hw is only writable from secure world so one would 
need a monitor running to have access to this hw (If it can not be switched to 
be accessible from normal world). Further with the stack pointer not set up in 
normal world i have no idea how the versatile express should work without 
setting the stack. 

Best regards
Tim
diff mbox

Patch

From a2b7d1cf22a41f09f00a7088ca69acd03329cc0c Mon Sep 17 00:00:00 2001
From: Tim Sander <tim@krieglstein.org>
Date: Wed, 26 Mar 2014 13:51:30 +0100
Subject: [PATCH 3/3] move secure mode switch directly in front of kernel boot

---
 arch/arm/lib/bootm.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 35abccf..39dcf9c 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -337,7 +337,6 @@  static void boot_prep_linux(bootm_headers_t *images)
 		hang();
 #endif /* all tags */
 	}
-	do_nonsec_virt_switch();
 }
 
 /* Subcommand: GO */
@@ -368,6 +367,7 @@  static void boot_jump_linux(bootm_headers_t *images)
 #endif
 		r2 = gd->bd->bi_boot_params;
 
+	do_nonsec_virt_switch();
 	kernel_entry(0, machid, r2);
 }
 
-- 
1.7.9.5