Blame view

cmd/tpm-v1.c 21.2 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
576fb1ed3   Vadim Bendebury   Add a cli command...
2
  /*
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
3
   * Copyright (c) 2013 The Chromium OS Authors.
576fb1ed3   Vadim Bendebury   Add a cli command...
4
5
6
   */
  
  #include <common.h>
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
7
  #include <malloc.h>
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
8
  #include <asm/unaligned.h>
d677bfe2f   Miquel Raynal   tpm: disociate TP...
9
10
11
  #include <tpm-common.h>
  #include <tpm-v1.h>
  #include "tpm-user-utils.h"
576fb1ed3   Vadim Bendebury   Add a cli command...
12

c61791876   Miquel Raynal   tpm: align argume...
13
14
  static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag, int argc,
  			  char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
15
16
  {
  	enum tpm_startup_type mode;
abdc7b8a2   Simon Glass   tpm: Convert to u...
17
18
  	struct udevice *dev;
  	int rc;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
19

abdc7b8a2   Simon Glass   tpm: Convert to u...
20
21
22
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
23
24
25
26
27
28
29
30
31
32
33
34
35
  	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;
  	}
abdc7b8a2   Simon Glass   tpm: Convert to u...
36
  	return report_return_code(tpm_startup(dev, mode));
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
37
  }
c61791876   Miquel Raynal   tpm: align argume...
38
39
  static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag, int argc,
  				  char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
40
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
41
  	u32 index, perm, size;
abdc7b8a2   Simon Glass   tpm: Convert to u...
42
43
44
45
46
47
  	struct udevice *dev;
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
48
49
50
51
52
53
  
  	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);
abdc7b8a2   Simon Glass   tpm: Convert to u...
54
  	return report_return_code(tpm_nv_define_space(dev, index, perm, size));
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
55
  }
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
56

c61791876   Miquel Raynal   tpm: align argume...
57
58
  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...
59
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
60
  	u32 index, count, rc;
abdc7b8a2   Simon Glass   tpm: Convert to u...
61
  	struct udevice *dev;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
62
  	void *data;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
63

abdc7b8a2   Simon Glass   tpm: Convert to u...
64
65
66
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
67
68
69
70
71
  	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);
abdc7b8a2   Simon Glass   tpm: Convert to u...
72
  	rc = tpm_nv_read_value(dev, index, data, count);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
73
74
75
76
  	if (!rc) {
  		puts("area content:
  ");
  		print_byte_string(data, count);
576fb1ed3   Vadim Bendebury   Add a cli command...
77
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
78
  	return report_return_code(rc);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
79
  }
c61791876   Miquel Raynal   tpm: align argume...
80
81
  static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag, int argc,
  				 char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
82
  {
abdc7b8a2   Simon Glass   tpm: Convert to u...
83
  	struct udevice *dev;
b9804e5bf   Miquel Raynal   tpm: substitute d...
84
  	u32 index, rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
85
86
  	size_t count;
  	void *data;
abdc7b8a2   Simon Glass   tpm: Convert to u...
87
88
89
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
90
91
92
93
94
95
96
97
  	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...
98
  	}
abdc7b8a2   Simon Glass   tpm: Convert to u...
99
  	rc = tpm_nv_write_value(dev, index, data, count);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
100
  	free(data);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
101
  	return report_return_code(rc);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
102
  }
c61791876   Miquel Raynal   tpm: align argume...
103
104
  static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag, int argc,
  			 char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
105
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
106
  	u8 in_digest[20], out_digest[20];
abdc7b8a2   Simon Glass   tpm: Convert to u...
107
108
109
110
111
112
  	struct udevice *dev;
  	u32 index, rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
113
114
115
116
117
118
119
120
  
  	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...
121
  	}
abdc7b8a2   Simon Glass   tpm: Convert to u...
122
  	rc = tpm_extend(dev, index, in_digest, out_digest);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
123
124
125
126
  	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...
127
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
128
  	return report_return_code(rc);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
129
  }
c61791876   Miquel Raynal   tpm: align argume...
130
131
  static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
  			   char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
132
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
133
  	u32 index, count, rc;
