Commit c6b4183d authored by Haoran.Wang's avatar Haoran.Wang Committed by Jason Liu

MA-9478 [iot] Add boot Trusty OS codes for imx6 and imx7

Use trusty_os_init to load Trusty OS from CONFIG_TRUSTY_OS_ENTRY
before u-boot ready.

Add "tos" partition following the Android bootloader requirement.

Change-Id: I294df0ea1b44ffd12135a8325a73d1ac9399b5f5
Signed-off-by: default avatarHaoran.Wang <elven.wang@nxp.com>
parent f10e383e
......@@ -211,6 +211,35 @@ u32 __weak get_board_rev(void)
}
#endif
#ifdef CONFIG_IMX_TRUSTY_OS
#ifdef CONFIG_MX6UL
void smp_set_core_boot_addr(unsigned long addr, int corenr)
{
return;
}
void smp_waitloop(unsigned previous_address)
{
return;
}
#endif
#endif
static void init_csu(void)
{
#ifdef CONFIG_ARMV7_NONSEC
int i;
u32 csu = CSU_BASE_ADDR;
/*
* This is to allow device can be accessed in non-secure world.
* All imx6 chips CSU have 40 Config security level registers.
*/
for (i = 0; i < 40; i ++) {
*((u32 *)csu + i) = 0xffffffff;
}
#endif
}
static void clear_ldo_ramp(void)
{
struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
......@@ -416,6 +445,17 @@ void vadc_power_down(void)
writel(val, &iomux->gpr[5]);
}
static void init_csu(void)
{
#ifdef CONFIG_ARMV7_NONSEC
int i;
u32 csu = CSU_IPS_BASE_ADDR;
/* This is to allow device can be accessed in non-secure world */
for (i = 0; i < 64; i ++) {
*((u32 *)csu + i) = 0xffffffff;
}
#endif
}
void pcie_power_up(void)
{
set_ldo_voltage(LDO_PU, 1100); /* Set VDDPU to 1.1V */
......@@ -498,6 +538,8 @@ int arch_cpu_init(void)
init_aips();
init_csu();
/* Need to clear MMDC_CHx_MASK to make warm reset work. */
clear_mmdc_ch_mask();
......
......@@ -497,6 +497,20 @@ void reset_misc(void)
#endif
}
#ifdef CONFIG_IMX_TRUSTY_OS
#ifdef CONFIG_MX7D
void smp_set_core_boot_addr(unsigned long addr, int corenr)
{
return;
}
void smp_waitloop(unsigned previous_address)
{
return;
}
#endif
#endif
void reset_cpu(ulong addr)
{
struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
......
......@@ -195,7 +195,6 @@ ENTRY(_nonsec_init)
ldreq r1, =CONFIG_TIMER_CLK_FREQ
mcreq p15, 0, r1, c14, c0, 0 @ write CNTFRQ
#endif
adr r1, _monitor_vectors
mcr p15, 0, r1, c12, c0, 1 @ set MVBAR to secure vectors
isb
......
......@@ -54,3 +54,7 @@ config IMX_M4_BIND
help
Select this to bind a ULP M4 image to final u-boot image
User needs put the M4 image ulp_m4.bin under u-boot directory
config IMX_TRUSTY_OS
bool "Support Trusty OS related feature"
depends on ARCH_MX6 || ARCH_MX7
......@@ -39,6 +39,7 @@ obj-$(CONFIG_IMX_BOOTAUX) += imx_bootaux.o
obj-$(CONFIG_SECURE_BOOT) += hab.o
obj-$(CONFIG_GPT_TIMER) += timer.o
obj-$(CONFIG_SYSCOUNTER_TIMER) += syscounter.o
obj-$(CONFIG_IMX_TRUSTY_OS) += trusty.o
endif
ifeq ($(SOC),$(filter $(SOC),mx7ulp))
obj-y += cache.o
......
/*
* (C) Copyright 2009-2016 Freescale Semiconductor, Inc.
*
* Copyright 2017 NXP
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <config.h>
#include <linux/linkage.h>
#include <asm/gic.h>
#include <asm/armv7.h>
_regs_save:
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
.word 0
#ifdef CONFIG_IMX_TRUSTY_OS
ENTRY(trusty_os_init)
isb
/* Save current registers */
mov ip, r0
adr r0, _regs_save
str ip, [r0]
add r0, r0, #4 @ Get _regs_save from instruction offset
str sp, [r0]
add r0, r0, #4
stmia r0!, {r1-r12} @ Save r1 - r12
str lr, [r0]
adr lr, end_init_tee @ save return address to lr
dsb
ldr r1, =TRUSTY_OS_ENTRY
ldr r0, =TRUSTY_OS_RAM_SIZE
movs pc, r1 @ Go to TEE codes
end_init_tee:
/* Restore saved registers */
adr lr, _regs_save
ldr r0, [lr]
add lr, lr, #4
ldr sp, [lr]
add lr, lr, #4
ldmfd lr!, {r1-r12}
ldr lr, [lr]
dsb
bx lr
ENDPROC(trusty_os_init)
#endif
......@@ -736,6 +736,15 @@ static int initr_check_fastboot(void)
}
#endif
#ifdef CONFIG_IMX_TRUSTY_OS
static int initr_tee_setup(void)
{
tee_setup();
return 0;
}
#endif
static int run_main_loop(void)
{
#ifdef CONFIG_SANDBOX
......@@ -964,6 +973,9 @@ static init_fnc_t init_sequence_r[] = {
#if defined(CONFIG_SPARC)
prom_init,
#endif
#ifdef CONFIG_IMX_TRUSTY_OS
initr_tee_setup,
#endif
#ifdef CONFIG_FSL_FASTBOOT
initr_check_fastboot,
#endif
......
......@@ -32,6 +32,11 @@
#include <fb_nand.h>
#endif
#ifdef CONFIG_IMX_TRUSTY_OS
extern int armv7_init_nonsec(void);
extern void trusty_os_init(void);
#endif
#ifdef CONFIG_FSL_FASTBOOT
#include <asm/imx-common/sys_proto.h>
#include <fsl_fastboot.h>
......@@ -196,6 +201,12 @@ static struct usb_gadget_strings *fastboot_strings[] = {
#ifdef CONFIG_FSL_FASTBOOT
#ifndef TRUSTY_OS_MMC_BLKS
#define TRUSTY_OS_MMC_BLKS 0x7FF
#endif
#ifndef TEE_HWPARTITION_ID
#define TEE_HWPARTITION_ID 2
#endif
#define ANDROID_MBR_OFFSET 0
#define ANDROID_MBR_SIZE 0x200
......@@ -210,8 +221,6 @@ static struct usb_gadget_strings *fastboot_strings[] = {
#define ANDROID_URAMDISK_OFFSET 0x600000
#define ANDROID_URAMDISK_SIZE 0x100000
#define MMC_SATA_BLOCK_SIZE 512
#define FASTBOOT_FBPARTS_ENV_MAX_LEN 1024
/* To support the Android-style naming of flash */
......@@ -223,7 +232,8 @@ struct fastboot_device_info fastboot_devinfo;
enum {
PTN_GPT_INDEX = 0,
PTN_BOOTLOADER_INDEX
PTN_TEE_INDEX,
PTN_BOOTLOADER_INDEX,
};
static unsigned int download_bytes_unpadded;
......@@ -1451,6 +1461,13 @@ static int _fastboot_parts_load_from_ptable(void)
ptable[PTN_GPT_INDEX].length = ANDROID_GPT_SIZE / dev_desc->blksz;
ptable[PTN_GPT_INDEX].partition_id = user_partition;
ptable[PTN_GPT_INDEX].flags = FASTBOOT_PTENTRY_FLAGS_UNERASEABLE;
/* Trusty OS */
strcpy(ptable[PTN_TEE_INDEX].name, FASTBOOT_PARTITION_TEE);
ptable[PTN_TEE_INDEX].start = 0;
ptable[PTN_TEE_INDEX].length = TRUSTY_OS_MMC_BLKS;
ptable[PTN_TEE_INDEX].partition_id = TEE_HWPARTITION_ID;
/* Bootloader */
strcpy(ptable[PTN_BOOTLOADER_INDEX].name, FASTBOOT_PARTITION_BOOTLOADER);
ptable[PTN_BOOTLOADER_INDEX].start =
......@@ -1463,7 +1480,7 @@ static int _fastboot_parts_load_from_ptable(void)
int tbl_idx;
int part_idx = 1;
int ret;
for (tbl_idx = 2; tbl_idx < MAX_PTN; tbl_idx++) {
for (tbl_idx = PTN_BOOTLOADER_INDEX + 1; tbl_idx < MAX_PTN; tbl_idx++) {
ret = _fastboot_parts_add_ptable_entry(tbl_idx,
part_idx++,
user_partition,
......@@ -1857,6 +1874,57 @@ static AvbOps fsl_avb_ops = {
};
#endif
#ifdef CONFIG_IMX_TRUSTY_OS
void tee_setup(void)
{
/* load tee from boot1 of eMMC. */
int mmcc = mmc_get_env_dev();
struct blk_desc *dev_desc = NULL;
struct mmc *mmc;
mmc = find_mmc_device(mmcc);
if (!mmc) {
printf("boota: cannot find '%d' mmc device\n", mmcc);
goto fail;
}
dev_desc = blk_get_dev("mmc", mmcc);
if (NULL == dev_desc) {
printf("** Block device MMC %d not supported\n", mmcc);
goto fail;
}
/* below was i.MX mmc operation code */
if (mmc_init(mmc)) {
printf("mmc%d init failed\n", mmcc);
goto fail;
}
struct fastboot_ptentry *tee_pte;
char *tee_ptn = FASTBOOT_PARTITION_TEE;
tee_pte = fastboot_flash_find_ptn(tee_ptn);
mmc_switch_part(mmc, TEE_HWPARTITION_ID);
if (!tee_pte) {
printf("boota: cannot find tee partition!\n");
}
if (mmc->block_dev.block_read(dev_desc, tee_pte->start,
tee_pte->length, (void *)TRUSTY_OS_ENTRY) < 0) {
printf("Failed to load tee.");
}
mmc_switch_part(mmc, FASTBOOT_MMC_USER_PARTITION_ID);
#ifdef NON_SECURE_FASTBOOT
armv7_init_nonsec();
trusty_os_init();
#endif
fail:
return;
}
#endif
void fastboot_setup(void)
{
#ifdef CONFIG_USB_GADGET
......
......@@ -52,7 +52,7 @@
int fastboot_flash_find_index(const char *name);
#ifndef FASTBOOT_ENCRYPT_LOCK
#if !defined(FASTBOOT_ENCRYPT_LOCK) || defined(NON_SECURE_FASTBOOT)
/*
* This will return FASTBOOT_LOCK, FASTBOOT_UNLOCK or FASTBOOT_ERROR
......
......@@ -17,7 +17,6 @@
#endif
#define CONFIG_ANDROID_AB_SUPPORT
#define FASTBOOT_ENCRYPT_LOCK
#define CONFIG_FSL_CAAM_KB
#define CONFIG_SHA1
......
......@@ -37,6 +37,7 @@
#define FASTBOOT_MMC_BOOT_PARTITION_ID 1
#define FASTBOOT_MMC_USER_PARTITION_ID 0
#define FASTBOOT_MMC_NONE_PARTITION_ID -1
#define FASTBOOT_MMC_BOOT1_PARTITION_ID 2
#ifdef CONFIG_ANDROID_THINGS_SUPPORT
#define FASTBOOT_PARTITION_BOOT_A "boot_a"
......@@ -46,6 +47,7 @@
#define FASTBOOT_PARTITION_DATA "userdata"
#define FASTBOOT_PARTITION_BOOT_B "boot_b"
#define FASTBOOT_PARTITION_SYSTEM_B "system_b"
#define FASTBOOT_PARTITION_TEE "tos"
#ifdef CONFIG_AVB_SUPPORT
#define FASTBOOT_PARTITION_VBMETA_A "vbmeta_a"
#define FASTBOOT_PARTITION_VBMETA_B "vbmeta_b"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment