xref: /openbmc/u-boot/cmd/tpm-v1.c (revision 5c8fd32b)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2013 The Chromium OS Authors.
4  */
5 
6 #include <common.h>
7 #include <malloc.h>
8 #include <asm/unaligned.h>
9 #include <tpm-common.h>
10 #include <tpm-v1.h>
11 #include "tpm-user-utils.h"
12 
13 static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag, int argc,
14 			  char * const argv[])
15 {
16 	enum tpm_startup_type mode;
17 
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 
31 	return report_return_code(tpm_startup(mode));
32 }
33 
34 static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag, int argc,
35 				  char * const argv[])
36 {
37 	u32 index, perm, size;
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 
45 	return report_return_code(tpm_nv_define_space(index, perm, size));
46 }
47 
48 static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag, int argc,
49 				char * const argv[])
50 {
51 	u32 index, count, rc;
52 	void *data;
53 
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);
64 	}
65 
66 	return report_return_code(rc);
67 }
68 
69 static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag, int argc,
70 				 char * const argv[])
71 {
72 	u32 index, rc;
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;
83 	}
84 
85 	rc = tpm_nv_write_value(index, data, count);
86 	free(data);
87 
88 	return report_return_code(rc);
89 }
90 
91 static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag, int argc,
92 			 char * const argv[])
93 {
94 	u32 index, rc;
95 	u8 in_digest[20], out_digest[20];
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;
103 	}
104 
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));
109 	}
110 
111 	return report_return_code(rc);
112 }
113 
114 static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
115 			   char * const argv[])
116 {
117 	u32 index, count, rc;
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);
125 
126 	rc = tpm_pcr_read(index, data, count);
127 	if (!rc) {
128 		puts("Named PCR content:\n");
129 		print_byte_string(data, count);
130 	}
131 
132 	return report_return_code(rc);
133 }
134 
135 static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag, int argc,
136 					char * const argv[])
137 {
138 	u16 presence;
139 
140 	if (argc != 2)
141 		return CMD_RET_USAGE;
142 	presence = (u16)simple_strtoul(argv[1], NULL, 0);
143 
144 	return report_return_code(tpm_tsc_physical_presence(presence));
145 }
146 
147 static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag, int argc,
148 			     char * const argv[])
149 {
150 	u32 count, rc;
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 
164 	return report_return_code(rc);
165 }
166 
167 static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag, int argc,
168 					   char * const argv[])
169 {
170 	u8 state;
171 
172 	if (argc != 2)
173 		return CMD_RET_USAGE;
174 	state = (u8)simple_strtoul(argv[1], NULL, 0);
175 
176 	return report_return_code(tpm_physical_set_deactivated(state));
177 }
178 
179 static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
180 				 char * const argv[])
181 {
182 	u32 cap_area, sub_cap, rc;
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 
199 	return report_return_code(rc);
200 }
201 
202 static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag, int argc,
203 			       char * const argv[])
204 {
205 	struct udevice *dev;
206 	void *command;
207 	u8 response[1024];
208 	size_t count, response_length = sizeof(response);
209 	u32 rc;
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 
217 	rc = get_tpm(&dev);
218 	if (rc)
219 		return rc;
220 
221 	rc = tpm_xfer(dev, command, count, response, &response_length);
222 	free(command);
223 	if (!rc) {
224 		puts("tpm response:\n");
225 		print_byte_string(response, response_length);
226 	}
227 
228 	return report_return_code(rc);
229 }
230 
231 static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag, int argc,
232 			    char * const argv[])
233 {
234 	u32 index, perm, size;
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 
246 	return report_return_code(tpm_nv_define_space(index, perm, size));
247 }
248 
249 static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag, int argc,
250 			  char * const argv[])
251 {
252 	u32 index, count, err;
253 	void *data;
254 
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;
264 	}
265 
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 		}
272 	}
273 	free(data);
274 
275 	return report_return_code(err);
276 }
277 
278 static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag, int argc,
279 			   char * const argv[])
280 {
281 	u32 index, count, err;
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 
303 	return report_return_code(err);
304 }
305 
306 #ifdef CONFIG_TPM_AUTH_SESSIONS
307 
308 static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
309 		       char * const argv[])
310 {
311 	u32 auth_handle, err;
312 
313 	err = tpm_oiap(&auth_handle);
314 
315 	return report_return_code(err);
316 }
317 
318 #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
319 static int do_tpm_load_key_by_sha1(cmd_tbl_t *cmdtp, int flag, int argc, char *
320 				   const argv[])
321 {
322 	u32 parent_handle = 0;
323 	u32 key_len, key_handle, err;
324 	u8 usage_auth[DIGEST_LENGTH];
325 	u8 parent_hash[DIGEST_LENGTH];
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);
350 		env_set_hex("key_handle", key_handle);
351 	}
352 
353 	return report_return_code(err);
354 }
355 #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
356 
357 static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
358 				 char * const argv[])
359 {
360 	u32 parent_handle, key_len, key_handle, err;
361 	u8 usage_auth[DIGEST_LENGTH];
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,
375 				 &key_handle);
376 	if (!err)
377 		printf("Key handle is 0x%x\n", key_handle);
378 
379 	return report_return_code(err);
380 }
381 
382 static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
383 				   char * const argv[])
384 {
385 	u32 key_handle, err;
386 	u8 usage_auth[DIGEST_LENGTH];
387 	u8 pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
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 
398 	err = tpm_get_pub_key_oiap(key_handle, usage_auth, pub_key_buffer,
399 				   &pub_key_len);
400 	if (!err) {
401 		printf("dump of received pub key structure:\n");
402 		print_byte_string(pub_key_buffer, pub_key_len);
403 	}
404 	return report_return_code(err);
405 }
406 
407 TPM_COMMAND_NO_ARG(tpm_end_oiap)
408 
409 #endif /* CONFIG_TPM_AUTH_SESSIONS */
410 
411 #ifdef CONFIG_TPM_FLUSH_RESOURCES
412 static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc,
413 			char * const argv[])
414 {
415 	int type = 0;
416 
417 	if (argc != 3)
418 		return CMD_RET_USAGE;
419 
420 	if (!strcasecmp(argv[1], "key"))
421 		type = TPM_RT_KEY;
422 	else if (!strcasecmp(argv[1], "auth"))
423 		type = TPM_RT_AUTH;
424 	else if (!strcasecmp(argv[1], "hash"))
425 		type = TPM_RT_HASH;
426 	else if (!strcasecmp(argv[1], "trans"))
427 		type = TPM_RT_TRANS;
428 	else if (!strcasecmp(argv[1], "context"))
429 		type = TPM_RT_CONTEXT;
430 	else if (!strcasecmp(argv[1], "counter"))
431 		type = TPM_RT_COUNTER;
432 	else if (!strcasecmp(argv[1], "delegate"))
433 		type = TPM_RT_DELEGATE;
434 	else if (!strcasecmp(argv[1], "daa_tpm"))
435 		type = TPM_RT_DAA_TPM;
436 	else if (!strcasecmp(argv[1], "daa_v0"))
437 		type = TPM_RT_DAA_V0;
438 	else if (!strcasecmp(argv[1], "daa_v1"))
439 		type = TPM_RT_DAA_V1;
440 
441 	if (!type) {
442 		printf("Resource type %s unknown.\n", argv[1]);
443 		return -1;
444 	}
445 
446 	if (!strcasecmp(argv[2], "all")) {
447 		u16 res_count;
448 		u8 buf[288];
449 		u8 *ptr;
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));
456 		if (err) {
457 			printf("tpm_get_capability returned error %d.\n", err);
458 			return -1;
459 		}
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 {
465 		u32 handle = simple_strtoul(argv[2], NULL, 0);
466 
467 		if (!handle) {
468 			printf("Illegal resource handle %s\n", argv[2]);
469 			return -1;
470 		}
471 		tpm_flush_specific(cpu_to_be32(handle), type);
472 	}
473 
474 	return 0;
475 }
476 #endif /* CONFIG_TPM_FLUSH_RESOURCES */
477 
478 #ifdef CONFIG_TPM_LIST_RESOURCES
479 static int do_tpm_list(cmd_tbl_t *cmdtp, int flag, int argc,
480 		       char * const argv[])
481 {
482 	int type = 0;
483 	u16 res_count;
484 	u8 buf[288];
485 	u8 *ptr;
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 
540 TPM_COMMAND_NO_ARG(tpm_self_test_full)
541 TPM_COMMAND_NO_ARG(tpm_continue_self_test)
542 TPM_COMMAND_NO_ARG(tpm_force_clear)
543 TPM_COMMAND_NO_ARG(tpm_physical_enable)
544 TPM_COMMAND_NO_ARG(tpm_physical_disable)
545 
546 static cmd_tbl_t tpm1_commands[] = {
547 	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
548 	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
549 	U_BOOT_CMD_MKENT(startup, 0, 1,
550 			 do_tpm_startup, "", ""),
551 	U_BOOT_CMD_MKENT(self_test_full, 0, 1,
552 			 do_tpm_self_test_full, "", ""),
553 	U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
554 			 do_tpm_continue_self_test, "", ""),
555 	U_BOOT_CMD_MKENT(force_clear, 0, 1,
556 			 do_tpm_force_clear, "", ""),
557 	U_BOOT_CMD_MKENT(physical_enable, 0, 1,
558 			 do_tpm_physical_enable, "", ""),
559 	U_BOOT_CMD_MKENT(physical_disable, 0, 1,
560 			 do_tpm_physical_disable, "", ""),
561 	U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
562 			 do_tpm_nv_define_space, "", ""),
563 	U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
564 			 do_tpm_nv_read_value, "", ""),
565 	U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
566 			 do_tpm_nv_write_value, "", ""),
567 	U_BOOT_CMD_MKENT(extend, 0, 1,
568 			 do_tpm_extend, "", ""),
569 	U_BOOT_CMD_MKENT(pcr_read, 0, 1,
570 			 do_tpm_pcr_read, "", ""),
571 	U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
572 			 do_tpm_tsc_physical_presence, "", ""),
573 	U_BOOT_CMD_MKENT(read_pubek, 0, 1,
574 			 do_tpm_read_pubek, "", ""),
575 	U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
576 			 do_tpm_physical_set_deactivated, "", ""),
577 	U_BOOT_CMD_MKENT(get_capability, 0, 1,
578 			 do_tpm_get_capability, "", ""),
579 	U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
580 			 do_tpm_raw_transfer, "", ""),
581 	U_BOOT_CMD_MKENT(nv_define, 0, 1,
582 			 do_tpm_nv_define, "", ""),
583 	U_BOOT_CMD_MKENT(nv_read, 0, 1,
584 			 do_tpm_nv_read, "", ""),
585 	U_BOOT_CMD_MKENT(nv_write, 0, 1,
586 			 do_tpm_nv_write, "", ""),
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, "", ""),
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 */
598 	U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1,
599 			 do_tpm_get_pub_key_oiap, "", ""),
600 #endif /* CONFIG_TPM_AUTH_SESSIONS */
601 #ifdef CONFIG_TPM_FLUSH_RESOURCES
602 	U_BOOT_CMD_MKENT(flush, 0, 1,
603 			 do_tpm_flush, "", ""),
604 #endif /* CONFIG_TPM_FLUSH_RESOURCES */
605 #ifdef CONFIG_TPM_LIST_RESOURCES
606 	U_BOOT_CMD_MKENT(list, 0, 1,
607 			 do_tpm_list, "", ""),
608 #endif /* CONFIG_TPM_LIST_RESOURCES */
609 };
610 
611 cmd_tbl_t *get_tpm1_commands(unsigned int *size)
612 {
613 	*size = ARRAY_SIZE(tpm1_commands);
614 
615 	return tpm1_commands;
616 }
617 
618 U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
619 "Issue a TPMv1.x command",
620 "cmd args...\n"
621 "    - Issue TPM command <cmd> with arguments <args...>.\n"
622 "Admin Startup and State Commands:\n"
623 "  info - Show information about the TPM\n"
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"
652 #if defined(CONFIG_TPM_FLUSH_RESOURCES) || defined(CONFIG_TPM_LIST_RESOURCES)
653 "Resource management functions\n"
654 #endif
655 #ifdef CONFIG_TPM_FLUSH_RESOURCES
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 */
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 */
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"
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 */
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 */
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"
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 */
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"
723 );
724