Skip to contentSkip to conversation

experimental TrustZone for Zynq (defunct)

PATCH New Tim Sander 1 participant 1 message Mar 28, 2014

Subsystems (2)
lore
Share & tools
lore

Tim Sander

author
#0 lore raw

PATCH 1/1 experimental TrustZone for Zynq (defunct)

---
 arch/arm/cpu/armv7/nonsec_virt.S |   18 +-
 arch/arm/cpu/armv7/virt-v7.c     |   20 ++-
 arch/arm/cpu/u-boot.lds          |    1 +
 arch/arm/dts/zynq-zed.dts        |  337 +++++++++++++++++++++++++++++++++++++-
 arch/arm/include/asm/armv7.h     |    8 +-
 board/xilinx/zynq/board.c        |   17 ++
 include/configs/zynq-common.h    |    4 +-
 include/configs/zynq_zed.h       |    7 +
 8 files changed, 395 insertions(+), 17 deletions(-)
arch/arm/cpu/armv7/nonsec_virt.S +17 -1
index 6367e09..c0d406c 100644
@@ -52,7 +52,15 @@ _secure_monitor:
 	mcreq	p15, 4, r0, c12, c0, 0		@ write HVBAR
 #endif
 
-	movs	pc, lr				@ return to non-secure SVC
+	@ Reset CNTVOFF to 0 before leaving monitor mode
+	mrc	p15, 0, r0, c0, c1, 1		@ read ID_PFR1
+	ands	r0, r0, #CPUID_ARM_GENTIMER_MASK	@ test arch timer bits
+	movne	r0, #0
+	mcrrne	p15, 4, r0, r0, c14		@ Reset CNTVOFF to zero
+
+	mov     sp,r2					@ restore stack pointer from caller (eq to secure mode stack)
+
+	movs	pc, lr					@ return to non-secure SVC
 
 _hyp_trap:
 	mrs	lr, elr_hyp	@ for older asm: .byte 0x00, 0xe3, 0x0e, 0xe1
@@ -152,11 +160,19 @@ ENTRY(_nonsec_init)
 
 	mrc	p15, 0, ip, c12, c0, 0		@ save secure copy of VBAR
 
+	stmfd sp!,{r2}					@ save r2 as it is clobbered in monitor mode
+	mov r1,sp
 	isb
 	smc	#0				@ call into MONITOR mode
 
 	mcr	p15, 0, ip, c12, c0, 0		@ write non-secure copy of VBAR
 
