1 // SPDX-License-Identifier: GPL-2.0
3 * (C) Copyright 2018 Xilinx, Inc.
4 * Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
9 #include <asm/arch/sys_proto.h>
12 static int zynqmp_verify_secure(u8 *key_ptr, u8 *src_ptr, u32 len)
18 u32 ret_payload[PAYLOAD_ARG_CNT];
21 if ((ulong)src_ptr != ALIGN((ulong)src_ptr,
22 CONFIG_SYS_CACHELINE_SIZE)) {
23 printf("Failed: source address not aligned:%p\n", src_ptr);
27 src_lo = lower_32_bits((ulong)src_ptr);
28 src_hi = upper_32_bits((ulong)src_ptr);
29 flush_dcache_range((ulong)src_ptr, (ulong)(src_ptr + len));
32 key_lo = lower_32_bits((ulong)key_ptr);
33 key_hi = upper_32_bits((ulong)key_ptr);
34 flush_dcache_range((ulong)key_ptr,
35 (ulong)(key_ptr + KEY_PTR_LEN));
38 ret = invoke_smc(ZYNQMP_SIP_SVC_PM_SECURE_IMG_LOAD, src_lo, src_hi,
39 key_lo, key_hi, ret_payload);
41 printf("Failed: secure op status:0x%x\n", ret);
43 addr = (u64)ret_payload[1] << 32 | ret_payload[2];
44 printf("Verified image at 0x%llx\n", addr);
45 env_set_hex("zynqmp_verified_img_addr", addr);
52 * do_zynqmp - Handle the "zynqmp" command-line command
53 * @cmdtp: Command data struct pointer
55 * @argc: Command-line argument count
56 * @argv: Array of command-line arguments
58 * Processes the zynqmp specific commands
60 * Return: return 0 on success and CMD_RET_USAGE incase of misuse and error
62 static int do_zynqmp(cmd_tbl_t *cmdtp, int flag, int argc,
71 if (argc > 5 || argc < 4 || strncmp(argv[1], "secure", 6))
74 src_addr = simple_strtoull(argv[2], NULL, 16);
76 len = simple_strtoul(argv[3], NULL, 16);
79 key_ptr = (uint8_t *)(uintptr_t)simple_strtoull(argv[4],
82 src_ptr = (uint8_t *)(uintptr_t)src_addr;
84 ret = zynqmp_verify_secure(key_ptr, src_ptr, len);
86 return CMD_RET_FAILURE;
88 return CMD_RET_SUCCESS;
91 /***************************************************/
92 #ifdef CONFIG_SYS_LONGHELP
93 static char zynqmp_help_text[] =
94 "secure src len [key_addr] - verifies secure images of $len bytes\n"
95 " long at address $src. Optional key_addr\n"
96 " can be specified if user key needs to\n"
97 " be used for decryption\n";
101 zynqmp, 5, 1, do_zynqmp,
102 "Verify and load secure images",