blob: 0efb079b0a9b73aa57068404fbfba6fe61d9c6b4 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vadim Bendebury576fb1e2011-10-15 15:13:34 +00002/*
Che-liang Chiou8732b072013-02-28 09:34:57 +00003 * Copyright (c) 2013 The Chromium OS Authors.
Vadim Bendebury576fb1e2011-10-15 15:13:34 +00004 */
5
6#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -06007#include <command.h>
Simon Glassc7694dd2019-08-01 09:46:46 -06008#include <env.h>
Che-liang Chiou8732b072013-02-28 09:34:57 +00009#include <malloc.h>
Che-liang Chiou8732b072013-02-28 09:34:57 +000010#include <asm/unaligned.h>
Miquel Raynald677bfe2018-05-15 11:57:06 +020011#include <tpm-common.h>
12#include <tpm-v1.h>
13#include "tpm-user-utils.h"
Simon Glassd6a885f2021-02-06 14:23:36 -070014#include <tpm_api.h>
Che-liang Chiou8732b072013-02-28 09:34:57 +000015
Simon Glass09140112020-05-10 11:40:03 -060016static int do_tpm_startup(struct cmd_tbl *cmdtp, int flag, int argc,
17 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +000018{
19 enum tpm_startup_type mode;
Simon Glassabdc7b82018-11-18 14:22:27 -070020 struct udevice *dev;
21 int rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +000022
Simon Glassabdc7b82018-11-18 14:22:27 -070023 rc = get_tpm(&dev);
24 if (rc)
25 return rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +000026 if (argc != 2)
27 return CMD_RET_USAGE;
28 if (!strcasecmp("TPM_ST_CLEAR", argv[1])) {
29 mode = TPM_ST_CLEAR;
30 } else if (!strcasecmp("TPM_ST_STATE", argv[1])) {
31 mode = TPM_ST_STATE;
32 } else if (!strcasecmp("TPM_ST_DEACTIVATED", argv[1])) {
33 mode = TPM_ST_DEACTIVATED;
34 } else {
35 printf("Couldn't recognize mode string: %s\n", argv[1]);
36 return CMD_RET_FAILURE;
37 }
38
Simon Glassabdc7b82018-11-18 14:22:27 -070039 return report_return_code(tpm_startup(dev, mode));
Che-liang Chiou8732b072013-02-28 09:34:57 +000040}
41
Simon Glass09140112020-05-10 11:40:03 -060042static int do_tpm_nv_define_space(struct cmd_tbl *cmdtp, int flag, int argc,
43 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +000044{
Miquel Raynalb9804e52018-05-15 11:56:59 +020045 u32 index, perm, size;
Simon Glassabdc7b82018-11-18 14:22:27 -070046 struct udevice *dev;
47 int rc;
48
49 rc = get_tpm(&dev);
50 if (rc)
51 return rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +000052
53 if (argc != 4)
54 return CMD_RET_USAGE;
55 index = simple_strtoul(argv[1], NULL, 0);
56 perm = simple_strtoul(argv[2], NULL, 0);
57 size = simple_strtoul(argv[3], NULL, 0);
58
Simon Glassd6a885f2021-02-06 14:23:36 -070059 return report_return_code(tpm1_nv_define_space(dev, index, perm, size));
Che-liang Chiou8732b072013-02-28 09:34:57 +000060}
61
Simon Glass09140112020-05-10 11:40:03 -060062static int do_tpm_nv_read_value(struct cmd_tbl *cmdtp, int flag, int argc,
63 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +000064{
Miquel Raynalb9804e52018-05-15 11:56:59 +020065 u32 index, count, rc;
Simon Glassabdc7b82018-11-18 14:22:27 -070066 struct udevice *dev;
Che-liang Chiou8732b072013-02-28 09:34:57 +000067 void *data;
68
Simon Glassabdc7b82018-11-18 14:22:27 -070069 rc = get_tpm(&dev);
70 if (rc)
71 return rc;
72
Che-liang Chiou8732b072013-02-28 09:34:57 +000073 if (argc != 4)
74 return CMD_RET_USAGE;
75 index = simple_strtoul(argv[1], NULL, 0);
76 data = (void *)simple_strtoul(argv[2], NULL, 0);
77 count = simple_strtoul(argv[3], NULL, 0);
78
Simon Glassabdc7b82018-11-18 14:22:27 -070079 rc = tpm_nv_read_value(dev, index, data, count);
Che-liang Chiou8732b072013-02-28 09:34:57 +000080 if (!rc) {
81 puts("area content:\n");
82 print_byte_string(data, count);
83 }
84
Simon Glassf8f1fe12015-08-22 18:31:34 -060085 return report_return_code(rc);
Che-liang Chiou8732b072013-02-28 09:34:57 +000086}
87
Simon Glass09140112020-05-10 11:40:03 -060088static int do_tpm_nv_write_value(struct cmd_tbl *cmdtp, int flag, int argc,
89 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +000090{
Simon Glassabdc7b82018-11-18 14:22:27 -070091 struct udevice *dev;
Miquel Raynalb9804e52018-05-15 11:56:59 +020092 u32 index, rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +000093 size_t count;
94 void *data;
95
Simon Glassabdc7b82018-11-18 14:22:27 -070096 rc = get_tpm(&dev);
97 if (rc)
98 return rc;
99
Che-liang Chiou8732b072013-02-28 09:34:57 +0000100 if (argc != 3)
101 return CMD_RET_USAGE;
102 index = simple_strtoul(argv[1], NULL, 0);
103 data = parse_byte_string(argv[2], NULL, &count);
104 if (!data) {
105 printf("Couldn't parse byte string %s\n", argv[2]);
106 return CMD_RET_FAILURE;
107 }
108
Simon Glassabdc7b82018-11-18 14:22:27 -0700109 rc = tpm_nv_write_value(dev, index, data, count);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000110 free(data);
111
Simon Glassf8f1fe12015-08-22 18:31:34 -0600112 return report_return_code(rc);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000113}
114
Simon Glass09140112020-05-10 11:40:03 -0600115static int do_tpm_extend(struct cmd_tbl *cmdtp, int flag, int argc,
116 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +0000117{
Miquel Raynalb9804e52018-05-15 11:56:59 +0200118 u8 in_digest[20], out_digest[20];
Simon Glassabdc7b82018-11-18 14:22:27 -0700119 struct udevice *dev;
120 u32 index, rc;
121
122 rc = get_tpm(&dev);
123 if (rc)
124 return rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000125
126 if (argc != 3)
127 return CMD_RET_USAGE;
128 index = simple_strtoul(argv[1], NULL, 0);
129 if (!parse_byte_string(argv[2], in_digest, NULL)) {
130 printf("Couldn't parse byte string %s\n", argv[2]);
131 return CMD_RET_FAILURE;
132 }
133
Simon Glassa557d252022-08-30 21:05:32 -0600134 rc = tpm_pcr_extend(dev, index, in_digest, sizeof(in_digest),
135 out_digest, "cmd");
Che-liang Chiou8732b072013-02-28 09:34:57 +0000136 if (!rc) {
137 puts("PCR value after execution of the command:\n");
138 print_byte_string(out_digest, sizeof(out_digest));
139 }
140
Simon Glassf8f1fe12015-08-22 18:31:34 -0600141 return report_return_code(rc);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000142}
143
Simon Glass09140112020-05-10 11:40:03 -0600144static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc,
145 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +0000146{
Miquel Raynalb9804e52018-05-15 11:56:59 +0200147 u32 index, count, rc;
Simon Glassabdc7b82018-11-18 14:22:27 -0700148 struct udevice *dev;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000149 void *data;
150
Simon Glassabdc7b82018-11-18 14:22:27 -0700151 rc = get_tpm(&dev);
152 if (rc)
153 return rc;
154
Che-liang Chiou8732b072013-02-28 09:34:57 +0000155 if (argc != 4)
156 return CMD_RET_USAGE;
157 index = simple_strtoul(argv[1], NULL, 0);
158 data = (void *)simple_strtoul(argv[2], NULL, 0);
159 count = simple_strtoul(argv[3], NULL, 0);
160
Simon Glassabdc7b82018-11-18 14:22:27 -0700161 rc = tpm_pcr_read(dev, index, data, count);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000162 if (!rc) {
163 puts("Named PCR content:\n");
164 print_byte_string(data, count);
165 }
166
Simon Glassf8f1fe12015-08-22 18:31:34 -0600167 return report_return_code(rc);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000168}
169
Simon Glass09140112020-05-10 11:40:03 -0600170static int do_tpm_tsc_physical_presence(struct cmd_tbl *cmdtp, int flag,
171 int argc, char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +0000172{
Simon Glassabdc7b82018-11-18 14:22:27 -0700173 struct udevice *dev;
Miquel Raynalb9804e52018-05-15 11:56:59 +0200174 u16 presence;
Simon Glassabdc7b82018-11-18 14:22:27 -0700175 int rc;
176
177 rc = get_tpm(&dev);
178 if (rc)
179 return rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000180
181 if (argc != 2)
182 return CMD_RET_USAGE;
Miquel Raynalb9804e52018-05-15 11:56:59 +0200183 presence = (u16)simple_strtoul(argv[1], NULL, 0);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000184
Simon Glassabdc7b82018-11-18 14:22:27 -0700185 return report_return_code(tpm_tsc_physical_presence(dev, presence));
Che-liang Chiou8732b072013-02-28 09:34:57 +0000186}
187
Simon Glass09140112020-05-10 11:40:03 -0600188static int do_tpm_read_pubek(struct cmd_tbl *cmdtp, int flag, int argc,
189 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +0000190{
Simon Glassabdc7b82018-11-18 14:22:27 -0700191 struct udevice *dev;
Miquel Raynalb9804e52018-05-15 11:56:59 +0200192 u32 count, rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000193 void *data;
194
Simon Glassabdc7b82018-11-18 14:22:27 -0700195 rc = get_tpm(&dev);
196 if (rc)
197 return rc;
198
Che-liang Chiou8732b072013-02-28 09:34:57 +0000199 if (argc != 3)
200 return CMD_RET_USAGE;
201 data = (void *)simple_strtoul(argv[1], NULL, 0);
202 count = simple_strtoul(argv[2], NULL, 0);
203
Simon Glassabdc7b82018-11-18 14:22:27 -0700204 rc = tpm_read_pubek(dev, data, count);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000205 if (!rc) {
206 puts("pubek value:\n");
207 print_byte_string(data, count);
208 }
209
Simon Glassf8f1fe12015-08-22 18:31:34 -0600210 return report_return_code(rc);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000211}
212
Simon Glass09140112020-05-10 11:40:03 -0600213static int do_tpm_physical_set_deactivated(struct cmd_tbl *cmdtp, int flag,
214 int argc, char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +0000215{
Simon Glassabdc7b82018-11-18 14:22:27 -0700216 struct udevice *dev;
Miquel Raynalb9804e52018-05-15 11:56:59 +0200217 u8 state;
Simon Glassabdc7b82018-11-18 14:22:27 -0700218 int rc;
219
220 rc = get_tpm(&dev);
221 if (rc)
222 return rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000223
224 if (argc != 2)
225 return CMD_RET_USAGE;
Miquel Raynalb9804e52018-05-15 11:56:59 +0200226 state = (u8)simple_strtoul(argv[1], NULL, 0);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000227
Simon Glassabdc7b82018-11-18 14:22:27 -0700228 return report_return_code(tpm_physical_set_deactivated(dev, state));
Che-liang Chiou8732b072013-02-28 09:34:57 +0000229}
230
Simon Glass09140112020-05-10 11:40:03 -0600231static int do_tpm_get_capability(struct cmd_tbl *cmdtp, int flag, int argc,
232 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +0000233{
Miquel Raynalb9804e52018-05-15 11:56:59 +0200234 u32 cap_area, sub_cap, rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000235 void *cap;
236 size_t count;
Simon Glassabdc7b82018-11-18 14:22:27 -0700237 struct udevice *dev;
238
239 rc = get_tpm(&dev);
240 if (rc)
241 return rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000242
243 if (argc != 5)
244 return CMD_RET_USAGE;
245 cap_area = simple_strtoul(argv[1], NULL, 0);
246 sub_cap = simple_strtoul(argv[2], NULL, 0);
247 cap = (void *)simple_strtoul(argv[3], NULL, 0);
248 count = simple_strtoul(argv[4], NULL, 0);
249
Simon Glassabdc7b82018-11-18 14:22:27 -0700250 rc = tpm_get_capability(dev, cap_area, sub_cap, cap, count);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000251 if (!rc) {
252 puts("capability information:\n");
253 print_byte_string(cap, count);
254 }
255
Simon Glassf8f1fe12015-08-22 18:31:34 -0600256 return report_return_code(rc);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000257}
258
Simon Glass09140112020-05-10 11:40:03 -0600259static int do_tpm_raw_transfer(struct cmd_tbl *cmdtp, int flag, int argc,
260 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +0000261{
Christophe Ricardc2b0f602015-10-06 22:54:43 +0200262 struct udevice *dev;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000263 void *command;
Miquel Raynalb9804e52018-05-15 11:56:59 +0200264 u8 response[1024];
Che-liang Chiou8732b072013-02-28 09:34:57 +0000265 size_t count, response_length = sizeof(response);
Miquel Raynalb9804e52018-05-15 11:56:59 +0200266 u32 rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000267
268 command = parse_byte_string(argv[1], NULL, &count);
269 if (!command) {
270 printf("Couldn't parse byte string %s\n", argv[1]);
271 return CMD_RET_FAILURE;
272 }
273
Simon Glassc8a8c512015-08-22 18:31:32 -0600274 rc = get_tpm(&dev);
275 if (rc)
276 return rc;
277
278 rc = tpm_xfer(dev, command, count, response, &response_length);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000279 free(command);
280 if (!rc) {
281 puts("tpm response:\n");
282 print_byte_string(response, response_length);
283 }
284
Simon Glassf8f1fe12015-08-22 18:31:34 -0600285 return report_return_code(rc);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000286}
287
Simon Glass09140112020-05-10 11:40:03 -0600288static int do_tpm_nv_define(struct cmd_tbl *cmdtp, int flag, int argc,
289 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +0000290{
Miquel Raynalb9804e52018-05-15 11:56:59 +0200291 u32 index, perm, size;
Simon Glassabdc7b82018-11-18 14:22:27 -0700292 struct udevice *dev;
293 int rc;
294
295 rc = get_tpm(&dev);
296 if (rc)
297 return rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000298
299 if (argc != 4)
300 return CMD_RET_USAGE;
301 size = type_string_get_space_size(argv[1]);
302 if (!size) {
303 printf("Couldn't parse arguments\n");
304 return CMD_RET_USAGE;
305 }
306 index = simple_strtoul(argv[2], NULL, 0);
307 perm = simple_strtoul(argv[3], NULL, 0);
308
Simon Glassd6a885f2021-02-06 14:23:36 -0700309 return report_return_code(tpm1_nv_define_space(dev, index, perm, size));
Che-liang Chiou8732b072013-02-28 09:34:57 +0000310}
311
Simon Glass09140112020-05-10 11:40:03 -0600312static int do_tpm_nv_read(struct cmd_tbl *cmdtp, int flag, int argc,
313 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +0000314{
Miquel Raynalb9804e52018-05-15 11:56:59 +0200315 u32 index, count, err;
Simon Glassabdc7b82018-11-18 14:22:27 -0700316 struct udevice *dev;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000317 void *data;
Simon Glassabdc7b82018-11-18 14:22:27 -0700318 int rc;
319
320 rc = get_tpm(&dev);
321 if (rc)
322 return rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000323
324 if (argc < 3)
325 return CMD_RET_USAGE;
326 if (argc != 3 + type_string_get_num_values(argv[1]))
327 return CMD_RET_USAGE;
328 index = simple_strtoul(argv[2], NULL, 0);
329 data = type_string_alloc(argv[1], &count);
330 if (!data) {
331 printf("Couldn't parse arguments\n");
332 return CMD_RET_USAGE;
333 }
334
Simon Glassabdc7b82018-11-18 14:22:27 -0700335 err = tpm_nv_read_value(dev, index, data, count);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000336 if (!err) {
337 if (type_string_write_vars(argv[1], data, argv + 3)) {
338 printf("Couldn't write to variables\n");
339 err = ~0;
340 }
341 }
342 free(data);
343
Simon Glassf8f1fe12015-08-22 18:31:34 -0600344 return report_return_code(err);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000345}
346
Simon Glass09140112020-05-10 11:40:03 -0600347static int do_tpm_nv_write(struct cmd_tbl *cmdtp, int flag, int argc,
348 char *const argv[])
Che-liang Chiou8732b072013-02-28 09:34:57 +0000349{
Miquel Raynalb9804e52018-05-15 11:56:59 +0200350 u32 index, count, err;
Simon Glassabdc7b82018-11-18 14:22:27 -0700351 struct udevice *dev;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000352 void *data;
Simon Glassabdc7b82018-11-18 14:22:27 -0700353 int rc;
354
355 rc = get_tpm(&dev);
356 if (rc)
357 return rc;
Che-liang Chiou8732b072013-02-28 09:34:57 +0000358
359 if (argc < 3)
360 return CMD_RET_USAGE;
361 if (argc != 3 + type_string_get_num_values(argv[1]))
362 return CMD_RET_USAGE;
363 index = simple_strtoul(argv[2], NULL, 0);
364 data = type_string_alloc(argv[1], &count);
365 if (!data) {
366 printf("Couldn't parse arguments\n");
367 return CMD_RET_USAGE;
368 }
369 if (type_string_pack(argv[1], argv + 3, data)) {
370 printf("Couldn't parse arguments\n");
371 free(data);
372 return CMD_RET_USAGE;
373 }
374
Simon Glassabdc7b82018-11-18 14:22:27 -0700375 err = tpm_nv_write_value(dev, index, data, count);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000376 free(data);
377
Simon Glassf8f1fe12015-08-22 18:31:34 -0600378 return report_return_code(err);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000379}
380
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200381#ifdef CONFIG_TPM_AUTH_SESSIONS
382
Simon Glass09140112020-05-10 11:40:03 -0600383static int do_tpm_oiap(struct cmd_tbl *cmdtp, int flag, int argc,
384 char *const argv[])
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200385{
Miquel Raynalb9804e52018-05-15 11:56:59 +0200386 u32 auth_handle, err;
Simon Glassabdc7b82018-11-18 14:22:27 -0700387 struct udevice *dev;
388 int rc;
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200389
Simon Glassabdc7b82018-11-18 14:22:27 -0700390 rc = get_tpm(&dev);
391 if (rc)
392 return rc;
393
Simon Glassd6a885f2021-02-06 14:23:36 -0700394 err = tpm1_oiap(dev, &auth_handle);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200395
Simon Glassf8f1fe12015-08-22 18:31:34 -0600396 return report_return_code(err);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200397}
398
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100399#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
Simon Glass09140112020-05-10 11:40:03 -0600400static int do_tpm_load_key_by_sha1(struct cmd_tbl *cmdtp, int flag, int argc,
401 char *const argv[])
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100402{
Miquel Raynalb9804e52018-05-15 11:56:59 +0200403 u32 parent_handle = 0;
404 u32 key_len, key_handle, err;
405 u8 usage_auth[DIGEST_LENGTH];
406 u8 parent_hash[DIGEST_LENGTH];
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100407 void *key;
Simon Glassabdc7b82018-11-18 14:22:27 -0700408 struct udevice *dev;
409
Mathew McBridee845dd72021-11-11 04:06:27 +0000410 err = get_tpm(&dev);
411 if (err)
412 return err;
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100413
414 if (argc < 5)
415 return CMD_RET_USAGE;
416
417 parse_byte_string(argv[1], parent_hash, NULL);
418 key = (void *)simple_strtoul(argv[2], NULL, 0);
419 key_len = simple_strtoul(argv[3], NULL, 0);
420 if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
421 return CMD_RET_FAILURE;
422 parse_byte_string(argv[4], usage_auth, NULL);
423
Mathew McBridee845dd72021-11-11 04:06:27 +0000424 err = tpm1_find_key_sha1(dev, usage_auth, parent_hash, &parent_handle);
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100425 if (err) {
426 printf("Could not find matching parent key (err = %d)\n", err);
427 return CMD_RET_FAILURE;
428 }
429
430 printf("Found parent key %08x\n", parent_handle);
431
Mathew McBridee845dd72021-11-11 04:06:27 +0000432 err = tpm1_load_key2_oiap(dev, parent_handle, key, key_len, usage_auth,
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100433 &key_handle);
434 if (!err) {
435 printf("Key handle is 0x%x\n", key_handle);
Simon Glass018f5302017-08-03 12:22:10 -0600436 env_set_hex("key_handle", key_handle);
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100437 }
438
439 return report_return_code(err);
440}
441#endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
442
Simon Glass09140112020-05-10 11:40:03 -0600443static int do_tpm_load_key2_oiap(struct cmd_tbl *cmdtp, int flag, int argc,
444 char *const argv[])
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200445{
Miquel Raynalb9804e52018-05-15 11:56:59 +0200446 u32 parent_handle, key_len, key_handle, err;
447 u8 usage_auth[DIGEST_LENGTH];
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200448 void *key;
Simon Glassabdc7b82018-11-18 14:22:27 -0700449 struct udevice *dev;
450 int rc;
451
452 rc = get_tpm(&dev);
453 if (rc)
454 return rc;
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200455
456 if (argc < 5)
457 return CMD_RET_USAGE;
458
459 parent_handle = simple_strtoul(argv[1], NULL, 0);
460 key = (void *)simple_strtoul(argv[2], NULL, 0);
461 key_len = simple_strtoul(argv[3], NULL, 0);
462 if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
463 return CMD_RET_FAILURE;
464 parse_byte_string(argv[4], usage_auth, NULL);
465
Simon Glassd6a885f2021-02-06 14:23:36 -0700466 err = tpm1_load_key2_oiap(dev, parent_handle, key, key_len, usage_auth,
467 &key_handle);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200468 if (!err)
469 printf("Key handle is 0x%x\n", key_handle);
470
Simon Glassf8f1fe12015-08-22 18:31:34 -0600471 return report_return_code(err);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200472}
473
Simon Glass09140112020-05-10 11:40:03 -0600474static int do_tpm_get_pub_key_oiap(struct cmd_tbl *cmdtp, int flag, int argc,
475 char *const argv[])
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200476{
Miquel Raynalb9804e52018-05-15 11:56:59 +0200477 u32 key_handle, err;
478 u8 usage_auth[DIGEST_LENGTH];
479 u8 pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200480 size_t pub_key_len = sizeof(pub_key_buffer);
Simon Glassabdc7b82018-11-18 14:22:27 -0700481 struct udevice *dev;
482 int rc;
483
484 rc = get_tpm(&dev);
485 if (rc)
486 return rc;
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200487
488 if (argc < 3)
489 return CMD_RET_USAGE;
490
491 key_handle = simple_strtoul(argv[1], NULL, 0);
492 if (strlen(argv[2]) != 2 * DIGEST_LENGTH)
493 return CMD_RET_FAILURE;
494 parse_byte_string(argv[2], usage_auth, NULL);
495
Simon Glassd6a885f2021-02-06 14:23:36 -0700496 err = tpm1_get_pub_key_oiap(dev, key_handle, usage_auth, pub_key_buffer,
497 &pub_key_len);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200498 if (!err) {
499 printf("dump of received pub key structure:\n");
500 print_byte_string(pub_key_buffer, pub_key_len);
501 }
Simon Glassf8f1fe12015-08-22 18:31:34 -0600502 return report_return_code(err);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200503}
504
Simon Glassd6a885f2021-02-06 14:23:36 -0700505TPM_COMMAND_NO_ARG(tpm1_end_oiap)
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200506
507#endif /* CONFIG_TPM_AUTH_SESSIONS */
508
Mario Six7690be32017-01-11 16:00:50 +0100509#ifdef CONFIG_TPM_FLUSH_RESOURCES
Simon Glass09140112020-05-10 11:40:03 -0600510static int do_tpm_flush(struct cmd_tbl *cmdtp, int flag, int argc,
511 char *const argv[])
Mario Six7690be32017-01-11 16:00:50 +0100512{
Simon Glassabdc7b82018-11-18 14:22:27 -0700513 struct udevice *dev;
Mario Six7690be32017-01-11 16:00:50 +0100514 int type = 0;
Simon Glassabdc7b82018-11-18 14:22:27 -0700515 int rc;
516
517 rc = get_tpm(&dev);
518 if (rc)
519 return rc;
Mario Six7690be32017-01-11 16:00:50 +0100520
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100521 if (argc != 3)
Mario Six7690be32017-01-11 16:00:50 +0100522 return CMD_RET_USAGE;
523
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100524 if (!strcasecmp(argv[1], "key"))
Mario Six7690be32017-01-11 16:00:50 +0100525 type = TPM_RT_KEY;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100526 else if (!strcasecmp(argv[1], "auth"))
Mario Six7690be32017-01-11 16:00:50 +0100527 type = TPM_RT_AUTH;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100528 else if (!strcasecmp(argv[1], "hash"))
Mario Six7690be32017-01-11 16:00:50 +0100529 type = TPM_RT_HASH;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100530 else if (!strcasecmp(argv[1], "trans"))
Mario Six7690be32017-01-11 16:00:50 +0100531 type = TPM_RT_TRANS;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100532 else if (!strcasecmp(argv[1], "context"))
Mario Six7690be32017-01-11 16:00:50 +0100533 type = TPM_RT_CONTEXT;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100534 else if (!strcasecmp(argv[1], "counter"))
Mario Six7690be32017-01-11 16:00:50 +0100535 type = TPM_RT_COUNTER;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100536 else if (!strcasecmp(argv[1], "delegate"))
Mario Six7690be32017-01-11 16:00:50 +0100537 type = TPM_RT_DELEGATE;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100538 else if (!strcasecmp(argv[1], "daa_tpm"))
Mario Six7690be32017-01-11 16:00:50 +0100539 type = TPM_RT_DAA_TPM;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100540 else if (!strcasecmp(argv[1], "daa_v0"))
Mario Six7690be32017-01-11 16:00:50 +0100541 type = TPM_RT_DAA_V0;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100542 else if (!strcasecmp(argv[1], "daa_v1"))
Mario Six7690be32017-01-11 16:00:50 +0100543 type = TPM_RT_DAA_V1;
544
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100545 if (!type) {
546 printf("Resource type %s unknown.\n", argv[1]);
547 return -1;
548 }
549
550 if (!strcasecmp(argv[2], "all")) {
Miquel Raynalb9804e52018-05-15 11:56:59 +0200551 u16 res_count;
552 u8 buf[288];
553 u8 *ptr;
Mario Six7690be32017-01-11 16:00:50 +0100554 int err;
555 uint i;
556
557 /* fetch list of already loaded resources in the TPM */
Simon Glassabdc7b82018-11-18 14:22:27 -0700558 err = tpm_get_capability(dev, TPM_CAP_HANDLE, type, buf,
Mario Six7690be32017-01-11 16:00:50 +0100559 sizeof(buf));
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100560 if (err) {
561 printf("tpm_get_capability returned error %d.\n", err);
Mario Six7690be32017-01-11 16:00:50 +0100562 return -1;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100563 }
Mario Six7690be32017-01-11 16:00:50 +0100564 res_count = get_unaligned_be16(buf);
565 ptr = buf + 2;
566 for (i = 0; i < res_count; ++i, ptr += 4)
Simon Glassd6a885f2021-02-06 14:23:36 -0700567 tpm1_flush_specific(dev, get_unaligned_be32(ptr), type);
Mario Six7690be32017-01-11 16:00:50 +0100568 } else {
Miquel Raynalb9804e52018-05-15 11:56:59 +0200569 u32 handle = simple_strtoul(argv[2], NULL, 0);
Mario Six7690be32017-01-11 16:00:50 +0100570
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100571 if (!handle) {
572 printf("Illegal resource handle %s\n", argv[2]);
Mario Six7690be32017-01-11 16:00:50 +0100573 return -1;
mario.six@gdsys.cc1c08b212017-03-20 10:28:29 +0100574 }
Simon Glassd6a885f2021-02-06 14:23:36 -0700575 tpm1_flush_specific(dev, cpu_to_be32(handle), type);
Mario Six7690be32017-01-11 16:00:50 +0100576 }
577
578 return 0;
579}
580#endif /* CONFIG_TPM_FLUSH_RESOURCES */
581
mario.six@gdsys.cc3d1df0e2017-03-20 10:28:30 +0100582#ifdef CONFIG_TPM_LIST_RESOURCES
Simon Glass09140112020-05-10 11:40:03 -0600583static int do_tpm_list(struct cmd_tbl *cmdtp, int flag, int argc,
584 char *const argv[])
mario.six@gdsys.cc3d1df0e2017-03-20 10:28:30 +0100585{
Mathew McBrideebb6d742021-11-11 04:06:26 +0000586 struct udevice *dev;
mario.six@gdsys.cc3d1df0e2017-03-20 10:28:30 +0100587 int type = 0;
Miquel Raynalb9804e52018-05-15 11:56:59 +0200588 u16 res_count;
589 u8 buf[288];
590 u8 *ptr;
mario.six@gdsys.cc3d1df0e2017-03-20 10:28:30 +0100591 int err;
592 uint i;
593
Mathew McBrideebb6d742021-11-11 04:06:26 +0000594 err = get_tpm(&dev);
595 if (err)
596 return err;
597
mario.six@gdsys.cc3d1df0e2017-03-20 10:28:30 +0100598 if (argc != 2)
599 return CMD_RET_USAGE;
600
601 if (!strcasecmp(argv[1], "key"))
602 type = TPM_RT_KEY;
603 else if (!strcasecmp(argv[1], "auth"))
604 type = TPM_RT_AUTH;
605 else if (!strcasecmp(argv[1], "hash"))
606 type = TPM_RT_HASH;
607 else if (!strcasecmp(argv[1], "trans"))
608 type = TPM_RT_TRANS;
609 else if (!strcasecmp(argv[1], "context"))
610 type = TPM_RT_CONTEXT;
611 else if (!strcasecmp(argv[1], "counter"))
612 type = TPM_RT_COUNTER;
613 else if (!strcasecmp(argv[1], "delegate"))
614 type = TPM_RT_DELEGATE;
615 else if (!strcasecmp(argv[1], "daa_tpm"))
616 type = TPM_RT_DAA_TPM;
617 else if (!strcasecmp(argv[1], "daa_v0"))
618 type = TPM_RT_DAA_V0;
619 else if (!strcasecmp(argv[1], "daa_v1"))
620 type = TPM_RT_DAA_V1;
621
622 if (!type) {
623 printf("Resource type %s unknown.\n", argv[1]);
624 return -1;
625 }
626
627 /* fetch list of already loaded resources in the TPM */
Mathew McBrideebb6d742021-11-11 04:06:26 +0000628 err = tpm_get_capability(dev, TPM_CAP_HANDLE, type, buf,
mario.six@gdsys.cc3d1df0e2017-03-20 10:28:30 +0100629 sizeof(buf));
630 if (err) {
631 printf("tpm_get_capability returned error %d.\n", err);
632 return -1;
633 }
634 res_count = get_unaligned_be16(buf);
635 ptr = buf + 2;
636
637 printf("Resources of type %s (%02x):\n", argv[1], type);
638 if (!res_count) {
639 puts("None\n");
640 } else {
641 for (i = 0; i < res_count; ++i, ptr += 4)
642 printf("Index %d: %08x\n", i, get_unaligned_be32(ptr));
643 }
644
645 return 0;
646}
647#endif /* CONFIG_TPM_LIST_RESOURCES */
648
Miquel Raynald677bfe2018-05-15 11:57:06 +0200649TPM_COMMAND_NO_ARG(tpm_self_test_full)
650TPM_COMMAND_NO_ARG(tpm_continue_self_test)
651TPM_COMMAND_NO_ARG(tpm_force_clear)
652TPM_COMMAND_NO_ARG(tpm_physical_enable)
653TPM_COMMAND_NO_ARG(tpm_physical_disable)
Che-liang Chiou8732b072013-02-28 09:34:57 +0000654
Simon Glass09140112020-05-10 11:40:03 -0600655static struct cmd_tbl tpm1_commands[] = {
Philippe Reynes3780e2d2020-01-09 18:45:46 +0100656 U_BOOT_CMD_MKENT(device, 0, 1, do_tpm_device, "", ""),
Simon Glassad776942015-08-22 18:31:40 -0600657 U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
Miquel Raynalc6179182018-05-15 11:57:00 +0200658 U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000659 U_BOOT_CMD_MKENT(startup, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200660 do_tpm_startup, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000661 U_BOOT_CMD_MKENT(self_test_full, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200662 do_tpm_self_test_full, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000663 U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200664 do_tpm_continue_self_test, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000665 U_BOOT_CMD_MKENT(force_clear, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200666 do_tpm_force_clear, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000667 U_BOOT_CMD_MKENT(physical_enable, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200668 do_tpm_physical_enable, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000669 U_BOOT_CMD_MKENT(physical_disable, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200670 do_tpm_physical_disable, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000671 U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200672 do_tpm_nv_define_space, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000673 U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200674 do_tpm_nv_read_value, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000675 U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200676 do_tpm_nv_write_value, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000677 U_BOOT_CMD_MKENT(extend, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200678 do_tpm_extend, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000679 U_BOOT_CMD_MKENT(pcr_read, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200680 do_tpm_pcr_read, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000681 U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200682 do_tpm_tsc_physical_presence, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000683 U_BOOT_CMD_MKENT(read_pubek, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200684 do_tpm_read_pubek, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000685 U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200686 do_tpm_physical_set_deactivated, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000687 U_BOOT_CMD_MKENT(get_capability, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200688 do_tpm_get_capability, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000689 U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200690 do_tpm_raw_transfer, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000691 U_BOOT_CMD_MKENT(nv_define, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200692 do_tpm_nv_define, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000693 U_BOOT_CMD_MKENT(nv_read, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200694 do_tpm_nv_read, "", ""),
Che-liang Chiou8732b072013-02-28 09:34:57 +0000695 U_BOOT_CMD_MKENT(nv_write, 0, 1,
Miquel Raynalc6179182018-05-15 11:57:00 +0200696 do_tpm_nv_write, "", ""),
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200697#ifdef CONFIG_TPM_AUTH_SESSIONS
698 U_BOOT_CMD_MKENT(oiap, 0, 1,
699 do_tpm_oiap, "", ""),
700 U_BOOT_CMD_MKENT(end_oiap, 0, 1,
Simon Glassd6a885f2021-02-06 14:23:36 -0700701 do_tpm1_end_oiap, "", ""),
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200702 U_BOOT_CMD_MKENT(load_key2_oiap, 0, 1,
703 do_tpm_load_key2_oiap, "", ""),
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100704#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
705 U_BOOT_CMD_MKENT(load_key_by_sha1, 0, 1,
706 do_tpm_load_key_by_sha1, "", ""),
707#endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200708 U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1,
709 do_tpm_get_pub_key_oiap, "", ""),
710#endif /* CONFIG_TPM_AUTH_SESSIONS */
Mario Six7690be32017-01-11 16:00:50 +0100711#ifdef CONFIG_TPM_FLUSH_RESOURCES
712 U_BOOT_CMD_MKENT(flush, 0, 1,
713 do_tpm_flush, "", ""),
714#endif /* CONFIG_TPM_FLUSH_RESOURCES */
mario.six@gdsys.cc3d1df0e2017-03-20 10:28:30 +0100715#ifdef CONFIG_TPM_LIST_RESOURCES
716 U_BOOT_CMD_MKENT(list, 0, 1,
717 do_tpm_list, "", ""),
718#endif /* CONFIG_TPM_LIST_RESOURCES */
Che-liang Chiou8732b072013-02-28 09:34:57 +0000719};
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +0000720
Simon Glass09140112020-05-10 11:40:03 -0600721struct cmd_tbl *get_tpm1_commands(unsigned int *size)
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +0000722{
Miquel Raynald677bfe2018-05-15 11:57:06 +0200723 *size = ARRAY_SIZE(tpm1_commands);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000724
Miquel Raynald677bfe2018-05-15 11:57:06 +0200725 return tpm1_commands;
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +0000726}
727
Che-liang Chiou8732b072013-02-28 09:34:57 +0000728U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
Miquel Raynald677bfe2018-05-15 11:57:06 +0200729"Issue a TPMv1.x command",
Che-liang Chiou8732b072013-02-28 09:34:57 +0000730"cmd args...\n"
731" - Issue TPM command <cmd> with arguments <args...>.\n"
732"Admin Startup and State Commands:\n"
Philippe Reynes3780e2d2020-01-09 18:45:46 +0100733" device [num device]\n"
734" - Show all devices or set the specified device\n"
Simon Glassad776942015-08-22 18:31:40 -0600735" info - Show information about the TPM\n"
Che-liang Chiou8732b072013-02-28 09:34:57 +0000736" init\n"
737" - Put TPM into a state where it waits for 'startup' command.\n"
738" startup mode\n"
739" - Issue TPM_Starup command. <mode> is one of TPM_ST_CLEAR,\n"
740" TPM_ST_STATE, and TPM_ST_DEACTIVATED.\n"
741"Admin Testing Commands:\n"
742" self_test_full\n"
743" - Test all of the TPM capabilities.\n"
744" continue_self_test\n"
745" - Inform TPM that it should complete the self-test.\n"
746"Admin Opt-in Commands:\n"
747" physical_enable\n"
748" - Set the PERMANENT disable flag to FALSE using physical presence as\n"
749" authorization.\n"
750" physical_disable\n"
751" - Set the PERMANENT disable flag to TRUE using physical presence as\n"
752" authorization.\n"
753" physical_set_deactivated 0|1\n"
754" - Set deactivated flag.\n"
755"Admin Ownership Commands:\n"
756" force_clear\n"
757" - Issue TPM_ForceClear command.\n"
758" tsc_physical_presence flags\n"
759" - Set TPM device's Physical Presence flags to <flags>.\n"
760"The Capability Commands:\n"
761" get_capability cap_area sub_cap addr count\n"
762" - Read <count> bytes of TPM capability indexed by <cap_area> and\n"
763" <sub_cap> to memory address <addr>.\n"
mario.six@gdsys.cc3d1df0e2017-03-20 10:28:30 +0100764#if defined(CONFIG_TPM_FLUSH_RESOURCES) || defined(CONFIG_TPM_LIST_RESOURCES)
Mario Six7690be32017-01-11 16:00:50 +0100765"Resource management functions\n"
mario.six@gdsys.cc3d1df0e2017-03-20 10:28:30 +0100766#endif
767#ifdef CONFIG_TPM_FLUSH_RESOURCES
Mario Six7690be32017-01-11 16:00:50 +0100768" flush resource_type id\n"
769" - flushes a resource of type <resource_type> (may be one of key, auth,\n"
770" hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1),\n"
771" and id <id> from the TPM. Use an <id> of \"all\" to flush all\n"
772" resources of that type.\n"
773#endif /* CONFIG_TPM_FLUSH_RESOURCES */
mario.six@gdsys.cc3d1df0e2017-03-20 10:28:30 +0100774#ifdef CONFIG_TPM_LIST_RESOURCES
775" list resource_type\n"
776" - lists resources of type <resource_type> (may be one of key, auth,\n"
777" hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1),\n"
778" contained in the TPM.\n"
779#endif /* CONFIG_TPM_LIST_RESOURCES */
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200780#ifdef CONFIG_TPM_AUTH_SESSIONS
781"Storage functions\n"
782" loadkey2_oiap parent_handle key_addr key_len usage_auth\n"
783" - loads a key data from memory address <key_addr>, <key_len> bytes\n"
784" into TPM using the parent key <parent_handle> with authorization\n"
785" <usage_auth> (20 bytes hex string).\n"
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100786#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
787" load_key_by_sha1 parent_hash key_addr key_len usage_auth\n"
788" - loads a key data from memory address <key_addr>, <key_len> bytes\n"
789" into TPM using the parent hash <parent_hash> (20 bytes hex string)\n"
790" with authorization <usage_auth> (20 bytes hex string).\n"
791#endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200792" get_pub_key_oiap key_handle usage_auth\n"
793" - get the public key portion of a loaded key <key_handle> using\n"
794" authorization <usage auth> (20 bytes hex string)\n"
795#endif /* CONFIG_TPM_AUTH_SESSIONS */
Che-liang Chiou8732b072013-02-28 09:34:57 +0000796"Endorsement Key Handling Commands:\n"
797" read_pubek addr count\n"
798" - Read <count> bytes of the public endorsement key to memory\n"
799" address <addr>\n"
800"Integrity Collection and Reporting Commands:\n"
801" extend index digest_hex_string\n"
802" - Add a new measurement to a PCR. Update PCR <index> with the 20-bytes\n"
803" <digest_hex_string>\n"
804" pcr_read index addr count\n"
805" - Read <count> bytes from PCR <index> to memory address <addr>.\n"
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200806#ifdef CONFIG_TPM_AUTH_SESSIONS
807"Authorization Sessions\n"
808" oiap\n"
809" - setup an OIAP session\n"
810" end_oiap\n"
811" - terminates an active OIAP session\n"
812#endif /* CONFIG_TPM_AUTH_SESSIONS */
Che-liang Chiou8732b072013-02-28 09:34:57 +0000813"Non-volatile Storage Commands:\n"
814" nv_define_space index permission size\n"
815" - Establish a space at index <index> with <permission> of <size> bytes.\n"
816" nv_read_value index addr count\n"
817" - Read <count> bytes from space <index> to memory address <addr>.\n"
818" nv_write_value index addr count\n"
819" - Write <count> bytes from memory address <addr> to space <index>.\n"
820"Miscellaneous helper functions:\n"
821" raw_transfer byte_string\n"
822" - Send a byte string <byte_string> to TPM and print the response.\n"
823" Non-volatile storage helper functions:\n"
824" These helper functions treat a non-volatile space as a non-padded\n"
825" sequence of integer values. These integer values are defined by a type\n"
826" string, which is a text string of 'bwd' characters: 'b' means a 8-bit\n"
827" value, 'w' 16-bit value, 'd' 32-bit value. All helper functions take\n"
828" a type string as their first argument.\n"
829" nv_define type_string index perm\n"
830" - Define a space <index> with permission <perm>.\n"
831" nv_read types_string index vars...\n"
832" - Read from space <index> to environment variables <vars...>.\n"
833" nv_write types_string index values...\n"
834" - Write to space <index> from values <values...>.\n"
Luigi Semenzatoeea3f4d2012-12-05 14:46:44 +0000835);