+	ldr r1,=0xC5087A				@ this is the value the register has in secure mode (ALIGNMENT!)
+	mcr p15,0,r1,c1,c0,0			@ write control register 
+
+	ldr r1,=0xffffffff
+	mcr p15,0,r1,c3,c0,0			@ write Domain Access Control Register
+
 	mov	r1, #1
 	str	r1, [r3, #GICC_CTLR]		@ enable non-secure CPU i/f
 	add	r2, r2, #GIC_DIST_OFFSET
arch/arm/cpu/armv7/virt-v7.c +19 -1
index 2cd604f..b540dbc 100644
@@ -46,7 +46,9 @@ static unsigned long get_gicd_base_address(void)
 	 * which we know only for sure for those two CPUs.
 	 */
 	asm("mrc p15, 0, %0, c0, c0, 0\n" : "=r"(midr));
+	debug("midr: %x masked:%x\n",midr,midr & MIDR_PRIMARY_PART_MASK);
 	switch (midr & MIDR_PRIMARY_PART_MASK) {
+	case MIDR_CORTEX_A9_R0P0:
 	case MIDR_CORTEX_A9_R0P1:
 	case MIDR_CORTEX_A15_R0P0:
 	case MIDR_CORTEX_A7_R0P0:
@@ -59,6 +61,7 @@ static unsigned long get_gicd_base_address(void)
 	/* get the GIC base address from the CBAR register */
 	asm("mrc p15, 4, %0, c15, c0, 0\n" : "=r" (periphbase));
 
+	debug("periphbase: %x working_address:%x\n",periphbase, (periphbase & CBAR_MASK)+GIC_DIST_OFFSET);
 	/* the PERIPHBASE can be mapped above 4 GB (lower 8 bits used to
 	 * encode this). Bail out here since we cannot access this without
 	 * enabling paging.
@@ -132,7 +135,8 @@ int armv7_switch_nonsec(void)
 	gic_dist_addr = get_gicd_base_address();
 	if (gic_dist_addr == -1)
 		return -1;
-
+	
+	debug("enable GIC\n");
 	/* enable the GIC distributor */
 	writel(readl(gic_dist_addr + GICD_CTLR) | 0x03,
 	       gic_dist_addr + GICD_CTLR);
@@ -144,14 +148,28 @@ int armv7_switch_nonsec(void)
 	 * from non-secure state. The first 32 interrupts are private per
 	 * CPU and will be set later when enabling the GIC for each core
 	 */
+	debug("allow non secure access\n");
 	for (i = 1; i <= itlinesnr; i++)
 		writel((unsigned)-1, gic_dist_addr + GICD_IGROUPRn + 4 * i);
 
+	debug("set core boot addr\n");
 	smp_set_core_boot_addr((unsigned long)_smp_pen, -1);
+	debug("kick cpus\n");
 	smp_kick_all_cpus();
 
+	/* read Monitor Vector Base Address Register */
+	asm("mrc p15, 0, %0, c12, c0, 1" : "=r"(reg) : : "cc");
+    printf("MVBAR (p15,0,c12,c0,1):%x\n",reg);
+
+	writel(0xffffffff,0xf800430); // unknown trustzone register, enable non-secure mode for ddr?
+	writel(0x00000001,0xf800440); // trustzone: DMA Non-Secure
+	writel(0x0000ffff,0xf800444); // trustzone: DMA IRQ Non-Secure 
+	writel(0x0000000f,0xf800448); // trustzone: DMA DMA Periph Non-Secure
+
 	/* call the non-sec switching code on this CPU also */
+	debug("nonsec init");
 	_nonsec_init();
+	debug("nonsec init finished");
 
 	return 0;
 }
arch/arm/cpu/u-boot.lds +1 -0
index 87c2de2..bead35f 100644
@@ -101,6 +101,7 @@ SECTIONS
 	.dynstr : { *(.dynstr*) }
 	.dynamic : { *(.dynamic*) }
 	.plt : { *(.plt*) }
+	.rel.plt  : { *(.rel.plt) }
 	.interp : { *(.interp*) }
 	.gnu : { *(.gnu*) }
 	.ARM.exidx : { *(.ARM.exidx*) }
arch/arm/dts/zynq-zed.dts +329 -8

343 lines not on this page · raw message

arch/arm/include/asm/armv7.h +4 -4
index 395444e..847a504 100644
@@ -9,9 +9,10 @@
 #define ARMV7_H
 
 /* Cortex-A9 revisions */
-#define MIDR_CORTEX_A9_R0P1	0x410FC091
-#define MIDR_CORTEX_A9_R1P2	0x411FC092
-#define MIDR_CORTEX_A9_R1P3	0x411FC093
+#define MIDR_CORTEX_A9_R0P0		0x410FC090
+#define MIDR_CORTEX_A9_R0P1		0x410FC091
+#define MIDR_CORTEX_A9_R1P2		0x411FC092
+#define MIDR_CORTEX_A9_R1P3		0x411FC093
 #define MIDR_CORTEX_A9_R2P10	0x412FC09A
 
 /* Cortex-A15 revisions */
@@ -77,7 +78,6 @@ void v7_outer_cache_flush_range(u32 start, u32 end);
 void v7_outer_cache_inval_range(u32 start, u32 end);
 
 #if defined(CONFIG_ARMV7_NONSEC) || defined(CONFIG_ARMV7_VIRT)
-
 int armv7_switch_nonsec(void);
 int armv7_switch_hyp(void);
 
board/xilinx/zynq/board.c +17 -0
index 485a5e4..bdc7976 100644
@@ -160,3 +160,20 @@ int dram_init(void)
 
 	return 0;
 }
+
+#if defined(CONFIG_ARMV7_NONSEC) || defined(CONFIG_ARMV7_VIRT)
+/* Setting the address at which secondary cores start from.
+ * Versatile Express uses one address for all cores, so ignore corenr
+ */
+void smp_set_core_boot_addr(unsigned long addr, int corenr)
+{
+	/* The SYSFLAGS register on VExpress needs to be cleared first
+	 * by writing to the next address, since any writes to the address
+	 * at offset 0 will only be ORed in
+	 */
+	 /*
+	writel(~0, CONFIG_SYSFLAGS_ADDR + 4);
+	writel(addr, CONFIG_SYSFLAGS_ADDR);
+	*/
+}
+#endif
include/configs/zynq-common.h +1 -3
index 731e69b..02208a8 100644
@@ -145,9 +145,7 @@
 	"norboot=echo Copying FIT from NOR flash to RAM... && " \
 		"cp.b ${nor_flash_off} ${load_addr} ${fit_size} && " \
 		"bootm ${load_addr}\0" \
-	"sdboot=echo Copying FIT from SD to RAM... && " \
-		"fatload mmc 0 ${load_addr} ${fit_image} && " \
-		"bootm ${load_addr}\0" \
+	"sdboot=mmcinfo;fatload mmc 0 0x79c0 linuximage;fatload mmc 0 0 zynq-zed.dtb; bootm 0x79c0 - 0\0" \
 	"jtagboot=echo TFTPing FIT to RAM... && " \
 		"tftpboot ${load_addr} ${fit_image} && " \
 		"bootm ${load_addr}\0"
include/configs/zynq_zed.h +7 -0
index 274140c..ca7959c 100644
@@ -24,4 +24,11 @@
 
 #include <configs/zynq-common.h>
 
+#define CONFIG_SYSFLAGS_ADDR        0x1c010030
+#define CONFIG_SMP_PEN_ADDR CONFIG_SYSFLAGS_ADDR
+#define CONFIG_SYS_CLK_FREQ  33333333
+
+#define CONFIG_ARMV7_NONSEC
+#define CONFIG_SYSFLAGS_ADDR        0x1c010030
+
 #endif /* __CONFIG_ZYNQ_ZED_H */
Signature · 4 lines
1.7.9.5


--nextPart1790889.UfpAQZOPOp--