blob: bad20066ef8f31c5655409aa9d509ccf525bfec2 [file] [log] [blame]
Vadim Bendebury576fb1e2011-10-15 15:13:34 +00001/*
Che-liang Chiou8732b072013-02-28 09:34:57 +00002 * Copyright (c) 2013 The Chromium OS Authors.
Vadim Bendebury576fb1e2011-10-15 15:13:34 +00003 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Vadim Bendebury576fb1e2011-10-15 15:13:34 +00005 */
6
7#include <common.h>
8#include <command.h>
Simon Glassc8a8c512015-08-22 18:31:32 -06009#include <dm.h>
Che-liang Chiou8732b072013-02-28 09:34:57 +000010#include <malloc.h>
Vadim Bendebury576fb1e2011-10-15 15:13:34 +000011#include <tpm.h>
Che-liang Chiou8732b072013-02-28 09:34:57 +000012#include <asm/unaligned.h>
13#include <linux/string.h>
Vadim Bendebury576fb1e2011-10-15 15:13:34 +000014
Reinhard Pfaube6c1522013-06-26 15:55:13 +020015/* Useful constants */
16enum {
17 DIGEST_LENGTH = 20,
18 /* max lengths, valid for RSA keys <= 2048 bits */
19 TPM_PUBKEY_MAX_LENGTH = 288,
20};
21
Che-liang Chiou8732b072013-02-28 09:34:57 +000022/**
23 * Print a byte string in hexdecimal format, 16-bytes per line.
Vadim Bendebury576fb1e2011-10-15 15:13:34 +000024 *
Che-liang Chiou8732b072013-02-28 09:34:57 +000025 * @param data byte string to be printed
26 * @param count number of bytes to be printed
Vadim Bendebury576fb1e2011-10-15 15:13:34 +000027 */
Che-liang Chiou8732b072013-02-28 09:34:57 +000028static void print_byte_string(uint8_t *data, size_t count)
Vadim Bendebury576fb1e2011-10-15 15:13:34 +000029{
Che-liang Chiou8732b072013-02-28 09:34:57 +000030 int i, print_newline = 0;
Vadim Bendebury576fb1e2011-10-15 15:13:34 +000031
Che-liang Chiou8732b072013-02-28 09:34:57 +000032 for (i = 0; i < count; i++) {
33 printf(" %02x", data[i]);
34 print_newline = (i % 16 == 15);
35 if (print_newline)
36 putc('\n');
Vadim Bendebury576fb1e2011-10-15 15:13:34 +000037 }
Che-liang Chiou8732b072013-02-28 09:34:57 +000038 /* Avoid duplicated newline at the end */
39 if (!print_newline)
40 putc('\n');
Vadim Bendebury576fb1e2011-10-15 15:13:34 +000041}
42
Che-liang Chiou8732b072013-02-28 09:34:57 +000043/**
44 * Convert a text string of hexdecimal values into a byte string.
45 *
46 * @param bytes text string of hexdecimal values with no space
47 * between them
48 * @param data output buffer for byte string. The caller has to make
49 * sure it is large enough for storing the output. If
50 * NULL is passed, a large enough buffer will be allocated,
51 * and the caller must free it.
52 * @param count_ptr output variable for the length of byte string
53 * @return pointer to output buffer
54 */
55static void *parse_byte_string(char *bytes, uint8_t *data, size_t *count_ptr)
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +000056{
Che-liang Chiou8732b072013-02-28 09:34:57 +000057 char byte[3];
58 size_t count, length;
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +000059 int i;
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +000060
Che-liang Chiou8732b072013-02-28 09:34:57 +000061 length = strlen(bytes);
62 count = length / 2;
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +000063
Che-liang Chiou8732b072013-02-28 09:34:57 +000064 if (!data)
65 data = malloc(count);
66 if (!data)
67 return NULL;
68
69 byte[2] = '\0';
70 for (i = 0; i < length; i += 2) {
71 byte[0] = bytes[i];
72 byte[1] = bytes[i + 1];
73 data[i / 2] = (uint8_t)simple_strtoul(byte, NULL, 16);
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +000074 }
Che-liang Chiou8732b072013-02-28 09:34:57 +000075
76 if (count_ptr)
77 *count_ptr = count;
78
79 return data;
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +000080}
81
Che-liang Chiou8732b072013-02-28 09:34:57 +000082/**
83 * Convert TPM command return code to U-Boot command error codes.
84 *
85 * @param return_code TPM command return code
86 * @return value of enum command_ret_t
87 */
88static int convert_return_code(uint32_t return_code)
Vadim Bendebury576fb1e2011-10-15 15:13:34 +000089{
Che-liang Chiou8732b072013-02-28 09:34:57 +000090 if (return_code)
91 return CMD_RET_FAILURE;
92 else
93 return CMD_RET_SUCCESS;
Vadim Bendebury576fb1e2011-10-15 15:13:34 +000094}
95
Che-liang Chiou8732b072013-02-28 09:34:57 +000096/**
97 * Return number of values defined by a type string.
98 *
99 * @param type_str type string
100 * @return number of values of type string
101 */
102static int type_string_get_num_values(const char *type_str)
103{
104 return strlen(type_str);
105}
106
107/**
108 * Return total size of values defined by a type string.
109 *
110 * @param type_str type string
111 * @return total size of values of type string, or 0 if type string
112 * contains illegal type character.
113 */
114static size_t type_string_get_space_size(const char *type_str)
115{
116 size_t size;
117
118 for (size = 0; *type_str; type_str++) {
119 switch (*type_str) {
120 case 'b':
121 size += 1;
122 break;
123 case 'w':
124 size += 2;
125 break;
126 case 'd':
127 size += 4;
128 break;
129 default:
130 return 0;
131 }
132 }
133
134 return size;
135}
136
137/**
138 * Allocate a buffer large enough to hold values defined by a type
139 * string. The caller has to free the buffer.
140 *
141 * @param type_str type string
142 * @param count pointer for storing size of buffer
143 * @return pointer to buffer or NULL on error
144 */
145static void *type_string_alloc(const char *type_str, uint32_t *count)
146{
147 void *data;
148 size_t size;
149
150 size = type_string_get_space_size(type_str);
151 if (!size)
152 return NULL;
153 data = malloc(size);
154 if (data)
155 *count = size;
156
157 return data;
158}
159
160/**
161 * Pack values defined by a type string into a buffer. The buffer must have
162 * large enough space.
163 *
164 * @param type_str type string
165 * @param values text strings of values to be packed
166 * @param data output buffer of values
167 * @return 0 on success, non-0 on error
168 */
169static int type_string_pack(const char *type_str, char * const values[],
170 uint8_t *data)
171{
172 size_t offset;
173 uint32_t value;
174
175 for (offset = 0; *type_str; type_str++, values++) {
176 value = simple_strtoul(values[0], NULL, 0);
177 switch (*type_str) {
178 case 'b':
179 data[offset] = value;
180 offset += 1;
181 break;
182 case 'w':
183 put_unaligned_be16(value, data + offset);
184 offset += 2;
185 break;
186 case 'd':
187 put_unaligned_be32(value, data + offset);
188 offset += 4;
189 break;
190 default:
191 return -1;
192 }
193 }
194
195 return 0;
196}
197
198/**
199 * Read values defined by a type string from a buffer, and write these values
200 * to environment variables.
201 *
202 * @param type_str type string
203 * @param data input buffer of values
204 * @param vars names of environment variables
205 * @return 0 on success, non-0 on error
206 */
207static int type_string_write_vars(const char *type_str, uint8_t *data,
208 char * const vars[])
209{
210 size_t offset;
211 uint32_t value;
212
213 for (offset = 0; *type_str; type_str++, vars++) {
214 switch (*type_str) {
215 case 'b':
216 value = data[offset];
217 offset += 1;
218 break;
219 case 'w':
220 value = get_unaligned_be16(data + offset);
221 offset += 2;
222 break;
223 case 'd':
224 value = get_unaligned_be32(data + offset);
225 offset += 4;
226 break;
227 default:
228 return -1;
229 }
230 if (setenv_ulong(*vars, value))
231 return -1;
232 }
233
234 return 0;
235}
236
237static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag,
238 int argc, char * const argv[])
239{
240 enum tpm_startup_type mode;
241
242 if (argc != 2)
243 return CMD_RET_USAGE;
244 if (!strcasecmp("TPM_ST_CLEAR", argv[1])) {
245 mode = TPM_ST_CLEAR;
246 } else if (!strcasecmp("TPM_ST_STATE", argv[1])) {
247 mode = TPM_ST_STATE;
248 } else if (!strcasecmp("TPM_ST_DEACTIVATED", argv[1])) {
249 mode = TPM_ST_DEACTIVATED;
250 } else {
251 printf("Couldn't recognize mode string: %s\n", argv[1]);
252 return CMD_RET_FAILURE;
253 }
254
255 return convert_return_code(tpm_startup(mode));
256}
257
258static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag,
259 int argc, char * const argv[])
260{
261 uint32_t index, perm, size;
262
263 if (argc != 4)
264 return CMD_RET_USAGE;
265 index = simple_strtoul(argv[1], NULL, 0);
266 perm = simple_strtoul(argv[2], NULL, 0);
267 size = simple_strtoul(argv[3], NULL, 0);
268
269 return convert_return_code(tpm_nv_define_space(index, perm, size));
270}
271
272static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag,
273 int argc, char * const argv[])
274{
275 uint32_t index, count, rc;
276 void *data;
277
278 if (argc != 4)
279 return CMD_RET_USAGE;
280 index = simple_strtoul(argv[1], NULL, 0);
281 data = (void *)simple_strtoul(argv[2], NULL, 0);
282 count = simple_strtoul(argv[3], NULL, 0);
283
284 rc = tpm_nv_read_value(index, data, count);
285 if (!rc) {
286 puts("area content:\n");
287 print_byte_string(data, count);
288 }
289
290 return convert_return_code(rc);
291}
292
293static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,
294 int argc, char * const argv[])
295{
296 uint32_t index, rc;
297 size_t count;
298 void *data;
299
300 if (argc != 3)
301 return CMD_RET_USAGE;
302 index = simple_strtoul(argv[1], NULL, 0);
303 data = parse_byte_string(argv[2], NULL, &count);
304 if (!data) {
305 printf("Couldn't parse byte string %s\n", argv[2]);
306 return CMD_RET_FAILURE;
307 }
308
309 rc = tpm_nv_write_value(index, data, count);
310 free(data);
311
312 return convert_return_code(rc);
313}
314
315static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
316 int argc, char * const argv[])
317{
318 uint32_t index, rc;
319 uint8_t in_digest[20], out_digest[20];
320
321 if (argc != 3)
322 return CMD_RET_USAGE;
323 index = simple_strtoul(argv[1], NULL, 0);
324 if (!parse_byte_string(argv[2], in_digest, NULL)) {
325 printf("Couldn't parse byte string %s\n", argv[2]);
326 return CMD_RET_FAILURE;
327 }
328
329 rc = tpm_extend(index, in_digest, out_digest);
330 if (!rc) {
331 puts("PCR value after execution of the command:\n");
332 print_byte_string(out_digest, sizeof(out_digest));
333 }
334
335 return convert_return_code(rc);
336}
337
338static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag,
339 int argc, char * const argv[])
340{
341 uint32_t index, count, rc;
342 void *data;
343
344 if (argc != 4)
345 return CMD_RET_USAGE;
346 index = simple_strtoul(argv[1], NULL, 0);
347 data = (void *)simple_strtoul(argv[2], NULL, 0);
348 count = simple_strtoul(argv[3], NULL, 0);
349
350 rc = tpm_pcr_read(index, data, count);
351 if (!rc) {
352 puts("Named PCR content:\n");
353 print_byte_string(data, count);
354 }
355
356 return convert_return_code(rc);
357}
358
359static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag,
360 int argc, char * const argv[])
361{
362 uint16_t presence;
363
364 if (argc != 2)
365 return CMD_RET_USAGE;
366 presence = (uint16_t)simple_strtoul(argv[1], NULL, 0);
367
368 return convert_return_code(tpm_tsc_physical_presence(presence));
369}
370
371static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag,
372 int argc, char * const argv[])
373{
374 uint32_t count, rc;
375 void *data;
376
377 if (argc != 3)
378 return CMD_RET_USAGE;
379 data = (void *)simple_strtoul(argv[1], NULL, 0);
380 count = simple_strtoul(argv[2], NULL, 0);
381
382 rc = tpm_read_pubek(data, count);
383 if (!rc) {
384 puts("pubek value:\n");
385 print_byte_string(data, count);
386 }
387
388 return convert_return_code(rc);
389}
390
391static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag,
392 int argc, char * const argv[])
393{
394 uint8_t state;
395
396 if (argc != 2)
397 return CMD_RET_USAGE;
398 state = (uint8_t)simple_strtoul(argv[1], NULL, 0);
399
400 return convert_return_code(tpm_physical_set_deactivated(state));
401}
402
403static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag,
404 int argc, char * const argv[])
405{
406 uint32_t cap_area, sub_cap, rc;
407 void *cap;
408 size_t count;
409
410 if (argc != 5)
411 return CMD_RET_USAGE;
412 cap_area = simple_strtoul(argv[1], NULL, 0);
413 sub_cap = simple_strtoul(argv[2], NULL, 0);
414 cap = (void *)simple_strtoul(argv[3], NULL, 0);
415 count = simple_strtoul(argv[4], NULL, 0);
416
417 rc = tpm_get_capability(cap_area, sub_cap, cap, count);
418 if (!rc) {
419 puts("capability information:\n");
420 print_byte_string(cap, count);
421 }
422
423 return convert_return_code(rc);
424}
425
426#define TPM_COMMAND_NO_ARG(cmd) \
427static int do_##cmd(cmd_tbl_t *cmdtp, int flag, \
428 int argc, char * const argv[]) \
429{ \
430 if (argc != 1) \
431 return CMD_RET_USAGE; \
432 return convert_return_code(cmd()); \
433}
434
435TPM_COMMAND_NO_ARG(tpm_init)
436TPM_COMMAND_NO_ARG(tpm_self_test_full)
437TPM_COMMAND_NO_ARG(tpm_continue_self_test)
438TPM_COMMAND_NO_ARG(tpm_force_clear)
439TPM_COMMAND_NO_ARG(tpm_physical_enable)
440TPM_COMMAND_NO_ARG(tpm_physical_disable)
441
Simon Glassc8a8c512015-08-22 18:31:32 -0600442#ifdef CONFIG_DM_TPM
443static int get_tpm(struct udevice **devp)
444{
445 int rc;
446
447 rc = uclass_first_device(UCLASS_TPM, devp);
448 if (rc) {
449 printf("Could not find TPM (ret=%d)\n", rc);
450 return CMD_RET_FAILURE;
451 }
452
453 return 0;
454}
455#endif
456
Che-liang Chiou8732b072013-02-28 09:34:57 +0000457static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
458 int argc, char * const argv[])
459{
460 void *command;
461 uint8_t response[1024];
462 size_t count, response_length = sizeof(response);
463 uint32_t rc;
464
465 command = parse_byte_string(argv[1], NULL, &count);
466 if (!command) {
467 printf("Couldn't parse byte string %s\n", argv[1]);
468 return CMD_RET_FAILURE;
469 }
470
Simon Glassc8a8c512015-08-22 18:31:32 -0600471#ifdef CONFIG_DM_TPM
472 struct udevice *dev;
473
474 rc = get_tpm(&dev);
475 if (rc)
476 return rc;
477
478 rc = tpm_xfer(dev, command, count, response, &response_length);
479#else
Che-liang Chiou8732b072013-02-28 09:34:57 +0000480 rc = tis_sendrecv(command, count, response, &response_length);
Simon Glassc8a8c512015-08-22 18:31:32 -0600481#endif
Che-liang Chiou8732b072013-02-28 09:34:57 +0000482 free(command);
483 if (!rc) {
484 puts("tpm response:\n");
485 print_byte_string(response, response_length);
486 }
487
488 return convert_return_code(rc);
489}
490
491static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag,
492 int argc, char * const argv[])
493{
494 uint32_t index, perm, size;
495
496 if (argc != 4)
497 return CMD_RET_USAGE;
498 size = type_string_get_space_size(argv[1]);
499 if (!size) {
500 printf("Couldn't parse arguments\n");
501 return CMD_RET_USAGE;
502 }
503 index = simple_strtoul(argv[2], NULL, 0);
504 perm = simple_strtoul(argv[3], NULL, 0);
505
506 return convert_return_code(tpm_nv_define_space(index, perm, size));
507}
508
509static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag,
510 int argc, char * const argv[])
511{
512 uint32_t index, count, err;
513 void *data;
514
515 if (argc < 3)
516 return CMD_RET_USAGE;
517 if (argc != 3 + type_string_get_num_values(argv[1]))
518 return CMD_RET_USAGE;
519 index = simple_strtoul(argv[2], NULL, 0);
520 data = type_string_alloc(argv[1], &count);
521 if (!data) {
522 printf("Couldn't parse arguments\n");
523 return CMD_RET_USAGE;
524 }
525
526 err = tpm_nv_read_value(index, data, count);
527 if (!err) {
528 if (type_string_write_vars(argv[1], data, argv + 3)) {
529 printf("Couldn't write to variables\n");
530 err = ~0;
531 }
532 }
533 free(data);
534
535 return convert_return_code(err);
536}
537
538static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag,
539 int argc, char * const argv[])
540{
541 uint32_t index, count, err;
542 void *data;
543
544 if (argc < 3)
545 return CMD_RET_USAGE;
546 if (argc != 3 + type_string_get_num_values(argv[1]))
547 return CMD_RET_USAGE;
548 index = simple_strtoul(argv[2], NULL, 0);
549 data = type_string_alloc(argv[1], &count);
550 if (!data) {
551 printf("Couldn't parse arguments\n");
552 return CMD_RET_USAGE;
553 }
554 if (type_string_pack(argv[1], argv + 3, data)) {
555 printf("Couldn't parse arguments\n");
556 free(data);
557 return CMD_RET_USAGE;
558 }
559
560 err = tpm_nv_write_value(index, data, count);
561 free(data);
562
563 return convert_return_code(err);
564}
565
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200566#ifdef CONFIG_TPM_AUTH_SESSIONS
567
568static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag,
569 int argc, char * const argv[])
570{
571 uint32_t auth_handle, err;
572
573 err = tpm_oiap(&auth_handle);
574
575 return convert_return_code(err);
576}
577
578static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag,
579 int argc, char * const argv[])
580{
581 uint32_t parent_handle, key_len, key_handle, err;
582 uint8_t usage_auth[DIGEST_LENGTH];
583 void *key;
584
585 if (argc < 5)
586 return CMD_RET_USAGE;
587
588 parent_handle = simple_strtoul(argv[1], NULL, 0);
589 key = (void *)simple_strtoul(argv[2], NULL, 0);
590 key_len = simple_strtoul(argv[3], NULL, 0);
591 if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
592 return CMD_RET_FAILURE;
593 parse_byte_string(argv[4], usage_auth, NULL);
594
595 err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth,
596 &key_handle);
597 if (!err)
598 printf("Key handle is 0x%x\n", key_handle);
599
600 return convert_return_code(err);
601}
602
603static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag,
604 int argc, char * const argv[])
605{
606 uint32_t key_handle, err;
607 uint8_t usage_auth[DIGEST_LENGTH];
608 uint8_t pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
609 size_t pub_key_len = sizeof(pub_key_buffer);
610
611 if (argc < 3)
612 return CMD_RET_USAGE;
613
614 key_handle = simple_strtoul(argv[1], NULL, 0);
615 if (strlen(argv[2]) != 2 * DIGEST_LENGTH)
616 return CMD_RET_FAILURE;
617 parse_byte_string(argv[2], usage_auth, NULL);
618
619 err = tpm_get_pub_key_oiap(key_handle, usage_auth,
620 pub_key_buffer, &pub_key_len);
621 if (!err) {
622 printf("dump of received pub key structure:\n");
623 print_byte_string(pub_key_buffer, pub_key_len);
624 }
625 return convert_return_code(err);
626}
627
628TPM_COMMAND_NO_ARG(tpm_end_oiap)
629
630#endif /* CONFIG_TPM_AUTH_SESSIONS */
631
Che-liang Chiou8732b072013-02-28 09:34:57 +0000632#define MAKE_TPM_CMD_ENTRY(cmd) \
633 U_BOOT_CMD_MKENT(cmd, 0, 1, do_tpm_ ## cmd, "", "")
634
635static cmd_tbl_t tpm_commands[] = {
636 U_BOOT_CMD_MKENT(init, 0, 1,
637 do_tpm_init, "", ""),
638 U_BOOT_CMD_MKENT(startup, 0, 1,
639 do_tpm_startup, "", ""),
640 U_BOOT_CMD_MKENT(self_test_full, 0, 1,
641 do_tpm_self_test_full, "", ""),
642 U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
643 do_tpm_continue_self_test, "", ""),
644 U_BOOT_CMD_MKENT(force_clear, 0, 1,
645 do_tpm_force_clear, "", ""),
646 U_BOOT_CMD_MKENT(physical_enable, 0, 1,
647 do_tpm_physical_enable, "", ""),
648 U_BOOT_CMD_MKENT(physical_disable, 0, 1,
649 do_tpm_physical_disable, "", ""),
650 U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
651 do_tpm_nv_define_space, "", ""),
652 U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
653 do_tpm_nv_read_value, "", ""),
654 U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
655 do_tpm_nv_write_value, "", ""),
656 U_BOOT_CMD_MKENT(extend, 0, 1,
657 do_tpm_extend, "", ""),
658 U_BOOT_CMD_MKENT(pcr_read, 0, 1,
659 do_tpm_pcr_read, "", ""),
660 U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
661 do_tpm_tsc_physical_presence, "", ""),
662 U_BOOT_CMD_MKENT(read_pubek, 0, 1,
663 do_tpm_read_pubek, "", ""),
664 U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
665 do_tpm_physical_set_deactivated, "", ""),
666 U_BOOT_CMD_MKENT(get_capability, 0, 1,
667 do_tpm_get_capability, "", ""),
668 U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
669 do_tpm_raw_transfer, "", ""),
670 U_BOOT_CMD_MKENT(nv_define, 0, 1,
671 do_tpm_nv_define, "", ""),
672 U_BOOT_CMD_MKENT(nv_read, 0, 1,
673 do_tpm_nv_read, "", ""),
674 U_BOOT_CMD_MKENT(nv_write, 0, 1,
675 do_tpm_nv_write, "", ""),
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200676#ifdef CONFIG_TPM_AUTH_SESSIONS
677 U_BOOT_CMD_MKENT(oiap, 0, 1,
678 do_tpm_oiap, "", ""),
679 U_BOOT_CMD_MKENT(end_oiap, 0, 1,
680 do_tpm_end_oiap, "", ""),
681 U_BOOT_CMD_MKENT(load_key2_oiap, 0, 1,
682 do_tpm_load_key2_oiap, "", ""),
683 U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1,
684 do_tpm_get_pub_key_oiap, "", ""),
685#endif /* CONFIG_TPM_AUTH_SESSIONS */
Che-liang Chiou8732b072013-02-28 09:34:57 +0000686};
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +0000687
688static int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
689{
Che-liang Chiou8732b072013-02-28 09:34:57 +0000690 cmd_tbl_t *tpm_cmd;
691
692 if (argc < 2)
693 return CMD_RET_USAGE;
694 tpm_cmd = find_cmd_tbl(argv[1], tpm_commands, ARRAY_SIZE(tpm_commands));
695 if (!tpm_cmd)
696 return CMD_RET_USAGE;
697
698 return tpm_cmd->cmd(cmdtp, flag, argc - 1, argv + 1);
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +0000699}
700
Che-liang Chiou8732b072013-02-28 09:34:57 +0000701U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
702"Issue a TPM command",
703"cmd args...\n"
704" - Issue TPM command <cmd> with arguments <args...>.\n"
705"Admin Startup and State Commands:\n"
706" init\n"
707" - Put TPM into a state where it waits for 'startup' command.\n"
708" startup mode\n"
709" - Issue TPM_Starup command. <mode> is one of TPM_ST_CLEAR,\n"
710" TPM_ST_STATE, and TPM_ST_DEACTIVATED.\n"
711"Admin Testing Commands:\n"
712" self_test_full\n"
713" - Test all of the TPM capabilities.\n"
714" continue_self_test\n"
715" - Inform TPM that it should complete the self-test.\n"
716"Admin Opt-in Commands:\n"
717" physical_enable\n"
718" - Set the PERMANENT disable flag to FALSE using physical presence as\n"
719" authorization.\n"
720" physical_disable\n"
721" - Set the PERMANENT disable flag to TRUE using physical presence as\n"
722" authorization.\n"
723" physical_set_deactivated 0|1\n"
724" - Set deactivated flag.\n"
725"Admin Ownership Commands:\n"
726" force_clear\n"
727" - Issue TPM_ForceClear command.\n"
728" tsc_physical_presence flags\n"
729" - Set TPM device's Physical Presence flags to <flags>.\n"
730"The Capability Commands:\n"
731" get_capability cap_area sub_cap addr count\n"
732" - Read <count> bytes of TPM capability indexed by <cap_area> and\n"
733" <sub_cap> to memory address <addr>.\n"
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200734#ifdef CONFIG_TPM_AUTH_SESSIONS
735"Storage functions\n"
736" loadkey2_oiap parent_handle key_addr key_len usage_auth\n"
737" - loads a key data from memory address <key_addr>, <key_len> bytes\n"
738" into TPM using the parent key <parent_handle> with authorization\n"
739" <usage_auth> (20 bytes hex string).\n"
740" get_pub_key_oiap key_handle usage_auth\n"
741" - get the public key portion of a loaded key <key_handle> using\n"
742" authorization <usage auth> (20 bytes hex string)\n"
743#endif /* CONFIG_TPM_AUTH_SESSIONS */
Che-liang Chiou8732b072013-02-28 09:34:57 +0000744"Endorsement Key Handling Commands:\n"
745" read_pubek addr count\n"
746" - Read <count> bytes of the public endorsement key to memory\n"
747" address <addr>\n"
748"Integrity Collection and Reporting Commands:\n"
749" extend index digest_hex_string\n"
750" - Add a new measurement to a PCR. Update PCR <index> with the 20-bytes\n"
751" <digest_hex_string>\n"
752" pcr_read index addr count\n"
753" - Read <count> bytes from PCR <index> to memory address <addr>.\n"
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200754#ifdef CONFIG_TPM_AUTH_SESSIONS
755"Authorization Sessions\n"
756" oiap\n"
757" - setup an OIAP session\n"
758" end_oiap\n"
759" - terminates an active OIAP session\n"
760#endif /* CONFIG_TPM_AUTH_SESSIONS */
Che-liang Chiou8732b072013-02-28 09:34:57 +0000761"Non-volatile Storage Commands:\n"
762" nv_define_space index permission size\n"
763" - Establish a space at index <index> with <permission> of <size> bytes.\n"
764" nv_read_value index addr count\n"
765" - Read <count> bytes from space <index> to memory address <addr>.\n"
766" nv_write_value index addr count\n"
767" - Write <count> bytes from memory address <addr> to space <index>.\n"
768"Miscellaneous helper functions:\n"
769" raw_transfer byte_string\n"
770" - Send a byte string <byte_string> to TPM and print the response.\n"
771" Non-volatile storage helper functions:\n"
772" These helper functions treat a non-volatile space as a non-padded\n"
773" sequence of integer values. These integer values are defined by a type\n"
774" string, which is a text string of 'bwd' characters: 'b' means a 8-bit\n"
775" value, 'w' 16-bit value, 'd' 32-bit value. All helper functions take\n"
776" a type string as their first argument.\n"
777" nv_define type_string index perm\n"
778" - Define a space <index> with permission <perm>.\n"
779" nv_read types_string index vars...\n"
780" - Read from space <index> to environment variables <vars...>.\n"
781" nv_write types_string index values...\n"
782" - Write to space <index> from values <values...>.\n"
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +0000783);