abdc7b8a2   Simon Glass   tpm: Convert to u...
134
  	struct udevice *dev;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
135
  	void *data;
abdc7b8a2   Simon Glass   tpm: Convert to u...
136
137
138
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
139
140
141
142
143
  	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...
144

abdc7b8a2   Simon Glass   tpm: Convert to u...
145
  	rc = tpm_pcr_read(dev, index, data, count);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
146
147
148
149
  	if (!rc) {
  		puts("Named PCR content:
  ");
  		print_byte_string(data, count);
576fb1ed3   Vadim Bendebury   Add a cli command...
150
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
151
  	return report_return_code(rc);
576fb1ed3   Vadim Bendebury   Add a cli command...
152
  }
c61791876   Miquel Raynal   tpm: align argume...
153
154
  static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag, int argc,
  					char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
155
  {
abdc7b8a2   Simon Glass   tpm: Convert to u...
156
  	struct udevice *dev;
b9804e5bf   Miquel Raynal   tpm: substitute d...
157
  	u16 presence;
abdc7b8a2   Simon Glass   tpm: Convert to u...
158
159
160
161
162
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
163
164
165
  
  	if (argc != 2)
  		return CMD_RET_USAGE;
b9804e5bf   Miquel Raynal   tpm: substitute d...
166
  	presence = (u16)simple_strtoul(argv[1], NULL, 0);
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
167

abdc7b8a2   Simon Glass   tpm: Convert to u...
168
  	return report_return_code(tpm_tsc_physical_presence(dev, presence));
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
169
  }
c61791876   Miquel Raynal   tpm: align argume...
170
171
  static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag, int argc,
  			     char * const argv[])
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
172
  {
abdc7b8a2   Simon Glass   tpm: Convert to u...
173
  	struct udevice *dev;
b9804e5bf   Miquel Raynal   tpm: substitute d...
174
  	u32 count, rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
175
  	void *data;
abdc7b8a2   Simon Glass   tpm: Convert to u...
176
177
178
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
179
180
181
182
  	if (argc != 3)
  		return CMD_RET_USAGE;
  	data = (void *)simple_strtoul(argv[1], NULL, 0);
  	count = simple_strtoul(argv[2], NULL, 0);
abdc7b8a2   Simon Glass   tpm: Convert to u...
183
  	rc = tpm_read_pubek(dev, data, count);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
184
185
186
187
188
  	if (!rc) {
  		puts("pubek value:
  ");
  		print_byte_string(data, count);
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
189
  	return report_return_code(rc);
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
190
  }
c61791876   Miquel Raynal   tpm: align argume...
191
192
  static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag, int argc,
  					   char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
193
  {
abdc7b8a2   Simon Glass   tpm: Convert to u...
194
  	struct udevice *dev;
b9804e5bf   Miquel Raynal   tpm: substitute d...
195
  	u8 state;
abdc7b8a2   Simon Glass   tpm: Convert to u...
196
197
198
199
200
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
201
202
203
  
  	if (argc != 2)
  		return CMD_RET_USAGE;
b9804e5bf   Miquel Raynal   tpm: substitute d...
204
  	state = (u8)simple_strtoul(argv[1], NULL, 0);
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
205

abdc7b8a2   Simon Glass   tpm: Convert to u...
206
  	return report_return_code(tpm_physical_set_deactivated(dev, state));
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
207
  }
c61791876   Miquel Raynal   tpm: align argume...
208
209
  static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
  				 char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
210
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
211
  	u32 cap_area, sub_cap, rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
212
213
  	void *cap;
  	size_t count;
abdc7b8a2   Simon Glass   tpm: Convert to u...
214
215
216
217
218
  	struct udevice *dev;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
219
220
221
222
223
224
225
  
  	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);
abdc7b8a2   Simon Glass   tpm: Convert to u...
226
  	rc = tpm_get_capability(dev, cap_area, sub_cap, cap, count);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
227
228
229
230
231
  	if (!rc) {
  		puts("capability information:
  ");
  		print_byte_string(cap, count);
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
232
  	return report_return_code(rc);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
233
  }
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
234

c61791876   Miquel Raynal   tpm: align argume...
235
236
  static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag, int argc,
  			       char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
237
  {
c2b0f600a   Christophe Ricard   dm: tpm: Remove e...
238
  	struct udevice *dev;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
239
  	void *command;
b9804e5bf   Miquel Raynal   tpm: substitute d...
240
  	u8 response[1024];
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
241
  	size_t count, response_length = sizeof(response);
b9804e5bf   Miquel Raynal   tpm: substitute d...
242
  	u32 rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
243
244
245
246
247
248
249
  
  	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 ...
250
251
252
253
254
  	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...
255
256
257
258
259
260
  	free(command);
  	if (!rc) {
  		puts("tpm response:
  ");
  		print_byte_string(response, response_length);
  	}
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
261
  	return report_return_code(rc);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
262
  }
c61791876   Miquel Raynal   tpm: align argume...
263
264
  static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag, int argc,
  			    char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
265
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
266
  	u32 index, perm, size;
abdc7b8a2   Simon Glass   tpm: Convert to u...
267
268
269
270
271
272
  	struct udevice *dev;
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
273
274
275
276
277
278
279
280
281
282
283
  
  	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);
abdc7b8a2   Simon Glass   tpm: Convert to u...
284
  	return report_return_code(tpm_nv_define_space(dev, index, perm, size));
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
285
  }
c61791876   Miquel Raynal   tpm: align argume...
286
287
  static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag, int argc,
  			  char * const argv[])
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
288
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
289
  	u32 index, count, err;
