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