Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2018 Xilinx, Inc. |
Michal Simek | a8c9436 | 2023-07-10 14:35:49 +0200 | [diff] [blame] | 4 | * Siva Durga Prasad Paladugu <siva.durga.prasad.paladugu@amd.com>> |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 9 | #include <env.h> |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 10 | #include <malloc.h> |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 11 | #include <memalign.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 12 | #include <vsprintf.h> |
Ibai Erkiaga | c8a3efa | 2019-09-27 11:37:01 +0100 | [diff] [blame] | 13 | #include <zynqmp_firmware.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 14 | #include <linux/errno.h> |
Siva Durga Prasad Paladugu | 48eaa0c | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 15 | #include <asm/arch/hardware.h> |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
| 17 | #include <asm/io.h> |
Christian Taedcke | c4c41a1 | 2023-07-25 09:26:58 +0200 | [diff] [blame] | 18 | #include <mach/zynqmp_aes.h> |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 19 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 20 | static int do_zynqmp_verify_secure(struct cmd_tbl *cmdtp, int flag, int argc, |
| 21 | char *const argv[]) |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 22 | { |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 23 | u64 src_addr, addr; |
| 24 | u32 len, src_lo, src_hi; |
| 25 | u8 *key_ptr = NULL; |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 26 | int ret; |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 27 | u32 key_lo = 0; |
| 28 | u32 key_hi = 0; |
| 29 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 30 | |
| 31 | if (argc < 4) |
| 32 | return CMD_RET_USAGE; |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 33 | |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 34 | src_addr = simple_strtoull(argv[2], NULL, 16); |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 35 | len = hextoul(argv[3], NULL); |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 36 | |
| 37 | if (argc == 5) |
| 38 | key_ptr = (uint8_t *)(uintptr_t)simple_strtoull(argv[4], |
| 39 | NULL, 16); |
| 40 | |
| 41 | if ((ulong)src_addr != ALIGN((ulong)src_addr, |
| 42 | CONFIG_SYS_CACHELINE_SIZE)) { |
| 43 | printf("Failed: source address not aligned:%lx\n", |
| 44 | (ulong)src_addr); |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 45 | return -EINVAL; |
| 46 | } |
| 47 | |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 48 | src_lo = lower_32_bits((ulong)src_addr); |
| 49 | src_hi = upper_32_bits((ulong)src_addr); |
| 50 | flush_dcache_range((ulong)src_addr, (ulong)(src_addr + len)); |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 51 | |
| 52 | if (key_ptr) { |
| 53 | key_lo = lower_32_bits((ulong)key_ptr); |
| 54 | key_hi = upper_32_bits((ulong)key_ptr); |
| 55 | flush_dcache_range((ulong)key_ptr, |
| 56 | (ulong)(key_ptr + KEY_PTR_LEN)); |
| 57 | } |
| 58 | |
Michal Simek | 4c3de37 | 2019-10-04 15:35:45 +0200 | [diff] [blame] | 59 | ret = xilinx_pm_request(PM_SECURE_IMAGE, src_lo, src_hi, |
| 60 | key_lo, key_hi, ret_payload); |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 61 | if (ret) { |
| 62 | printf("Failed: secure op status:0x%x\n", ret); |
| 63 | } else { |
| 64 | addr = (u64)ret_payload[1] << 32 | ret_payload[2]; |
| 65 | printf("Verified image at 0x%llx\n", addr); |
| 66 | env_set_hex("zynqmp_verified_img_addr", addr); |
| 67 | } |
| 68 | |
| 69 | return ret; |
| 70 | } |
| 71 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 72 | static int do_zynqmp_mmio_read(struct cmd_tbl *cmdtp, int flag, int argc, |
| 73 | char *const argv[]) |
Vipul Kumar | 869ed8c | 2018-07-16 18:04:22 +0530 | [diff] [blame] | 74 | { |
| 75 | u32 read_val, addr; |
| 76 | int ret; |
| 77 | |
| 78 | if (argc != cmdtp->maxargs) |
| 79 | return CMD_RET_USAGE; |
| 80 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 81 | addr = hextoul(argv[2], NULL); |
Vipul Kumar | 869ed8c | 2018-07-16 18:04:22 +0530 | [diff] [blame] | 82 | |
| 83 | ret = zynqmp_mmio_read(addr, &read_val); |
| 84 | if (!ret) |
| 85 | printf("mmio read value at 0x%x = 0x%x\n", |
| 86 | addr, read_val); |
| 87 | else |
| 88 | printf("Failed: mmio read\n"); |
| 89 | |
| 90 | return ret; |
| 91 | } |
| 92 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 93 | static int do_zynqmp_mmio_write(struct cmd_tbl *cmdtp, int flag, int argc, |
| 94 | char *const argv[]) |
Vipul Kumar | 869ed8c | 2018-07-16 18:04:22 +0530 | [diff] [blame] | 95 | { |
| 96 | u32 addr, mask, val; |
| 97 | int ret; |
| 98 | |
| 99 | if (argc != cmdtp->maxargs) |
| 100 | return CMD_RET_USAGE; |
| 101 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 102 | addr = hextoul(argv[2], NULL); |
| 103 | mask = hextoul(argv[3], NULL); |
| 104 | val = hextoul(argv[4], NULL); |
Vipul Kumar | 869ed8c | 2018-07-16 18:04:22 +0530 | [diff] [blame] | 105 | |
| 106 | ret = zynqmp_mmio_write(addr, mask, val); |
| 107 | if (ret != 0) |
| 108 | printf("Failed: mmio write\n"); |
| 109 | |
| 110 | return ret; |
| 111 | } |
| 112 | |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 113 | static int do_zynqmp_aes(struct cmd_tbl *cmdtp, int flag, int argc, |
| 114 | char * const argv[]) |
| 115 | { |
Christian Taedcke | c4c41a1 | 2023-07-25 09:26:58 +0200 | [diff] [blame] | 116 | ALLOC_CACHE_ALIGN_BUFFER(struct zynqmp_aes, aes, 1); |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 117 | |
| 118 | if (zynqmp_firmware_version() <= PMUFW_V1_0) { |
| 119 | puts("ERR: PMUFW v1.0 or less is detected\n"); |
| 120 | puts("ERR: Encrypt/Decrypt feature is not supported\n"); |
| 121 | puts("ERR: Please upgrade PMUFW\n"); |
| 122 | return CMD_RET_FAILURE; |
| 123 | } |
| 124 | |
| 125 | if (argc < cmdtp->maxargs - 1) |
| 126 | return CMD_RET_USAGE; |
| 127 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 128 | aes->srcaddr = hextoul(argv[2], NULL); |
| 129 | aes->ivaddr = hextoul(argv[3], NULL); |
| 130 | aes->len = hextoul(argv[4], NULL); |
| 131 | aes->op = hextoul(argv[5], NULL); |
| 132 | aes->keysrc = hextoul(argv[6], NULL); |
| 133 | aes->dstaddr = hextoul(argv[7], NULL); |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 134 | |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 135 | if (aes->keysrc == 0) { |
| 136 | if (argc < cmdtp->maxargs) |
| 137 | return CMD_RET_USAGE; |
| 138 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 139 | aes->keyaddr = hextoul(argv[8], NULL); |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 140 | } |
| 141 | |
Christian Taedcke | c4c41a1 | 2023-07-25 09:26:58 +0200 | [diff] [blame] | 142 | return zynqmp_aes_operation(aes); |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 143 | } |
| 144 | |
Siva Durga Prasad Paladugu | 48eaa0c | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 145 | #ifdef CONFIG_DEFINE_TCM_OCM_MMAP |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 146 | static int do_zynqmp_tcm_init(struct cmd_tbl *cmdtp, int flag, int argc, |
| 147 | char *const argv[]) |
Siva Durga Prasad Paladugu | 48eaa0c | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 148 | { |
| 149 | u8 mode; |
| 150 | |
| 151 | if (argc != cmdtp->maxargs) |
| 152 | return CMD_RET_USAGE; |
| 153 | |
Venkatesh Yadav Abbarapu | 5389fb5 | 2023-06-08 08:51:51 +0530 | [diff] [blame] | 154 | if (strcmp(argv[2], "lockstep") && strcmp(argv[2], "split")) { |
| 155 | printf("mode param should be lockstep or split\n"); |
| 156 | return CMD_RET_FAILURE; |
| 157 | } |
| 158 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 159 | mode = hextoul(argv[2], NULL); |
Siva Durga Prasad Paladugu | 48eaa0c | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 160 | if (mode != TCM_LOCK && mode != TCM_SPLIT) { |
| 161 | printf("Mode should be either 0(lock)/1(split)\n"); |
| 162 | return CMD_RET_FAILURE; |
| 163 | } |
| 164 | |
| 165 | dcache_disable(); |
| 166 | tcm_init(mode); |
| 167 | dcache_enable(); |
| 168 | |
| 169 | return CMD_RET_SUCCESS; |
| 170 | } |
| 171 | #endif |
| 172 | |
Michal Simek | b0e4b23 | 2020-04-27 11:26:31 +0200 | [diff] [blame] | 173 | static int do_zynqmp_pmufw(struct cmd_tbl *cmdtp, int flag, int argc, |
| 174 | char * const argv[]) |
| 175 | { |
| 176 | u32 addr, size; |
| 177 | |
| 178 | if (argc != cmdtp->maxargs) |
| 179 | return CMD_RET_USAGE; |
| 180 | |
Michal Simek | 07168c6 | 2022-01-14 13:25:38 +0100 | [diff] [blame] | 181 | if (!strncmp(argv[2], "node", 4)) { |
| 182 | u32 id; |
Michal Simek | 15dce44 | 2023-06-01 13:25:04 +0200 | [diff] [blame] | 183 | int ret; |
Michal Simek | 07168c6 | 2022-01-14 13:25:38 +0100 | [diff] [blame] | 184 | |
| 185 | if (!strncmp(argv[3], "close", 5)) |
| 186 | return zynqmp_pmufw_config_close(); |
| 187 | |
| 188 | id = dectoul(argv[3], NULL); |
Michal Simek | 43ced3c | 2023-06-01 12:32:36 +0200 | [diff] [blame] | 189 | if (!id) { |
| 190 | printf("Incorrect ID passed\n"); |
| 191 | return CMD_RET_USAGE; |
| 192 | } |
Michal Simek | 07168c6 | 2022-01-14 13:25:38 +0100 | [diff] [blame] | 193 | |
| 194 | printf("Enable permission for node ID %d\n", id); |
| 195 | |
Michal Simek | 15dce44 | 2023-06-01 13:25:04 +0200 | [diff] [blame] | 196 | ret = zynqmp_pmufw_node(id); |
| 197 | if (ret == -ENODEV) |
| 198 | ret = 0; |
| 199 | |
| 200 | return ret; |
Michal Simek | 07168c6 | 2022-01-14 13:25:38 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 203 | addr = hextoul(argv[2], NULL); |
| 204 | size = hextoul(argv[3], NULL); |
Michal Simek | b0e4b23 | 2020-04-27 11:26:31 +0200 | [diff] [blame] | 205 | |
| 206 | zynqmp_pmufw_load_config_object((const void *)(uintptr_t)addr, |
| 207 | (size_t)size); |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
T Karthik Reddy | 59ec641 | 2019-01-07 17:05:10 +0530 | [diff] [blame] | 212 | static int do_zynqmp_rsa(struct cmd_tbl *cmdtp, int flag, int argc, |
| 213 | char * const argv[]) |
| 214 | { |
| 215 | u64 srcaddr, mod, exp; |
| 216 | u32 srclen, rsaop, size, ret_payload[PAYLOAD_ARG_CNT]; |
| 217 | int ret; |
| 218 | |
| 219 | if (argc != cmdtp->maxargs) |
| 220 | return CMD_RET_USAGE; |
| 221 | |
| 222 | if (zynqmp_firmware_version() <= PMUFW_V1_0) { |
| 223 | puts("ERR: PMUFW v1.0 or less is detected\n"); |
| 224 | puts("ERR: Encrypt/Decrypt feature is not supported\n"); |
| 225 | puts("ERR: Please upgrade PMUFW\n"); |
| 226 | return CMD_RET_FAILURE; |
| 227 | } |
| 228 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 229 | srcaddr = hextoul(argv[2], NULL); |
| 230 | srclen = hextoul(argv[3], NULL); |
T Karthik Reddy | 59ec641 | 2019-01-07 17:05:10 +0530 | [diff] [blame] | 231 | if (srclen != RSA_KEY_SIZE) { |
| 232 | puts("ERR: srclen should be equal to 0x200(512 bytes)\n"); |
| 233 | return CMD_RET_USAGE; |
| 234 | } |
| 235 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 236 | mod = hextoul(argv[4], NULL); |
| 237 | exp = hextoul(argv[5], NULL); |
| 238 | rsaop = hextoul(argv[6], NULL); |
T Karthik Reddy | 59ec641 | 2019-01-07 17:05:10 +0530 | [diff] [blame] | 239 | if (!(rsaop == 0 || rsaop == 1)) { |
| 240 | puts("ERR: rsaop should be either 0 or 1\n"); |
| 241 | return CMD_RET_USAGE; |
| 242 | } |
| 243 | |
| 244 | memcpy((void *)srcaddr + srclen, (void *)mod, MODULUS_LEN); |
| 245 | |
| 246 | /* |
| 247 | * For encryption we load public exponent (key size 4096-bits), |
| 248 | * for decryption we load private exponent (32-bits) |
| 249 | */ |
| 250 | if (rsaop) { |
| 251 | memcpy((void *)srcaddr + srclen + MODULUS_LEN, |
| 252 | (void *)exp, PUB_EXPO_LEN); |
| 253 | size = srclen + MODULUS_LEN + PUB_EXPO_LEN; |
| 254 | } else { |
| 255 | memcpy((void *)srcaddr + srclen + MODULUS_LEN, |
| 256 | (void *)exp, PRIV_EXPO_LEN); |
| 257 | size = srclen + MODULUS_LEN + PRIV_EXPO_LEN; |
| 258 | } |
| 259 | |
| 260 | flush_dcache_range((ulong)srcaddr, |
| 261 | (ulong)(srcaddr) + roundup(size, ARCH_DMA_MINALIGN)); |
| 262 | |
| 263 | ret = xilinx_pm_request(PM_SECURE_RSA, upper_32_bits((ulong)srcaddr), |
| 264 | lower_32_bits((ulong)srcaddr), srclen, rsaop, |
| 265 | ret_payload); |
| 266 | if (ret || ret_payload[1]) { |
| 267 | printf("Failed: RSA status:0x%x, errcode:0x%x\n", |
| 268 | ret, ret_payload[1]); |
| 269 | return CMD_RET_FAILURE; |
| 270 | } |
| 271 | |
| 272 | return CMD_RET_SUCCESS; |
| 273 | } |
| 274 | |
T Karthik Reddy | 89cbce9 | 2019-01-07 17:05:11 +0530 | [diff] [blame] | 275 | static int do_zynqmp_sha3(struct cmd_tbl *cmdtp, int flag, |
| 276 | int argc, char * const argv[]) |
| 277 | { |
Michal Simek | d5c3747 | 2020-10-20 08:29:25 +0200 | [diff] [blame] | 278 | u64 srcaddr, hashaddr; |
T Karthik Reddy | 89cbce9 | 2019-01-07 17:05:11 +0530 | [diff] [blame] | 279 | u32 srclen, ret_payload[PAYLOAD_ARG_CNT]; |
| 280 | int ret; |
| 281 | |
Michal Simek | d5c3747 | 2020-10-20 08:29:25 +0200 | [diff] [blame] | 282 | if (argc > cmdtp->maxargs || argc < (cmdtp->maxargs - 1)) |
T Karthik Reddy | 89cbce9 | 2019-01-07 17:05:11 +0530 | [diff] [blame] | 283 | return CMD_RET_USAGE; |
| 284 | |
| 285 | if (zynqmp_firmware_version() <= PMUFW_V1_0) { |
| 286 | puts("ERR: PMUFW v1.0 or less is detected\n"); |
| 287 | puts("ERR: Encrypt/Decrypt feature is not supported\n"); |
| 288 | puts("ERR: Please upgrade PMUFW\n"); |
| 289 | return CMD_RET_FAILURE; |
| 290 | } |
| 291 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 292 | srcaddr = hextoul(argv[2], NULL); |
| 293 | srclen = hextoul(argv[3], NULL); |
T Karthik Reddy | 89cbce9 | 2019-01-07 17:05:11 +0530 | [diff] [blame] | 294 | |
Michal Simek | d5c3747 | 2020-10-20 08:29:25 +0200 | [diff] [blame] | 295 | if (argc == 5) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 296 | hashaddr = hextoul(argv[4], NULL); |
Michal Simek | d5c3747 | 2020-10-20 08:29:25 +0200 | [diff] [blame] | 297 | flush_dcache_range(hashaddr, |
| 298 | hashaddr + roundup(ZYNQMP_SHA3_SIZE, |
| 299 | ARCH_DMA_MINALIGN)); |
| 300 | } else { |
| 301 | hashaddr = srcaddr; |
| 302 | } |
| 303 | |
T Karthik Reddy | 89cbce9 | 2019-01-07 17:05:11 +0530 | [diff] [blame] | 304 | /* Check srcaddr or srclen != 0 */ |
| 305 | if (!srcaddr || !srclen) { |
| 306 | puts("ERR: srcaddr & srclen should not be 0\n"); |
| 307 | return CMD_RET_USAGE; |
| 308 | } |
| 309 | |
| 310 | flush_dcache_range(srcaddr, |
| 311 | srcaddr + roundup(srclen, ARCH_DMA_MINALIGN)); |
| 312 | |
| 313 | ret = xilinx_pm_request(PM_SECURE_SHA, 0, 0, 0, |
| 314 | ZYNQMP_SHA3_INIT, ret_payload); |
| 315 | if (ret || ret_payload[1]) { |
| 316 | printf("Failed: SHA INIT status:0x%x, errcode:0x%x\n", |
| 317 | ret, ret_payload[1]); |
| 318 | return CMD_RET_FAILURE; |
| 319 | } |
| 320 | |
| 321 | ret = xilinx_pm_request(PM_SECURE_SHA, upper_32_bits((ulong)srcaddr), |
| 322 | lower_32_bits((ulong)srcaddr), |
| 323 | srclen, ZYNQMP_SHA3_UPDATE, ret_payload); |
| 324 | if (ret || ret_payload[1]) { |
| 325 | printf("Failed: SHA UPDATE status:0x%x, errcode:0x%x\n", |
| 326 | ret, ret_payload[1]); |
| 327 | return CMD_RET_FAILURE; |
| 328 | } |
| 329 | |
Michal Simek | d5c3747 | 2020-10-20 08:29:25 +0200 | [diff] [blame] | 330 | ret = xilinx_pm_request(PM_SECURE_SHA, upper_32_bits((ulong)hashaddr), |
| 331 | lower_32_bits((ulong)hashaddr), |
| 332 | ZYNQMP_SHA3_SIZE, ZYNQMP_SHA3_FINAL, |
| 333 | ret_payload); |
T Karthik Reddy | 89cbce9 | 2019-01-07 17:05:11 +0530 | [diff] [blame] | 334 | if (ret || ret_payload[1]) { |
| 335 | printf("Failed: SHA FINAL status:0x%x, errcode:0x%x\n", |
| 336 | ret, ret_payload[1]); |
| 337 | return CMD_RET_FAILURE; |
| 338 | } |
| 339 | |
| 340 | return CMD_RET_SUCCESS; |
| 341 | } |
| 342 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 343 | static struct cmd_tbl cmd_zynqmp_sub[] = { |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 344 | U_BOOT_CMD_MKENT(secure, 5, 0, do_zynqmp_verify_secure, "", ""), |
Michal Simek | b0e4b23 | 2020-04-27 11:26:31 +0200 | [diff] [blame] | 345 | U_BOOT_CMD_MKENT(pmufw, 4, 0, do_zynqmp_pmufw, "", ""), |
Vipul Kumar | 869ed8c | 2018-07-16 18:04:22 +0530 | [diff] [blame] | 346 | U_BOOT_CMD_MKENT(mmio_read, 3, 0, do_zynqmp_mmio_read, "", ""), |
| 347 | U_BOOT_CMD_MKENT(mmio_write, 5, 0, do_zynqmp_mmio_write, "", ""), |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 348 | U_BOOT_CMD_MKENT(aes, 9, 0, do_zynqmp_aes, "", ""), |
T Karthik Reddy | 59ec641 | 2019-01-07 17:05:10 +0530 | [diff] [blame] | 349 | U_BOOT_CMD_MKENT(rsa, 7, 0, do_zynqmp_rsa, "", ""), |
Michal Simek | d5c3747 | 2020-10-20 08:29:25 +0200 | [diff] [blame] | 350 | U_BOOT_CMD_MKENT(sha3, 5, 0, do_zynqmp_sha3, "", ""), |
Siva Durga Prasad Paladugu | 48eaa0c | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 351 | #ifdef CONFIG_DEFINE_TCM_OCM_MMAP |
| 352 | U_BOOT_CMD_MKENT(tcminit, 3, 0, do_zynqmp_tcm_init, "", ""), |
| 353 | #endif |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 354 | }; |
| 355 | |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 356 | /** |
| 357 | * do_zynqmp - Handle the "zynqmp" command-line command |
| 358 | * @cmdtp: Command data struct pointer |
| 359 | * @flag: Command flag |
| 360 | * @argc: Command-line argument count |
| 361 | * @argv: Array of command-line arguments |
| 362 | * |
| 363 | * Processes the zynqmp specific commands |
| 364 | * |
| 365 | * Return: return 0 on success and CMD_RET_USAGE incase of misuse and error |
| 366 | */ |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 367 | static int do_zynqmp(struct cmd_tbl *cmdtp, int flag, int argc, |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 368 | char *const argv[]) |
| 369 | { |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 370 | struct cmd_tbl *c; |
Michal Simek | 36556a0 | 2023-06-01 13:21:07 +0200 | [diff] [blame] | 371 | int ret = CMD_RET_USAGE; |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 372 | |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 373 | if (argc < 2) |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 374 | return CMD_RET_USAGE; |
| 375 | |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 376 | c = find_cmd_tbl(argv[1], &cmd_zynqmp_sub[0], |
| 377 | ARRAY_SIZE(cmd_zynqmp_sub)); |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 378 | if (c) |
Michal Simek | 36556a0 | 2023-06-01 13:21:07 +0200 | [diff] [blame] | 379 | ret = c->cmd(c, flag, argc, argv); |
| 380 | |
| 381 | return cmd_process_error(c, ret); |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /***************************************************/ |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 385 | U_BOOT_LONGHELP(zynqmp, |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 386 | "secure src len [key_addr] - verifies secure images of $len bytes\n" |
| 387 | " long at address $src. Optional key_addr\n" |
| 388 | " can be specified if user key needs to\n" |
Vipul Kumar | 869ed8c | 2018-07-16 18:04:22 +0530 | [diff] [blame] | 389 | " be used for decryption\n" |
| 390 | "zynqmp mmio_read address - read from address\n" |
| 391 | "zynqmp mmio_write address mask value - write value after masking to\n" |
Siva Durga Prasad Paladugu | 48eaa0c | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 392 | " address\n" |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 393 | "zynqmp aes srcaddr ivaddr len aesop keysrc dstaddr [keyaddr] -\n" |
| 394 | " Encrypts or decrypts blob of data at src address and puts it\n" |
| 395 | " back to dstaddr using key and iv at keyaddr and ivaddr\n" |
| 396 | " respectively. keysrc value specifies from which source key\n" |
| 397 | " has to be used, it can be User/Device/PUF key. A value of 0\n" |
| 398 | " for KUP(user key),1 for DeviceKey and 2 for PUF key. The\n" |
| 399 | " aesop value specifies the operation which can be 0 for\n" |
| 400 | " decrypt and 1 for encrypt operation\n" |
Siva Durga Prasad Paladugu | 48eaa0c | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 401 | #ifdef CONFIG_DEFINE_TCM_OCM_MMAP |
Michal Simek | 3a5642d | 2018-11-21 07:49:18 +0100 | [diff] [blame] | 402 | "zynqmp tcminit mode - Initialize the TCM with zeros. TCM needs to be\n" |
| 403 | " initialized before accessing to avoid ECC\n" |
| 404 | " errors. mode specifies in which mode TCM has\n" |
| 405 | " to be initialized. Supported modes will be\n" |
| 406 | " lock(0)/split(1)\n" |
Siva Durga Prasad Paladugu | 48eaa0c | 2018-10-05 15:09:05 +0530 | [diff] [blame] | 407 | #endif |
Michal Simek | b0e4b23 | 2020-04-27 11:26:31 +0200 | [diff] [blame] | 408 | "zynqmp pmufw address size - load PMU FW configuration object\n" |
Michal Simek | 43ced3c | 2023-06-01 12:32:36 +0200 | [diff] [blame] | 409 | "zynqmp pmufw node <id> - load PMU FW configuration object, <id> in dec\n" |
Michal Simek | 07168c6 | 2022-01-14 13:25:38 +0100 | [diff] [blame] | 410 | "zynqmp pmufw node close - disable config object loading\n" |
| 411 | " node: keyword, id: NODE_ID in decimal format\n" |
T Karthik Reddy | 59ec641 | 2019-01-07 17:05:10 +0530 | [diff] [blame] | 412 | "zynqmp rsa srcaddr srclen mod exp rsaop -\n" |
| 413 | " Performs RSA encryption and RSA decryption on blob of data\n" |
| 414 | " at srcaddr and puts it back in srcaddr using modulus and\n" |
| 415 | " public or private exponent\n" |
| 416 | " srclen : must be key size(4096 bits)\n" |
| 417 | " exp : private key exponent for RSA decryption(4096 bits)\n" |
| 418 | " public key exponent for RSA encryption(32 bits)\n" |
| 419 | " rsaop : 0 for RSA Decryption, 1 for RSA Encryption\n" |
Michal Simek | d5c3747 | 2020-10-20 08:29:25 +0200 | [diff] [blame] | 420 | "zynqmp sha3 srcaddr srclen [key_addr] -\n" |
T Karthik Reddy | 89cbce9 | 2019-01-07 17:05:11 +0530 | [diff] [blame] | 421 | " Generates sha3 hash value for data blob at srcaddr and puts\n" |
| 422 | " 48 bytes hash value into srcaddr\n" |
Michal Simek | d5c3747 | 2020-10-20 08:29:25 +0200 | [diff] [blame] | 423 | " Optional key_addr can be specified for saving sha3 hash value\n" |
T Karthik Reddy | 89cbce9 | 2019-01-07 17:05:11 +0530 | [diff] [blame] | 424 | " Note: srcaddr/srclen should not be 0\n" |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 425 | ); |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 426 | |
| 427 | U_BOOT_CMD( |
Siva Durga Prasad Paladugu | 8b75ad6 | 2018-09-06 16:34:44 +0530 | [diff] [blame] | 428 | zynqmp, 9, 1, do_zynqmp, |
Vipul Kumar | 95a3f87 | 2018-07-11 15:18:28 +0530 | [diff] [blame] | 429 | "ZynqMP sub-system", |
Siva Durga Prasad Paladugu | b1acb65 | 2018-02-28 13:26:53 +0530 | [diff] [blame] | 430 | zynqmp_help_text |
Simon Glass | 761d602 | 2023-11-18 14:04:52 -0700 | [diff] [blame] | 431 | ); |