OP-TEE on i.MX6Q

cancel
Showing results for 
Search instead for 
Did you mean: 

OP-TEE on i.MX6Q

2,296 Views
Contributor III

Hello,

I have i.MX6Q Sabre Automotive board, and I am trying to run OP-TEE OS from u-boot.

I use this u-boot patch https://github.com/MrVan/uboot/commit/4f016adae573aaadd7bf6a37f8c58a882b391ae6, but it is for i.MX6UL and don't work for me. Can you help me to determine steps for running OP-TEE OS?

I see so:

1. Initialize CSU

2. Realize smp_set_core_boot_addr function

void smp_set_core_boot_addr(unsigned long addr, int corenr)

{

    int cpu, val;

    for (cpu = 1; cpu <= 3;  ++cpu) {

        writel(addr, SRC_BASE_ADDR + 0x20 + 8 * cpu);

        writel(0, SRC_BASE_ADDR + 0x20 + 8 * cpu + 4);

        val = readl(SRC_BASE_ADDR);

        val |= 1 << (SRC_SCR_CORE_1_RESET_OFFSET + cpu - 1);

        val |= 1 << (SRC_SCR_CORE_1_ENABLE_OFFSET + cpu  -1);

        writel(val, SRC_BASE_ADDR);

    }

}

3. Put 3 cores to pending as in patch

4. Run OP-TEE OS from _nonsec_init

Thanks

Labels (2)
Tags (3)
7 Replies

154 Views
Contributor II

Hi Eugene,

Did you apply the OP-TEE on i.MX6Q?

Please share how to do that if you apply that?

I'm trying to do that.

Best Regards,

Eric.

0 Kudos

154 Views
Contributor III

Hi Eric,

I did follow steps to apply OP-TEE on i.MX6Q

1. u-boot patch

u-boot/board/freescale/mx6qsabreauto/mx6qsabreauto.c
 int dram_init(void)
 {
+#ifdef CONFIG_TEE_RAM_SIZE
+       gd->ram_size = imx_ddr_size() - CONFIG_TEE_RAM_SIZE;
+#else
        gd->ram_size = imx_ddr_size();
+#endif
 
        return 0;
 }

u-boot/configs/mx6qsabreauto_defconfig
 CONFIG_ARM=y
 CONFIG_ARCH_MX6=y
 CONFIG_TARGET_MX6QSABREAUTO=y
-CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/mx6qsabreauto/imximage.cfg,MX6Q"
+CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/mx6qsabreauto/imximage.cfg,MX6Q,TEE_RAM_SIZE=0x2000000"
 CONFIG_BOOTDELAY=3
 CONFIG_HUSH_PARSER=y
 CONFIG_CMD_BOOTZ=y
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

You need to reserve last 32MB of DRAM for OPTEE-OS.

2. linux patch GitHub - linaro-swg/linux: Linux kernel source tree 

diff --git a/arch/arm/mach-imx/platsmp.c b/arch/arm/mach-imx/platsmp.c
index 711dbbd..411585c 100644
--- a/arch/arm/mach-imx/platsmp.c
+++ b/arch/arm/mach-imx/platsmp.c
@@ -23,6 +23,14 @@
 #include "common.h"
 #include "hardware.h"
 
+#include <linux/arm-smccc.h>
+
+#define OPTEE_SMC_CALLID_BOOT_SECONDARY       12
+#define OPTEE_SMC_BOOT_SECONDARY  \
+    ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
+    ARM_SMCCC_OWNER_TRUSTED_OS, OPTEE_SMC_CALLID_BOOT_SECONDARY)
+
+
 u32 g_diag_reg;
 static void __iomem *scu_base;
 
@@ -48,8 +56,15 @@ void __init imx_scu_map_io(void)
 
 static int imx_boot_secondary(unsigned int cpu, struct task_struct *idle)
 {
+#ifdef CONFIG_OPTEE
+    struct arm_smccc_res  res;
+    arm_smccc_smc(OPTEE_SMC_BOOT_SECONDARY,
+        cpu, virt_to_phys(secondary_startup),
+        0, 0, 0, 0, 0, &res);
+#else
        imx_set_cpu_jump(cpu, v7_secondary_startup);
        imx_enable_cpu(cpu, true);
+#endif
        return 0;
 }
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

build Linux Kernel with follow options

CONFIG_TEE=y
CONFIG_OPTEE=y‍‍

3. build OP-TEE OS GitHub - OP-TEE/optee_os: Trusted side of the TEE 

#!/bin/sh

export ARCH=arm
export CROSS_COMPILE="/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-"
export PLATFORM_FLAVOR=mx6qsabreauto
export PLATFORM=imx

make -j$(nproc) CFG_TEE_CORE_LOG_LEVEL=3 CFG_BOOT_SYNC_CPU=n CFG_NS_ENTRY_ADDR=0x12000000 CFG_DT_ADDR=0x18000000 CFG_DT=y

mkimage -A arm -O linux -C none -a 0x8dffffe4 -e 0x8e000000 -d out/arm-plat-imx/core/tee.bin uTee
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

4. run OP-TEE OS from u-boot

run netargs;tftpboot 0x12000000 zImage;tftpboot 0x18000000 imx6q-sabreauto.dtb;tftpboot 0x20000000 uTee;bootm 0x20000000 - 0x18000000‍

I did this a long time ago and I'm not sure is it necessary or not to patch Linux Kernel and use CFG_BOOT_SYNC_CPU=n now.

Last board where I tried OP-TEE OS was i.MX7, and all worked out of box, I patched u-boot only.

Best Regards,

Eugene

154 Views
Contributor II

Dear Eugene,

Thanks for your response.

It's helpful to me, I'll try to the OP-TEE patch into our code.

I have additional question.

I know TEE has the following functions.

- 2 OS on i.MX6Q, Rich OS & Trusted OS

- Data is passed through Monitor between the 2 OSes.

Could you give me some example for data communication between 2 OSes?

Mono-Gram_TEE_01-2.1_TEE.Concept.png

Mono-Gram_TEE_01-2.2_TEE.Concept_TEE.SW.Stack.png

Best Regards,
Eric.

0 Kudos

154 Views
Contributor III

Dear Eric,

Data is passed between OSes through shared memory. Communication is provided by Linux Kernel driver by means of SMC call.

You may find examples here: GitHub - linaro-swg/optee_examples: OP-TEE Sample Applications 

Best Regards,

Eugene

0 Kudos

154 Views
NXP TechSupport
NXP TechSupport

Hi Eugene

i.MX6Q and i.MX6UL are quite different processors with

different cores, you may need to carefully check original codes

and make necessary changes for new processor using descriptions

in Reference Manuals:

i.MX6DQ Reference Manual

http://cache.freescale.com/files/32bit/doc/ref_manual/IMX6DQRM.pdf

i.MX6UL Reference Manual

http://cache.freescale.com/files/32bit/doc/ref_manual/IMX6ULRM.pdf

Best regards

igor

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos

154 Views
Contributor III

Hi Igor,

Thanks for your answer. I use both of this manuals. And I still don't understand what my problem is(

I heard that in NXP there is a team who is working on OPTEE in i.MX6Q. Can you find out this?

All the best,

Eugene

0 Kudos

154 Views
NXP TechSupport
NXP TechSupport

Hi Eugene

please try to get more info using local fae channel.

Best regards

igor

0 Kudos