Skip to content

Commit 4f016ad

Browse files
committed
imx: mx6ulevk: support optee
Use this configuration file, mx6ul_14x14_evk_optee_defconfig Steps: make ARCH=arm mx6ul_14x14_evk_optee_defconfig make ARCH=arm Flash u-boot.imx to the sd card. Signed-off-by: Peng Fan <[email protected]>
1 parent c23d370 commit 4f016ad

File tree

7 files changed

+164
-0
lines changed

7 files changed

+164
-0
lines changed

arch/arm/cpu/armv7/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ config CPU_V7_HAS_NONSEC
66
config CPU_V7_HAS_VIRT
77
bool
88

9+
config ARMV7_TEE
10+
boolean "Enable tee support for booting in non-secure mode" if EXPERT
11+
depends on CPU_V7_HAS_NONSEC
12+
default y
13+
---help---
14+
Say Y here to enable support for booting in non-secure / SVC mode.
15+
916
config ARMV7_NONSEC
1017
boolean "Enable support for booting in non-secure mode" if EXPERT
1118
depends on CPU_V7_HAS_NONSEC

arch/arm/cpu/armv7/mx6/soc.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ void init_aips(void)
170170
#endif
171171
}
172172

173+
static void init_csu(void)
174+
{
175+
#ifdef CONFIG_ARMV7_NONSEC
176+
int i;
177+
u32 csu = 0x21c0000;
178+
/* This is to allow device can be accessed in non-secure world */
179+
for (i = 0; i < 40; i ++) {
180+
*((u32 *)csu + i) = 0xffffffff;
181+
}
182+
#endif
183+
}
184+
173185
static void clear_ldo_ramp(void)
174186
{
175187
struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
@@ -450,6 +462,8 @@ int arch_cpu_init(void)
450462

451463
init_aips();
452464

465+
init_csu();
466+
453467
/* Need to clear MMDC_CHx_MASK to make warm reset work. */
454468
clear_mmdc_ch_mask();
455469

@@ -1128,3 +1142,21 @@ void reset_usb_phy1(void)
11281142
writel(0, USB_PHY0_BASE_ADDR + HW_USBPHY_PWD);
11291143
}
11301144
#endif
1145+
1146+
#ifdef CONFIG_ARMV7_TEE
1147+
#ifdef CONFIG_MX6UL
1148+
void smp_kick_all_cpus(void)
1149+
{
1150+
return;
1151+
}
1152+
void smp_set_core_boot_addr(unsigned long addr, int corenr)
1153+
{
1154+
return;
1155+
}
1156+
1157+
void smp_waitloop(unsigned previous_address)
1158+
{
1159+
return;
1160+
}
1161+
#endif
1162+
#endif

arch/arm/cpu/armv7/nonsec_virt.S

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,39 @@
1111
#include <asm/gic.h>
1212
#include <asm/armv7.h>
1313
#include <asm/proc-armv/ptrace.h>
14+
#ifdef CONFIG_ARMV7_TEE
15+
#ifndef CONFIG_OPTEE_ENTRY
16+
#error "error optee entry"
17+
#endif
18+
#define OPTEE_ENTRY CONFIG_OPTEE_ENTRY
19+
#endif
1420

1521
.arch_extension sec
1622
.arch_extension virt
1723

1824
.pushsection ._secure.text, "ax"
1925

2026
.align 5
27+
/* Ugly code which can only boot smp 2 cores, enough for 7d */
28+
_regs_save:
29+
.word 0
30+
.word 0
31+
.word 0
32+
.word 0
33+
.word 0
34+
.word 0
35+
.word 0
36+
.word 0
37+
.word 0
38+
.word 0
39+
.word 0
40+
.word 0
41+
.word 0
42+
.word 0
43+
.word 0
44+
/* Maybe we can use cpu sync in optee os, but not in uboot */
45+
_cpu_sync:
46+
.word 0
2147
/* the vector table for secure state and HYP mode */
2248
_monitor_vectors:
2349
.word 0 /* reset */
@@ -113,6 +139,16 @@ ENDPROC(_do_nonsec_entry)
113139
add \addr, \addr, \tmp
114140
.endm
115141

142+
.macro get_core_pos reg, tmp
143+
#define MPIDR_CPU_MASK 0xff
144+
#define MPIDR_CLUSTER_SHIFT 8
145+
#define MPIDR_CLUSTER_MASK (0xff << MPIDR_CLUSTER_SHIFT)
146+
mrc p15, 0, \reg, c0, c0, 5
147+
and \tmp, \reg, #MPIDR_CPU_MASK
148+
and \reg, \reg, #MPIDR_CLUSTER_MASK
149+
add \reg, \tmp, \reg, LSR #6
150+
.endm
151+
116152
#ifndef CONFIG_ARMV7_PSCI
117153
/*
118154
* Secondary CPUs start here and call the code for the core specific parts
@@ -121,9 +157,26 @@ ENDPROC(_do_nonsec_entry)
121157
* Then they go back to wfi and wait to be woken up by the kernel again.
122158
*/
123159
ENTRY(_smp_pen)
160+
/* Remove this in future */
161+
ldr sp, =0x80001000
124162
cpsid i
125163
cpsid f
126164

