Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2018 Bootlin |
| 4 | * Author: Miquel Raynal <miquel.raynal@bootlin.com> |
| 5 | */ |
| 6 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 7 | #include <command.h> |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <log.h> |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 10 | #include <mapmem.h> |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 11 | #include <tpm-common.h> |
| 12 | #include <tpm-v2.h> |
| 13 | #include "tpm-user-utils.h" |
| 14 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 15 | static int do_tpm2_startup(struct cmd_tbl *cmdtp, int flag, int argc, |
| 16 | char *const argv[]) |
Miquel Raynal | 65a1a6c | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 17 | { |
| 18 | enum tpm2_startup_types mode; |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 19 | struct udevice *dev; |
| 20 | int ret; |
Miquel Raynal | 65a1a6c | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 21 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 22 | ret = get_tpm(&dev); |
| 23 | if (ret) |
| 24 | return ret; |
Miquel Raynal | 65a1a6c | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 25 | if (argc != 2) |
| 26 | return CMD_RET_USAGE; |
| 27 | |
| 28 | if (!strcasecmp("TPM2_SU_CLEAR", argv[1])) { |
| 29 | mode = TPM2_SU_CLEAR; |
| 30 | } else if (!strcasecmp("TPM2_SU_STATE", argv[1])) { |
| 31 | mode = TPM2_SU_STATE; |
| 32 | } else { |
| 33 | printf("Couldn't recognize mode string: %s\n", argv[1]); |
| 34 | return CMD_RET_FAILURE; |
| 35 | } |
| 36 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 37 | return report_return_code(tpm2_startup(dev, mode)); |
Miquel Raynal | 65a1a6c | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 40 | static int do_tpm2_self_test(struct cmd_tbl *cmdtp, int flag, int argc, |
| 41 | char *const argv[]) |
Miquel Raynal | 39c7608 | 2018-05-15 11:57:13 +0200 | [diff] [blame] | 42 | { |
| 43 | enum tpm2_yes_no full_test; |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 44 | struct udevice *dev; |
| 45 | int ret; |
Miquel Raynal | 39c7608 | 2018-05-15 11:57:13 +0200 | [diff] [blame] | 46 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 47 | ret = get_tpm(&dev); |
| 48 | if (ret) |
| 49 | return ret; |
Miquel Raynal | 39c7608 | 2018-05-15 11:57:13 +0200 | [diff] [blame] | 50 | if (argc != 2) |
| 51 | return CMD_RET_USAGE; |
| 52 | |
| 53 | if (!strcasecmp("full", argv[1])) { |
| 54 | full_test = TPMI_YES; |
| 55 | } else if (!strcasecmp("continue", argv[1])) { |
| 56 | full_test = TPMI_NO; |
| 57 | } else { |
| 58 | printf("Couldn't recognize test mode: %s\n", argv[1]); |
| 59 | return CMD_RET_FAILURE; |
| 60 | } |
| 61 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 62 | return report_return_code(tpm2_self_test(dev, full_test)); |
Miquel Raynal | 39c7608 | 2018-05-15 11:57:13 +0200 | [diff] [blame] | 63 | } |
| 64 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 65 | static int do_tpm2_clear(struct cmd_tbl *cmdtp, int flag, int argc, |
| 66 | char *const argv[]) |
Miquel Raynal | 8df6f8d | 2018-05-15 11:57:14 +0200 | [diff] [blame] | 67 | { |
| 68 | u32 handle = 0; |
| 69 | const char *pw = (argc < 3) ? NULL : argv[2]; |
| 70 | const ssize_t pw_sz = pw ? strlen(pw) : 0; |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 71 | struct udevice *dev; |
| 72 | int ret; |
| 73 | |
| 74 | ret = get_tpm(&dev); |
| 75 | if (ret) |
| 76 | return ret; |
Miquel Raynal | 8df6f8d | 2018-05-15 11:57:14 +0200 | [diff] [blame] | 77 | |
| 78 | if (argc < 2 || argc > 3) |
| 79 | return CMD_RET_USAGE; |
| 80 | |
| 81 | if (pw_sz > TPM2_DIGEST_LEN) |
| 82 | return -EINVAL; |
| 83 | |
| 84 | if (!strcasecmp("TPM2_RH_LOCKOUT", argv[1])) |
| 85 | handle = TPM2_RH_LOCKOUT; |
| 86 | else if (!strcasecmp("TPM2_RH_PLATFORM", argv[1])) |
| 87 | handle = TPM2_RH_PLATFORM; |
| 88 | else |
| 89 | return CMD_RET_USAGE; |
| 90 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 91 | return report_return_code(tpm2_clear(dev, handle, pw, pw_sz)); |
Miquel Raynal | 8df6f8d | 2018-05-15 11:57:14 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 94 | static int do_tpm2_pcr_extend(struct cmd_tbl *cmdtp, int flag, int argc, |
| 95 | char *const argv[]) |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 96 | { |
| 97 | struct udevice *dev; |
| 98 | struct tpm_chip_priv *priv; |
| 99 | u32 index = simple_strtoul(argv[1], NULL, 0); |
| 100 | void *digest = map_sysmem(simple_strtoul(argv[2], NULL, 0), 0); |
| 101 | int ret; |
| 102 | u32 rc; |
| 103 | |
| 104 | if (argc != 3) |
| 105 | return CMD_RET_USAGE; |
| 106 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 107 | ret = get_tpm(&dev); |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 108 | if (ret) |
| 109 | return ret; |
| 110 | |
| 111 | priv = dev_get_uclass_priv(dev); |
| 112 | if (!priv) |
| 113 | return -EINVAL; |
| 114 | |
| 115 | if (index >= priv->pcr_count) |
| 116 | return -EINVAL; |
| 117 | |
Ilias Apalodimas | 7f59c71 | 2020-11-26 23:07:22 +0200 | [diff] [blame] | 118 | rc = tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, digest, |
| 119 | TPM2_DIGEST_LEN); |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 120 | |
| 121 | unmap_sysmem(digest); |
| 122 | |
| 123 | return report_return_code(rc); |
| 124 | } |
| 125 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 126 | static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc, |
| 127 | char *const argv[]) |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 128 | { |
| 129 | struct udevice *dev; |
| 130 | struct tpm_chip_priv *priv; |
| 131 | u32 index, rc; |
| 132 | unsigned int updates; |
| 133 | void *data; |
| 134 | int ret; |
| 135 | |
| 136 | if (argc != 3) |
| 137 | return CMD_RET_USAGE; |
| 138 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 139 | ret = get_tpm(&dev); |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 140 | if (ret) |
| 141 | return ret; |
| 142 | |
| 143 | priv = dev_get_uclass_priv(dev); |
| 144 | if (!priv) |
| 145 | return -EINVAL; |
| 146 | |
| 147 | index = simple_strtoul(argv[1], NULL, 0); |
| 148 | if (index >= priv->pcr_count) |
| 149 | return -EINVAL; |
| 150 | |
| 151 | data = map_sysmem(simple_strtoul(argv[2], NULL, 0), 0); |
| 152 | |
Ruchika Gupta | 686bedb | 2021-11-29 13:09:45 +0530 | [diff] [blame] | 153 | rc = tpm2_pcr_read(dev, index, priv->pcr_select_min, TPM2_ALG_SHA256, |
| 154 | data, TPM2_DIGEST_LEN, &updates); |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 155 | if (!rc) { |
Heinrich Schuchardt | 37aef53 | 2019-01-06 12:09:10 +0100 | [diff] [blame] | 156 | printf("PCR #%u content (%u known updates):\n", index, updates); |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 157 | print_byte_string(data, TPM2_DIGEST_LEN); |
| 158 | } |
| 159 | |
| 160 | unmap_sysmem(data); |
| 161 | |
| 162 | return report_return_code(rc); |
| 163 | } |
| 164 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 165 | static int do_tpm_get_capability(struct cmd_tbl *cmdtp, int flag, int argc, |
| 166 | char *const argv[]) |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 167 | { |
| 168 | u32 capability, property, rc; |
| 169 | u8 *data; |
| 170 | size_t count; |
| 171 | int i, j; |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 172 | struct udevice *dev; |
| 173 | int ret; |
| 174 | |
| 175 | ret = get_tpm(&dev); |
| 176 | if (ret) |
| 177 | return ret; |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 178 | |
| 179 | if (argc != 5) |
| 180 | return CMD_RET_USAGE; |
| 181 | |
| 182 | capability = simple_strtoul(argv[1], NULL, 0); |
| 183 | property = simple_strtoul(argv[2], NULL, 0); |
| 184 | data = map_sysmem(simple_strtoul(argv[3], NULL, 0), 0); |
| 185 | count = simple_strtoul(argv[4], NULL, 0); |
| 186 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 187 | rc = tpm2_get_capability(dev, capability, property, data, count); |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 188 | if (rc) |
| 189 | goto unmap_data; |
| 190 | |
| 191 | printf("Capabilities read from TPM:\n"); |
| 192 | for (i = 0; i < count; i++) { |
| 193 | printf("Property 0x"); |
| 194 | for (j = 0; j < 4; j++) |
Ilias Apalodimas | a078915 | 2020-11-05 23:58:43 +0200 | [diff] [blame] | 195 | printf("%02x", data[(i * 8) + j + sizeof(u32)]); |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 196 | printf(": 0x"); |
| 197 | for (j = 4; j < 8; j++) |
Ilias Apalodimas | a078915 | 2020-11-05 23:58:43 +0200 | [diff] [blame] | 198 | printf("%02x", data[(i * 8) + j + sizeof(u32)]); |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 199 | printf("\n"); |
| 200 | } |
| 201 | |
| 202 | unmap_data: |
| 203 | unmap_sysmem(data); |
| 204 | |
| 205 | return report_return_code(rc); |
| 206 | } |
| 207 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 208 | static int do_tpm_dam_reset(struct cmd_tbl *cmdtp, int flag, int argc, |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 209 | char *const argv[]) |
| 210 | { |
| 211 | const char *pw = (argc < 2) ? NULL : argv[1]; |
| 212 | const ssize_t pw_sz = pw ? strlen(pw) : 0; |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 213 | struct udevice *dev; |
| 214 | int ret; |
| 215 | |
| 216 | ret = get_tpm(&dev); |
| 217 | if (ret) |
| 218 | return ret; |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 219 | |
| 220 | if (argc > 2) |
| 221 | return CMD_RET_USAGE; |
| 222 | |
| 223 | if (pw_sz > TPM2_DIGEST_LEN) |
| 224 | return -EINVAL; |
| 225 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 226 | return report_return_code(tpm2_dam_reset(dev, pw, pw_sz)); |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 229 | static int do_tpm_dam_parameters(struct cmd_tbl *cmdtp, int flag, int argc, |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 230 | char *const argv[]) |
| 231 | { |
| 232 | const char *pw = (argc < 5) ? NULL : argv[4]; |
| 233 | const ssize_t pw_sz = pw ? strlen(pw) : 0; |
| 234 | /* |
| 235 | * No Dictionary Attack Mitigation (DAM) means: |
| 236 | * maxtries = 0xFFFFFFFF, recovery_time = 1, lockout_recovery = 0 |
| 237 | */ |
| 238 | unsigned long int max_tries; |
| 239 | unsigned long int recovery_time; |
| 240 | unsigned long int lockout_recovery; |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 241 | struct udevice *dev; |
| 242 | int ret; |
| 243 | |
| 244 | ret = get_tpm(&dev); |
| 245 | if (ret) |
| 246 | return ret; |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 247 | |
| 248 | if (argc < 4 || argc > 5) |
| 249 | return CMD_RET_USAGE; |
| 250 | |
| 251 | if (pw_sz > TPM2_DIGEST_LEN) |
| 252 | return -EINVAL; |
| 253 | |
| 254 | if (strict_strtoul(argv[1], 0, &max_tries)) |
| 255 | return CMD_RET_USAGE; |
| 256 | |
| 257 | if (strict_strtoul(argv[2], 0, &recovery_time)) |
| 258 | return CMD_RET_USAGE; |
| 259 | |
| 260 | if (strict_strtoul(argv[3], 0, &lockout_recovery)) |
| 261 | return CMD_RET_USAGE; |
| 262 | |
| 263 | log(LOGC_NONE, LOGL_INFO, "Changing dictionary attack parameters:\n"); |
| 264 | log(LOGC_NONE, LOGL_INFO, "- maxTries: %lu", max_tries); |
| 265 | log(LOGC_NONE, LOGL_INFO, "- recoveryTime: %lu\n", recovery_time); |
| 266 | log(LOGC_NONE, LOGL_INFO, "- lockoutRecovery: %lu\n", lockout_recovery); |
| 267 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 268 | return report_return_code(tpm2_dam_parameters(dev, pw, pw_sz, max_tries, |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 269 | recovery_time, |
| 270 | lockout_recovery)); |
| 271 | } |
| 272 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 273 | static int do_tpm_change_auth(struct cmd_tbl *cmdtp, int flag, int argc, |
Miquel Raynal | 05d7be3 | 2018-05-15 11:57:19 +0200 | [diff] [blame] | 274 | char *const argv[]) |
| 275 | { |
| 276 | u32 handle; |
| 277 | const char *newpw = argv[2]; |
| 278 | const char *oldpw = (argc == 3) ? NULL : argv[3]; |
| 279 | const ssize_t newpw_sz = strlen(newpw); |
| 280 | const ssize_t oldpw_sz = oldpw ? strlen(oldpw) : 0; |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 281 | struct udevice *dev; |
| 282 | int ret; |
| 283 | |
| 284 | ret = get_tpm(&dev); |
| 285 | if (ret) |
| 286 | return ret; |
Miquel Raynal | 05d7be3 | 2018-05-15 11:57:19 +0200 | [diff] [blame] | 287 | |
| 288 | if (argc < 3 || argc > 4) |
| 289 | return CMD_RET_USAGE; |
| 290 | |
| 291 | if (newpw_sz > TPM2_DIGEST_LEN || oldpw_sz > TPM2_DIGEST_LEN) |
| 292 | return -EINVAL; |
| 293 | |
| 294 | if (!strcasecmp("TPM2_RH_LOCKOUT", argv[1])) |
| 295 | handle = TPM2_RH_LOCKOUT; |
| 296 | else if (!strcasecmp("TPM2_RH_ENDORSEMENT", argv[1])) |
| 297 | handle = TPM2_RH_ENDORSEMENT; |
| 298 | else if (!strcasecmp("TPM2_RH_OWNER", argv[1])) |
| 299 | handle = TPM2_RH_OWNER; |
| 300 | else if (!strcasecmp("TPM2_RH_PLATFORM", argv[1])) |
| 301 | handle = TPM2_RH_PLATFORM; |
| 302 | else |
| 303 | return CMD_RET_USAGE; |
| 304 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 305 | return report_return_code(tpm2_change_auth(dev, handle, newpw, newpw_sz, |
Miquel Raynal | 05d7be3 | 2018-05-15 11:57:19 +0200 | [diff] [blame] | 306 | oldpw, oldpw_sz)); |
| 307 | } |
| 308 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 309 | static int do_tpm_pcr_setauthpolicy(struct cmd_tbl *cmdtp, int flag, int argc, |
| 310 | char *const argv[]) |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 311 | { |
| 312 | u32 index = simple_strtoul(argv[1], NULL, 0); |
| 313 | char *key = argv[2]; |
| 314 | const char *pw = (argc < 4) ? NULL : argv[3]; |
| 315 | const ssize_t pw_sz = pw ? strlen(pw) : 0; |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 316 | struct udevice *dev; |
| 317 | int ret; |
| 318 | |
| 319 | ret = get_tpm(&dev); |
| 320 | if (ret) |
| 321 | return ret; |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 322 | |
| 323 | if (strlen(key) != TPM2_DIGEST_LEN) |
| 324 | return -EINVAL; |
| 325 | |
| 326 | if (argc < 3 || argc > 4) |
| 327 | return CMD_RET_USAGE; |
| 328 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 329 | return report_return_code(tpm2_pcr_setauthpolicy(dev, pw, pw_sz, index, |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 330 | key)); |
| 331 | } |
| 332 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 333 | static int do_tpm_pcr_setauthvalue(struct cmd_tbl *cmdtp, int flag, |
| 334 | int argc, char *const argv[]) |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 335 | { |
| 336 | u32 index = simple_strtoul(argv[1], NULL, 0); |
| 337 | char *key = argv[2]; |
| 338 | const ssize_t key_sz = strlen(key); |
| 339 | const char *pw = (argc < 4) ? NULL : argv[3]; |
| 340 | const ssize_t pw_sz = pw ? strlen(pw) : 0; |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 341 | struct udevice *dev; |
| 342 | int ret; |
| 343 | |
| 344 | ret = get_tpm(&dev); |
| 345 | if (ret) |
| 346 | return ret; |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 347 | |
| 348 | if (strlen(key) != TPM2_DIGEST_LEN) |
| 349 | return -EINVAL; |
| 350 | |
| 351 | if (argc < 3 || argc > 4) |
| 352 | return CMD_RET_USAGE; |
| 353 | |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 354 | return report_return_code(tpm2_pcr_setauthvalue(dev, pw, pw_sz, index, |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 355 | key, key_sz)); |
| 356 | } |
| 357 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 358 | static struct cmd_tbl tpm2_commands[] = { |
Philippe Reynes | cbe9739 | 2020-01-09 18:45:46 +0100 | [diff] [blame] | 359 | U_BOOT_CMD_MKENT(device, 0, 1, do_tpm_device, "", ""), |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 360 | U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""), |
Simon Glass | 11a075c | 2022-08-30 21:05:36 -0600 | [diff] [blame] | 361 | U_BOOT_CMD_MKENT(state, 0, 1, do_tpm_report_state, "", ""), |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 362 | U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""), |
Miquel Raynal | 65a1a6c | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 363 | U_BOOT_CMD_MKENT(startup, 0, 1, do_tpm2_startup, "", ""), |
Miquel Raynal | 39c7608 | 2018-05-15 11:57:13 +0200 | [diff] [blame] | 364 | U_BOOT_CMD_MKENT(self_test, 0, 1, do_tpm2_self_test, "", ""), |
Miquel Raynal | 8df6f8d | 2018-05-15 11:57:14 +0200 | [diff] [blame] | 365 | U_BOOT_CMD_MKENT(clear, 0, 1, do_tpm2_clear, "", ""), |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 366 | U_BOOT_CMD_MKENT(pcr_extend, 0, 1, do_tpm2_pcr_extend, "", ""), |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 367 | U_BOOT_CMD_MKENT(pcr_read, 0, 1, do_tpm_pcr_read, "", ""), |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 368 | U_BOOT_CMD_MKENT(get_capability, 0, 1, do_tpm_get_capability, "", ""), |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 369 | U_BOOT_CMD_MKENT(dam_reset, 0, 1, do_tpm_dam_reset, "", ""), |
| 370 | U_BOOT_CMD_MKENT(dam_parameters, 0, 1, do_tpm_dam_parameters, "", ""), |
Miquel Raynal | 05d7be3 | 2018-05-15 11:57:19 +0200 | [diff] [blame] | 371 | U_BOOT_CMD_MKENT(change_auth, 0, 1, do_tpm_change_auth, "", ""), |
Ilias Apalodimas | 3be8926 | 2023-06-07 12:18:10 +0300 | [diff] [blame] | 372 | U_BOOT_CMD_MKENT(autostart, 0, 1, do_tpm_autostart, "", ""), |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 373 | U_BOOT_CMD_MKENT(pcr_setauthpolicy, 0, 1, |
| 374 | do_tpm_pcr_setauthpolicy, "", ""), |
| 375 | U_BOOT_CMD_MKENT(pcr_setauthvalue, 0, 1, |
| 376 | do_tpm_pcr_setauthvalue, "", ""), |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 377 | }; |
| 378 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 379 | struct cmd_tbl *get_tpm2_commands(unsigned int *size) |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 380 | { |
| 381 | *size = ARRAY_SIZE(tpm2_commands); |
| 382 | |
| 383 | return tpm2_commands; |
| 384 | } |
| 385 | |
Miquel Raynal | 79920d1 | 2018-07-19 22:35:09 +0200 | [diff] [blame] | 386 | U_BOOT_CMD(tpm2, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command", |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 387 | "<command> [<arguments>]\n" |
| 388 | "\n" |
Philippe Reynes | cbe9739 | 2020-01-09 18:45:46 +0100 | [diff] [blame] | 389 | "device [num device]\n" |
| 390 | " Show all devices or set the specified device\n" |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 391 | "info\n" |
| 392 | " Show information about the TPM.\n" |
Simon Glass | 11a075c | 2022-08-30 21:05:36 -0600 | [diff] [blame] | 393 | "state\n" |
| 394 | " Show internal state from the TPM (if available)\n" |
Ilias Apalodimas | 3be8926 | 2023-06-07 12:18:10 +0300 | [diff] [blame] | 395 | "autostart\n" |
| 396 | " Initalize the tpm, perform a Startup(clear) and run a full selftest\n" |
| 397 | " sequence\n" |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 398 | "init\n" |
| 399 | " Initialize the software stack. Always the first command to issue.\n" |
Ilias Apalodimas | 3be8926 | 2023-06-07 12:18:10 +0300 | [diff] [blame] | 400 | " 'tpm startup' is the only acceptable command after a 'tpm init' has been\n" |
| 401 | " issued\n" |
Miquel Raynal | 65a1a6c | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 402 | "startup <mode>\n" |
| 403 | " Issue a TPM2_Startup command.\n" |
| 404 | " <mode> is one of:\n" |
| 405 | " * TPM2_SU_CLEAR (reset state)\n" |
| 406 | " * TPM2_SU_STATE (preserved state)\n" |
Miquel Raynal | 39c7608 | 2018-05-15 11:57:13 +0200 | [diff] [blame] | 407 | "self_test <type>\n" |
| 408 | " Test the TPM capabilities.\n" |
| 409 | " <type> is one of:\n" |
| 410 | " * full (perform all tests)\n" |
| 411 | " * continue (only check untested tests)\n" |
Miquel Raynal | 8df6f8d | 2018-05-15 11:57:14 +0200 | [diff] [blame] | 412 | "clear <hierarchy>\n" |
| 413 | " Issue a TPM2_Clear command.\n" |
| 414 | " <hierarchy> is one of:\n" |
| 415 | " * TPM2_RH_LOCKOUT\n" |
| 416 | " * TPM2_RH_PLATFORM\n" |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 417 | "pcr_extend <pcr> <digest_addr>\n" |
| 418 | " Extend PCR #<pcr> with digest at <digest_addr>.\n" |
| 419 | " <pcr>: index of the PCR\n" |
| 420 | " <digest_addr>: address of a 32-byte SHA256 digest\n" |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 421 | "pcr_read <pcr> <digest_addr>\n" |
| 422 | " Read PCR #<pcr> to memory address <digest_addr>.\n" |
| 423 | " <pcr>: index of the PCR\n" |
| 424 | " <digest_addr>: address to store the a 32-byte SHA256 digest\n" |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 425 | "get_capability <capability> <property> <addr> <count>\n" |
| 426 | " Read and display <count> entries indexed by <capability>/<property>.\n" |
| 427 | " Values are 4 bytes long and are written at <addr>.\n" |
| 428 | " <capability>: capability\n" |
| 429 | " <property>: property\n" |
| 430 | " <addr>: address to store <count> entries of 4 bytes\n" |
| 431 | " <count>: number of entries to retrieve\n" |
Miquel Raynal | 05d7be3 | 2018-05-15 11:57:19 +0200 | [diff] [blame] | 432 | "dam_reset [<password>]\n" |
| 433 | " If the TPM is not in a LOCKOUT state, reset the internal error counter.\n" |
| 434 | " <password>: optional password\n" |
| 435 | "dam_parameters <max_tries> <recovery_time> <lockout_recovery> [<password>]\n" |
| 436 | " If the TPM is not in a LOCKOUT state, set the DAM parameters\n" |
| 437 | " <maxTries>: maximum number of failures before lockout,\n" |
| 438 | " 0 means always locking\n" |
| 439 | " <recoveryTime>: time before decrement of the error counter,\n" |
| 440 | " 0 means no lockout\n" |
| 441 | " <lockoutRecovery>: time of a lockout (before the next try),\n" |
| 442 | " 0 means a reboot is needed\n" |
| 443 | " <password>: optional password of the LOCKOUT hierarchy\n" |
| 444 | "change_auth <hierarchy> <new_pw> [<old_pw>]\n" |
| 445 | " <hierarchy>: the hierarchy\n" |
| 446 | " <new_pw>: new password for <hierarchy>\n" |
| 447 | " <old_pw>: optional previous password of <hierarchy>\n" |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 448 | "pcr_setauthpolicy|pcr_setauthvalue <pcr> <key> [<password>]\n" |
| 449 | " Change the <key> to access PCR #<pcr>.\n" |
| 450 | " hierarchy and may be empty.\n" |
| 451 | " /!\\WARNING: untested function, use at your own risks !\n" |
| 452 | " <pcr>: index of the PCR\n" |
| 453 | " <key>: secret to protect the access of PCR #<pcr>\n" |
| 454 | " <password>: optional password of the PLATFORM hierarchy\n" |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 455 | ); |