abdc7b8a2   Simon Glass   tpm: Convert to u...
290
  	struct udevice *dev;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
291
  	void *data;
abdc7b8a2   Simon Glass   tpm: Convert to u...
292
293
294
295
296
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
297

8732b0700   Che-liang Chiou   tpm: Add TPM comm...
298
299
300
301
302
303
304
305
306
307
  	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...
308
  	}
abdc7b8a2   Simon Glass   tpm: Convert to u...
309
  	err = tpm_nv_read_value(dev, index, data, count);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
310
311
312
313
314
315
  	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...
316
  	}
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
317
  	free(data);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
318
  	return report_return_code(err);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
319
  }
c61791876   Miquel Raynal   tpm: align argume...
320
321
  static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag, int argc,
  			   char * const argv[])
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
322
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
323
  	u32 index, count, err;
abdc7b8a2   Simon Glass   tpm: Convert to u...
324
  	struct udevice *dev;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
325
  	void *data;
abdc7b8a2   Simon Glass   tpm: Convert to u...
326
327
328
329
330
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
  
  	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;
  	}
abdc7b8a2   Simon Glass   tpm: Convert to u...
349
  	err = tpm_nv_write_value(dev, index, data, count);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
350
  	free(data);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
351
  	return report_return_code(err);
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
352
  }
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
353
  #ifdef CONFIG_TPM_AUTH_SESSIONS
c61791876   Miquel Raynal   tpm: align argume...
354
355
  static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
  		       char * const argv[])
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
356
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
357
  	u32 auth_handle, err;
abdc7b8a2   Simon Glass   tpm: Convert to u...
358
359
360
361
362
363
  	struct udevice *dev;
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
364

abdc7b8a2   Simon Glass   tpm: Convert to u...
365
  	err = tpm_oiap(dev, &auth_handle);
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
366

f8f1fe1d5   Simon Glass   tpm: Report tpm e...
367
  	return report_return_code(err);
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
368
  }
0f4b2ba17   mario.six@gdsys.cc   tpm: Add function...
369
370
371
372
  #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[])
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
373
374
375
376
  	u32 parent_handle = 0;
  	u32 key_len, key_handle, err;
  	u8 usage_auth[DIGEST_LENGTH];
  	u8 parent_hash[DIGEST_LENGTH];
0f4b2ba17   mario.six@gdsys.cc   tpm: Add function...
377
  	void *key;
abdc7b8a2   Simon Glass   tpm: Convert to u...
378
379
380
381
382
  	struct udevice *dev;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
0f4b2ba17   mario.six@gdsys.cc   tpm: Add function...
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
  
  	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...
409
  		env_set_hex("key_handle", key_handle);
