2 * (C) Copyright 2018 Xilinx, Inc.
3 * Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
5 * SPDX-License-Identifier: GPL-2.0
10 #include <asm/arch/sys_proto.h>
13 static int zynqmp_verify_secure(u8 *key_ptr, u8 *src_ptr, u32 len)
19 u32 ret_payload[PAYLOAD_ARG_CNT];
22 if ((ulong)src_ptr != ALIGN((ulong)src_ptr,
23 CONFIG_SYS_CACHELINE_SIZE)) {
24 printf("Failed: source address not aligned:%p\n", src_ptr);
28 src_lo = lower_32_bits((ulong)src_ptr);
29 src_hi = upper_32_bits((ulong)src_ptr);
30 flush_dcache_range((ulong)src_ptr, (ulong)(src_ptr + len));
33 key_lo = lower_32_bits((ulong)key_ptr);
34 key_hi = upper_32_bits((ulong)key_ptr);
35 flush_dcache_range((ulong)key_ptr,
36 (ulong)(key_ptr + KEY_PTR_LEN));
39 ret = invoke_smc(ZYNQMP_SIP_SVC_PM_SECURE_IMG_LOAD, src_lo, src_hi,
40 key_lo, key_hi, ret_payload);
42 printf("Failed: secure op status:0x%x\n", ret);
44 addr = (u64)ret_payload[1] << 32 | ret_payload[2];
45 printf("Verified image at 0x%llx\n", addr);
46 env_set_hex("zynqmp_verified_img_addr", addr);
53 * do_zynqmp - Handle the "zynqmp" command-line command
54 * @cmdtp: Command data struct pointer
56 * @argc: Command-line argument count
57 * @argv: Array of command-line arguments
59 * Processes the zynqmp specific commands
61 * Return: return 0 on success and CMD_RET_USAGE incase of misuse and error
63 static int do_zynqmp(cmd_tbl_t *cmdtp, int flag, int argc,
72 if (argc > 5 || argc < 4 || strncmp(argv[1], "secure", 6))
75 src_addr = simple_strtoull(argv[2], NULL, 16);
77 len = simple_strtoul(argv[3], NULL, 16);
80 key_ptr = (uint8_t *)(uintptr_t)simple_strtoull(argv[4],
83 src_ptr = (uint8_t *)(uintptr_t)src_addr;
85 ret = zynqmp_verify_secure(key_ptr, src_ptr, len);
87 return CMD_RET_FAILURE;
89 return CMD_RET_SUCCESS;
92 /***************************************************/
93 #ifdef CONFIG_SYS_LONGHELP
94 static char zynqmp_help_text[] =
95 "secure src len [key_addr] - verifies secure images of $len bytes\n"
96 " long at address $src. Optional key_addr\n"
97 " can be specified if user key needs to\n"
98 " be used for decryption\n";
102 zynqmp, 5, 1, do_zynqmp,
103 "Verify and load secure images",