165+
/* Ugly sync code, use cpu sync in optee os in future */
166+
wait_cpu0:
167+
dsb
168+
adr r0, _cpu_sync
169+
ldr r1, [r0]
170+
ldr r2, =0x55555555
171+
cmp r1, r2
172+
bne wait_cpu0
173+
174+
adr r0, _cpu_sync
175+
ldr r1, =0xaaaabbbb
176+
str r1, [r0]
177+
178+
dsb
179+
127180
bl _nonsec_init
128181

129182
adr r0, _smp_pen @ do not use this address again
@@ -177,12 +230,54 @@ ENTRY(_nonsec_init)
177230
mcreq p15, 0, r1, c14, c0, 0 @ write CNTFRQ
178231
#endif
179232

233+
#ifdef CONFIG_ARMV7_TEE
234+
isb
235+
236+
mov ip, r0
237+
adr r0, _regs_save
238+
str ip, [r0]
239+
add r0, r0, #4
240+
241+
str sp, [r0]
242+
add r0, r0, #4
243+
244+
stmia r0!, {r1-r12}
245+
246+
str lr, [r0]
247+
adr lr, end_init_optee
248+
249+
ldr r0, =OPTEE_ENTRY
250+
movs pc, r0
251+
b .
252+
end_init_optee:
253+
#if 0
254+
b end_init_optee @for test use
255+
#endif
256+
adr lr, _regs_save
257+
ldr r0, [lr]
258+
add lr, lr, #4
259+
260+
ldr sp, [lr]
261+
add lr, lr, #4
262+
263+
ldmfd lr!, {r1-r12}
264+
ldr lr, [lr]
265+
266+
adr r0, _cpu_sync
267+
ldr r1, =0x55555555
268+
str r1, [r0]
269+
270+
dsb
271+
272+
bx lr
273+
#else
180274
adr r1, _monitor_vectors
181275
mcr p15, 0, r1, c12, c0, 1 @ set MVBAR to secure vectors
182276
isb
183277

184278
mov r0, r3 @ return GICC address
185279
bx lr
280+
#endif
186281
ENDPROC(_nonsec_init)
187282

188283
#ifdef CONFIG_SMP_PEN_ADDR
@@ -197,7 +292,13 @@ ENTRY(smp_waitloop)
197292
cmp r0, r1 @ make sure we dont execute this code
198293
beq smp_waitloop @ again (due to a spurious wakeup)
199294
mov r0, r1
295+
#ifdef CONFIG_ARMV7_TEE
296+
mrs r1, cpsr
297+
msr spsr, r1
298+
movs pc, r0
299+
#else
200300
b _do_nonsec_entry
301+
#endif
201302
ENDPROC(smp_waitloop)
202303
.weak smp_waitloop
203304
#endif

arch/arm/lib/bootm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,17 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
307307
#if defined(CONFIG_ARMV7_NONSEC) || defined(CONFIG_ARMV7_VIRT)
308308
if (armv7_boot_nonsec()) {
309309
armv7_init_nonsec();
310+
#if defined(CONFIG_ARMV7_TEE)
311+
/*
312+
* Optee os will reopen cache, so cleanup again
313+
* before boot into linux
314+
*/
315+
cleanup_before_linux();
316+
kernel_entry(0, machid, r2);
317+
#else
310318
secure_ram_addr(_do_nonsec_entry)(kernel_entry,
311319
0, machid, r2);
320+
#endif
312321
} else
313322
#endif
314323
kernel_entry(0, machid, r2);

board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,11 @@ struct i2c_pads_info i2c_pad_info1 = {
253253

254254
int dram_init(void)
255255
{
256+
#ifdef CONFIG_ARMV7_TEE
257+
gd->ram_size = PHYS_SDRAM_SIZE - CONFIG_TEE_RAM_SIZE;
258+
#else
256259
gd->ram_size = PHYS_SDRAM_SIZE;
260+
#endif
257261

258262
return 0;
259263
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/mx6ul_14x14_evk/imximage.cfg,MX6UL,TEE_RAM_SIZE=0x4000000,ARMV7_TEE,ARMV7_NONSEC,OPTEE_ENTRY=0x9c100000"
2+
CONFIG_ARM=y
3+
CONFIG_TARGET_MX6UL_14X14_EVK=y
4+
CONFIG_DM=y
5+
CONFIG_DM_THERMAL=y

include/configs/mx6ul_14x14_evk.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#define CONFIG_DISPLAY_CPUINFO
2121
#define CONFIG_DISPLAY_BOARDINFO
2222

23+
#ifdef CONFIG_ARMV7_TEE
24+
#define CONFIG_SMP_PEN_ADDR 0
25+
#define CONFIG_TIMER_CLK_FREQ CONFIG_SC_TIMER_CLK
26+
#define CONFIG_ARMV7_SECURE_BASE (IRAM_BASE_ADDR + SZ_32K)
27+
#endif
28+
2329
#if !defined(CONFIG_MX6UL_9X9_LPDDR2)
2430
/* DCDC used on 14x14 EVK, no PMIC */
2531
#undef CONFIG_LDO_BYPASS_CHECK

0 commit comments

Comments
 (0)