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