blob: 0e2168aea67040d60b3b9e68cf5859ed4ff35edf [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vadim Bendebury7acba0b2011-10-15 15:13:34 +00002/*
Che-liang Chiouc18f9012013-02-28 09:34:57 +00003 * Copyright (c) 2013 The Chromium OS Authors.
Vadim Bendebury7acba0b2011-10-15 15:13:34 +00004 */
5
6#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06007#include <command.h>
Simon Glass313112a2019-08-01 09:46:46 -06008#include <env.h>
Che-liang Chiouc18f9012013-02-28 09:34:57 +00009#include <malloc.h>
Che-liang Chiouc18f9012013-02-28 09:34:57 +000010#include <asm/unaligned.h>
Miquel Raynal4c6759e2018-05-15 11:57:06 +020011#include <tpm-common.h>
12#include <tpm-v1.h>
13#include "tpm-user-utils.h"
Luigi Semenzato04d1bd22012-12-05 14:46:44 +000014
Simon Glassed38aef2020-05-10 11:40:03 -060015static int do_tpm_startup(struct cmd_tbl *cmdtp, int flag, int argc,
16 char *const argv[])
Vadim Bendebury7acba0b2011-10-15 15:13:34 +000017{
Che-liang Chiouc18f9012013-02-28 09:34:57 +000018 enum tpm_startup_type mode;
Simon Glass8ceca1d2018-11-18 14:22:27 -070019 struct udevice *dev;
20 int rc;
Vadim Bendebury7acba0b2011-10-15 15:13:34 +000021
Simon Glass8ceca1d2018-11-18 14:22:27 -070022 rc = get_tpm(&dev);
23 if (rc)
24 return rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +000025 if (argc != 2)
26 return CMD_RET_USAGE;
27 if (!strcasecmp("TPM_ST_CLEAR", argv[1])) {
28 mode = TPM_ST_CLEAR;
29 } else if (!strcasecmp("TPM_ST_STATE", argv[1])) {
30 mode = TPM_ST_STATE;
31 } else if (!strcasecmp("TPM_ST_DEACTIVATED", argv[1])) {
32 mode = TPM_ST_DEACTIVATED;
33 } else {
34 printf("Couldn't recognize mode string: %s\n", argv[1]);
35 return CMD_RET_FAILURE;
Vadim Bendebury7acba0b2011-10-15 15:13:34 +000036 }
37
Simon Glass8ceca1d2018-11-18 14:22:27 -070038 return report_return_code(tpm_startup(dev, mode));
Che-liang Chiouc18f9012013-02-28 09:34:57 +000039}
40
Simon Glassed38aef2020-05-10 11:40:03 -060041static int do_tpm_nv_define_space(struct cmd_tbl *cmdtp, int flag, int argc,
42 char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +000043{
Miquel Raynald790f552018-05-15 11:56:59 +020044 u32 index, perm, size;
Simon Glass8ceca1d2018-11-18 14:22:27 -070045 struct udevice *dev;
46 int rc;
47
48 rc = get_tpm(&dev);
49 if (rc)
50 return rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +000051
52 if (argc != 4)
53 return CMD_RET_USAGE;
54 index = simple_strtoul(argv[1], NULL, 0);
55 perm = simple_strtoul(argv[2], NULL, 0);
56 size = simple_strtoul(argv[3], NULL, 0);
57
Simon Glass8ceca1d2018-11-18 14:22:27 -070058 return report_return_code(tpm_nv_define_space(dev, index, perm, size));
Che-liang Chiouc18f9012013-02-28 09:34:57 +000059}
60
Simon Glassed38aef2020-05-10 11:40:03 -060061static int do_tpm_nv_read_value(struct cmd_tbl *cmdtp, int flag, int argc,
62 char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +000063{
Miquel Raynald790f552018-05-15 11:56:59 +020064 u32 index, count, rc;
Simon Glass8ceca1d2018-11-18 14:22:27 -070065 struct udevice *dev;
Che-liang Chiouc18f9012013-02-28 09:34:57 +000066 void *data;
67
Simon Glass8ceca1d2018-11-18 14:22:27 -070068 rc = get_tpm(&dev);
69 if (rc)
70 return rc;
71
Che-liang Chiouc18f9012013-02-28 09:34:57 +000072 if (argc != 4)
73 return CMD_RET_USAGE;
74 index = simple_strtoul(argv[1], NULL, 0);
75 data = (void *)simple_strtoul(argv[2], NULL, 0);
76 count = simple_strtoul(argv[3], NULL, 0);
77
Simon Glass8ceca1d2018-11-18 14:22:27 -070078 rc = tpm_nv_read_value(dev, index, data, count);
Che-liang Chiouc18f9012013-02-28 09:34:57 +000079 if (!rc) {
80 puts("area content:\n");
81 print_byte_string(data, count);
Luigi Semenzato04d1bd22012-12-05 14:46:44 +000082 }
83
Simon Glass8105c442015-08-22 18:31:34 -060084 return report_return_code(rc);
Che-liang Chiouc18f9012013-02-28 09:34:57 +000085}
86
Simon Glassed38aef2020-05-10 11:40:03 -060087static int do_tpm_nv_write_value(struct cmd_tbl *cmdtp, int flag, int argc,
88 char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +000089{
Simon Glass8ceca1d2018-11-18 14:22:27 -070090 struct udevice *dev;
Miquel Raynald790f552018-05-15 11:56:59 +020091 u32 index, rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +000092 size_t count;
93 void *data;
94
Simon Glass8ceca1d2018-11-18 14:22:27 -070095 rc = get_tpm(&dev);
96 if (rc)
97 return rc;
98
Che-liang Chiouc18f9012013-02-28 09:34:57 +000099 if (argc != 3)
100 return CMD_RET_USAGE;
101 index = simple_strtoul(argv[1], NULL, 0);
102 data = parse_byte_string(argv[2], NULL, &count);
103 if (!data) {
104 printf("Couldn't parse byte string %s\n", argv[2]);
105 return CMD_RET_FAILURE;
Vadim Bendebury7acba0b2011-10-15 15:13:34 +0000106 }
107
Simon Glass8ceca1d2018-11-18 14:22:27 -0700108 rc = tpm_nv_write_value(dev, index, data, count);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000109 free(data);
110
Simon Glass8105c442015-08-22 18:31:34 -0600111 return report_return_code(rc);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000112}
113
Simon Glassed38aef2020-05-10 11:40:03 -0600114static int do_tpm_extend(struct cmd_tbl *cmdtp, int flag, int argc,
115 char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000116{
Miquel Raynald790f552018-05-15 11:56:59 +0200117 u8 in_digest[20], out_digest[20];
Simon Glass8ceca1d2018-11-18 14:22:27 -0700118 struct udevice *dev;
119 u32 index, rc;
120
121 rc = get_tpm(&dev);
122 if (rc)
123 return rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000124
125 if (argc != 3)
126 return CMD_RET_USAGE;
127 index = simple_strtoul(argv[1], NULL, 0);
128 if (!parse_byte_string(argv[2], in_digest, NULL)) {
129 printf("Couldn't parse byte string %s\n", argv[2]);
130 return CMD_RET_FAILURE;
Vadim Bendebury7acba0b2011-10-15 15:13:34 +0000131 }
132
Simon Glass8ceca1d2018-11-18 14:22:27 -0700133 rc = tpm_extend(dev, index, in_digest, out_digest);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000134 if (!rc) {
135 puts("PCR value after execution of the command:\n");
136 print_byte_string(out_digest, sizeof(out_digest));
137 }
Vadim Bendebury7acba0b2011-10-15 15:13:34 +0000138
Simon Glass8105c442015-08-22 18:31:34 -0600139 return report_return_code(rc);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000140}
141
Simon Glassed38aef2020-05-10 11:40:03 -0600142static int do_tpm_pcr_read(struct cmd_tbl *cmdtp, int flag, int argc,
143 char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000144{
Miquel Raynald790f552018-05-15 11:56:59 +0200145 u32 index, count, rc;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700146 struct udevice *dev;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000147 void *data;
148
Simon Glass8ceca1d2018-11-18 14:22:27 -0700149 rc = get_tpm(&dev);
150 if (rc)
151 return rc;
152
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000153 if (argc != 4)
154 return CMD_RET_USAGE;
155 index = simple_strtoul(argv[1], NULL, 0);
156 data = (void *)simple_strtoul(argv[2], NULL, 0);
157 count = simple_strtoul(argv[3], NULL, 0);
158
Simon Glass8ceca1d2018-11-18 14:22:27 -0700159 rc = tpm_pcr_read(dev, index, data, count);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000160 if (!rc) {
161 puts("Named PCR content:\n");
162 print_byte_string(data, count);
Vadim Bendebury7acba0b2011-10-15 15:13:34 +0000163 }
164
Simon Glass8105c442015-08-22 18:31:34 -0600165 return report_return_code(rc);
Vadim Bendebury7acba0b2011-10-15 15:13:34 +0000166}
167
Simon Glassed38aef2020-05-10 11:40:03 -0600168static int do_tpm_tsc_physical_presence(struct cmd_tbl *cmdtp, int flag,
169 int argc, char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000170{
Simon Glass8ceca1d2018-11-18 14:22:27 -0700171 struct udevice *dev;
Miquel Raynald790f552018-05-15 11:56:59 +0200172 u16 presence;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700173 int rc;
174
175 rc = get_tpm(&dev);
176 if (rc)
177 return rc;
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000178
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000179 if (argc != 2)
180 return CMD_RET_USAGE;
Miquel Raynald790f552018-05-15 11:56:59 +0200181 presence = (u16)simple_strtoul(argv[1], NULL, 0);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000182
Simon Glass8ceca1d2018-11-18 14:22:27 -0700183 return report_return_code(tpm_tsc_physical_presence(dev, presence));
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000184}
185
Simon Glassed38aef2020-05-10 11:40:03 -0600186static int do_tpm_read_pubek(struct cmd_tbl *cmdtp, int flag, int argc,
187 char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000188{
Simon Glass8ceca1d2018-11-18 14:22:27 -0700189 struct udevice *dev;
Miquel Raynald790f552018-05-15 11:56:59 +0200190 u32 count, rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000191 void *data;
192
Simon Glass8ceca1d2018-11-18 14:22:27 -0700193 rc = get_tpm(&dev);
194 if (rc)
195 return rc;
196
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000197 if (argc != 3)
198 return CMD_RET_USAGE;
199 data = (void *)simple_strtoul(argv[1], NULL, 0);
200 count = simple_strtoul(argv[2], NULL, 0);
201
Simon Glass8ceca1d2018-11-18 14:22:27 -0700202 rc = tpm_read_pubek(dev, data, count);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000203 if (!rc) {
204 puts("pubek value:\n");
205 print_byte_string(data, count);
206 }
207
Simon Glass8105c442015-08-22 18:31:34 -0600208 return report_return_code(rc);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000209}
210
Simon Glassed38aef2020-05-10 11:40:03 -0600211static int do_tpm_physical_set_deactivated(struct cmd_tbl *cmdtp, int flag,
212 int argc, char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000213{
Simon Glass8ceca1d2018-11-18 14:22:27 -0700214 struct udevice *dev;
Miquel Raynald790f552018-05-15 11:56:59 +0200215 u8 state;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700216 int rc;
217
218 rc = get_tpm(&dev);
219 if (rc)
220 return rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000221
222 if (argc != 2)
223 return CMD_RET_USAGE;
Miquel Raynald790f552018-05-15 11:56:59 +0200224 state = (u8)simple_strtoul(argv[1], NULL, 0);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000225
Simon Glass8ceca1d2018-11-18 14:22:27 -0700226 return report_return_code(tpm_physical_set_deactivated(dev, state));
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000227}
228
Simon Glassed38aef2020-05-10 11:40:03 -0600229static int do_tpm_get_capability(struct cmd_tbl *cmdtp, int flag, int argc,
230 char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000231{
Miquel Raynald790f552018-05-15 11:56:59 +0200232 u32 cap_area, sub_cap, rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000233 void *cap;
234 size_t count;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700235 struct udevice *dev;
236
237 rc = get_tpm(&dev);
238 if (rc)
239 return rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000240
241 if (argc != 5)
242 return CMD_RET_USAGE;
243 cap_area = simple_strtoul(argv[1], NULL, 0);
244 sub_cap = simple_strtoul(argv[2], NULL, 0);
245 cap = (void *)simple_strtoul(argv[3], NULL, 0);
246 count = simple_strtoul(argv[4], NULL, 0);
247
Simon Glass8ceca1d2018-11-18 14:22:27 -0700248 rc = tpm_get_capability(dev, cap_area, sub_cap, cap, count);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000249 if (!rc) {
250 puts("capability information:\n");
251 print_byte_string(cap, count);
252 }
253
Simon Glass8105c442015-08-22 18:31:34 -0600254 return report_return_code(rc);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000255}
256
Simon Glassed38aef2020-05-10 11:40:03 -0600257static int do_tpm_raw_transfer(struct cmd_tbl *cmdtp, int flag, int argc,
258 char *const argv[])
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000259{
Christophe Ricard52d309b2015-10-06 22:54:43 +0200260 struct udevice *dev;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000261 void *command;
Miquel Raynald790f552018-05-15 11:56:59 +0200262 u8 response[1024];
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000263 size_t count, response_length = sizeof(response);
Miquel Raynald790f552018-05-15 11:56:59 +0200264 u32 rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000265
266 command = parse_byte_string(argv[1], NULL, &count);
267 if (!command) {
268 printf("Couldn't parse byte string %s\n", argv[1]);
269 return CMD_RET_FAILURE;
270 }
271
Simon Glass3e4f2fd2015-08-22 18:31:32 -0600272 rc = get_tpm(&dev);
273 if (rc)
274 return rc;
275
276 rc = tpm_xfer(dev, command, count, response, &response_length);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000277 free(command);
278 if (!rc) {
279 puts("tpm response:\n");
280 print_byte_string(response, response_length);
281 }
282
Simon Glass8105c442015-08-22 18:31:34 -0600283 return report_return_code(rc);
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000284}
285
Simon Glassed38aef2020-05-10 11:40:03 -0600286static int do_tpm_nv_define(struct cmd_tbl *cmdtp, int flag, int argc,
287 char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000288{
Miquel Raynald790f552018-05-15 11:56:59 +0200289 u32 index, perm, size;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700290 struct udevice *dev;
291 int rc;
292
293 rc = get_tpm(&dev);
294 if (rc)
295 return rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000296
297 if (argc != 4)
298 return CMD_RET_USAGE;
299 size = type_string_get_space_size(argv[1]);
300 if (!size) {
301 printf("Couldn't parse arguments\n");
302 return CMD_RET_USAGE;
303 }
304 index = simple_strtoul(argv[2], NULL, 0);
305 perm = simple_strtoul(argv[3], NULL, 0);
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000306
Simon Glass8ceca1d2018-11-18 14:22:27 -0700307 return report_return_code(tpm_nv_define_space(dev, index, perm, size));
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000308}
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000309
Simon Glassed38aef2020-05-10 11:40:03 -0600310static int do_tpm_nv_read(struct cmd_tbl *cmdtp, int flag, int argc,
311 char *const argv[])
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000312{
Miquel Raynald790f552018-05-15 11:56:59 +0200313 u32 index, count, err;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700314 struct udevice *dev;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000315 void *data;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700316 int rc;
317
318 rc = get_tpm(&dev);
319 if (rc)
320 return rc;
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000321
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000322 if (argc < 3)
323 return CMD_RET_USAGE;
324 if (argc != 3 + type_string_get_num_values(argv[1]))
325 return CMD_RET_USAGE;
326 index = simple_strtoul(argv[2], NULL, 0);
327 data = type_string_alloc(argv[1], &count);
328 if (!data) {
329 printf("Couldn't parse arguments\n");
330 return CMD_RET_USAGE;
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000331 }
332
Simon Glass8ceca1d2018-11-18 14:22:27 -0700333 err = tpm_nv_read_value(dev, index, data, count);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000334 if (!err) {
335 if (type_string_write_vars(argv[1], data, argv + 3)) {
336 printf("Couldn't write to variables\n");
337 err = ~0;
338 }
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000339 }
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000340 free(data);
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000341
Simon Glass8105c442015-08-22 18:31:34 -0600342 return report_return_code(err);
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000343}
344
Simon Glassed38aef2020-05-10 11:40:03 -0600345static int do_tpm_nv_write(struct cmd_tbl *cmdtp, int flag, int argc,
346 char *const argv[])
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000347{
Miquel Raynald790f552018-05-15 11:56:59 +0200348 u32 index, count, err;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700349 struct udevice *dev;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000350 void *data;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700351 int rc;
352
353 rc = get_tpm(&dev);
354 if (rc)
355 return rc;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000356
357 if (argc < 3)
358 return CMD_RET_USAGE;
359 if (argc != 3 + type_string_get_num_values(argv[1]))
360 return CMD_RET_USAGE;
361 index = simple_strtoul(argv[2], NULL, 0);
362 data = type_string_alloc(argv[1], &count);
363 if (!data) {
364 printf("Couldn't parse arguments\n");
365 return CMD_RET_USAGE;
366 }
367 if (type_string_pack(argv[1], argv + 3, data)) {
368 printf("Couldn't parse arguments\n");
369 free(data);
370 return CMD_RET_USAGE;
371 }
372
Simon Glass8ceca1d2018-11-18 14:22:27 -0700373 err = tpm_nv_write_value(dev, index, data, count);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000374 free(data);
375
Simon Glass8105c442015-08-22 18:31:34 -0600376 return report_return_code(err);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200377}
378
379#ifdef CONFIG_TPM_AUTH_SESSIONS
380
Simon Glassed38aef2020-05-10 11:40:03 -0600381static int do_tpm_oiap(struct cmd_tbl *cmdtp, int flag, int argc,
382 char *const argv[])
Reinhard Pfau4fece432013-06-26 15:55:13 +0200383{
Miquel Raynald790f552018-05-15 11:56:59 +0200384 u32 auth_handle, err;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700385 struct udevice *dev;
386 int rc;
387
388 rc = get_tpm(&dev);
389 if (rc)
390 return rc;
Reinhard Pfau4fece432013-06-26 15:55:13 +0200391
Simon Glass8ceca1d2018-11-18 14:22:27 -0700392 err = tpm_oiap(dev, &auth_handle);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200393
Simon Glass8105c442015-08-22 18:31:34 -0600394 return report_return_code(err);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200395}
396
mario.six@gdsys.cca5a7ea22017-03-20 10:28:28 +0100397#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
Simon Glassed38aef2020-05-10 11:40:03 -0600398static int do_tpm_load_key_by_sha1(struct cmd_tbl *cmdtp, int flag, int argc,
399 char *const argv[])
mario.six@gdsys.cca5a7ea22017-03-20 10:28:28 +0100400{
Miquel Raynald790f552018-05-15 11:56:59 +0200401 u32 parent_handle = 0;
402 u32 key_len, key_handle, err;
403 u8 usage_auth[DIGEST_LENGTH];
404 u8 parent_hash[DIGEST_LENGTH];
mario.six@gdsys.cca5a7ea22017-03-20 10:28:28 +0100405 void *key;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700406 struct udevice *dev;
407
408 rc = get_tpm(&dev);
409 if (rc)
410 return rc;
mario.six@gdsys.cca5a7ea22017-03-20 10:28:28 +0100411
412 if (argc < 5)
413 return CMD_RET_USAGE;
414
415 parse_byte_string(argv[1], parent_hash, NULL);
416 key = (void *)simple_strtoul(argv[2], NULL, 0);
417 key_len = simple_strtoul(argv[3], NULL, 0);
418 if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
419 return CMD_RET_FAILURE;
420 parse_byte_string(argv[4], usage_auth, NULL);
421
422 err = tpm_find_key_sha1(usage_auth, parent_hash, &parent_handle);
423 if (err) {
424 printf("Could not find matching parent key (err = %d)\n", err);
425 return CMD_RET_FAILURE;
426 }
427
428 printf("Found parent key %08x\n", parent_handle);
429
430 err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth,
431 &key_handle);
432 if (!err) {
433 printf("Key handle is 0x%x\n", key_handle);
Simon Glass4d949a22017-08-03 12:22:10 -0600434 env_set_hex("key_handle", key_handle);
mario.six@gdsys.cca5a7ea22017-03-20 10:28:28 +0100435 }
436
437 return report_return_code(err);
438}
439#endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
440
Simon Glassed38aef2020-05-10 11:40:03 -0600441static int do_tpm_load_key2_oiap(struct cmd_tbl *cmdtp, int flag, int argc,
442 char *const argv[])
Reinhard Pfau4fece432013-06-26 15:55:13 +0200443{
Miquel Raynald790f552018-05-15 11:56:59 +0200444 u32 parent_handle, key_len, key_handle, err;
445 u8 usage_auth[DIGEST_LENGTH];
Reinhard Pfau4fece432013-06-26 15:55:13 +0200446 void *key;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700447 struct udevice *dev;
448 int rc;
449
450 rc = get_tpm(&dev);
451 if (rc)
452 return rc;
Reinhard Pfau4fece432013-06-26 15:55:13 +0200453
454 if (argc < 5)
455 return CMD_RET_USAGE;
456
457 parent_handle = simple_strtoul(argv[1], NULL, 0);
458 key = (void *)simple_strtoul(argv[2], NULL, 0);
459 key_len = simple_strtoul(argv[3], NULL, 0);
460 if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
461 return CMD_RET_FAILURE;
462 parse_byte_string(argv[4], usage_auth, NULL);
463
Simon Glass8ceca1d2018-11-18 14:22:27 -0700464 err = tpm_load_key2_oiap(dev, parent_handle, key, key_len, usage_auth,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200465 &key_handle);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200466 if (!err)
467 printf("Key handle is 0x%x\n", key_handle);
468
Simon Glass8105c442015-08-22 18:31:34 -0600469 return report_return_code(err);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200470}
471
Simon Glassed38aef2020-05-10 11:40:03 -0600472static int do_tpm_get_pub_key_oiap(struct cmd_tbl *cmdtp, int flag, int argc,
473 char *const argv[])
Reinhard Pfau4fece432013-06-26 15:55:13 +0200474{
Miquel Raynald790f552018-05-15 11:56:59 +0200475 u32 key_handle, err;
476 u8 usage_auth[DIGEST_LENGTH];
477 u8 pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
Reinhard Pfau4fece432013-06-26 15:55:13 +0200478 size_t pub_key_len = sizeof(pub_key_buffer);
Simon Glass8ceca1d2018-11-18 14:22:27 -0700479 struct udevice *dev;
480 int rc;
481
482 rc = get_tpm(&dev);
483 if (rc)
484 return rc;
Reinhard Pfau4fece432013-06-26 15:55:13 +0200485
486 if (argc < 3)
487 return CMD_RET_USAGE;
488
489 key_handle = simple_strtoul(argv[1], NULL, 0);
490 if (strlen(argv[2]) != 2 * DIGEST_LENGTH)
491 return CMD_RET_FAILURE;
492 parse_byte_string(argv[2], usage_auth, NULL);
493
Simon Glass8ceca1d2018-11-18 14:22:27 -0700494 err = tpm_get_pub_key_oiap(dev, key_handle, usage_auth, pub_key_buffer,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200495 &pub_key_len);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200496 if (!err) {
497 printf("dump of received pub key structure:\n");
498 print_byte_string(pub_key_buffer, pub_key_len);
499 }
Simon Glass8105c442015-08-22 18:31:34 -0600500 return report_return_code(err);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000501}
502
Reinhard Pfau4fece432013-06-26 15:55:13 +0200503TPM_COMMAND_NO_ARG(tpm_end_oiap)
504
505#endif /* CONFIG_TPM_AUTH_SESSIONS */
506
Mario Six4eceb6c2017-01-11 16:00:50 +0100507#ifdef CONFIG_TPM_FLUSH_RESOURCES
Simon Glassed38aef2020-05-10 11:40:03 -0600508static int do_tpm_flush(struct cmd_tbl *cmdtp, int flag, int argc,
509 char *const argv[])
Mario Six4eceb6c2017-01-11 16:00:50 +0100510{
Simon Glass8ceca1d2018-11-18 14:22:27 -0700511 struct udevice *dev;
Mario Six4eceb6c2017-01-11 16:00:50 +0100512 int type = 0;
Simon Glass8ceca1d2018-11-18 14:22:27 -0700513 int rc;
514
515 rc = get_tpm(&dev);
516 if (rc)
517 return rc;
Mario Six4eceb6c2017-01-11 16:00:50 +0100518
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100519 if (argc != 3)
Mario Six4eceb6c2017-01-11 16:00:50 +0100520 return CMD_RET_USAGE;
521
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100522 if (!strcasecmp(argv[1], "key"))
Mario Six4eceb6c2017-01-11 16:00:50 +0100523 type = TPM_RT_KEY;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100524 else if (!strcasecmp(argv[1], "auth"))
Mario Six4eceb6c2017-01-11 16:00:50 +0100525 type = TPM_RT_AUTH;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100526 else if (!strcasecmp(argv[1], "hash"))
Mario Six4eceb6c2017-01-11 16:00:50 +0100527 type = TPM_RT_HASH;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100528 else if (!strcasecmp(argv[1], "trans"))
Mario Six4eceb6c2017-01-11 16:00:50 +0100529 type = TPM_RT_TRANS;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100530 else if (!strcasecmp(argv[1], "context"))
Mario Six4eceb6c2017-01-11 16:00:50 +0100531 type = TPM_RT_CONTEXT;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100532 else if (!strcasecmp(argv[1], "counter"))
Mario Six4eceb6c2017-01-11 16:00:50 +0100533 type = TPM_RT_COUNTER;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100534 else if (!strcasecmp(argv[1], "delegate"))
Mario Six4eceb6c2017-01-11 16:00:50 +0100535 type = TPM_RT_DELEGATE;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100536 else if (!strcasecmp(argv[1], "daa_tpm"))
Mario Six4eceb6c2017-01-11 16:00:50 +0100537 type = TPM_RT_DAA_TPM;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100538 else if (!strcasecmp(argv[1], "daa_v0"))
Mario Six4eceb6c2017-01-11 16:00:50 +0100539 type = TPM_RT_DAA_V0;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100540 else if (!strcasecmp(argv[1], "daa_v1"))
Mario Six4eceb6c2017-01-11 16:00:50 +0100541 type = TPM_RT_DAA_V1;
542
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100543 if (!type) {
544 printf("Resource type %s unknown.\n", argv[1]);
545 return -1;
546 }
547
548 if (!strcasecmp(argv[2], "all")) {
Miquel Raynald790f552018-05-15 11:56:59 +0200549 u16 res_count;
550 u8 buf[288];
551 u8 *ptr;
Mario Six4eceb6c2017-01-11 16:00:50 +0100552 int err;
553 uint i;
554
555 /* fetch list of already loaded resources in the TPM */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700556 err = tpm_get_capability(dev, TPM_CAP_HANDLE, type, buf,
Mario Six4eceb6c2017-01-11 16:00:50 +0100557 sizeof(buf));
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100558 if (err) {
559 printf("tpm_get_capability returned error %d.\n", err);
Mario Six4eceb6c2017-01-11 16:00:50 +0100560 return -1;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100561 }
Mario Six4eceb6c2017-01-11 16:00:50 +0100562 res_count = get_unaligned_be16(buf);
563 ptr = buf + 2;
564 for (i = 0; i < res_count; ++i, ptr += 4)
Simon Glass8ceca1d2018-11-18 14:22:27 -0700565 tpm_flush_specific(dev, get_unaligned_be32(ptr), type);
Mario Six4eceb6c2017-01-11 16:00:50 +0100566 } else {
Miquel Raynald790f552018-05-15 11:56:59 +0200567 u32 handle = simple_strtoul(argv[2], NULL, 0);
Mario Six4eceb6c2017-01-11 16:00:50 +0100568
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100569 if (!handle) {
570 printf("Illegal resource handle %s\n", argv[2]);
Mario Six4eceb6c2017-01-11 16:00:50 +0100571 return -1;
mario.six@gdsys.cc9ae88142017-03-20 10:28:29 +0100572 }
Simon Glass8ceca1d2018-11-18 14:22:27 -0700573 tpm_flush_specific(dev, cpu_to_be32(handle), type);
Mario Six4eceb6c2017-01-11 16:00:50 +0100574 }
575
576 return 0;
577}
578#endif /* CONFIG_TPM_FLUSH_RESOURCES */
579
mario.six@gdsys.cca5bfcc52017-03-20 10:28:30 +0100580#ifdef CONFIG_TPM_LIST_RESOURCES
Simon Glassed38aef2020-05-10 11:40:03 -0600581static int do_tpm_list(struct cmd_tbl *cmdtp, int flag, int argc,
582 char *const argv[])
mario.six@gdsys.cca5bfcc52017-03-20 10:28:30 +0100583{
584 int type = 0;
Miquel Raynald790f552018-05-15 11:56:59 +0200585 u16 res_count;
586 u8 buf[288];
587 u8 *ptr;
mario.six@gdsys.cca5bfcc52017-03-20 10:28:30 +0100588 int err;
589 uint i;
590
591 if (argc != 2)
592 return CMD_RET_USAGE;
593
594 if (!strcasecmp(argv[1], "key"))
595 type = TPM_RT_KEY;
596 else if (!strcasecmp(argv[1], "auth"))
597 type = TPM_RT_AUTH;
598 else if (!strcasecmp(argv[1], "hash"))
599 type = TPM_RT_HASH;
600 else if (!strcasecmp(argv[1], "trans"))
601 type = TPM_RT_TRANS;
602 else if (!strcasecmp(argv[1], "context"))
603 type = TPM_RT_CONTEXT;
604 else if (!strcasecmp(argv[1], "counter"))
605 type = TPM_RT_COUNTER;
606 else if (!strcasecmp(argv[1], "delegate"))
607 type = TPM_RT_DELEGATE;
608 else if (!strcasecmp(argv[1], "daa_tpm"))
609 type = TPM_RT_DAA_TPM;
610 else if (!strcasecmp(argv[1], "daa_v0"))
611 type = TPM_RT_DAA_V0;
612 else if (!strcasecmp(argv[1], "daa_v1"))
613 type = TPM_RT_DAA_V1;
614
615 if (!type) {
616 printf("Resource type %s unknown.\n", argv[1]);
617 return -1;
618 }
619
620 /* fetch list of already loaded resources in the TPM */
621 err = tpm_get_capability(TPM_CAP_HANDLE, type, buf,
622 sizeof(buf));
623 if (err) {
624 printf("tpm_get_capability returned error %d.\n", err);
625 return -1;
626 }
627 res_count = get_unaligned_be16(buf);
628 ptr = buf + 2;
629
630 printf("Resources of type %s (%02x):\n", argv[1], type);
631 if (!res_count) {
632 puts("None\n");
633 } else {
634 for (i = 0; i < res_count; ++i, ptr += 4)
635 printf("Index %d: %08x\n", i, get_unaligned_be32(ptr));
636 }
637
638 return 0;
639}
640#endif /* CONFIG_TPM_LIST_RESOURCES */
641
Miquel Raynal4c6759e2018-05-15 11:57:06 +0200642TPM_COMMAND_NO_ARG(tpm_self_test_full)
643TPM_COMMAND_NO_ARG(tpm_continue_self_test)
644TPM_COMMAND_NO_ARG(tpm_force_clear)
645TPM_COMMAND_NO_ARG(tpm_physical_enable)
646TPM_COMMAND_NO_ARG(tpm_physical_disable)
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000647
Simon Glassed38aef2020-05-10 11:40:03 -0600648static struct cmd_tbl tpm1_commands[] = {
Philippe Reynescbe97392020-01-09 18:45:46 +0100649 U_BOOT_CMD_MKENT(device, 0, 1, do_tpm_device, "", ""),
Simon Glassaa6ac632015-08-22 18:31:40 -0600650 U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
Miquel Raynal886ccc02018-05-15 11:57:00 +0200651 U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000652 U_BOOT_CMD_MKENT(startup, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200653 do_tpm_startup, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000654 U_BOOT_CMD_MKENT(self_test_full, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200655 do_tpm_self_test_full, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000656 U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200657 do_tpm_continue_self_test, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000658 U_BOOT_CMD_MKENT(force_clear, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200659 do_tpm_force_clear, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000660 U_BOOT_CMD_MKENT(physical_enable, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200661 do_tpm_physical_enable, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000662 U_BOOT_CMD_MKENT(physical_disable, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200663 do_tpm_physical_disable, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000664 U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200665 do_tpm_nv_define_space, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000666 U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200667 do_tpm_nv_read_value, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000668 U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200669 do_tpm_nv_write_value, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000670 U_BOOT_CMD_MKENT(extend, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200671 do_tpm_extend, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000672 U_BOOT_CMD_MKENT(pcr_read, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200673 do_tpm_pcr_read, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000674 U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200675 do_tpm_tsc_physical_presence, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000676 U_BOOT_CMD_MKENT(read_pubek, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200677 do_tpm_read_pubek, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000678 U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200679 do_tpm_physical_set_deactivated, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000680 U_BOOT_CMD_MKENT(get_capability, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200681 do_tpm_get_capability, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000682 U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200683 do_tpm_raw_transfer, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000684 U_BOOT_CMD_MKENT(nv_define, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200685 do_tpm_nv_define, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000686 U_BOOT_CMD_MKENT(nv_read, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200687 do_tpm_nv_read, "", ""),
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000688 U_BOOT_CMD_MKENT(nv_write, 0, 1,
Miquel Raynal886ccc02018-05-15 11:57:00 +0200689 do_tpm_nv_write, "", ""),
Reinhard Pfau4fece432013-06-26 15:55:13 +0200690#ifdef CONFIG_TPM_AUTH_SESSIONS
691 U_BOOT_CMD_MKENT(oiap, 0, 1,
692 do_tpm_oiap, "", ""),
693 U_BOOT_CMD_MKENT(end_oiap, 0, 1,
694 do_tpm_end_oiap, "", ""),
695 U_BOOT_CMD_MKENT(load_key2_oiap, 0, 1,
696 do_tpm_load_key2_oiap, "", ""),
mario.six@gdsys.cca5a7ea22017-03-20 10:28:28 +0100697#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
698 U_BOOT_CMD_MKENT(load_key_by_sha1, 0, 1,
699 do_tpm_load_key_by_sha1, "", ""),
700#endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
Reinhard Pfau4fece432013-06-26 15:55:13 +0200701 U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1,
702 do_tpm_get_pub_key_oiap, "", ""),
703#endif /* CONFIG_TPM_AUTH_SESSIONS */
Mario Six4eceb6c2017-01-11 16:00:50 +0100704#ifdef CONFIG_TPM_FLUSH_RESOURCES
705 U_BOOT_CMD_MKENT(flush, 0, 1,
706 do_tpm_flush, "", ""),
707#endif /* CONFIG_TPM_FLUSH_RESOURCES */
mario.six@gdsys.cca5bfcc52017-03-20 10:28:30 +0100708#ifdef CONFIG_TPM_LIST_RESOURCES
709 U_BOOT_CMD_MKENT(list, 0, 1,
710 do_tpm_list, "", ""),
711#endif /* CONFIG_TPM_LIST_RESOURCES */
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000712};
713
Simon Glassed38aef2020-05-10 11:40:03 -0600714struct cmd_tbl *get_tpm1_commands(unsigned int *size)
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000715{
Miquel Raynal4c6759e2018-05-15 11:57:06 +0200716 *size = ARRAY_SIZE(tpm1_commands);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000717
Miquel Raynal4c6759e2018-05-15 11:57:06 +0200718 return tpm1_commands;
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000719}
720
721U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
Miquel Raynal4c6759e2018-05-15 11:57:06 +0200722"Issue a TPMv1.x command",
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000723"cmd args...\n"
724" - Issue TPM command <cmd> with arguments <args...>.\n"
725"Admin Startup and State Commands:\n"
Philippe Reynescbe97392020-01-09 18:45:46 +0100726" device [num device]\n"
727" - Show all devices or set the specified device\n"
Simon Glassaa6ac632015-08-22 18:31:40 -0600728" info - Show information about the TPM\n"
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000729" init\n"
730" - Put TPM into a state where it waits for 'startup' command.\n"
731" startup mode\n"
732" - Issue TPM_Starup command. <mode> is one of TPM_ST_CLEAR,\n"
733" TPM_ST_STATE, and TPM_ST_DEACTIVATED.\n"
734"Admin Testing Commands:\n"
735" self_test_full\n"
736" - Test all of the TPM capabilities.\n"
737" continue_self_test\n"
738" - Inform TPM that it should complete the self-test.\n"
739"Admin Opt-in Commands:\n"
740" physical_enable\n"
741" - Set the PERMANENT disable flag to FALSE using physical presence as\n"
742" authorization.\n"
743" physical_disable\n"
744" - Set the PERMANENT disable flag to TRUE using physical presence as\n"
745" authorization.\n"
746" physical_set_deactivated 0|1\n"
747" - Set deactivated flag.\n"
748"Admin Ownership Commands:\n"
749" force_clear\n"
750" - Issue TPM_ForceClear command.\n"
751" tsc_physical_presence flags\n"
752" - Set TPM device's Physical Presence flags to <flags>.\n"
753"The Capability Commands:\n"
754" get_capability cap_area sub_cap addr count\n"
755" - Read <count> bytes of TPM capability indexed by <cap_area> and\n"
756" <sub_cap> to memory address <addr>.\n"
mario.six@gdsys.cca5bfcc52017-03-20 10:28:30 +0100757#if defined(CONFIG_TPM_FLUSH_RESOURCES) || defined(CONFIG_TPM_LIST_RESOURCES)
Mario Six4eceb6c2017-01-11 16:00:50 +0100758"Resource management functions\n"
mario.six@gdsys.cca5bfcc52017-03-20 10:28:30 +0100759#endif
760#ifdef CONFIG_TPM_FLUSH_RESOURCES
Mario Six4eceb6c2017-01-11 16:00:50 +0100761" flush resource_type id\n"
762" - flushes a resource of type <resource_type> (may be one of key, auth,\n"
763" hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1),\n"
764" and id <id> from the TPM. Use an <id> of \"all\" to flush all\n"
765" resources of that type.\n"
766#endif /* CONFIG_TPM_FLUSH_RESOURCES */
mario.six@gdsys.cca5bfcc52017-03-20 10:28:30 +0100767#ifdef CONFIG_TPM_LIST_RESOURCES
768" list resource_type\n"
769" - lists resources 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" contained in the TPM.\n"
772#endif /* CONFIG_TPM_LIST_RESOURCES */
Reinhard Pfau4fece432013-06-26 15:55:13 +0200773#ifdef CONFIG_TPM_AUTH_SESSIONS
774"Storage functions\n"
775" loadkey2_oiap parent_handle key_addr key_len usage_auth\n"
776" - loads a key data from memory address <key_addr>, <key_len> bytes\n"
777" into TPM using the parent key <parent_handle> with authorization\n"
778" <usage_auth> (20 bytes hex string).\n"
mario.six@gdsys.cca5a7ea22017-03-20 10:28:28 +0100779#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
780" load_key_by_sha1 parent_hash key_addr key_len usage_auth\n"
781" - loads a key data from memory address <key_addr>, <key_len> bytes\n"
782" into TPM using the parent hash <parent_hash> (20 bytes hex string)\n"
783" with authorization <usage_auth> (20 bytes hex string).\n"
784#endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
Reinhard Pfau4fece432013-06-26 15:55:13 +0200785" get_pub_key_oiap key_handle usage_auth\n"
786" - get the public key portion of a loaded key <key_handle> using\n"
787" authorization <usage auth> (20 bytes hex string)\n"
788#endif /* CONFIG_TPM_AUTH_SESSIONS */
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000789"Endorsement Key Handling Commands:\n"
790" read_pubek addr count\n"
791" - Read <count> bytes of the public endorsement key to memory\n"
792" address <addr>\n"
793"Integrity Collection and Reporting Commands:\n"
794" extend index digest_hex_string\n"
795" - Add a new measurement to a PCR. Update PCR <index> with the 20-bytes\n"
796" <digest_hex_string>\n"
797" pcr_read index addr count\n"
798" - Read <count> bytes from PCR <index> to memory address <addr>.\n"
Reinhard Pfau4fece432013-06-26 15:55:13 +0200799#ifdef CONFIG_TPM_AUTH_SESSIONS
800"Authorization Sessions\n"
801" oiap\n"
802" - setup an OIAP session\n"
803" end_oiap\n"
804" - terminates an active OIAP session\n"
805#endif /* CONFIG_TPM_AUTH_SESSIONS */
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000806"Non-volatile Storage Commands:\n"
807" nv_define_space index permission size\n"
808" - Establish a space at index <index> with <permission> of <size> bytes.\n"
809" nv_read_value index addr count\n"
810" - Read <count> bytes from space <index> to memory address <addr>.\n"
811" nv_write_value index addr count\n"
812" - Write <count> bytes from memory address <addr> to space <index>.\n"
813"Miscellaneous helper functions:\n"
814" raw_transfer byte_string\n"
815" - Send a byte string <byte_string> to TPM and print the response.\n"
816" Non-volatile storage helper functions:\n"
817" These helper functions treat a non-volatile space as a non-padded\n"
818" sequence of integer values. These integer values are defined by a type\n"
819" string, which is a text string of 'bwd' characters: 'b' means a 8-bit\n"
820" value, 'w' 16-bit value, 'd' 32-bit value. All helper functions take\n"
821" a type string as their first argument.\n"
822" nv_define type_string index perm\n"
823" - Define a space <index> with permission <perm>.\n"
824" nv_read types_string index vars...\n"
825" - Read from space <index> to environment variables <vars...>.\n"
826" nv_write types_string index values...\n"
827" - Write to space <index> from values <values...>.\n"
Luigi Semenzato04d1bd22012-12-05 14:46:44 +0000828);