2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2018-02-28 07:56:53 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2018 Xilinx, Inc.
|
|
|
|
* Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <malloc.h>
|
2018-10-05 09:39:05 +00:00
|
|
|
#include <asm/arch/hardware.h>
|
2018-02-28 07:56:53 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
2018-07-11 09:48:28 +00:00
|
|
|
static int do_zynqmp_verify_secure(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char * const argv[])
|
2018-02-28 07:56:53 +00:00
|
|
|
{
|
2018-07-11 09:48:28 +00:00
|
|
|
u64 src_addr, addr;
|
|
|
|
u32 len, src_lo, src_hi;
|
|
|
|
u8 *key_ptr = NULL;
|
2018-02-28 07:56:53 +00:00
|
|
|
int ret;
|
|
|
|
u32 key_lo = 0;
|
|
|
|
u32 key_hi = 0;
|
|
|
|
u32 ret_payload[PAYLOAD_ARG_CNT];
|
|
|
|
|
2018-07-11 09:48:28 +00:00
|
|
|
if (argc < 4)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
src_addr = simple_strtoull(argv[2], NULL, 16);
|
|
|
|
len = simple_strtoul(argv[3], NULL, 16);
|
|
|
|
|
|
|
|
if (argc == 5)
|
|
|
|
key_ptr = (uint8_t *)(uintptr_t)simple_strtoull(argv[4],
|
|
|
|
NULL, 16);
|
|
|
|
|
|
|
|
if ((ulong)src_addr != ALIGN((ulong)src_addr,
|
|
|
|
CONFIG_SYS_CACHELINE_SIZE)) {
|
|
|
|
printf("Failed: source address not aligned:%lx\n",
|
|
|
|
(ulong)src_addr);
|
2018-02-28 07:56:53 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-07-11 09:48:28 +00:00
|
|
|
src_lo = lower_32_bits((ulong)src_addr);
|
|
|
|
src_hi = upper_32_bits((ulong)src_addr);
|
|
|
|
flush_dcache_range((ulong)src_addr, (ulong)(src_addr + len));
|
2018-02-28 07:56:53 +00:00
|
|
|
|
|
|
|
if (key_ptr) {
|
|
|
|
key_lo = lower_32_bits((ulong)key_ptr);
|
|
|
|
key_hi = upper_32_bits((ulong)key_ptr);
|
|
|
|
flush_dcache_range((ulong)key_ptr,
|
|
|
|
(ulong)(key_ptr + KEY_PTR_LEN));
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = invoke_smc(ZYNQMP_SIP_SVC_PM_SECURE_IMG_LOAD, src_lo, src_hi,
|
|
|
|
key_lo, key_hi, ret_payload);
|
|
|
|
if (ret) {
|
|
|
|
printf("Failed: secure op status:0x%x\n", ret);
|
|
|
|
} else {
|
|
|
|
addr = (u64)ret_payload[1] << 32 | ret_payload[2];
|
|
|
|
printf("Verified image at 0x%llx\n", addr);
|
|
|
|
env_set_hex("zynqmp_verified_img_addr", addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-16 12:34:22 +00:00
|
|
|
static int do_zynqmp_mmio_read(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
u32 read_val, addr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (argc != cmdtp->maxargs)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
addr = simple_strtoul(argv[2], NULL, 16);
|
|
|
|
|
|
|
|
ret = zynqmp_mmio_read(addr, &read_val);
|
|
|
|
if (!ret)
|
|
|
|
printf("mmio read value at 0x%x = 0x%x\n",
|
|
|
|
addr, read_val);
|
|
|
|
else
|
|
|
|
printf("Failed: mmio read\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_zynqmp_mmio_write(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
u32 addr, mask, val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (argc != cmdtp->maxargs)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
addr = simple_strtoul(argv[2], NULL, 16);
|
|
|
|
mask = simple_strtoul(argv[3], NULL, 16);
|
|
|
|
val = simple_strtoul(argv[4], NULL, 16);
|
|
|
|
|
|
|
|
ret = zynqmp_mmio_write(addr, mask, val);
|
|
|
|
if (ret != 0)
|
|
|
|
printf("Failed: mmio write\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-05 09:39:05 +00:00
|
|
|
#ifdef CONFIG_DEFINE_TCM_OCM_MMAP
|
|
|
|
static int do_zynqmp_tcm_init(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
u8 mode;
|
|
|
|
|
|
|
|
if (argc != cmdtp->maxargs)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
mode = simple_strtoul(argv[2], NULL, 16);
|
|
|
|
if (mode != TCM_LOCK && mode != TCM_SPLIT) {
|
|
|
|
printf("Mode should be either 0(lock)/1(split)\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
dcache_disable();
|
|
|
|
tcm_init(mode);
|
|
|
|
dcache_enable();
|
|
|
|
|
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-07-11 09:48:28 +00:00
|
|
|
static cmd_tbl_t cmd_zynqmp_sub[] = {
|
|
|
|
U_BOOT_CMD_MKENT(secure, 5, 0, do_zynqmp_verify_secure, "", ""),
|
2018-07-16 12:34:22 +00:00
|
|
|
U_BOOT_CMD_MKENT(mmio_read, 3, 0, do_zynqmp_mmio_read, "", ""),
|
|
|
|
U_BOOT_CMD_MKENT(mmio_write, 5, 0, do_zynqmp_mmio_write, "", ""),
|
2018-10-05 09:39:05 +00:00
|
|
|
#ifdef CONFIG_DEFINE_TCM_OCM_MMAP
|
|
|
|
U_BOOT_CMD_MKENT(tcminit, 3, 0, do_zynqmp_tcm_init, "", ""),
|
|
|
|
#endif
|
2018-07-11 09:48:28 +00:00
|
|
|
};
|
|
|
|
|
2018-02-28 07:56:53 +00:00
|
|
|
/**
|
|
|
|
* do_zynqmp - Handle the "zynqmp" command-line command
|
|
|
|
* @cmdtp: Command data struct pointer
|
|
|
|
* @flag: Command flag
|
|
|
|
* @argc: Command-line argument count
|
|
|
|
* @argv: Array of command-line arguments
|
|
|
|
*
|
|
|
|
* Processes the zynqmp specific commands
|
|
|
|
*
|
|
|
|
* Return: return 0 on success and CMD_RET_USAGE incase of misuse and error
|
|
|
|
*/
|
|
|
|
static int do_zynqmp(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
|
|
|
{
|
2018-07-11 09:48:28 +00:00
|
|
|
cmd_tbl_t *c;
|
2018-02-28 07:56:53 +00:00
|
|
|
|
2018-07-11 09:48:28 +00:00
|
|
|
if (argc < 2)
|
2018-02-28 07:56:53 +00:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2018-07-11 09:48:28 +00:00
|
|
|
c = find_cmd_tbl(argv[1], &cmd_zynqmp_sub[0],
|
|
|
|
ARRAY_SIZE(cmd_zynqmp_sub));
|
2018-02-28 07:56:53 +00:00
|
|
|
|
2018-07-11 09:48:28 +00:00
|
|
|
if (c)
|
|
|
|
return c->cmd(c, flag, argc, argv);
|
|
|
|
else
|
|
|
|
return CMD_RET_USAGE;
|
2018-02-28 07:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************/
|
|
|
|
#ifdef CONFIG_SYS_LONGHELP
|
|
|
|
static char zynqmp_help_text[] =
|
|
|
|
"secure src len [key_addr] - verifies secure images of $len bytes\n"
|
|
|
|
" long at address $src. Optional key_addr\n"
|
|
|
|
" can be specified if user key needs to\n"
|
2018-07-16 12:34:22 +00:00
|
|
|
" be used for decryption\n"
|
|
|
|
"zynqmp mmio_read address - read from address\n"
|
|
|
|
"zynqmp mmio_write address mask value - write value after masking to\n"
|
2018-10-05 09:39:05 +00:00
|
|
|
" address\n"
|
|
|
|
#ifdef CONFIG_DEFINE_TCM_OCM_MMAP
|
2018-11-21 06:49:18 +00:00
|
|
|
"zynqmp tcminit mode - Initialize the TCM with zeros. TCM needs to be\n"
|
|
|
|
" initialized before accessing to avoid ECC\n"
|
|
|
|
" errors. mode specifies in which mode TCM has\n"
|
|
|
|
" to be initialized. Supported modes will be\n"
|
|
|
|
" lock(0)/split(1)\n"
|
2018-10-05 09:39:05 +00:00
|
|
|
#endif
|
|
|
|
;
|
2018-02-28 07:56:53 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
zynqmp, 5, 1, do_zynqmp,
|
2018-07-11 09:48:28 +00:00
|
|
|
"ZynqMP sub-system",
|
2018-02-28 07:56:53 +00:00
|
|
|
zynqmp_help_text
|
|
|
|
)
|