0f4b2ba17   mario.six@gdsys.cc   tpm: Add function...
410
411
412
413
414
  	}
  
  	return report_return_code(err);
  }
  #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
c61791876   Miquel Raynal   tpm: align argume...
415
416
  static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
  				 char * const argv[])
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
417
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
418
419
  	u32 parent_handle, key_len, key_handle, err;
  	u8 usage_auth[DIGEST_LENGTH];
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
420
  	void *key;
abdc7b8a2   Simon Glass   tpm: Convert to u...
421
422
423
424
425
426
  	struct udevice *dev;
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
427
428
429
430
431
432
433
434
435
436
  
  	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);
abdc7b8a2   Simon Glass   tpm: Convert to u...
437
  	err = tpm_load_key2_oiap(dev, parent_handle, key, key_len, usage_auth,
c61791876   Miquel Raynal   tpm: align argume...
438
  				 &key_handle);
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
439
440
441
  	if (!err)
  		printf("Key handle is 0x%x
  ", key_handle);
f8f1fe1d5   Simon Glass   tpm: Report tpm e...
442
  	return report_return_code(err);
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
443
  }
c61791876   Miquel Raynal   tpm: align argume...
444
445
  static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
  				   char * const argv[])
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
446
  {
b9804e5bf   Miquel Raynal   tpm: substitute d...
447
448
449
  	u32 key_handle, err;
  	u8 usage_auth[DIGEST_LENGTH];
  	u8 pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
450
  	size_t pub_key_len = sizeof(pub_key_buffer);
abdc7b8a2   Simon Glass   tpm: Convert to u...
451
452
453
454
455
456
  	struct udevice *dev;
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
457
458
459
460
461
462
463
464
  
  	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);
abdc7b8a2   Simon Glass   tpm: Convert to u...
465
  	err = tpm_get_pub_key_oiap(dev, key_handle, usage_auth, pub_key_buffer,
c61791876   Miquel Raynal   tpm: align argume...
466
  				   &pub_key_len);
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
467
468
469
470
471
  	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...
472
  	return report_return_code(err);
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
473
474
475
476
477
  }
  
  TPM_COMMAND_NO_ARG(tpm_end_oiap)
  
  #endif /* CONFIG_TPM_AUTH_SESSIONS */
