1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013 The Chromium OS Authors.
11 #include <asm/unaligned.h>
12 #include <linux/string.h>
14 /* Useful constants */
17 /* max lengths, valid for RSA keys <= 2048 bits */
18 TPM_PUBKEY_MAX_LENGTH
= 288,
22 * Print a byte string in hexdecimal format, 16-bytes per line.
24 * @param data byte string to be printed
25 * @param count number of bytes to be printed
27 static void print_byte_string(u8
*data
, size_t count
)
29 int i
, print_newline
= 0;
31 for (i
= 0; i
< count
; i
++) {
32 printf(" %02x", data
[i
]);
33 print_newline
= (i
% 16 == 15);
37 /* Avoid duplicated newline at the end */
43 * Convert a text string of hexdecimal values into a byte string.
45 * @param bytes text string of hexdecimal values with no space
47 * @param data output buffer for byte string. The caller has to make
48 * sure it is large enough for storing the output. If
49 * NULL is passed, a large enough buffer will be allocated,
50 * and the caller must free it.
51 * @param count_ptr output variable for the length of byte string
52 * @return pointer to output buffer
54 static void *parse_byte_string(char *bytes
, u8
*data
, size_t *count_ptr
)
62 length
= strlen(bytes
);
71 for (i
= 0; i
< length
; i
+= 2) {
73 byte
[1] = bytes
[i
+ 1];
74 data
[i
/ 2] = (u8
)simple_strtoul(byte
, NULL
, 16);
84 * report_return_code() - Report any error and return failure or success
86 * @param return_code TPM command return code
87 * @return value of enum command_ret_t
89 static int report_return_code(int return_code
)
92 printf("Error: %d\n", return_code
);
93 return CMD_RET_FAILURE
;
95 return CMD_RET_SUCCESS
;
100 * Return number of values defined by a type string.
102 * @param type_str type string
103 * @return number of values of type string
105 static int type_string_get_num_values(const char *type_str
)
107 return strlen(type_str
);
111 * Return total size of values defined by a type string.
113 * @param type_str type string
114 * @return total size of values of type string, or 0 if type string
115 * contains illegal type character.
117 static size_t type_string_get_space_size(const char *type_str
)
121 for (size
= 0; *type_str
; type_str
++) {
141 * Allocate a buffer large enough to hold values defined by a type
142 * string. The caller has to free the buffer.
144 * @param type_str type string
145 * @param count pointer for storing size of buffer
146 * @return pointer to buffer or NULL on error
148 static void *type_string_alloc(const char *type_str
, u32
*count
)
153 size
= type_string_get_space_size(type_str
);
164 * Pack values defined by a type string into a buffer. The buffer must have
165 * large enough space.
167 * @param type_str type string
168 * @param values text strings of values to be packed
169 * @param data output buffer of values
170 * @return 0 on success, non-0 on error
172 static int type_string_pack(const char *type_str
, char * const values
[],
178 for (offset
= 0; *type_str
; type_str
++, values
++) {
179 value
= simple_strtoul(values
[0], NULL
, 0);
182 data
[offset
] = value
;
186 put_unaligned_be16(value
, data
+ offset
);
190 put_unaligned_be32(value
, data
+ offset
);
202 * Read values defined by a type string from a buffer, and write these values
203 * to environment variables.
205 * @param type_str type string
206 * @param data input buffer of values
207 * @param vars names of environment variables
208 * @return 0 on success, non-0 on error
210 static int type_string_write_vars(const char *type_str
, u8
*data
,
216 for (offset
= 0; *type_str
; type_str
++, vars
++) {
219 value
= data
[offset
];
223 value
= get_unaligned_be16(data
+ offset
);
227 value
= get_unaligned_be32(data
+ offset
);
233 if (env_set_ulong(*vars
, value
))
240 static int do_tpm_startup(cmd_tbl_t
*cmdtp
, int flag
,
241 int argc
, char * const argv
[])
243 enum tpm_startup_type mode
;
246 return CMD_RET_USAGE
;
247 if (!strcasecmp("TPM_ST_CLEAR", argv
[1])) {
249 } else if (!strcasecmp("TPM_ST_STATE", argv
[1])) {
251 } else if (!strcasecmp("TPM_ST_DEACTIVATED", argv
[1])) {
252 mode
= TPM_ST_DEACTIVATED
;
254 printf("Couldn't recognize mode string: %s\n", argv
[1]);
255 return CMD_RET_FAILURE
;
258 return report_return_code(tpm_startup(mode
));
261 static int do_tpm_nv_define_space(cmd_tbl_t
*cmdtp
, int flag
,
262 int argc
, char * const argv
[])
264 u32 index
, perm
, size
;
267 return CMD_RET_USAGE
;
268 index
= simple_strtoul(argv
[1], NULL
, 0);
269 perm
= simple_strtoul(argv
[2], NULL
, 0);
270 size
= simple_strtoul(argv
[3], NULL
, 0);
272 return report_return_code(tpm_nv_define_space(index
, perm
, size
));
275 static int do_tpm_nv_read_value(cmd_tbl_t
*cmdtp
, int flag
,
276 int argc
, char * const argv
[])
278 u32 index
, count
, rc
;
282 return CMD_RET_USAGE
;
283 index
= simple_strtoul(argv
[1], NULL
, 0);
284 data
= (void *)simple_strtoul(argv
[2], NULL
, 0);
285 count
= simple_strtoul(argv
[3], NULL
, 0);
287 rc
= tpm_nv_read_value(index
, data
, count
);
289 puts("area content:\n");
290 print_byte_string(data
, count
);
293 return report_return_code(rc
);
296 static int do_tpm_nv_write_value(cmd_tbl_t
*cmdtp
, int flag
,
297 int argc
, char * const argv
[])
304 return CMD_RET_USAGE
;
305 index
= simple_strtoul(argv
[1], NULL
, 0);
306 data
= parse_byte_string(argv
[2], NULL
, &count
);
308 printf("Couldn't parse byte string %s\n", argv
[2]);
309 return CMD_RET_FAILURE
;
312 rc
= tpm_nv_write_value(index
, data
, count
);
315 return report_return_code(rc
);
318 static int do_tpm_extend(cmd_tbl_t
*cmdtp
, int flag
,
319 int argc
, char * const argv
[])
322 u8 in_digest
[20], out_digest
[20];
325 return CMD_RET_USAGE
;
326 index
= simple_strtoul(argv
[1], NULL
, 0);
327 if (!parse_byte_string(argv
[2], in_digest
, NULL
)) {
328 printf("Couldn't parse byte string %s\n", argv
[2]);
329 return CMD_RET_FAILURE
;
332 rc
= tpm_extend(index
, in_digest
, out_digest
);
334 puts("PCR value after execution of the command:\n");
335 print_byte_string(out_digest
, sizeof(out_digest
));
338 return report_return_code(rc
);
341 static int do_tpm_pcr_read(cmd_tbl_t
*cmdtp
, int flag
,
342 int argc
, char * const argv
[])
344 u32 index
, count
, rc
;
348 return CMD_RET_USAGE
;
349 index
= simple_strtoul(argv
[1], NULL
, 0);
350 data
= (void *)simple_strtoul(argv
[2], NULL
, 0);
351 count
= simple_strtoul(argv
[3], NULL
, 0);
353 rc
= tpm_pcr_read(index
, data
, count
);
355 puts("Named PCR content:\n");
356 print_byte_string(data
, count
);
359 return report_return_code(rc
);
362 static int do_tpm_tsc_physical_presence(cmd_tbl_t
*cmdtp
, int flag
,
363 int argc
, char * const argv
[])
368 return CMD_RET_USAGE
;
369 presence
= (u16
)simple_strtoul(argv
[1], NULL
, 0);
371 return report_return_code(tpm_tsc_physical_presence(presence
));
374 static int do_tpm_read_pubek(cmd_tbl_t
*cmdtp
, int flag
,
375 int argc
, char * const argv
[])
381 return CMD_RET_USAGE
;
382 data
= (void *)simple_strtoul(argv
[1], NULL
, 0);
383 count
= simple_strtoul(argv
[2], NULL
, 0);
385 rc
= tpm_read_pubek(data
, count
);
387 puts("pubek value:\n");
388 print_byte_string(data
, count
);
391 return report_return_code(rc
);
394 static int do_tpm_physical_set_deactivated(cmd_tbl_t
*cmdtp
, int flag
,
395 int argc
, char * const argv
[])
400 return CMD_RET_USAGE
;
401 state
= (u8
)simple_strtoul(argv
[1], NULL
, 0);
403 return report_return_code(tpm_physical_set_deactivated(state
));
406 static int do_tpm_get_capability(cmd_tbl_t
*cmdtp
, int flag
,
407 int argc
, char * const argv
[])
409 u32 cap_area
, sub_cap
, rc
;
414 return CMD_RET_USAGE
;
415 cap_area
= simple_strtoul(argv
[1], NULL
, 0);
416 sub_cap
= simple_strtoul(argv
[2], NULL
, 0);
417 cap
= (void *)simple_strtoul(argv
[3], NULL
, 0);
418 count
= simple_strtoul(argv
[4], NULL
, 0);
420 rc
= tpm_get_capability(cap_area
, sub_cap
, cap
, count
);
422 puts("capability information:\n");
423 print_byte_string(cap
, count
);
426 return report_return_code(rc
);
429 #define TPM_COMMAND_NO_ARG(cmd) \
430 static int do_##cmd(cmd_tbl_t *cmdtp, int flag, \
431 int argc, char * const argv[]) \
434 return CMD_RET_USAGE; \
435 return report_return_code(cmd()); \
438 TPM_COMMAND_NO_ARG(tpm_init
)
439 TPM_COMMAND_NO_ARG(tpm_self_test_full
)
440 TPM_COMMAND_NO_ARG(tpm_continue_self_test
)
441 TPM_COMMAND_NO_ARG(tpm_force_clear
)
442 TPM_COMMAND_NO_ARG(tpm_physical_enable
)
443 TPM_COMMAND_NO_ARG(tpm_physical_disable
)
445 static int get_tpm(struct udevice
**devp
)
449 rc
= uclass_first_device_err(UCLASS_TPM
, devp
);
451 printf("Could not find TPM (ret=%d)\n", rc
);
452 return CMD_RET_FAILURE
;
458 static int do_tpm_info(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
468 rc
= tpm_get_desc(dev
, buf
, sizeof(buf
));
470 printf("Couldn't get TPM info (%d)\n", rc
);
471 return CMD_RET_FAILURE
;
478 static int do_tpm_raw_transfer(cmd_tbl_t
*cmdtp
, int flag
,
479 int argc
, char * const argv
[])
484 size_t count
, response_length
= sizeof(response
);
487 command
= parse_byte_string(argv
[1], NULL
, &count
);
489 printf("Couldn't parse byte string %s\n", argv
[1]);
490 return CMD_RET_FAILURE
;
497 rc
= tpm_xfer(dev
, command
, count
, response
, &response_length
);
500 puts("tpm response:\n");
501 print_byte_string(response
, response_length
);
504 return report_return_code(rc
);
507 static int do_tpm_nv_define(cmd_tbl_t
*cmdtp
, int flag
,
508 int argc
, char * const argv
[])
510 u32 index
, perm
, size
;
513 return CMD_RET_USAGE
;
514 size
= type_string_get_space_size(argv
[1]);
516 printf("Couldn't parse arguments\n");
517 return CMD_RET_USAGE
;
519 index
= simple_strtoul(argv
[2], NULL
, 0);
520 perm
= simple_strtoul(argv
[3], NULL
, 0);
522 return report_return_code(tpm_nv_define_space(index
, perm
, size
));
525 static int do_tpm_nv_read(cmd_tbl_t
*cmdtp
, int flag
,
526 int argc
, char * const argv
[])
528 u32 index
, count
, err
;
532 return CMD_RET_USAGE
;
533 if (argc
!= 3 + type_string_get_num_values(argv
[1]))
534 return CMD_RET_USAGE
;
535 index
= simple_strtoul(argv
[2], NULL
, 0);
536 data
= type_string_alloc(argv
[1], &count
);
538 printf("Couldn't parse arguments\n");
539 return CMD_RET_USAGE
;
542 err
= tpm_nv_read_value(index
, data
, count
);
544 if (type_string_write_vars(argv
[1], data
, argv
+ 3)) {
545 printf("Couldn't write to variables\n");
551 return report_return_code(err
);
554 static int do_tpm_nv_write(cmd_tbl_t
*cmdtp
, int flag
,
555 int argc
, char * const argv
[])
557 u32 index
, count
, err
;
561 return CMD_RET_USAGE
;
562 if (argc
!= 3 + type_string_get_num_values(argv
[1]))
563 return CMD_RET_USAGE
;
564 index
= simple_strtoul(argv
[2], NULL
, 0);
565 data
= type_string_alloc(argv
[1], &count
);
567 printf("Couldn't parse arguments\n");
568 return CMD_RET_USAGE
;
570 if (type_string_pack(argv
[1], argv
+ 3, data
)) {
571 printf("Couldn't parse arguments\n");
573 return CMD_RET_USAGE
;
576 err
= tpm_nv_write_value(index
, data
, count
);
579 return report_return_code(err
);
582 #ifdef CONFIG_TPM_AUTH_SESSIONS
584 static int do_tpm_oiap(cmd_tbl_t
*cmdtp
, int flag
,
585 int argc
, char * const argv
[])
587 u32 auth_handle
, err
;
589 err
= tpm_oiap(&auth_handle
);
591 return report_return_code(err
);
594 #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
595 static int do_tpm_load_key_by_sha1(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *
598 u32 parent_handle
= 0;
599 u32 key_len
, key_handle
, err
;
600 u8 usage_auth
[DIGEST_LENGTH
];
601 u8 parent_hash
[DIGEST_LENGTH
];
605 return CMD_RET_USAGE
;
607 parse_byte_string(argv
[1], parent_hash
, NULL
);
608 key
= (void *)simple_strtoul(argv
[2], NULL
, 0);
609 key_len
= simple_strtoul(argv
[3], NULL
, 0);
610 if (strlen(argv
[4]) != 2 * DIGEST_LENGTH
)
611 return CMD_RET_FAILURE
;
612 parse_byte_string(argv
[4], usage_auth
, NULL
);
614 err
= tpm_find_key_sha1(usage_auth
, parent_hash
, &parent_handle
);
616 printf("Could not find matching parent key (err = %d)\n", err
);
617 return CMD_RET_FAILURE
;
620 printf("Found parent key %08x\n", parent_handle
);
622 err
= tpm_load_key2_oiap(parent_handle
, key
, key_len
, usage_auth
,
625 printf("Key handle is 0x%x\n", key_handle
);
626 env_set_hex("key_handle", key_handle
);
629 return report_return_code(err
);
631 #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
633 static int do_tpm_load_key2_oiap(cmd_tbl_t
*cmdtp
, int flag
,
634 int argc
, char * const argv
[])
636 u32 parent_handle
, key_len
, key_handle
, err
;
637 u8 usage_auth
[DIGEST_LENGTH
];
641 return CMD_RET_USAGE
;
643 parent_handle
= simple_strtoul(argv
[1], NULL
, 0);
644 key
= (void *)simple_strtoul(argv
[2], NULL
, 0);
645 key_len
= simple_strtoul(argv
[3], NULL
, 0);
646 if (strlen(argv
[4]) != 2 * DIGEST_LENGTH
)
647 return CMD_RET_FAILURE
;
648 parse_byte_string(argv
[4], usage_auth
, NULL
);
650 err
= tpm_load_key2_oiap(parent_handle
, key
, key_len
, usage_auth
,
653 printf("Key handle is 0x%x\n", key_handle
);
655 return report_return_code(err
);
658 static int do_tpm_get_pub_key_oiap(cmd_tbl_t
*cmdtp
, int flag
,
659 int argc
, char * const argv
[])
662 u8 usage_auth
[DIGEST_LENGTH
];
663 u8 pub_key_buffer
[TPM_PUBKEY_MAX_LENGTH
];
664 size_t pub_key_len
= sizeof(pub_key_buffer
);
667 return CMD_RET_USAGE
;
669 key_handle
= simple_strtoul(argv
[1], NULL
, 0);
670 if (strlen(argv
[2]) != 2 * DIGEST_LENGTH
)
671 return CMD_RET_FAILURE
;
672 parse_byte_string(argv
[2], usage_auth
, NULL
);
674 err
= tpm_get_pub_key_oiap(key_handle
, usage_auth
,
675 pub_key_buffer
, &pub_key_len
);
677 printf("dump of received pub key structure:\n");
678 print_byte_string(pub_key_buffer
, pub_key_len
);
680 return report_return_code(err
);
683 TPM_COMMAND_NO_ARG(tpm_end_oiap
)
685 #endif /* CONFIG_TPM_AUTH_SESSIONS */
687 #ifdef CONFIG_TPM_FLUSH_RESOURCES
688 static int do_tpm_flush(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
694 return CMD_RET_USAGE
;
696 if (!strcasecmp(argv
[1], "key"))
698 else if (!strcasecmp(argv
[1], "auth"))
700 else if (!strcasecmp(argv
[1], "hash"))
702 else if (!strcasecmp(argv
[1], "trans"))
704 else if (!strcasecmp(argv
[1], "context"))
705 type
= TPM_RT_CONTEXT
;
706 else if (!strcasecmp(argv
[1], "counter"))
707 type
= TPM_RT_COUNTER
;
708 else if (!strcasecmp(argv
[1], "delegate"))
709 type
= TPM_RT_DELEGATE
;
710 else if (!strcasecmp(argv
[1], "daa_tpm"))
711 type
= TPM_RT_DAA_TPM
;
712 else if (!strcasecmp(argv
[1], "daa_v0"))
713 type
= TPM_RT_DAA_V0
;
714 else if (!strcasecmp(argv
[1], "daa_v1"))
715 type
= TPM_RT_DAA_V1
;
718 printf("Resource type %s unknown.\n", argv
[1]);
722 if (!strcasecmp(argv
[2], "all")) {
729 /* fetch list of already loaded resources in the TPM */
730 err
= tpm_get_capability(TPM_CAP_HANDLE
, type
, buf
,
733 printf("tpm_get_capability returned error %d.\n", err
);
736 res_count
= get_unaligned_be16(buf
);
738 for (i
= 0; i
< res_count
; ++i
, ptr
+= 4)
739 tpm_flush_specific(get_unaligned_be32(ptr
), type
);
741 u32 handle
= simple_strtoul(argv
[2], NULL
, 0);
744 printf("Illegal resource handle %s\n", argv
[2]);
747 tpm_flush_specific(cpu_to_be32(handle
), type
);
752 #endif /* CONFIG_TPM_FLUSH_RESOURCES */
754 #ifdef CONFIG_TPM_LIST_RESOURCES
755 static int do_tpm_list(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
766 return CMD_RET_USAGE
;
768 if (!strcasecmp(argv
[1], "key"))
770 else if (!strcasecmp(argv
[1], "auth"))
772 else if (!strcasecmp(argv
[1], "hash"))
774 else if (!strcasecmp(argv
[1], "trans"))
776 else if (!strcasecmp(argv
[1], "context"))
777 type
= TPM_RT_CONTEXT
;
778 else if (!strcasecmp(argv
[1], "counter"))
779 type
= TPM_RT_COUNTER
;
780 else if (!strcasecmp(argv
[1], "delegate"))
781 type
= TPM_RT_DELEGATE
;
782 else if (!strcasecmp(argv
[1], "daa_tpm"))
783 type
= TPM_RT_DAA_TPM
;
784 else if (!strcasecmp(argv
[1], "daa_v0"))
785 type
= TPM_RT_DAA_V0
;
786 else if (!strcasecmp(argv
[1], "daa_v1"))
787 type
= TPM_RT_DAA_V1
;
790 printf("Resource type %s unknown.\n", argv
[1]);
794 /* fetch list of already loaded resources in the TPM */
795 err
= tpm_get_capability(TPM_CAP_HANDLE
, type
, buf
,
798 printf("tpm_get_capability returned error %d.\n", err
);
801 res_count
= get_unaligned_be16(buf
);
804 printf("Resources of type %s (%02x):\n", argv
[1], type
);
808 for (i
= 0; i
< res_count
; ++i
, ptr
+= 4)
809 printf("Index %d: %08x\n", i
, get_unaligned_be32(ptr
));
814 #endif /* CONFIG_TPM_LIST_RESOURCES */
816 #define MAKE_TPM_CMD_ENTRY(cmd) \
817 U_BOOT_CMD_MKENT(cmd, 0, 1, do_tpm_ ## cmd, "", "")
819 static cmd_tbl_t tpm_commands
[] = {
820 U_BOOT_CMD_MKENT(info
, 0, 1, do_tpm_info
, "", ""),
821 U_BOOT_CMD_MKENT(init
, 0, 1,
822 do_tpm_init
, "", ""),
823 U_BOOT_CMD_MKENT(startup
, 0, 1,
824 do_tpm_startup
, "", ""),
825 U_BOOT_CMD_MKENT(self_test_full
, 0, 1,
826 do_tpm_self_test_full
, "", ""),
827 U_BOOT_CMD_MKENT(continue_self_test
, 0, 1,
828 do_tpm_continue_self_test
, "", ""),
829 U_BOOT_CMD_MKENT(force_clear
, 0, 1,
830 do_tpm_force_clear
, "", ""),
831 U_BOOT_CMD_MKENT(physical_enable
, 0, 1,
832 do_tpm_physical_enable
, "", ""),
833 U_BOOT_CMD_MKENT(physical_disable
, 0, 1,
834 do_tpm_physical_disable
, "", ""),
835 U_BOOT_CMD_MKENT(nv_define_space
, 0, 1,
836 do_tpm_nv_define_space
, "", ""),
837 U_BOOT_CMD_MKENT(nv_read_value
, 0, 1,
838 do_tpm_nv_read_value
, "", ""),
839 U_BOOT_CMD_MKENT(nv_write_value
, 0, 1,
840 do_tpm_nv_write_value
, "", ""),
841 U_BOOT_CMD_MKENT(extend
, 0, 1,
842 do_tpm_extend
, "", ""),
843 U_BOOT_CMD_MKENT(pcr_read
, 0, 1,
844 do_tpm_pcr_read
, "", ""),
845 U_BOOT_CMD_MKENT(tsc_physical_presence
, 0, 1,
846 do_tpm_tsc_physical_presence
, "", ""),
847 U_BOOT_CMD_MKENT(read_pubek
, 0, 1,
848 do_tpm_read_pubek
, "", ""),
849 U_BOOT_CMD_MKENT(physical_set_deactivated
, 0, 1,
850 do_tpm_physical_set_deactivated
, "", ""),
851 U_BOOT_CMD_MKENT(get_capability
, 0, 1,
852 do_tpm_get_capability
, "", ""),
853 U_BOOT_CMD_MKENT(raw_transfer
, 0, 1,
854 do_tpm_raw_transfer
, "", ""),
855 U_BOOT_CMD_MKENT(nv_define
, 0, 1,
856 do_tpm_nv_define
, "", ""),
857 U_BOOT_CMD_MKENT(nv_read
, 0, 1,
858 do_tpm_nv_read
, "", ""),
859 U_BOOT_CMD_MKENT(nv_write
, 0, 1,
860 do_tpm_nv_write
, "", ""),
861 #ifdef CONFIG_TPM_AUTH_SESSIONS
862 U_BOOT_CMD_MKENT(oiap
, 0, 1,
863 do_tpm_oiap
, "", ""),
864 U_BOOT_CMD_MKENT(end_oiap
, 0, 1,
865 do_tpm_end_oiap
, "", ""),
866 U_BOOT_CMD_MKENT(load_key2_oiap
, 0, 1,
867 do_tpm_load_key2_oiap
, "", ""),
868 #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
869 U_BOOT_CMD_MKENT(load_key_by_sha1
, 0, 1,
870 do_tpm_load_key_by_sha1
, "", ""),
871 #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
872 U_BOOT_CMD_MKENT(get_pub_key_oiap
, 0, 1,
873 do_tpm_get_pub_key_oiap
, "", ""),
874 #endif /* CONFIG_TPM_AUTH_SESSIONS */
875 #ifdef CONFIG_TPM_FLUSH_RESOURCES
876 U_BOOT_CMD_MKENT(flush
, 0, 1,
877 do_tpm_flush
, "", ""),
878 #endif /* CONFIG_TPM_FLUSH_RESOURCES */
879 #ifdef CONFIG_TPM_LIST_RESOURCES
880 U_BOOT_CMD_MKENT(list
, 0, 1,
881 do_tpm_list
, "", ""),
882 #endif /* CONFIG_TPM_LIST_RESOURCES */
885 static int do_tpm(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
890 return CMD_RET_USAGE
;
891 tpm_cmd
= find_cmd_tbl(argv
[1], tpm_commands
, ARRAY_SIZE(tpm_commands
));
893 return CMD_RET_USAGE
;
895 return tpm_cmd
->cmd(cmdtp
, flag
, argc
- 1, argv
+ 1);
898 U_BOOT_CMD(tpm
, CONFIG_SYS_MAXARGS
, 1, do_tpm
,
899 "Issue a TPM command",
901 " - Issue TPM command <cmd> with arguments <args...>.\n"
902 "Admin Startup and State Commands:\n"
903 " info - Show information about the TPM\n"
905 " - Put TPM into a state where it waits for 'startup' command.\n"
907 " - Issue TPM_Starup command. <mode> is one of TPM_ST_CLEAR,\n"
908 " TPM_ST_STATE, and TPM_ST_DEACTIVATED.\n"
909 "Admin Testing Commands:\n"
911 " - Test all of the TPM capabilities.\n"
912 " continue_self_test\n"
913 " - Inform TPM that it should complete the self-test.\n"
914 "Admin Opt-in Commands:\n"
916 " - Set the PERMANENT disable flag to FALSE using physical presence as\n"
918 " physical_disable\n"
919 " - Set the PERMANENT disable flag to TRUE using physical presence as\n"
921 " physical_set_deactivated 0|1\n"
922 " - Set deactivated flag.\n"
923 "Admin Ownership Commands:\n"
925 " - Issue TPM_ForceClear command.\n"
926 " tsc_physical_presence flags\n"
927 " - Set TPM device's Physical Presence flags to <flags>.\n"
928 "The Capability Commands:\n"
929 " get_capability cap_area sub_cap addr count\n"
930 " - Read <count> bytes of TPM capability indexed by <cap_area> and\n"
931 " <sub_cap> to memory address <addr>.\n"
932 #if defined(CONFIG_TPM_FLUSH_RESOURCES) || defined(CONFIG_TPM_LIST_RESOURCES)
933 "Resource management functions\n"
935 #ifdef CONFIG_TPM_FLUSH_RESOURCES
936 " flush resource_type id\n"
937 " - flushes a resource of type <resource_type> (may be one of key, auth,\n"
938 " hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1),\n"
939 " and id <id> from the TPM. Use an <id> of \"all\" to flush all\n"
940 " resources of that type.\n"
941 #endif /* CONFIG_TPM_FLUSH_RESOURCES */
942 #ifdef CONFIG_TPM_LIST_RESOURCES
943 " list resource_type\n"
944 " - lists resources of type <resource_type> (may be one of key, auth,\n"
945 " hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1),\n"
946 " contained in the TPM.\n"
947 #endif /* CONFIG_TPM_LIST_RESOURCES */
948 #ifdef CONFIG_TPM_AUTH_SESSIONS
949 "Storage functions\n"
950 " loadkey2_oiap parent_handle key_addr key_len usage_auth\n"
951 " - loads a key data from memory address <key_addr>, <key_len> bytes\n"
952 " into TPM using the parent key <parent_handle> with authorization\n"
953 " <usage_auth> (20 bytes hex string).\n"
954 #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
955 " load_key_by_sha1 parent_hash key_addr key_len usage_auth\n"
956 " - loads a key data from memory address <key_addr>, <key_len> bytes\n"
957 " into TPM using the parent hash <parent_hash> (20 bytes hex string)\n"
958 " with authorization <usage_auth> (20 bytes hex string).\n"
959 #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
960 " get_pub_key_oiap key_handle usage_auth\n"
961 " - get the public key portion of a loaded key <key_handle> using\n"
962 " authorization <usage auth> (20 bytes hex string)\n"
963 #endif /* CONFIG_TPM_AUTH_SESSIONS */
964 "Endorsement Key Handling Commands:\n"
965 " read_pubek addr count\n"
966 " - Read <count> bytes of the public endorsement key to memory\n"
968 "Integrity Collection and Reporting Commands:\n"
969 " extend index digest_hex_string\n"
970 " - Add a new measurement to a PCR. Update PCR <index> with the 20-bytes\n"
971 " <digest_hex_string>\n"
972 " pcr_read index addr count\n"
973 " - Read <count> bytes from PCR <index> to memory address <addr>.\n"
974 #ifdef CONFIG_TPM_AUTH_SESSIONS
975 "Authorization Sessions\n"
977 " - setup an OIAP session\n"
979 " - terminates an active OIAP session\n"
980 #endif /* CONFIG_TPM_AUTH_SESSIONS */
981 "Non-volatile Storage Commands:\n"
982 " nv_define_space index permission size\n"
983 " - Establish a space at index <index> with <permission> of <size> bytes.\n"
984 " nv_read_value index addr count\n"
985 " - Read <count> bytes from space <index> to memory address <addr>.\n"
986 " nv_write_value index addr count\n"
987 " - Write <count> bytes from memory address <addr> to space <index>.\n"
988 "Miscellaneous helper functions:\n"
989 " raw_transfer byte_string\n"
990 " - Send a byte string <byte_string> to TPM and print the response.\n"
991 " Non-volatile storage helper functions:\n"
992 " These helper functions treat a non-volatile space as a non-padded\n"
993 " sequence of integer values. These integer values are defined by a type\n"
994 " string, which is a text string of 'bwd' characters: 'b' means a 8-bit\n"
995 " value, 'w' 16-bit value, 'd' 32-bit value. All helper functions take\n"
996 " a type string as their first argument.\n"
997 " nv_define type_string index perm\n"
998 " - Define a space <index> with permission <perm>.\n"
999 " nv_read types_string index vars...\n"
1000 " - Read from space <index> to environment variables <vars...>.\n"
1001 " nv_write types_string index values...\n"
1002 " - Write to space <index> from values <values...>.\n"