Blame view
cmd/tpm-v1.c
21.2 KB
83d290c56
|
1 |
// SPDX-License-Identifier: GPL-2.0+ |
576fb1ed3
|
2 |
/* |
8732b0700
|
3 |
* Copyright (c) 2013 The Chromium OS Authors. |
576fb1ed3
|
4 5 6 |
*/ #include <common.h> |
8732b0700
|
7 |
#include <malloc.h> |
8732b0700
|
8 |
#include <asm/unaligned.h> |
d677bfe2f
|
9 10 11 |
#include <tpm-common.h> #include <tpm-v1.h> #include "tpm-user-utils.h" |
576fb1ed3
|
12 |
|
c61791876
|
13 14 |
static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
15 16 |
{ enum tpm_startup_type mode; |
abdc7b8a2
|
17 18 |
struct udevice *dev; int rc; |
eea3f4d3e
|
19 |
|
abdc7b8a2
|
20 21 22 |
rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
23 24 25 26 27 28 29 30 31 32 33 34 35 |
if (argc != 2) return CMD_RET_USAGE; if (!strcasecmp("TPM_ST_CLEAR", argv[1])) { mode = TPM_ST_CLEAR; } else if (!strcasecmp("TPM_ST_STATE", argv[1])) { mode = TPM_ST_STATE; } else if (!strcasecmp("TPM_ST_DEACTIVATED", argv[1])) { mode = TPM_ST_DEACTIVATED; } else { printf("Couldn't recognize mode string: %s ", argv[1]); return CMD_RET_FAILURE; } |
abdc7b8a2
|
36 |
return report_return_code(tpm_startup(dev, mode)); |
8732b0700
|
37 |
} |
c61791876
|
38 39 |
static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
40 |
{ |
b9804e5bf
|
41 |
u32 index, perm, size; |
abdc7b8a2
|
42 43 44 45 46 47 |
struct udevice *dev; int rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
48 49 50 51 52 53 |
if (argc != 4) return CMD_RET_USAGE; index = simple_strtoul(argv[1], NULL, 0); perm = simple_strtoul(argv[2], NULL, 0); size = simple_strtoul(argv[3], NULL, 0); |
abdc7b8a2
|
54 |
return report_return_code(tpm_nv_define_space(dev, index, perm, size)); |
8732b0700
|
55 |
} |
eea3f4d3e
|
56 |
|
c61791876
|
57 58 |
static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
eea3f4d3e
|
59 |
{ |
b9804e5bf
|
60 |
u32 index, count, rc; |
abdc7b8a2
|
61 |
struct udevice *dev; |
8732b0700
|
62 |
void *data; |
eea3f4d3e
|
63 |
|
abdc7b8a2
|
64 65 66 |
rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
67 68 69 70 71 |
if (argc != 4) return CMD_RET_USAGE; index = simple_strtoul(argv[1], NULL, 0); data = (void *)simple_strtoul(argv[2], NULL, 0); count = simple_strtoul(argv[3], NULL, 0); |
abdc7b8a2
|
72 |
rc = tpm_nv_read_value(dev, index, data, count); |
8732b0700
|
73 74 75 76 |
if (!rc) { puts("area content: "); print_byte_string(data, count); |
576fb1ed3
|
77 |
} |
f8f1fe1d5
|
78 |
return report_return_code(rc); |
8732b0700
|
79 |
} |
c61791876
|
80 81 |
static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
82 |
{ |
abdc7b8a2
|
83 |
struct udevice *dev; |
b9804e5bf
|
84 |
u32 index, rc; |
8732b0700
|
85 86 |
size_t count; void *data; |
abdc7b8a2
|
87 88 89 |
rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
90 91 92 93 94 95 96 97 |
if (argc != 3) return CMD_RET_USAGE; index = simple_strtoul(argv[1], NULL, 0); data = parse_byte_string(argv[2], NULL, &count); if (!data) { printf("Couldn't parse byte string %s ", argv[2]); return CMD_RET_FAILURE; |
eea3f4d3e
|
98 |
} |
abdc7b8a2
|
99 |
rc = tpm_nv_write_value(dev, index, data, count); |
8732b0700
|
100 |
free(data); |
f8f1fe1d5
|
101 |
return report_return_code(rc); |
8732b0700
|
102 |
} |
c61791876
|
103 104 |
static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
105 |
{ |
b9804e5bf
|
106 |
u8 in_digest[20], out_digest[20]; |
abdc7b8a2
|
107 108 109 110 111 112 |
struct udevice *dev; u32 index, rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
113 114 115 116 117 118 119 120 |
if (argc != 3) return CMD_RET_USAGE; index = simple_strtoul(argv[1], NULL, 0); if (!parse_byte_string(argv[2], in_digest, NULL)) { printf("Couldn't parse byte string %s ", argv[2]); return CMD_RET_FAILURE; |
576fb1ed3
|
121 |
} |
abdc7b8a2
|
122 |
rc = tpm_extend(dev, index, in_digest, out_digest); |
8732b0700
|
123 124 125 126 |
if (!rc) { puts("PCR value after execution of the command: "); print_byte_string(out_digest, sizeof(out_digest)); |
576fb1ed3
|
127 |
} |
f8f1fe1d5
|
128 |
return report_return_code(rc); |
8732b0700
|
129 |
} |
c61791876
|
130 131 |
static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
132 |
{ |
b9804e5bf
|
133 |
u32 index, count, rc; |
abdc7b8a2
|
134 |
struct udevice *dev; |
8732b0700
|
135 |
void *data; |
abdc7b8a2
|
136 137 138 |
rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
139 140 141 142 143 |
if (argc != 4) return CMD_RET_USAGE; index = simple_strtoul(argv[1], NULL, 0); data = (void *)simple_strtoul(argv[2], NULL, 0); count = simple_strtoul(argv[3], NULL, 0); |
576fb1ed3
|
144 |
|
abdc7b8a2
|
145 |
rc = tpm_pcr_read(dev, index, data, count); |
8732b0700
|
146 147 148 149 |
if (!rc) { puts("Named PCR content: "); print_byte_string(data, count); |
576fb1ed3
|
150 |
} |
f8f1fe1d5
|
151 |
return report_return_code(rc); |
576fb1ed3
|
152 |
} |
c61791876
|
153 154 |
static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
155 |
{ |
abdc7b8a2
|
156 |
struct udevice *dev; |
b9804e5bf
|
157 |
u16 presence; |
abdc7b8a2
|
158 159 160 161 162 |
int rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
163 164 165 |
if (argc != 2) return CMD_RET_USAGE; |
b9804e5bf
|
166 |
presence = (u16)simple_strtoul(argv[1], NULL, 0); |
eea3f4d3e
|
167 |
|
abdc7b8a2
|
168 |
return report_return_code(tpm_tsc_physical_presence(dev, presence)); |
8732b0700
|
169 |
} |
c61791876
|
170 171 |
static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
eea3f4d3e
|
172 |
{ |
abdc7b8a2
|
173 |
struct udevice *dev; |
b9804e5bf
|
174 |
u32 count, rc; |
8732b0700
|
175 |
void *data; |
abdc7b8a2
|
176 177 178 |
rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
179 180 181 182 |
if (argc != 3) return CMD_RET_USAGE; data = (void *)simple_strtoul(argv[1], NULL, 0); count = simple_strtoul(argv[2], NULL, 0); |
abdc7b8a2
|
183 |
rc = tpm_read_pubek(dev, data, count); |
8732b0700
|
184 185 186 187 188 |
if (!rc) { puts("pubek value: "); print_byte_string(data, count); } |
f8f1fe1d5
|
189 |
return report_return_code(rc); |
eea3f4d3e
|
190 |
} |
c61791876
|
191 192 |
static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
193 |
{ |
abdc7b8a2
|
194 |
struct udevice *dev; |
b9804e5bf
|
195 |
u8 state; |
abdc7b8a2
|
196 197 198 199 200 |
int rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
201 202 203 |
if (argc != 2) return CMD_RET_USAGE; |
b9804e5bf
|
204 |
state = (u8)simple_strtoul(argv[1], NULL, 0); |
eea3f4d3e
|
205 |
|
abdc7b8a2
|
206 |
return report_return_code(tpm_physical_set_deactivated(dev, state)); |
8732b0700
|
207 |
} |
c61791876
|
208 209 |
static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
210 |
{ |
b9804e5bf
|
211 |
u32 cap_area, sub_cap, rc; |
8732b0700
|
212 213 |
void *cap; size_t count; |
abdc7b8a2
|
214 215 216 217 218 |
struct udevice *dev; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
219 220 221 222 223 224 225 |
if (argc != 5) return CMD_RET_USAGE; cap_area = simple_strtoul(argv[1], NULL, 0); sub_cap = simple_strtoul(argv[2], NULL, 0); cap = (void *)simple_strtoul(argv[3], NULL, 0); count = simple_strtoul(argv[4], NULL, 0); |
abdc7b8a2
|
226 |
rc = tpm_get_capability(dev, cap_area, sub_cap, cap, count); |
8732b0700
|
227 228 229 230 231 |
if (!rc) { puts("capability information: "); print_byte_string(cap, count); } |
f8f1fe1d5
|
232 |
return report_return_code(rc); |
8732b0700
|
233 |
} |
eea3f4d3e
|
234 |
|
c61791876
|
235 236 |
static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
237 |
{ |
c2b0f600a
|
238 |
struct udevice *dev; |
8732b0700
|
239 |
void *command; |
b9804e5bf
|
240 |
u8 response[1024]; |
8732b0700
|
241 |
size_t count, response_length = sizeof(response); |
b9804e5bf
|
242 |
u32 rc; |
8732b0700
|
243 244 245 246 247 248 249 |
command = parse_byte_string(argv[1], NULL, &count); if (!command) { printf("Couldn't parse byte string %s ", argv[1]); return CMD_RET_FAILURE; } |
c8a8c5103
|
250 251 252 253 254 |
rc = get_tpm(&dev); if (rc) return rc; rc = tpm_xfer(dev, command, count, response, &response_length); |
8732b0700
|
255 256 257 258 259 260 |
free(command); if (!rc) { puts("tpm response: "); print_byte_string(response, response_length); } |
f8f1fe1d5
|
261 |
return report_return_code(rc); |
8732b0700
|
262 |
} |
c61791876
|
263 264 |
static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
265 |
{ |
b9804e5bf
|
266 |
u32 index, perm, size; |
abdc7b8a2
|
267 268 269 270 271 272 |
struct udevice *dev; int rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
273 274 275 276 277 278 279 280 281 282 283 |
if (argc != 4) return CMD_RET_USAGE; size = type_string_get_space_size(argv[1]); if (!size) { printf("Couldn't parse arguments "); return CMD_RET_USAGE; } index = simple_strtoul(argv[2], NULL, 0); perm = simple_strtoul(argv[3], NULL, 0); |
abdc7b8a2
|
284 |
return report_return_code(tpm_nv_define_space(dev, index, perm, size)); |
8732b0700
|
285 |
} |
c61791876
|
286 287 |
static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
eea3f4d3e
|
288 |
{ |
b9804e5bf
|
289 |
u32 index, count, err; |
abdc7b8a2
|
290 |
struct udevice *dev; |
8732b0700
|
291 |
void *data; |
abdc7b8a2
|
292 293 294 295 296 |
int rc; rc = get_tpm(&dev); if (rc) return rc; |
eea3f4d3e
|
297 |
|
8732b0700
|
298 299 300 301 302 303 304 305 306 307 |
if (argc < 3) return CMD_RET_USAGE; if (argc != 3 + type_string_get_num_values(argv[1])) return CMD_RET_USAGE; index = simple_strtoul(argv[2], NULL, 0); data = type_string_alloc(argv[1], &count); if (!data) { printf("Couldn't parse arguments "); return CMD_RET_USAGE; |
eea3f4d3e
|
308 |
} |
abdc7b8a2
|
309 |
err = tpm_nv_read_value(dev, index, data, count); |
8732b0700
|
310 311 312 313 314 315 |
if (!err) { if (type_string_write_vars(argv[1], data, argv + 3)) { printf("Couldn't write to variables "); err = ~0; } |
eea3f4d3e
|
316 |
} |
8732b0700
|
317 |
free(data); |
f8f1fe1d5
|
318 |
return report_return_code(err); |
8732b0700
|
319 |
} |
c61791876
|
320 321 |
static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700
|
322 |
{ |
b9804e5bf
|
323 |
u32 index, count, err; |
abdc7b8a2
|
324 |
struct udevice *dev; |
8732b0700
|
325 |
void *data; |
abdc7b8a2
|
326 327 328 329 330 |
int rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700
|
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
if (argc < 3) return CMD_RET_USAGE; if (argc != 3 + type_string_get_num_values(argv[1])) return CMD_RET_USAGE; index = simple_strtoul(argv[2], NULL, 0); data = type_string_alloc(argv[1], &count); if (!data) { printf("Couldn't parse arguments "); return CMD_RET_USAGE; } if (type_string_pack(argv[1], argv + 3, data)) { printf("Couldn't parse arguments "); free(data); return CMD_RET_USAGE; } |
abdc7b8a2
|
349 |
err = tpm_nv_write_value(dev, index, data, count); |
8732b0700
|
350 |
free(data); |
f8f1fe1d5
|
351 |
return report_return_code(err); |
8732b0700
|
352 |
} |
be6c1529c
|
353 |
#ifdef CONFIG_TPM_AUTH_SESSIONS |
c61791876
|
354 355 |
static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
be6c1529c
|
356 |
{ |
b9804e5bf
|
357 |
u32 auth_handle, err; |
abdc7b8a2
|
358 359 360 361 362 363 |
struct udevice *dev; int rc; rc = get_tpm(&dev); if (rc) return rc; |
be6c1529c
|
364 |
|
abdc7b8a2
|
365 |
err = tpm_oiap(dev, &auth_handle); |
be6c1529c
|
366 |
|
f8f1fe1d5
|
367 |
return report_return_code(err); |
be6c1529c
|
368 |
} |
0f4b2ba17
|
369 370 371 372 |
#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1 static int do_tpm_load_key_by_sha1(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
b9804e5bf
|
373 374 375 376 |
u32 parent_handle = 0; u32 key_len, key_handle, err; u8 usage_auth[DIGEST_LENGTH]; u8 parent_hash[DIGEST_LENGTH]; |
0f4b2ba17
|
377 |
void *key; |
abdc7b8a2
|
378 379 380 381 382 |
struct udevice *dev; rc = get_tpm(&dev); if (rc) return rc; |
0f4b2ba17
|
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
if (argc < 5) return CMD_RET_USAGE; parse_byte_string(argv[1], parent_hash, NULL); key = (void *)simple_strtoul(argv[2], NULL, 0); key_len = simple_strtoul(argv[3], NULL, 0); if (strlen(argv[4]) != 2 * DIGEST_LENGTH) return CMD_RET_FAILURE; parse_byte_string(argv[4], usage_auth, NULL); err = tpm_find_key_sha1(usage_auth, parent_hash, &parent_handle); if (err) { printf("Could not find matching parent key (err = %d) ", err); return CMD_RET_FAILURE; } printf("Found parent key %08x ", parent_handle); err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth, &key_handle); if (!err) { printf("Key handle is 0x%x ", key_handle); |
018f53032
|
409 |
env_set_hex("key_handle", key_handle); |
0f4b2ba17
|
410 411 412 413 414 |
} return report_return_code(err); } #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */ |
c61791876
|
415 416 |
static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
be6c1529c
|
417 |
{ |
b9804e5bf
|
418 419 |
u32 parent_handle, key_len, key_handle, err; u8 usage_auth[DIGEST_LENGTH]; |
be6c1529c
|
420 |
void *key; |
abdc7b8a2
|
421 422 423 424 425 426 |
struct udevice *dev; int rc; rc = get_tpm(&dev); if (rc) return rc; |
be6c1529c
|
427 428 429 430 431 432 433 434 435 436 |
if (argc < 5) return CMD_RET_USAGE; parent_handle = simple_strtoul(argv[1], NULL, 0); key = (void *)simple_strtoul(argv[2], NULL, 0); key_len = simple_strtoul(argv[3], NULL, 0); if (strlen(argv[4]) != 2 * DIGEST_LENGTH) return CMD_RET_FAILURE; parse_byte_string(argv[4], usage_auth, NULL); |
abdc7b8a2
|
437 |
err = tpm_load_key2_oiap(dev, parent_handle, key, key_len, usage_auth, |
c61791876
|
438 |
&key_handle); |
be6c1529c
|
439 440 441 |
if (!err) printf("Key handle is 0x%x ", key_handle); |
f8f1fe1d5
|
442 |
return report_return_code(err); |
be6c1529c
|
443 |
} |
c61791876
|
444 445 |
static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
be6c1529c
|
446 |
{ |
b9804e5bf
|
447 448 449 |
u32 key_handle, err; u8 usage_auth[DIGEST_LENGTH]; u8 pub_key_buffer[TPM_PUBKEY_MAX_LENGTH]; |
be6c1529c
|
450 |
size_t pub_key_len = sizeof(pub_key_buffer); |
abdc7b8a2
|
451 452 453 454 455 456 |
struct udevice *dev; int rc; rc = get_tpm(&dev); if (rc) return rc; |
be6c1529c
|
457 458 459 460 461 462 463 464 |
if (argc < 3) return CMD_RET_USAGE; key_handle = simple_strtoul(argv[1], NULL, 0); if (strlen(argv[2]) != 2 * DIGEST_LENGTH) return CMD_RET_FAILURE; parse_byte_string(argv[2], usage_auth, NULL); |
abdc7b8a2
|
465 |
err = tpm_get_pub_key_oiap(dev, key_handle, usage_auth, pub_key_buffer, |
c61791876
|
466 |
&pub_key_len); |
be6c1529c
|
467 468 469 470 471 |
if (!err) { printf("dump of received pub key structure: "); print_byte_string(pub_key_buffer, pub_key_len); } |
f8f1fe1d5
|
472 |
return report_return_code(err); |
be6c1529c
|
473 474 475 476 477 |
} TPM_COMMAND_NO_ARG(tpm_end_oiap) #endif /* CONFIG_TPM_AUTH_SESSIONS */ |
7690be35d
|
478 479 480 481 |
#ifdef CONFIG_TPM_FLUSH_RESOURCES static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
abdc7b8a2
|
482 |
struct udevice *dev; |
7690be35d
|
483 |
int type = 0; |
abdc7b8a2
|
484 485 486 487 488 |
int rc; rc = get_tpm(&dev); if (rc) return rc; |
7690be35d
|
489 |
|
1c08b210a
|
490 |
if (argc != 3) |
7690be35d
|
491 |
return CMD_RET_USAGE; |
1c08b210a
|
492 |
if (!strcasecmp(argv[1], "key")) |
7690be35d
|
493 |
type = TPM_RT_KEY; |
1c08b210a
|
494 |
else if (!strcasecmp(argv[1], "auth")) |
7690be35d
|
495 |
type = TPM_RT_AUTH; |
1c08b210a
|
496 |
else if (!strcasecmp(argv[1], "hash")) |
7690be35d
|
497 |
type = TPM_RT_HASH; |
1c08b210a
|
498 |
else if (!strcasecmp(argv[1], "trans")) |
7690be35d
|
499 |
type = TPM_RT_TRANS; |
1c08b210a
|
500 |
else if (!strcasecmp(argv[1], "context")) |
7690be35d
|
501 |
type = TPM_RT_CONTEXT; |
1c08b210a
|
502 |
else if (!strcasecmp(argv[1], "counter")) |
7690be35d
|
503 |
type = TPM_RT_COUNTER; |
1c08b210a
|
504 |
else if (!strcasecmp(argv[1], "delegate")) |
7690be35d
|
505 |
type = TPM_RT_DELEGATE; |
1c08b210a
|
506 |
else if (!strcasecmp(argv[1], "daa_tpm")) |
7690be35d
|
507 |
type = TPM_RT_DAA_TPM; |
1c08b210a
|
508 |
else if (!strcasecmp(argv[1], "daa_v0")) |
7690be35d
|
509 |
type = TPM_RT_DAA_V0; |
1c08b210a
|
510 |
else if (!strcasecmp(argv[1], "daa_v1")) |
7690be35d
|
511 |
type = TPM_RT_DAA_V1; |
1c08b210a
|
512 513 514 515 516 517 518 |
if (!type) { printf("Resource type %s unknown. ", argv[1]); return -1; } if (!strcasecmp(argv[2], "all")) { |
b9804e5bf
|
519 520 521 |
u16 res_count; u8 buf[288]; u8 *ptr; |
7690be35d
|
522 523 524 525 |
int err; uint i; /* fetch list of already loaded resources in the TPM */ |
abdc7b8a2
|
526 |
err = tpm_get_capability(dev, TPM_CAP_HANDLE, type, buf, |
7690be35d
|
527 |
sizeof(buf)); |
1c08b210a
|
528 529 530 |
if (err) { printf("tpm_get_capability returned error %d. ", err); |
7690be35d
|
531 |
return -1; |
1c08b210a
|
532 |
} |
7690be35d
|
533 534 535 |
res_count = get_unaligned_be16(buf); ptr = buf + 2; for (i = 0; i < res_count; ++i, ptr += 4) |
abdc7b8a2
|
536 |
tpm_flush_specific(dev, get_unaligned_be32(ptr), type); |
7690be35d
|
537 |
} else { |
b9804e5bf
|
538 |
u32 handle = simple_strtoul(argv[2], NULL, 0); |
7690be35d
|
539 |
|
1c08b210a
|
540 541 542 |
if (!handle) { printf("Illegal resource handle %s ", argv[2]); |
7690be35d
|
543 |
return -1; |
1c08b210a
|
544 |
} |
abdc7b8a2
|
545 |
tpm_flush_specific(dev, cpu_to_be32(handle), type); |
7690be35d
|
546 547 548 549 550 |
} return 0; } #endif /* CONFIG_TPM_FLUSH_RESOURCES */ |
3d1df0e36
|
551 552 553 554 555 |
#ifdef CONFIG_TPM_LIST_RESOURCES static int do_tpm_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int type = 0; |
b9804e5bf
|
556 557 558 |
u16 res_count; u8 buf[288]; u8 *ptr; |
3d1df0e36
|
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
int err; uint i; if (argc != 2) return CMD_RET_USAGE; if (!strcasecmp(argv[1], "key")) type = TPM_RT_KEY; else if (!strcasecmp(argv[1], "auth")) type = TPM_RT_AUTH; else if (!strcasecmp(argv[1], "hash")) type = TPM_RT_HASH; else if (!strcasecmp(argv[1], "trans")) type = TPM_RT_TRANS; else if (!strcasecmp(argv[1], "context")) type = TPM_RT_CONTEXT; else if (!strcasecmp(argv[1], "counter")) type = TPM_RT_COUNTER; else if (!strcasecmp(argv[1], "delegate")) type = TPM_RT_DELEGATE; else if (!strcasecmp(argv[1], "daa_tpm")) type = TPM_RT_DAA_TPM; else if (!strcasecmp(argv[1], "daa_v0")) type = TPM_RT_DAA_V0; else if (!strcasecmp(argv[1], "daa_v1")) type = TPM_RT_DAA_V1; if (!type) { printf("Resource type %s unknown. ", argv[1]); return -1; } /* fetch list of already loaded resources in the TPM */ err = tpm_get_capability(TPM_CAP_HANDLE, type, buf, sizeof(buf)); if (err) { printf("tpm_get_capability returned error %d. ", err); return -1; } res_count = get_unaligned_be16(buf); ptr = buf + 2; printf("Resources of type %s (%02x): ", argv[1], type); if (!res_count) { puts("None "); } else { for (i = 0; i < res_count; ++i, ptr += 4) printf("Index %d: %08x ", i, get_unaligned_be32(ptr)); } return 0; } #endif /* CONFIG_TPM_LIST_RESOURCES */ |
d677bfe2f
|
617 618 619 620 621 |
TPM_COMMAND_NO_ARG(tpm_self_test_full) TPM_COMMAND_NO_ARG(tpm_continue_self_test) TPM_COMMAND_NO_ARG(tpm_force_clear) TPM_COMMAND_NO_ARG(tpm_physical_enable) TPM_COMMAND_NO_ARG(tpm_physical_disable) |
8732b0700
|
622 |
|
d677bfe2f
|
623 |
static cmd_tbl_t tpm1_commands[] = { |
ad77694e2
|
624 |
U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""), |
c61791876
|
625 |
U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""), |
8732b0700
|
626 |
U_BOOT_CMD_MKENT(startup, 0, 1, |
c61791876
|
627 |
do_tpm_startup, "", ""), |
8732b0700
|
628 |
U_BOOT_CMD_MKENT(self_test_full, 0, 1, |
c61791876
|
629 |
do_tpm_self_test_full, "", ""), |
8732b0700
|
630 |
U_BOOT_CMD_MKENT(continue_self_test, 0, 1, |
c61791876
|
631 |
do_tpm_continue_self_test, "", ""), |
8732b0700
|
632 |
U_BOOT_CMD_MKENT(force_clear, 0, 1, |
c61791876
|
633 |
do_tpm_force_clear, "", ""), |
8732b0700
|
634 |
U_BOOT_CMD_MKENT(physical_enable, 0, 1, |
c61791876
|
635 |
do_tpm_physical_enable, "", ""), |
8732b0700
|
636 |
U_BOOT_CMD_MKENT(physical_disable, 0, 1, |
c61791876
|
637 |
do_tpm_physical_disable, "", ""), |
8732b0700
|
638 |
U_BOOT_CMD_MKENT(nv_define_space, 0, 1, |
c61791876
|
639 |
do_tpm_nv_define_space, "", ""), |
8732b0700
|
640 |
U_BOOT_CMD_MKENT(nv_read_value, 0, 1, |
c61791876
|
641 |
do_tpm_nv_read_value, "", ""), |
8732b0700
|
642 |
U_BOOT_CMD_MKENT(nv_write_value, 0, 1, |
c61791876
|
643 |
do_tpm_nv_write_value, "", ""), |
8732b0700
|
644 |
U_BOOT_CMD_MKENT(extend, 0, 1, |
c61791876
|
645 |
do_tpm_extend, "", ""), |
8732b0700
|
646 |
U_BOOT_CMD_MKENT(pcr_read, 0, 1, |
c61791876
|
647 |
do_tpm_pcr_read, "", ""), |
8732b0700
|
648 |
U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1, |
c61791876
|
649 |
do_tpm_tsc_physical_presence, "", ""), |
8732b0700
|
650 |
U_BOOT_CMD_MKENT(read_pubek, 0, 1, |
c61791876
|
651 |
do_tpm_read_pubek, "", ""), |
8732b0700
|
652 |
U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1, |
c61791876
|
653 |
do_tpm_physical_set_deactivated, "", ""), |
8732b0700
|
654 |
U_BOOT_CMD_MKENT(get_capability, 0, 1, |
c61791876
|
655 |
do_tpm_get_capability, "", ""), |
8732b0700
|
656 |
U_BOOT_CMD_MKENT(raw_transfer, 0, 1, |
c61791876
|
657 |
do_tpm_raw_transfer, "", ""), |
8732b0700
|
658 |
U_BOOT_CMD_MKENT(nv_define, 0, 1, |
c61791876
|
659 |
do_tpm_nv_define, "", ""), |
8732b0700
|
660 |
U_BOOT_CMD_MKENT(nv_read, 0, 1, |
c61791876
|
661 |
do_tpm_nv_read, "", ""), |
8732b0700
|
662 |
U_BOOT_CMD_MKENT(nv_write, 0, 1, |
c61791876
|
663 |
do_tpm_nv_write, "", ""), |
be6c1529c
|
664 665 666 667 668 669 670 |
#ifdef CONFIG_TPM_AUTH_SESSIONS U_BOOT_CMD_MKENT(oiap, 0, 1, do_tpm_oiap, "", ""), U_BOOT_CMD_MKENT(end_oiap, 0, 1, do_tpm_end_oiap, "", ""), U_BOOT_CMD_MKENT(load_key2_oiap, 0, 1, do_tpm_load_key2_oiap, "", ""), |
0f4b2ba17
|
671 672 673 674 |
#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1 U_BOOT_CMD_MKENT(load_key_by_sha1, 0, 1, do_tpm_load_key_by_sha1, "", ""), #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */ |
be6c1529c
|
675 676 677 |
U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1, do_tpm_get_pub_key_oiap, "", ""), #endif /* CONFIG_TPM_AUTH_SESSIONS */ |
7690be35d
|
678 679 680 681 |
#ifdef CONFIG_TPM_FLUSH_RESOURCES U_BOOT_CMD_MKENT(flush, 0, 1, do_tpm_flush, "", ""), #endif /* CONFIG_TPM_FLUSH_RESOURCES */ |
3d1df0e36
|
682 683 684 685 |
#ifdef CONFIG_TPM_LIST_RESOURCES U_BOOT_CMD_MKENT(list, 0, 1, do_tpm_list, "", ""), #endif /* CONFIG_TPM_LIST_RESOURCES */ |
8732b0700
|
686 |
}; |
2a2096ea6
|
687 |
cmd_tbl_t *get_tpm1_commands(unsigned int *size) |
8732b0700
|
688 |
{ |
d677bfe2f
|
689 |
*size = ARRAY_SIZE(tpm1_commands); |
eea3f4d3e
|
690 |
|
d677bfe2f
|
691 |
return tpm1_commands; |
eea3f4d3e
|
692 |
} |
8732b0700
|
693 |
U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, |
d677bfe2f
|
694 |
"Issue a TPMv1.x command", |
8732b0700
|
695 696 697 698 699 700 |
"cmd args... " " - Issue TPM command <cmd> with arguments <args...>. " "Admin Startup and State Commands: " |
ad77694e2
|
701 702 |
" info - Show information about the TPM " |
8732b0700
|
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
" init " " - Put TPM into a state where it waits for 'startup' command. " " startup mode " " - Issue TPM_Starup command. <mode> is one of TPM_ST_CLEAR, " " TPM_ST_STATE, and TPM_ST_DEACTIVATED. " "Admin Testing Commands: " " self_test_full " " - Test all of the TPM capabilities. " " continue_self_test " " - Inform TPM that it should complete the self-test. " "Admin Opt-in Commands: " " physical_enable " " - Set the PERMANENT disable flag to FALSE using physical presence as " " authorization. " " physical_disable " " - Set the PERMANENT disable flag to TRUE using physical presence as " " authorization. " " physical_set_deactivated 0|1 " " - Set deactivated flag. " "Admin Ownership Commands: " " force_clear " " - Issue TPM_ForceClear command. " " tsc_physical_presence flags " " - Set TPM device's Physical Presence flags to <flags>. " "The Capability Commands: " " get_capability cap_area sub_cap addr count " " - Read <count> bytes of TPM capability indexed by <cap_area> and " " <sub_cap> to memory address <addr>. " |
3d1df0e36
|
759 |
#if defined(CONFIG_TPM_FLUSH_RESOURCES) || defined(CONFIG_TPM_LIST_RESOURCES) |
7690be35d
|
760 761 |
"Resource management functions " |
3d1df0e36
|
762 763 |
#endif #ifdef CONFIG_TPM_FLUSH_RESOURCES |
7690be35d
|
764 765 766 767 768 769 770 771 772 773 774 |
" flush resource_type id " " - flushes a resource of type <resource_type> (may be one of key, auth, " " hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1), " " and id <id> from the TPM. Use an <id> of \"all\" to flush all " " resources of that type. " #endif /* CONFIG_TPM_FLUSH_RESOURCES */ |
3d1df0e36
|
775 776 777 778 779 780 781 782 783 784 |
#ifdef CONFIG_TPM_LIST_RESOURCES " list resource_type " " - lists resources of type <resource_type> (may be one of key, auth, " " hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1), " " contained in the TPM. " #endif /* CONFIG_TPM_LIST_RESOURCES */ |
be6c1529c
|
785 786 787 788 789 790 791 792 793 794 795 |
#ifdef CONFIG_TPM_AUTH_SESSIONS "Storage functions " " loadkey2_oiap parent_handle key_addr key_len usage_auth " " - loads a key data from memory address <key_addr>, <key_len> bytes " " into TPM using the parent key <parent_handle> with authorization " " <usage_auth> (20 bytes hex string). " |
0f4b2ba17
|
796 797 798 799 800 801 802 803 804 805 |
#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1 " load_key_by_sha1 parent_hash key_addr key_len usage_auth " " - loads a key data from memory address <key_addr>, <key_len> bytes " " into TPM using the parent hash <parent_hash> (20 bytes hex string) " " with authorization <usage_auth> (20 bytes hex string). " #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */ |
be6c1529c
|
806 807 808 809 810 811 812 |
" get_pub_key_oiap key_handle usage_auth " " - get the public key portion of a loaded key <key_handle> using " " authorization <usage auth> (20 bytes hex string) " #endif /* CONFIG_TPM_AUTH_SESSIONS */ |
8732b0700
|
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 |
"Endorsement Key Handling Commands: " " read_pubek addr count " " - Read <count> bytes of the public endorsement key to memory " " address <addr> " "Integrity Collection and Reporting Commands: " " extend index digest_hex_string " " - Add a new measurement to a PCR. Update PCR <index> with the 20-bytes " " <digest_hex_string> " " pcr_read index addr count " " - Read <count> bytes from PCR <index> to memory address <addr>. " |
be6c1529c
|
833 834 835 836 837 838 839 840 841 842 843 844 |
#ifdef CONFIG_TPM_AUTH_SESSIONS "Authorization Sessions " " oiap " " - setup an OIAP session " " end_oiap " " - terminates an active OIAP session " #endif /* CONFIG_TPM_AUTH_SESSIONS */ |
8732b0700
|
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 |
"Non-volatile Storage Commands: " " nv_define_space index permission size " " - Establish a space at index <index> with <permission> of <size> bytes. " " nv_read_value index addr count " " - Read <count> bytes from space <index> to memory address <addr>. " " nv_write_value index addr count " " - Write <count> bytes from memory address <addr> to space <index>. " "Miscellaneous helper functions: " " raw_transfer byte_string " " - Send a byte string <byte_string> to TPM and print the response. " " Non-volatile storage helper functions: " " These helper functions treat a non-volatile space as a non-padded " " sequence of integer values. These integer values are defined by a type " " string, which is a text string of 'bwd' characters: 'b' means a 8-bit " " value, 'w' 16-bit value, 'd' 32-bit value. All helper functions take " " a type string as their first argument. " " nv_define type_string index perm " " - Define a space <index> with permission <perm>. " " nv_read types_string index vars... " " - Read from space <index> to environment variables <vars...>. " " nv_write types_string index values... " " - Write to space <index> from values <values...>. " |
eea3f4d3e
|
889 |
); |