1 // SPDX-License-Identifier: GPL-2.0
3 * (C) Copyright 2018 Xilinx, Inc.
12 #include <zynqmp_firmware.h>
13 #include <asm/arch/hardware.h>
14 #include <asm/arch/sys_proto.h>
17 static int do_zynqmp_verify_secure(struct cmd_tbl *cmdtp, int flag, int argc,
21 u32 len, src_lo, src_hi;
26 u32 ret_payload[PAYLOAD_ARG_CNT];
31 src_addr = simple_strtoull(argv[2], NULL, 16);
32 len = simple_strtoul(argv[3], NULL, 16);
35 key_ptr = (uint8_t *)(uintptr_t)simple_strtoull(argv[4],
38 if ((ulong)src_addr != ALIGN((ulong)src_addr,
39 CONFIG_SYS_CACHELINE_SIZE)) {
40 printf("Failed: source address not aligned:%lx\n",
45 src_lo = lower_32_bits((ulong)src_addr);
46 src_hi = upper_32_bits((ulong)src_addr);
47 flush_dcache_range((ulong)src_addr, (ulong)(src_addr + len));
50 key_lo = lower_32_bits((ulong)key_ptr);
51 key_hi = upper_32_bits((ulong)key_ptr);
52 flush_dcache_range((ulong)key_ptr,
53 (ulong)(key_ptr + KEY_PTR_LEN));
56 ret = xilinx_pm_request(PM_SECURE_IMAGE, src_lo, src_hi,
57 key_lo, key_hi, ret_payload);
59 printf("Failed: secure op status:0x%x\n", ret);
61 addr = (u64)ret_payload[1] << 32 | ret_payload[2];
62 printf("Verified image at 0x%llx\n", addr);
63 env_set_hex("zynqmp_verified_img_addr", addr);
69 static int do_zynqmp_mmio_read(struct cmd_tbl *cmdtp, int flag, int argc,
75 if (argc != cmdtp->maxargs)
78 addr = simple_strtoul(argv[2], NULL, 16);
80 ret = zynqmp_mmio_read(addr, &read_val);
82 printf("mmio read value at 0x%x = 0x%x\n",
85 printf("Failed: mmio read\n");
90 static int do_zynqmp_mmio_write(struct cmd_tbl *cmdtp, int flag, int argc,
96 if (argc != cmdtp->maxargs)
99 addr = simple_strtoul(argv[2], NULL, 16);
100 mask = simple_strtoul(argv[3], NULL, 16);
101 val = simple_strtoul(argv[4], NULL, 16);
103 ret = zynqmp_mmio_write(addr, mask, val);
105 printf("Failed: mmio write\n");
110 #ifdef CONFIG_DEFINE_TCM_OCM_MMAP
111 static int do_zynqmp_tcm_init(struct cmd_tbl *cmdtp, int flag, int argc,
116 if (argc != cmdtp->maxargs)
117 return CMD_RET_USAGE;
119 mode = simple_strtoul(argv[2], NULL, 16);
120 if (mode != TCM_LOCK && mode != TCM_SPLIT) {
121 printf("Mode should be either 0(lock)/1(split)\n");
122 return CMD_RET_FAILURE;
129 return CMD_RET_SUCCESS;
133 static struct cmd_tbl cmd_zynqmp_sub[] = {
134 U_BOOT_CMD_MKENT(secure, 5, 0, do_zynqmp_verify_secure, "", ""),
135 U_BOOT_CMD_MKENT(mmio_read, 3, 0, do_zynqmp_mmio_read, "", ""),
136 U_BOOT_CMD_MKENT(mmio_write, 5, 0, do_zynqmp_mmio_write, "", ""),
137 #ifdef CONFIG_DEFINE_TCM_OCM_MMAP
138 U_BOOT_CMD_MKENT(tcminit, 3, 0, do_zynqmp_tcm_init, "", ""),
143 * do_zynqmp - Handle the "zynqmp" command-line command
144 * @cmdtp: Command data struct pointer
145 * @flag: Command flag
146 * @argc: Command-line argument count
147 * @argv: Array of command-line arguments
149 * Processes the zynqmp specific commands
151 * Return: return 0 on success and CMD_RET_USAGE incase of misuse and error
153 static int do_zynqmp(struct cmd_tbl *cmdtp, int flag, int argc,
159 return CMD_RET_USAGE;
161 c = find_cmd_tbl(argv[1], &cmd_zynqmp_sub[0],
162 ARRAY_SIZE(cmd_zynqmp_sub));
165 return c->cmd(c, flag, argc, argv);
167 return CMD_RET_USAGE;
170 /***************************************************/
171 #ifdef CONFIG_SYS_LONGHELP
172 static char zynqmp_help_text[] =
173 "secure src len [key_addr] - verifies secure images of $len bytes\n"
174 " long at address $src. Optional key_addr\n"
175 " can be specified if user key needs to\n"
176 " be used for decryption\n"
177 "zynqmp mmio_read address - read from address\n"
178 "zynqmp mmio_write address mask value - write value after masking to\n"
180 #ifdef CONFIG_DEFINE_TCM_OCM_MMAP
181 "zynqmp tcminit mode - Initialize the TCM with zeros. TCM needs to be\n"
182 " initialized before accessing to avoid ECC\n"
183 " errors. mode specifies in which mode TCM has\n"
184 " to be initialized. Supported modes will be\n"
185 " lock(0)/split(1)\n"
191 zynqmp, 5, 1, do_zynqmp,