summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoffer Dall <cdall@cs.columbia.edu>2011-03-17 04:53:15 +0100
committerChristoffer Dall <cdall@cs.columbia.edu>2011-03-17 09:06:08 +0100
commitad9313fd6ab96257b7ae865effae95afa970bb92 (patch)
tree0ec1be17b750c3d98238afc6c09ca45d059f4cbf
parentc0e5e07d53ccdaf8b79c20cccb7751f07c7fbf2e (diff)
First attempt to change to non-secure mode - buggy
Warning: This doesn't yet work.
-rw-r--r--Makefile16
-rw-r--r--boot.S7
-rw-r--r--model.lds.S5
-rw-r--r--monitor.S31
4 files changed, 52 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 8aa4ab9..1306c66 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ CPPFLAGS += -DVEXPRESS
#CPPFLAGS += -march=armv7-m
#CPPFLAGS += -mthumb -Wa,-mthumb -Wa,-mimplicit-it=always
+MONITOR = monitor.S
BOOTLOADER = boot.S
KERNEL = uImage
FILESYSTEM = filesystem.cpio.gz
@@ -30,22 +31,23 @@ LD = $(CROSS_COMPILE)ld
all: $(IMAGE)
-src_kernel:
- cd ../linux-kvm-arm; make -j4 uImage
-
clean:
- rm -f $(IMAGE) boot.o model.lds
+ rm -f $(IMAGE) boot.o model.lds monitor.o uImage
-$(KERNEL): src_kernel ../linux-kvm-arm/arch/arm/boot/uImage
+$(KERNEL): ../linux-kvm-arm/arch/arm/boot/zImage
+ cd ../linux-kvm-arm; make -j4 uImage
cp ../linux-kvm-arm/arch/arm/boot/uImage $(KERNEL)
-$(IMAGE): boot.o model.lds $(KERNEL) $(FILESYSTEM) Makefile
+$(IMAGE): boot.o monitor.o model.lds $(KERNEL) $(FILESYSTEM) Makefile
$(LD) -o $@ --script=model.lds
boot.o: $(BOOTLOADER)
$(CC) $(CPPFLAGS) -c -o $@ $<
+monitor.o: $(MONITOR)
+ $(CC) $(CPPFLAGS) -c -o $@ $<
+
model.lds: $(LD_SCRIPT) Makefile
$(CC) $(CPPFLAGS) -E -P -C -o $@ $<
-.PHONY: all clean src_kernel
+.PHONY: all clean
diff --git a/boot.S b/boot.S
index abd5d6b..60425e3 100644
--- a/boot.S
+++ b/boot.S
@@ -44,6 +44,13 @@ _start:
mov pc, r1 @ branch to the given address
#endif
+ @
+ @ Hypervisor / TrustZone initialization
+ @
+2:
+ mov r0, #0
+ mcr p15, 0, r0, c12, c0, 1 @ Monitor vector base address
+ smc #0 @ Change to NS-mode
@
@ UART initialisation (38400 8N1)
diff --git a/model.lds.S b/model.lds.S
index 789bafa..dcf2860 100644
--- a/model.lds.S
+++ b/model.lds.S
@@ -11,6 +11,7 @@ OUTPUT_FORMAT("elf32-littlearm")
OUTPUT_ARCH(arm)
TARGET(binary)
+INPUT(./monitor.o)
INPUT(./boot.o)
INPUT(./uImage)
#ifdef USE_INITRD
@@ -27,6 +28,10 @@ PHYS_OFFSET = 0x80000000;
SECTIONS
{
+ . = 0x0;
+ monitor = .;
+ .monitor : { monitor.o }
+
. = PHYS_OFFSET;
.text : { boot.o }
diff --git a/monitor.S b/monitor.S
new file mode 100644
index 0000000..4747e70
--- /dev/null
+++ b/monitor.S
@@ -0,0 +1,31 @@
+/*
+ * monitor.S - simple monitor code to switch to NS state before executing kernel
+ *
+ * Copyright (C) 2011 Columbia University. All rights reserved.
+ * Christoffer Dall <cdall@cs.columbia.edu>
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE.txt file.
+ */
+
+#.syntax unified
+ .section monitor, "x"
+
+ .word 0
+ .word 0
+ b 1f
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+ .word 0
+
+ @
+ @ Secure Monitor Call
+ @
+1:
+ mrc p15, 0, r0, c1, c1, 0 @ Secure configuration register
+ bic r0, r0, #0x7f
+ orr r0, r0, #0x31
+ mcr p15, 0, r0, c1, c1, 0
+ movs pc, lr