1 // SPDX-License-Identifier: GPL-2.0
3 * (C) Copyright 2018 Xilinx, Inc.
4 * Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
11 #include <zynqmp_firmware.h>
12 #include <asm/arch/hardware.h>
13 #include <asm/arch/sys_proto.h>
16 static int do_zynqmp_verify_secure(cmd_tbl_t *cmdtp, int flag, int argc,
20 u32 len, src_lo, src_hi;
25 u32 ret_payload[PAYLOAD_ARG_CNT];
30 src_addr = simple_strtoull(argv[2], NULL, 16);
31 len = simple_strtoul(argv[3], NULL, 16);
34 key_ptr = (uint8_t *)(uintptr_t)simple_strtoull(argv[4],
37 if ((ulong)src_addr != ALIGN((ulong)src_addr,
38 CONFIG_SYS_CACHELINE_SIZE)) {
39 printf("Failed: source address not aligned:%lx\n",
44 src_lo = lower_32_bits((ulong)src_addr);
45 src_hi = upper_32_bits((ulong)src_addr);
46 flush_dcache_range((ulong)src_addr, (ulong)(src_addr + len));
49 key_lo = lower_32_bits((ulong)key_ptr);
50 key_hi = upper_32_bits((ulong)key_ptr);
51 flush_dcache_range((ulong)key_ptr,
52 (ulong)(key_ptr + KEY_PTR_LEN));
55 ret = xilinx_pm_request(PM_SECURE_IMAGE, src_lo, src_hi,
56 key_lo, key_hi, ret_payload);
58 printf("Failed: secure op status:0x%x\n", ret);
60 addr = (u64)ret_payload[1] << 32 | ret_payload[2];
61 printf("Verified image at 0x%llx\n", addr);
62 env_set_hex("zynqmp_verified_img_addr", addr);
68 static int do_zynqmp_mmio_read(cmd_tbl_t *cmdtp, int flag, int argc,
74 if (argc != cmdtp->maxargs)
77 addr = simple_strtoul(argv[2], NULL, 16);
79 ret = zynqmp_mmio_read(addr, &read_val);
81 printf("mmio read value at 0x%x = 0x%x\n",
84 printf("Failed: mmio read\n");
89 static int do_zynqmp_mmio_write(cmd_tbl_t *cmdtp, int flag, int argc,
95 if (argc != cmdtp->maxargs)
98 addr = simple_strtoul(argv[2], NULL, 16);
99 mask = simple_strtoul(argv[3], NULL, 16);
100 val = simple_strtoul(argv[4], NULL, 16);
102 ret = zynqmp_mmio_write(addr, mask, val);
104 printf("Failed: mmio write\n");
109 #ifdef CONFIG_DEFINE_TCM_OCM_MMAP
110 static int do_zynqmp_tcm_init(cmd_tbl_t *cmdtp, int flag, int argc,
115 if (argc != cmdtp->maxargs)
116 return CMD_RET_USAGE;
118 mode = simple_strtoul(argv[2], NULL, 16);
119 if (mode != TCM_LOCK && mode != TCM_SPLIT) {
120 printf("Mode should be either 0(lock)/1(split)\n");
121 return CMD_RET_FAILURE;
128 return CMD_RET_SUCCESS;
132 static cmd_tbl_t cmd_zynqmp_sub[] = {
133 U_BOOT_CMD_MKENT(secure, 5, 0, do_zynqmp_verify_secure, "", ""),
134 U_BOOT_CMD_MKENT(mmio_read, 3, 0, do_zynqmp_mmio_read, "", ""),
135 U_BOOT_CMD_MKENT(mmio_write, 5, 0, do_zynqmp_mmio_write, "", ""),
136 #ifdef CONFIG_DEFINE_TCM_OCM_MMAP
137 U_BOOT_CMD_MKENT(tcminit, 3, 0, do_zynqmp_tcm_init, "", ""),
142 * do_zynqmp - Handle the "zynqmp" command-line command
143 * @cmdtp: Command data struct pointer
144 * @flag: Command flag
145 * @argc: Command-line argument count
146 * @argv: Array of command-line arguments
148 * Processes the zynqmp specific commands
150 * Return: return 0 on success and CMD_RET_USAGE incase of misuse and error
152 static int do_zynqmp(cmd_tbl_t *cmdtp, int flag, int argc,
158 return CMD_RET_USAGE;
160 c = find_cmd_tbl(argv[1], &cmd_zynqmp_sub[0],
161 ARRAY_SIZE(cmd_zynqmp_sub));
164 return c->cmd(c, flag, argc, argv);
166 return CMD_RET_USAGE;
169 /***************************************************/
170 #ifdef CONFIG_SYS_LONGHELP
171 static char zynqmp_help_text[] =
172 "secure src len [key_addr] - verifies secure images of $len bytes\n"
173 " long at address $src. Optional key_addr\n"
174 " can be specified if user key needs to\n"
175 " be used for decryption\n"
176 "zynqmp mmio_read address - read from address\n"
177 "zynqmp mmio_write address mask value - write value after masking to\n"
179 #ifdef CONFIG_DEFINE_TCM_OCM_MMAP
180 "zynqmp tcminit mode - Initialize the TCM with zeros. TCM needs to be\n"
181 " initialized before accessing to avoid ECC\n"
182 " errors. mode specifies in which mode TCM has\n"
183 " to be initialized. Supported modes will be\n"
184 " lock(0)/split(1)\n"
190 zynqmp, 5, 1, do_zynqmp,