7690be35d   Mario Six   lib: tpm: Add com...
478
479
480
481
  #ifdef CONFIG_TPM_FLUSH_RESOURCES
  static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc,
  			char * const argv[])
  {
abdc7b8a2   Simon Glass   tpm: Convert to u...
482
  	struct udevice *dev;
7690be35d   Mario Six   lib: tpm: Add com...
483
  	int type = 0;
abdc7b8a2   Simon Glass   tpm: Convert to u...
484
485
486
487
488
  	int rc;
  
  	rc = get_tpm(&dev);
  	if (rc)
  		return rc;
7690be35d   Mario Six   lib: tpm: Add com...
489

1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
490
  	if (argc != 3)
7690be35d   Mario Six   lib: tpm: Add com...
491
  		return CMD_RET_USAGE;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
492
  	if (!strcasecmp(argv[1], "key"))
7690be35d   Mario Six   lib: tpm: Add com...
493
  		type = TPM_RT_KEY;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
494
  	else if (!strcasecmp(argv[1], "auth"))
7690be35d   Mario Six   lib: tpm: Add com...
495
  		type = TPM_RT_AUTH;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
496
  	else if (!strcasecmp(argv[1], "hash"))
7690be35d   Mario Six   lib: tpm: Add com...
497
  		type = TPM_RT_HASH;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
498
  	else if (!strcasecmp(argv[1], "trans"))
7690be35d   Mario Six   lib: tpm: Add com...
499
  		type = TPM_RT_TRANS;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
500
  	else if (!strcasecmp(argv[1], "context"))
7690be35d   Mario Six   lib: tpm: Add com...
501
  		type = TPM_RT_CONTEXT;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
502
  	else if (!strcasecmp(argv[1], "counter"))
7690be35d   Mario Six   lib: tpm: Add com...
503
  		type = TPM_RT_COUNTER;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
504
  	else if (!strcasecmp(argv[1], "delegate"))
7690be35d   Mario Six   lib: tpm: Add com...
505
  		type = TPM_RT_DELEGATE;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
506
  	else if (!strcasecmp(argv[1], "daa_tpm"))
7690be35d   Mario Six   lib: tpm: Add com...
507
  		type = TPM_RT_DAA_TPM;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
508
  	else if (!strcasecmp(argv[1], "daa_v0"))
7690be35d   Mario Six   lib: tpm: Add com...
509
  		type = TPM_RT_DAA_V0;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
510
  	else if (!strcasecmp(argv[1], "daa_v1"))
7690be35d   Mario Six   lib: tpm: Add com...
511
  		type = TPM_RT_DAA_V1;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
512
513
514
515
516
517
518
  	if (!type) {
  		printf("Resource type %s unknown.
  ", argv[1]);
  		return -1;
  	}
  
  	if (!strcasecmp(argv[2], "all")) {
b9804e5bf   Miquel Raynal   tpm: substitute d...
519
520
521
  		u16 res_count;
  		u8 buf[288];
  		u8 *ptr;
7690be35d   Mario Six   lib: tpm: Add com...
522
523
524
525
  		int err;
  		uint i;
  
  		/* fetch list of already loaded resources in the TPM */
abdc7b8a2   Simon Glass   tpm: Convert to u...
526
  		err = tpm_get_capability(dev, TPM_CAP_HANDLE, type, buf,
7690be35d   Mario Six   lib: tpm: Add com...
527
  					 sizeof(buf));
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
528
529
530
  		if (err) {
  			printf("tpm_get_capability returned error %d.
  ", err);
7690be35d   Mario Six   lib: tpm: Add com...
531
  			return -1;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
532
  		}
7690be35d   Mario Six   lib: tpm: Add com...
533
534
535
  		res_count = get_unaligned_be16(buf);
  		ptr = buf + 2;
  		for (i = 0; i < res_count; ++i, ptr += 4)
abdc7b8a2   Simon Glass   tpm: Convert to u...
536
  			tpm_flush_specific(dev, get_unaligned_be32(ptr), type);
7690be35d   Mario Six   lib: tpm: Add com...
537
  	} else {
b9804e5bf   Miquel Raynal   tpm: substitute d...
538
  		u32 handle = simple_strtoul(argv[2], NULL, 0);
7690be35d   Mario Six   lib: tpm: Add com...
539

1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
540
541
542
  		if (!handle) {
  			printf("Illegal resource handle %s
  ", argv[2]);
7690be35d   Mario Six   lib: tpm: Add com...
543
  			return -1;
1c08b210a   mario.six@gdsys.cc   cmd: tpm: Fix flu...
544
  		}
abdc7b8a2   Simon Glass   tpm: Convert to u...
545
  		tpm_flush_specific(dev, cpu_to_be32(handle), type);
7690be35d   Mario Six   lib: tpm: Add com...
546
547
548
549
550
  	}
  
  	return 0;
  }
  #endif /* CONFIG_TPM_FLUSH_RESOURCES */
3d1df0e36   mario.six@gdsys.cc   lib: tpm: Add com...
551
552
553
554
555
  #ifdef CONFIG_TPM_LIST_RESOURCES
  static int do_tpm_list(cmd_tbl_t *cmdtp, int flag, int argc,
  		       char * const argv[])
  {
  	int type = 0;
b9804e5bf   Miquel Raynal   tpm: substitute d...
556
557
558
  	u16 res_count;
  	u8 buf[288];
  	u8 *ptr;
3d1df0e36   mario.six@gdsys.cc   lib: tpm: Add com...
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
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
  	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 */
d677bfe2f   Miquel Raynal   tpm: disociate TP...
617
618
619
620
621
  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)
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
622

d677bfe2f   Miquel Raynal   tpm: disociate TP...
623
  static cmd_tbl_t tpm1_commands[] = {
ad77694e2   Simon Glass   tpm: Add a 'tpm i...
624
  	U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
c61791876   Miquel Raynal   tpm: align argume...
625
  	U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
626
  	U_BOOT_CMD_MKENT(startup, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
627
  			 do_tpm_startup, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
628
  	U_BOOT_CMD_MKENT(self_test_full, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
629
  			 do_tpm_self_test_full, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
630
  	U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
631
  			 do_tpm_continue_self_test, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
632
  	U_BOOT_CMD_MKENT(force_clear, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
633
  			 do_tpm_force_clear, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
634
  	U_BOOT_CMD_MKENT(physical_enable, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
635
  			 do_tpm_physical_enable, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
636
  	U_BOOT_CMD_MKENT(physical_disable, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
637
  			 do_tpm_physical_disable, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
638
  	U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
639
  			 do_tpm_nv_define_space, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
640
  	U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
641
  			 do_tpm_nv_read_value, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
642
  	U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
643
  			 do_tpm_nv_write_value, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
644
  	U_BOOT_CMD_MKENT(extend, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
645
  			 do_tpm_extend, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
646
  	U_BOOT_CMD_MKENT(pcr_read, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
647
  			 do_tpm_pcr_read, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
648
  	U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
649
  			 do_tpm_tsc_physical_presence, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
650
  	U_BOOT_CMD_MKENT(read_pubek, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
651
  			 do_tpm_read_pubek, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
652
  	U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
653
  			 do_tpm_physical_set_deactivated, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
654
  	U_BOOT_CMD_MKENT(get_capability, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
655
  			 do_tpm_get_capability, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
656
  	U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
657
  			 do_tpm_raw_transfer, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
658
  	U_BOOT_CMD_MKENT(nv_define, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
659
  			 do_tpm_nv_define, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
660
  	U_BOOT_CMD_MKENT(nv_read, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
661
  			 do_tpm_nv_read, "", ""),
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
662
  	U_BOOT_CMD_MKENT(nv_write, 0, 1,
c61791876   Miquel Raynal   tpm: align argume...
663
  			 do_tpm_nv_write, "", ""),
be6c1529c   Reinhard Pfau   tpm: add AUTH1 cm...
664
665
666
667
668
669
670
  #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...
671
672
673
674
  #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...
675
676
677
  	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...
678
679
680
681
  #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...
682
683
684
685
  #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...
686
  };
2a2096ea6   Miquel Raynal   tpm: allow TPM v1...
687
  cmd_tbl_t *get_tpm1_commands(unsigned int *size)
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
688
  {
d677bfe2f   Miquel Raynal   tpm: disociate TP...
689
  	*size = ARRAY_SIZE(tpm1_commands);
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
690

d677bfe2f   Miquel Raynal   tpm: disociate TP...
691
  	return tpm1_commands;
eea3f4d3e   Luigi Semenzato   tpm: Add TPM stre...
692
  }
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
693
  U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
d677bfe2f   Miquel Raynal   tpm: disociate TP...
694
  "Issue a TPMv1.x command",
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
695
696
697
698
699
700
  "cmd args...
  "
  "    - Issue TPM command <cmd> with arguments <args...>.
  "
  "Admin Startup and State Commands:
  "
ad77694e2   Simon Glass   tpm: Add a 'tpm i...
701
702
  "  info - Show information about the TPM
  "
8732b0700   Che-liang Chiou   tpm: Add TPM comm...
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
  "  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...
759
  #if defined(CONFIG_TPM_FLUSH_RESOURCES) || defined(CONFIG_TPM_LIST_RESOURCES)
7690be35d   Mario Six   lib: tpm: Add com...
760
761
  "Resource management functions
  "
3d1df0e36   mario.six@gdsys.cc   lib: tpm: Add com...
762
763
  #endif
  #ifdef CONFIG_TPM_FLUSH_RESOURCES
7690be35d   Mario Six   lib: tpm: Add com...
764
765
766
767
768
769
770
771
772
773
774
  "  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...
775
776
777
778
779
780
781
782
783
784
  #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...
785
786
787
788
789
790
791
792
793
794
795
  #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...
796
797
798
799
800
801
802
803
804
805
  #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...
806
807
808
809
810
811
812
  "  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...
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
  "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...
833
834
835
836
837
838
839
840
841
842
843
844
  #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...
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
  "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...
889
  );