Blame view

cmd/tpm.c 25.7 KB
576fb1ed3   Vadim Bendebury   Add a cli command...
1
  /*
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
2
   * Copyright (c) 2013 The Chromium OS Authors.
576fb1ed3   Vadim Bendebury   Add a cli command...
3
   *
1a4596601   Wolfgang Denk   Add GPL-2.0+ SPDX...
4
   * SPDX-License-Identifier:	GPL-2.0+
576fb1ed3   Vadim Bendebury   Add a cli command...
5
6
7
8
   */
  
  #include <common.h>
  #include <command.h>
c8a8c5103   Simon Glass   dm: tpm: Convert ...
9
  #include <dm.h>
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
10
  #include <malloc.h>
576fb1ed3   Vadim Bendebury   Add a cli command...
11
  #include <tpm.h>
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
12
13
  #include <asm/unaligned.h>
  #include <linux/string.h>
576fb1ed3   Vadim Bendebury   Add a cli command...
14

be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
15
16
17
18
19
20
  /* Useful constants */
  enum {
  	DIGEST_LENGTH		= 20,
  	/* max lengths, valid for RSA keys <= 2048 bits */
  	TPM_PUBKEY_MAX_LENGTH	= 288,
  };
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
21
22
23
24
25
26
27
28
29
  /**
   * Print a byte string in hexdecimal format, 16-bytes per line.
   *
   * @param data		byte string to be printed
   * @param count		number of bytes to be printed
   */
  static void print_byte_string(uint8_t *data, size_t count)
  {
  	int i, print_newline = 0;
576fb1ed3   Vadim Bendebury   Add a cli command...
30

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  	for (i = 0; i < count; i++) {
  		printf(" %02x", data[i]);
  		print_newline = (i % 16 == 15);
  		if (print_newline)
  			putc('
  ');
  	}
  	/* Avoid duplicated newline at the end */
  	if (!print_newline)
  		putc('
  ');
  }
  
  /**
   * Convert a text string of hexdecimal values into a byte string.
576fb1ed3   Vadim Bendebury   Add a cli command...
46
   *
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
47
48
49
50
51
52
53
54
   * @param bytes		text string of hexdecimal values with no space
   *			between them
   * @param data		output buffer for byte string.  The caller has to make
   *			sure it is large enough for storing the output.  If
   *			NULL is passed, a large enough buffer will be allocated,
   *			and the caller must free it.
   * @param count_ptr	output variable for the length of byte string
   * @return pointer to output buffer
576fb1ed3   Vadim Bendebury   Add a cli command...
55
   */
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
56
57
58
59
60
  static void *parse_byte_string(char *bytes, uint8_t *data, size_t *count_ptr)
  {
  	char byte[3];
  	size_t count, length;
  	int i;
5c51d8aa0   Simon Glass   tpm: Check that p...
61
62
  	if (!bytes)
  		return NULL;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
63
64
65
66
67
68
69
70
71
72
73
74
75
  	length = strlen(bytes);
  	count = length / 2;
  
  	if (!data)
  		data = malloc(count);
  	if (!data)
  		return NULL;
  
  	byte[2] = '\0';
  	for (i = 0; i < length; i += 2) {
  		byte[0] = bytes[i];
  		byte[1] = bytes[i + 1];
  		data[i / 2] = (uint8_t)simple_strtoul(byte, NULL, 16);
576fb1ed3   Vadim Bendebury   Add a cli command...
76
  	}
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
77
78
79
80
81
82
83
  	if (count_ptr)
  		*count_ptr = count;
  
  	return data;
  }
  
  /**
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
84
   * report_return_code() - Report any error and return failure or success
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
85
86
87
88
   *
   * @param return_code	TPM command return code
   * @return value of enum command_ret_t
   */
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
89
  static int report_return_code(int return_code)
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
90
  {
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
91
92
93
  	if (return_code) {
  		printf("Error: %d
  ", return_code);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
94
  		return CMD_RET_FAILURE;
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
95
  	} else {
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
96
  		return CMD_RET_SUCCESS;
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
97
  	}
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
  }
  
  /**
   * Return number of values defined by a type string.
   *
   * @param type_str	type string
   * @return number of values of type string
   */
  static int type_string_get_num_values(const char *type_str)
  {
  	return strlen(type_str);
  }
  
  /**
   * Return total size of values defined by a type string.
   *
   * @param type_str	type string
   * @return total size of values of type string, or 0 if type string
   *  contains illegal type character.
   */
  static size_t type_string_get_space_size(const char *type_str)
  {
  	size_t size;
  
  	for (size = 0; *type_str; type_str++) {
  		switch (*type_str) {
  		case 'b':
  			size += 1;
  			break;
  		case 'w':
  			size += 2;
  			break;
  		case 'd':
  			size += 4;
  			break;
  		default:
  			return 0;
  		}
576fb1ed3   Vadim Bendebury   Add a cli command...
136
  	}
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
137
138
  
  	return size;
576fb1ed3   Vadim Bendebury   Add a cli command...
139
  }
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  /**
   * Allocate a buffer large enough to hold values defined by a type
   * string.  The caller has to free the buffer.
   *
   * @param type_str	type string
   * @param count		pointer for storing size of buffer
   * @return pointer to buffer or NULL on error
   */
  static void *type_string_alloc(const char *type_str, uint32_t *count)
  {
  	void *data;
  	size_t size;
  
  	size = type_string_get_space_size(type_str);
  	if (!size)
  		return NULL;
  	data = malloc(size);
  	if (data)
  		*count = size;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
159

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  	return data;
  }
  
  /**
   * Pack values defined by a type string into a buffer.  The buffer must have
   * large enough space.
   *
   * @param type_str	type string
   * @param values	text strings of values to be packed
   * @param data		output buffer of values
   * @return 0 on success, non-0 on error
   */
  static int type_string_pack(const char *type_str, char * const values[],
  		uint8_t *data)
576fb1ed3   Vadim Bendebury   Add a cli command...
174
  {
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
  	size_t offset;
  	uint32_t value;
  
  	for (offset = 0; *type_str; type_str++, values++) {
  		value = simple_strtoul(values[0], NULL, 0);
  		switch (*type_str) {
  		case 'b':
  			data[offset] = value;
  			offset += 1;
  			break;
  		case 'w':
  			put_unaligned_be16(value, data + offset);
  			offset += 2;
  			break;
  		case 'd':
  			put_unaligned_be32(value, data + offset);
  			offset += 4;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
192
  			break;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
193
194
  		default:
  			return -1;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
195
  		}
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
  	}
  
  	return 0;
  }
  
  /**
   * Read values defined by a type string from a buffer, and write these values
   * to environment variables.
   *
   * @param type_str	type string
   * @param data		input buffer of values
   * @param vars		names of environment variables
   * @return 0 on success, non-0 on error
   */
  static int type_string_write_vars(const char *type_str, uint8_t *data,
  		char * const vars[])
  {
  	size_t offset;
  	uint32_t value;
  
  	for (offset = 0; *type_str; type_str++, vars++) {
  		switch (*type_str) {
  		case 'b':
  			value = data[offset];
  			offset += 1;
  			break;
  		case 'w':
  			value = get_unaligned_be16(data + offset);
  			offset += 2;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
225
  			break;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
226
227
228
229
230
231
  		case 'd':
  			value = get_unaligned_be32(data + offset);
  			offset += 4;
  			break;
  		default:
  			return -1;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
232
  		}
018f53032   Simon Glass   env: Rename commo...
233
  		if (env_set_ulong(*vars, value))
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
234
  			return -1;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
235
  	}
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
236
237
  
  	return 0;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
238
  }
576fb1ed3   Vadim Bendebury   Add a cli command...
239

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
240
241
242
243
  static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	enum tpm_startup_type mode;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
244

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
245
246
247
248
249
250
251
252
253
254
255
256
257
  	if (argc != 2)
  		return CMD_RET_USAGE;
  	if (!strcasecmp("TPM_ST_CLEAR", argv[1])) {
  		mode = TPM_ST_CLEAR;
  	} else if (!strcasecmp("TPM_ST_STATE", argv[1])) {
  		mode = TPM_ST_STATE;
  	} else if (!strcasecmp("TPM_ST_DEACTIVATED", argv[1])) {
  		mode = TPM_ST_DEACTIVATED;
  	} else {
  		printf("Couldn't recognize mode string: %s
  ", argv[1]);
  		return CMD_RET_FAILURE;
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
258
  	return report_return_code(tpm_startup(mode));
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
259
260
261
262
263
264
265
266
267
268
269
270
  }
  
  static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint32_t index, perm, size;
  
  	if (argc != 4)
  		return CMD_RET_USAGE;
  	index = simple_strtoul(argv[1], NULL, 0);
  	perm = simple_strtoul(argv[2], NULL, 0);
  	size = simple_strtoul(argv[3], NULL, 0);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
271
  	return report_return_code(tpm_nv_define_space(index, perm, size));
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
272
  }
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
273

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
274
275
  static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
276
  {
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
277
278
  	uint32_t index, count, rc;
  	void *data;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
279

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
280
281
282
283
284
285
286
287
288
289
290
  	if (argc != 4)
  		return CMD_RET_USAGE;
  	index = simple_strtoul(argv[1], NULL, 0);
  	data = (void *)simple_strtoul(argv[2], NULL, 0);
  	count = simple_strtoul(argv[3], NULL, 0);
  
  	rc = tpm_nv_read_value(index, data, count);
  	if (!rc) {
  		puts("area content:
  ");
  		print_byte_string(data, count);
576fb1ed3   Vadim Bendebury   Add a cli command...
291
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
292
  	return report_return_code(rc);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
  }
  
  static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint32_t index, rc;
  	size_t count;
  	void *data;
  
  	if (argc != 3)
  		return CMD_RET_USAGE;
  	index = simple_strtoul(argv[1], NULL, 0);
  	data = parse_byte_string(argv[2], NULL, &count);
  	if (!data) {
  		printf("Couldn't parse byte string %s
  ", argv[2]);
  		return CMD_RET_FAILURE;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
310
  	}
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
311
312
  	rc = tpm_nv_write_value(index, data, count);
  	free(data);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
313
  	return report_return_code(rc);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
  }
  
  static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint32_t index, rc;
  	uint8_t in_digest[20], out_digest[20];
  
  	if (argc != 3)
  		return CMD_RET_USAGE;
  	index = simple_strtoul(argv[1], NULL, 0);
  	if (!parse_byte_string(argv[2], in_digest, NULL)) {
  		printf("Couldn't parse byte string %s
  ", argv[2]);
  		return CMD_RET_FAILURE;
576fb1ed3   Vadim Bendebury   Add a cli command...
329
  	}
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
330
331
332
333
334
  	rc = tpm_extend(index, in_digest, out_digest);
  	if (!rc) {
  		puts("PCR value after execution of the command:
  ");
  		print_byte_string(out_digest, sizeof(out_digest));
576fb1ed3   Vadim Bendebury   Add a cli command...
335
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
336
  	return report_return_code(rc);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
337
338
339
340
341
342
343
344
345
346
347
348
349
  }
  
  static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint32_t index, count, rc;
  	void *data;
  
  	if (argc != 4)
  		return CMD_RET_USAGE;
  	index = simple_strtoul(argv[1], NULL, 0);
  	data = (void *)simple_strtoul(argv[2], NULL, 0);
  	count = simple_strtoul(argv[3], NULL, 0);
576fb1ed3   Vadim Bendebury   Add a cli command...
350

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
351
352
353
354
355
  	rc = tpm_pcr_read(index, data, count);
  	if (!rc) {
  		puts("Named PCR content:
  ");
  		print_byte_string(data, count);
576fb1ed3   Vadim Bendebury   Add a cli command...
356
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
357
  	return report_return_code(rc);
576fb1ed3   Vadim Bendebury   Add a cli command...
358
  }
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
359
360
361
362
363
364
365
366
  static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint16_t presence;
  
  	if (argc != 2)
  		return CMD_RET_USAGE;
  	presence = (uint16_t)simple_strtoul(argv[1], NULL, 0);
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
367

f8f1fe1d5   Simon Glass   tpm: Report tpm e...
368
  	return report_return_code(tpm_tsc_physical_presence(presence));
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
369
370
371
372
  }
  
  static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
373
  {
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
374
375
376
377
378
379
380
381
382
383
384
385
386
387
  	uint32_t count, rc;
  	void *data;
  
  	if (argc != 3)
  		return CMD_RET_USAGE;
  	data = (void *)simple_strtoul(argv[1], NULL, 0);
  	count = simple_strtoul(argv[2], NULL, 0);
  
  	rc = tpm_read_pubek(data, count);
  	if (!rc) {
  		puts("pubek value:
  ");
  		print_byte_string(data, count);
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
388
  	return report_return_code(rc);
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
389
  }
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
390
391
392
393
394
395
396
397
  static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint8_t state;
  
  	if (argc != 2)
  		return CMD_RET_USAGE;
  	state = (uint8_t)simple_strtoul(argv[1], NULL, 0);
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
398

f8f1fe1d5   Simon Glass   tpm: Report tpm e...
399
  	return report_return_code(tpm_physical_set_deactivated(state));
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
  }
  
  static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint32_t cap_area, sub_cap, rc;
  	void *cap;
  	size_t count;
  
  	if (argc != 5)
  		return CMD_RET_USAGE;
  	cap_area = simple_strtoul(argv[1], NULL, 0);
  	sub_cap = simple_strtoul(argv[2], NULL, 0);
  	cap = (void *)simple_strtoul(argv[3], NULL, 0);
  	count = simple_strtoul(argv[4], NULL, 0);
  
  	rc = tpm_get_capability(cap_area, sub_cap, cap, count);
  	if (!rc) {
  		puts("capability information:
  ");
  		print_byte_string(cap, count);
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
422
  	return report_return_code(rc);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
423
  }
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
424

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
425
426
427
428
429
430
  #define TPM_COMMAND_NO_ARG(cmd)				\
  static int do_##cmd(cmd_tbl_t *cmdtp, int flag,		\
  		int argc, char * const argv[])		\
  {							\
  	if (argc != 1)					\
  		return CMD_RET_USAGE;			\
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
431
  	return report_return_code(cmd());		\
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
432
433
434
435
436
437
438
439
  }
  
  TPM_COMMAND_NO_ARG(tpm_init)
  TPM_COMMAND_NO_ARG(tpm_self_test_full)
  TPM_COMMAND_NO_ARG(tpm_continue_self_test)
  TPM_COMMAND_NO_ARG(tpm_force_clear)
  TPM_COMMAND_NO_ARG(tpm_physical_enable)
  TPM_COMMAND_NO_ARG(tpm_physical_disable)
c8a8c5103   Simon Glass   dm: tpm: Convert ...
440
441
442
  static int get_tpm(struct udevice **devp)
  {
  	int rc;
3f603cbbb   Simon Glass   dm: Use uclass_fi...
443
444
  	rc = uclass_first_device_err(UCLASS_TPM, devp);
  	if (rc) {
c8a8c5103   Simon Glass   dm: tpm: Convert ...
445
446
447
448
449
450
451
  		printf("Could not find TPM (ret=%d)
  ", rc);
  		return CMD_RET_FAILURE;
  	}
  
  	return 0;
  }
ad77694e2   Simon Glass   tpm: Add a 'tpm i...
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
  
  static int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int argc,
  		       char *const argv[])
  {
  	struct udevice *dev;
  	char buf[80];
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
  	rc = tpm_get_desc(dev, buf, sizeof(buf));
  	if (rc < 0) {
  		printf("Couldn't get TPM info (%d)
  ", rc);
  		return CMD_RET_FAILURE;
  	}
  	printf("%s
  ", buf);
  
  	return 0;
  }
c8a8c5103   Simon Glass   dm: tpm: Convert ...
474

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
475
476
477
  static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
c2b0f600a   Christophe Ricard   dm: tpm: Remove e...
478
  	struct udevice *dev;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
479
480
481
482
483
484
485
486
487
488
489
  	void *command;
  	uint8_t response[1024];
  	size_t count, response_length = sizeof(response);
  	uint32_t rc;
  
  	command = parse_byte_string(argv[1], NULL, &count);
  	if (!command) {
  		printf("Couldn't parse byte string %s
  ", argv[1]);
  		return CMD_RET_FAILURE;
  	}
c8a8c5103   Simon Glass   dm: tpm: Convert ...
490
491
492
493
494
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
  
  	rc = tpm_xfer(dev, command, count, response, &response_length);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
495
496
497
498
499
500
  	free(command);
  	if (!rc) {
  		puts("tpm response:
  ");
  		print_byte_string(response, response_length);
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
501
  	return report_return_code(rc);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
  }
  
  static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint32_t index, perm, size;
  
  	if (argc != 4)
  		return CMD_RET_USAGE;
  	size = type_string_get_space_size(argv[1]);
  	if (!size) {
  		printf("Couldn't parse arguments
  ");
  		return CMD_RET_USAGE;
  	}
  	index = simple_strtoul(argv[2], NULL, 0);
  	perm = simple_strtoul(argv[3], NULL, 0);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
519
  	return report_return_code(tpm_nv_define_space(index, perm, size));
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
520
521
522
523
  }
  
  static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
524
  {
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
525
526
  	uint32_t index, count, err;
  	void *data;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
527

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
528
529
530
531
532
533
534
535
536
537
  	if (argc < 3)
  		return CMD_RET_USAGE;
  	if (argc != 3 + type_string_get_num_values(argv[1]))
  		return CMD_RET_USAGE;
  	index = simple_strtoul(argv[2], NULL, 0);
  	data = type_string_alloc(argv[1], &count);
  	if (!data) {
  		printf("Couldn't parse arguments
  ");
  		return CMD_RET_USAGE;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
538
  	}
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
539
540
541
542
543
544
545
  	err = tpm_nv_read_value(index, data, count);
  	if (!err) {
  		if (type_string_write_vars(argv[1], data, argv + 3)) {
  			printf("Couldn't write to variables
  ");
  			err = ~0;
  		}
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
546
  	}
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
547
  	free(data);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
548
  	return report_return_code(err);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
  }
  
  static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint32_t index, count, err;
  	void *data;
  
  	if (argc < 3)
  		return CMD_RET_USAGE;
  	if (argc != 3 + type_string_get_num_values(argv[1]))
  		return CMD_RET_USAGE;
  	index = simple_strtoul(argv[2], NULL, 0);
  	data = type_string_alloc(argv[1], &count);
  	if (!data) {
  		printf("Couldn't parse arguments
  ");
  		return CMD_RET_USAGE;
  	}
  	if (type_string_pack(argv[1], argv + 3, data)) {
  		printf("Couldn't parse arguments
  ");
  		free(data);
  		return CMD_RET_USAGE;
  	}
  
  	err = tpm_nv_write_value(index, data, count);
  	free(data);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
577
  	return report_return_code(err);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
578
  }
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
579
580
581
582
583
584
585
586
  #ifdef CONFIG_TPM_AUTH_SESSIONS
  
  static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint32_t auth_handle, err;
  
  	err = tpm_oiap(&auth_handle);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
587
  	return report_return_code(err);
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
588
  }
0f4b2ba17   mario.six@gdsys.cc   tpm: Add function...
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
  #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
  static int do_tpm_load_key_by_sha1(cmd_tbl_t *cmdtp, int flag, int argc, char *
  				   const argv[])
  {
  	uint32_t parent_handle = 0;
  	uint32_t key_len, key_handle, err;
  	uint8_t usage_auth[DIGEST_LENGTH];
  	uint8_t parent_hash[DIGEST_LENGTH];
  	void *key;
  
  	if (argc < 5)
  		return CMD_RET_USAGE;
  
  	parse_byte_string(argv[1], parent_hash, NULL);
  	key = (void *)simple_strtoul(argv[2], NULL, 0);
  	key_len = simple_strtoul(argv[3], NULL, 0);
  	if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
  		return CMD_RET_FAILURE;
  	parse_byte_string(argv[4], usage_auth, NULL);
  
  	err = tpm_find_key_sha1(usage_auth, parent_hash, &parent_handle);
  	if (err) {
  		printf("Could not find matching parent key (err = %d)
  ", err);
  		return CMD_RET_FAILURE;
  	}
  
  	printf("Found parent key %08x
  ", parent_handle);
  
  	err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth,
  				 &key_handle);
  	if (!err) {
  		printf("Key handle is 0x%x
  ", key_handle);
018f53032   Simon Glass   env: Rename commo...
624
  		env_set_hex("key_handle", key_handle);
0f4b2ba17   mario.six@gdsys.cc   tpm: Add function...
625
626
627
628
629
  	}
  
  	return report_return_code(err);
  }
  #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
  static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint32_t parent_handle, key_len, key_handle, err;
  	uint8_t usage_auth[DIGEST_LENGTH];
  	void *key;
  
  	if (argc < 5)
  		return CMD_RET_USAGE;
  
  	parent_handle = simple_strtoul(argv[1], NULL, 0);
  	key = (void *)simple_strtoul(argv[2], NULL, 0);
  	key_len = simple_strtoul(argv[3], NULL, 0);
  	if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
  		return CMD_RET_FAILURE;
  	parse_byte_string(argv[4], usage_auth, NULL);
  
  	err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth,
  			&key_handle);
  	if (!err)
  		printf("Key handle is 0x%x
  ", key_handle);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
652
  	return report_return_code(err);
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
  }
  
  static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag,
  		int argc, char * const argv[])
  {
  	uint32_t key_handle, err;
  	uint8_t usage_auth[DIGEST_LENGTH];
  	uint8_t pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
  	size_t pub_key_len = sizeof(pub_key_buffer);
  
  	if (argc < 3)
  		return CMD_RET_USAGE;
  
  	key_handle = simple_strtoul(argv[1], NULL, 0);
  	if (strlen(argv[2]) != 2 * DIGEST_LENGTH)
  		return CMD_RET_FAILURE;
  	parse_byte_string(argv[2], usage_auth, NULL);
  
  	err = tpm_get_pub_key_oiap(key_handle, usage_auth,
  			pub_key_buffer, &pub_key_len);
  	if (!err) {
  		printf("dump of received pub key structure:
  ");
  		print_byte_string(pub_key_buffer, pub_key_len);
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
678
  	return report_return_code(err);
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
679
680
681
682
683
  }
  
  TPM_COMMAND_NO_ARG(tpm_end_oiap)
  
  #endif /* CONFIG_TPM_AUTH_SESSIONS */
7690be35d   Mario Six   lib: tpm: Add com...
684
685
686
687
688
  #ifdef CONFIG_TPM_FLUSH_RESOURCES
  static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc,
  			char * const argv[])
  {
  	int type = 0;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
689
  	if (argc != 3)
7690be35d   Mario Six   lib: tpm: Add com...
690
  		return CMD_RET_USAGE;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
691
  	if (!strcasecmp(argv[1], "key"))
7690be35d   Mario Six   lib: tpm: Add com...
692
  		type = TPM_RT_KEY;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
693
  	else if (!strcasecmp(argv[1], "auth"))
7690be35d   Mario Six   lib: tpm: Add com...
694
  		type = TPM_RT_AUTH;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
695
  	else if (!strcasecmp(argv[1], "hash"))
7690be35d   Mario Six   lib: tpm: Add com...
696
  		type = TPM_RT_HASH;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
697
  	else if (!strcasecmp(argv[1], "trans"))
7690be35d   Mario Six   lib: tpm: Add com...
698
  		type = TPM_RT_TRANS;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
699
  	else if (!strcasecmp(argv[1], "context"))
7690be35d   Mario Six   lib: tpm: Add com...
700
  		type = TPM_RT_CONTEXT;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
701
  	else if (!strcasecmp(argv[1], "counter"))
7690be35d   Mario Six   lib: tpm: Add com...
702
  		type = TPM_RT_COUNTER;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
703
  	else if (!strcasecmp(argv[1], "delegate"))
7690be35d   Mario Six   lib: tpm: Add com...
704
  		type = TPM_RT_DELEGATE;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
705
  	else if (!strcasecmp(argv[1], "daa_tpm"))
7690be35d   Mario Six   lib: tpm: Add com...
706
  		type = TPM_RT_DAA_TPM;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
707
  	else if (!strcasecmp(argv[1], "daa_v0"))
7690be35d   Mario Six   lib: tpm: Add com...
708
  		type = TPM_RT_DAA_V0;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
709
  	else if (!strcasecmp(argv[1], "daa_v1"))
7690be35d   Mario Six   lib: tpm: Add com...
710
  		type = TPM_RT_DAA_V1;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
711
712
713
714
715
716
717
  	if (!type) {
  		printf("Resource type %s unknown.
  ", argv[1]);
  		return -1;
  	}
  
  	if (!strcasecmp(argv[2], "all")) {
7690be35d   Mario Six   lib: tpm: Add com...
718
719
720
721
722
723
724
725
726
  		uint16_t res_count;
  		uint8_t buf[288];
  		uint8_t *ptr;
  		int err;
  		uint i;
  
  		/* fetch list of already loaded resources in the TPM */
  		err = tpm_get_capability(TPM_CAP_HANDLE, type, buf,
  					 sizeof(buf));
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
727
728
729
  		if (err) {
  			printf("tpm_get_capability returned error %d.
  ", err);
7690be35d   Mario Six   lib: tpm: Add com...
730
  			return -1;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
731
  		}
7690be35d   Mario Six   lib: tpm: Add com...
732
733
734
735
736
737
  		res_count = get_unaligned_be16(buf);
  		ptr = buf + 2;
  		for (i = 0; i < res_count; ++i, ptr += 4)
  			tpm_flush_specific(get_unaligned_be32(ptr), type);
  	} else {
  		uint32_t handle = simple_strtoul(argv[2], NULL, 0);
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
738
739
740
  		if (!handle) {
  			printf("Illegal resource handle %s
  ", argv[2]);
7690be35d   Mario Six   lib: tpm: Add com...
741
  			return -1;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
742
  		}
7690be35d   Mario Six   lib: tpm: Add com...
743
744
745
746
747
748
  		tpm_flush_specific(cpu_to_be32(handle), type);
  	}
  
  	return 0;
  }
  #endif /* CONFIG_TPM_FLUSH_RESOURCES */
3d1df0e36   mario.six@gdsys.cc   lib: tpm: Add com...
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
  #ifdef CONFIG_TPM_LIST_RESOURCES
  static int do_tpm_list(cmd_tbl_t *cmdtp, int flag, int argc,
  		       char * const argv[])
  {
  	int type = 0;
  	uint16_t res_count;
  	uint8_t buf[288];
  	uint8_t *ptr;
  	int err;
  	uint i;
  
  	if (argc != 2)
  		return CMD_RET_USAGE;
  
  	if (!strcasecmp(argv[1], "key"))
  		type = TPM_RT_KEY;
  	else if (!strcasecmp(argv[1], "auth"))
  		type = TPM_RT_AUTH;
  	else if (!strcasecmp(argv[1], "hash"))
  		type = TPM_RT_HASH;
  	else if (!strcasecmp(argv[1], "trans"))
  		type = TPM_RT_TRANS;
  	else if (!strcasecmp(argv[1], "context"))
  		type = TPM_RT_CONTEXT;
  	else if (!strcasecmp(argv[1], "counter"))
  		type = TPM_RT_COUNTER;
  	else if (!strcasecmp(argv[1], "delegate"))
  		type = TPM_RT_DELEGATE;
  	else if (!strcasecmp(argv[1], "daa_tpm"))
  		type = TPM_RT_DAA_TPM;
  	else if (!strcasecmp(argv[1], "daa_v0"))
  		type = TPM_RT_DAA_V0;
  	else if (!strcasecmp(argv[1], "daa_v1"))
  		type = TPM_RT_DAA_V1;
  
  	if (!type) {
  		printf("Resource type %s unknown.
  ", argv[1]);
  		return -1;
  	}
  
  	/* fetch list of already loaded resources in the TPM */
  	err = tpm_get_capability(TPM_CAP_HANDLE, type, buf,
  				 sizeof(buf));
  	if (err) {
  		printf("tpm_get_capability returned error %d.
  ", err);
  		return -1;
  	}
  	res_count = get_unaligned_be16(buf);
  	ptr = buf + 2;
  
  	printf("Resources of type %s (%02x):
  ", argv[1], type);
  	if (!res_count) {
  		puts("None
  ");
  	} else {
  		for (i = 0; i < res_count; ++i, ptr += 4)
  			printf("Index %d: %08x
  ", i, get_unaligned_be32(ptr));
  	}
  
  	return 0;
  }
  #endif /* CONFIG_TPM_LIST_RESOURCES */
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
815
816
817
818
  #define MAKE_TPM_CMD_ENTRY(cmd) \
  	U_BOOT_CMD_MKENT(cmd, 0, 1, do_tpm_ ## cmd, "", "")
  
  static cmd_tbl_t tpm_commands[] = {
ad77694e2   Simon Glass   tpm: Add a 'tpm i...
819
  	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
  	U_BOOT_CMD_MKENT(init, 0, 1,
  			do_tpm_init, "", ""),
  	U_BOOT_CMD_MKENT(startup, 0, 1,
  			do_tpm_startup, "", ""),
  	U_BOOT_CMD_MKENT(self_test_full, 0, 1,
  			do_tpm_self_test_full, "", ""),
  	U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
  			do_tpm_continue_self_test, "", ""),
  	U_BOOT_CMD_MKENT(force_clear, 0, 1,
  			do_tpm_force_clear, "", ""),
  	U_BOOT_CMD_MKENT(physical_enable, 0, 1,
  			do_tpm_physical_enable, "", ""),
  	U_BOOT_CMD_MKENT(physical_disable, 0, 1,
  			do_tpm_physical_disable, "", ""),
  	U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
  			do_tpm_nv_define_space, "", ""),
  	U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
  			do_tpm_nv_read_value, "", ""),
  	U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
  			do_tpm_nv_write_value, "", ""),
  	U_BOOT_CMD_MKENT(extend, 0, 1,
  			do_tpm_extend, "", ""),
  	U_BOOT_CMD_MKENT(pcr_read, 0, 1,
  			do_tpm_pcr_read, "", ""),
  	U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
  			do_tpm_tsc_physical_presence, "", ""),
  	U_BOOT_CMD_MKENT(read_pubek, 0, 1,
  			do_tpm_read_pubek, "", ""),
  	U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
  			do_tpm_physical_set_deactivated, "", ""),
  	U_BOOT_CMD_MKENT(get_capability, 0, 1,
  			do_tpm_get_capability, "", ""),
  	U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
  			do_tpm_raw_transfer, "", ""),
  	U_BOOT_CMD_MKENT(nv_define, 0, 1,
  			do_tpm_nv_define, "", ""),
  	U_BOOT_CMD_MKENT(nv_read, 0, 1,
  			do_tpm_nv_read, "", ""),
  	U_BOOT_CMD_MKENT(nv_write, 0, 1,
  			do_tpm_nv_write, "", ""),
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
860
861
862
863
864
865
866
  #ifdef CONFIG_TPM_AUTH_SESSIONS
  	U_BOOT_CMD_MKENT(oiap, 0, 1,
  			 do_tpm_oiap, "", ""),
  	U_BOOT_CMD_MKENT(end_oiap, 0, 1,
  			 do_tpm_end_oiap, "", ""),
  	U_BOOT_CMD_MKENT(load_key2_oiap, 0, 1,
  			 do_tpm_load_key2_oiap, "", ""),
0f4b2ba17   mario.six@gdsys.cc   tpm: Add function...
867
868
869
870
  #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
  	U_BOOT_CMD_MKENT(load_key_by_sha1, 0, 1,
  			 do_tpm_load_key_by_sha1, "", ""),
  #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
871
872
873
  	U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1,
  			 do_tpm_get_pub_key_oiap, "", ""),
  #endif /* CONFIG_TPM_AUTH_SESSIONS */
7690be35d   Mario Six   lib: tpm: Add com...
874
875
876
877
  #ifdef CONFIG_TPM_FLUSH_RESOURCES
  	U_BOOT_CMD_MKENT(flush, 0, 1,
  			 do_tpm_flush, "", ""),
  #endif /* CONFIG_TPM_FLUSH_RESOURCES */
3d1df0e36   mario.six@gdsys.cc   lib: tpm: Add com...
878
879
880
881
  #ifdef CONFIG_TPM_LIST_RESOURCES
  	U_BOOT_CMD_MKENT(list, 0, 1,
  			 do_tpm_list, "", ""),
  #endif /* CONFIG_TPM_LIST_RESOURCES */
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
882
883
884
885
886
887
888
889
890
891
892
  };
  
  static int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
  	cmd_tbl_t *tpm_cmd;
  
  	if (argc < 2)
  		return CMD_RET_USAGE;
  	tpm_cmd = find_cmd_tbl(argv[1], tpm_commands, ARRAY_SIZE(tpm_commands));
  	if (!tpm_cmd)
  		return CMD_RET_USAGE;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
893

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
894
  	return tpm_cmd->cmd(cmdtp, flag, argc - 1, argv + 1);
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
895
  }
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
896
897
898
899
900
901
902
903
  U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
  "Issue a TPM command",
  "cmd args...
  "
  "    - Issue TPM command <cmd> with arguments <args...>.
  "
  "Admin Startup and State Commands:
  "
ad77694e2   Simon Glass   tpm: Add a 'tpm i...
904
905
  "  info - Show information about the TPM
  "
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
  "  init
  "
  "    - Put TPM into a state where it waits for 'startup' command.
  "
  "  startup mode
  "
  "    - Issue TPM_Starup command.  <mode> is one of TPM_ST_CLEAR,
  "
  "      TPM_ST_STATE, and TPM_ST_DEACTIVATED.
  "
  "Admin Testing Commands:
  "
  "  self_test_full
  "
  "    - Test all of the TPM capabilities.
  "
  "  continue_self_test
  "
  "    - Inform TPM that it should complete the self-test.
  "
  "Admin Opt-in Commands:
  "
  "  physical_enable
  "
  "    - Set the PERMANENT disable flag to FALSE using physical presence as
  "
  "      authorization.
  "
  "  physical_disable
  "
  "    - Set the PERMANENT disable flag to TRUE using physical presence as
  "
  "      authorization.
  "
  "  physical_set_deactivated 0|1
  "
  "    - Set deactivated flag.
  "
  "Admin Ownership Commands:
  "
  "  force_clear
  "
  "    - Issue TPM_ForceClear command.
  "
  "  tsc_physical_presence flags
  "
  "    - Set TPM device's Physical Presence flags to <flags>.
  "
  "The Capability Commands:
  "
  "  get_capability cap_area sub_cap addr count
  "
  "    - Read <count> bytes of TPM capability indexed by <cap_area> and
  "
  "      <sub_cap> to memory address <addr>.
  "
3d1df0e36   mario.six@gdsys.cc   lib: tpm: Add com...
962
  #if defined(CONFIG_TPM_FLUSH_RESOURCES) || defined(CONFIG_TPM_LIST_RESOURCES)
7690be35d   Mario Six   lib: tpm: Add com...
963
964
  "Resource management functions
  "
3d1df0e36   mario.six@gdsys.cc   lib: tpm: Add com...
965
966
  #endif
  #ifdef CONFIG_TPM_FLUSH_RESOURCES
7690be35d   Mario Six   lib: tpm: Add com...
967
968
969
970
971
972
973
974
975
976
977
  "  flush resource_type id
  "
  "    - flushes a resource of type <resource_type> (may be one of key, auth,
  "
  "      hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1),
  "
  "      and id <id> from the TPM. Use an <id> of \"all\" to flush all
  "
  "      resources of that type.
  "
  #endif /* CONFIG_TPM_FLUSH_RESOURCES */
3d1df0e36   mario.six@gdsys.cc   lib: tpm: Add com...
978
979
980
981
982
983
984
985
986
987
  #ifdef CONFIG_TPM_LIST_RESOURCES
  "  list resource_type
  "
  "    - lists resources of type <resource_type> (may be one of key, auth,
  "
  "      hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1),
  "
  "      contained in the TPM.
  "
  #endif /* CONFIG_TPM_LIST_RESOURCES */
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
988
989
990
991
992
993
994
995
996
997
998
  #ifdef CONFIG_TPM_AUTH_SESSIONS
  "Storage functions
  "
  "  loadkey2_oiap parent_handle key_addr key_len usage_auth
  "
  "    - loads a key data from memory address <key_addr>, <key_len> bytes
  "
  "      into TPM using the parent key <parent_handle> with authorization
  "
  "      <usage_auth> (20 bytes hex string).
  "
0f4b2ba17   mario.six@gdsys.cc   tpm: Add function...
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
  #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
  "  load_key_by_sha1 parent_hash key_addr key_len usage_auth
  "
  "    - loads a key data from memory address <key_addr>, <key_len> bytes
  "
  "      into TPM using the parent hash <parent_hash> (20 bytes hex string)
  "
  "      with authorization <usage_auth> (20 bytes hex string).
  "
  #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
1009
1010
1011
1012
1013
1014
1015
  "  get_pub_key_oiap key_handle usage_auth
  "
  "    - get the public key portion of a loaded key <key_handle> using
  "
  "      authorization <usage auth> (20 bytes hex string)
  "
  #endif /* CONFIG_TPM_AUTH_SESSIONS */
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
  "Endorsement Key Handling Commands:
  "
  "  read_pubek addr count
  "
  "    - Read <count> bytes of the public endorsement key to memory
  "
  "      address <addr>
  "
  "Integrity Collection and Reporting Commands:
  "
  "  extend index digest_hex_string
  "
  "    - Add a new measurement to a PCR.  Update PCR <index> with the 20-bytes
  "
  "      <digest_hex_string>
  "
  "  pcr_read index addr count
  "
  "    - Read <count> bytes from PCR <index> to memory address <addr>.
  "
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
  #ifdef CONFIG_TPM_AUTH_SESSIONS
  "Authorization Sessions
  "
  "  oiap
  "
  "    - setup an OIAP session
  "
  "  end_oiap
  "
  "    - terminates an active OIAP session
  "
  #endif /* CONFIG_TPM_AUTH_SESSIONS */
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
  "Non-volatile Storage Commands:
  "
  "  nv_define_space index permission size
  "
  "    - Establish a space at index <index> with <permission> of <size> bytes.
  "
  "  nv_read_value index addr count
  "
  "    - Read <count> bytes from space <index> to memory address <addr>.
  "
  "  nv_write_value index addr count
  "
  "    - Write <count> bytes from memory address <addr> to space <index>.
  "
  "Miscellaneous helper functions:
  "
  "  raw_transfer byte_string
  "
  "    - Send a byte string <byte_string> to TPM and print the response.
  "
  " Non-volatile storage helper functions:
  "
  "    These helper functions treat a non-volatile space as a non-padded
  "
  "    sequence of integer values.  These integer values are defined by a type
  "
  "    string, which is a text string of 'bwd' characters: 'b' means a 8-bit
  "
  "    value, 'w' 16-bit value, 'd' 32-bit value.  All helper functions take
  "
  "    a type string as their first argument.
  "
  "  nv_define type_string index perm
  "
  "    - Define a space <index> with permission <perm>.
  "
  "  nv_read types_string index vars...
  "
  "    - Read from space <index> to environment variables <vars...>.
  "
  "  nv_write types_string index values...
  "
  "    - Write to space <index> from values <values...>.
  "
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
1092
  );