Blame view
cmd/tpm-v1.c
21.4 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
576fb1ed3 Add a cli command... |
2 |
/* |
8732b0700 tpm: Add TPM comm... |
3 |
* Copyright (c) 2013 The Chromium OS Authors. |
576fb1ed3 Add a cli command... |
4 5 6 |
*/ #include <common.h> |
c7694dd48 env: Move env_set... |
7 |
#include <env.h> |
8732b0700 tpm: Add TPM comm... |
8 |
#include <malloc.h> |
8732b0700 tpm: Add TPM comm... |
9 |
#include <asm/unaligned.h> |
d677bfe2f tpm: disociate TP... |
10 11 12 |
#include <tpm-common.h> #include <tpm-v1.h> #include "tpm-user-utils.h" |
576fb1ed3 Add a cli command... |
13 |
|
c61791876 tpm: align argume... |
14 15 |
static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
16 17 |
{ enum tpm_startup_type mode; |
abdc7b8a2 tpm: Convert to u... |
18 19 |
struct udevice *dev; int rc; |
eea3f4d3e tpm: Add TPM stre... |
20 |
|
abdc7b8a2 tpm: Convert to u... |
21 22 23 |
rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
24 25 26 27 28 29 30 31 32 33 34 35 36 |
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 tpm: Convert to u... |
37 |
return report_return_code(tpm_startup(dev, mode)); |
8732b0700 tpm: Add TPM comm... |
38 |
} |
c61791876 tpm: align argume... |
39 40 |
static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
41 |
{ |
b9804e5bf tpm: substitute d... |
42 |
u32 index, perm, size; |
abdc7b8a2 tpm: Convert to u... |
43 44 45 46 47 48 |
struct udevice *dev; int rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
49 50 51 52 53 54 |
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 tpm: Convert to u... |
55 |
return report_return_code(tpm_nv_define_space(dev, index, perm, size)); |
8732b0700 tpm: Add TPM comm... |
56 |
} |
eea3f4d3e tpm: Add TPM stre... |
57 |
|
c61791876 tpm: align argume... |
58 59 |
static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
eea3f4d3e tpm: Add TPM stre... |
60 |
{ |
b9804e5bf tpm: substitute d... |
61 |
u32 index, count, rc; |
abdc7b8a2 tpm: Convert to u... |
62 |
struct udevice *dev; |
8732b0700 tpm: Add TPM comm... |
63 |
void *data; |
eea3f4d3e tpm: Add TPM stre... |
64 |
|
abdc7b8a2 tpm: Convert to u... |
65 66 67 |
rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
68 69 70 71 72 |
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 tpm: Convert to u... |
73 |
rc = tpm_nv_read_value(dev, index, data, count); |
8732b0700 tpm: Add TPM comm... |
74 75 76 77 |
if (!rc) { puts("area content: "); print_byte_string(data, count); |
576fb1ed3 Add a cli command... |
78 |
} |
f8f1fe1d5 tpm: Report tpm e... |
79 |
return report_return_code(rc); |
8732b0700 tpm: Add TPM comm... |
80 |
} |
c61791876 tpm: align argume... |
81 82 |
static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
83 |
{ |
abdc7b8a2 tpm: Convert to u... |
84 |
struct udevice *dev; |
b9804e5bf tpm: substitute d... |
85 |
u32 index, rc; |
8732b0700 tpm: Add TPM comm... |
86 87 |
size_t count; void *data; |
abdc7b8a2 tpm: Convert to u... |
88 89 90 |
rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
91 92 93 94 95 96 97 98 |
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 tpm: Add TPM stre... |
99 |
} |
abdc7b8a2 tpm: Convert to u... |
100 |
rc = tpm_nv_write_value(dev, index, data, count); |
8732b0700 tpm: Add TPM comm... |
101 |
free(data); |
f8f1fe1d5 tpm: Report tpm e... |
102 |
return report_return_code(rc); |
8732b0700 tpm: Add TPM comm... |
103 |
} |
c61791876 tpm: align argume... |
104 105 |
static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
106 |
{ |
b9804e5bf tpm: substitute d... |
107 |
u8 in_digest[20], out_digest[20]; |
abdc7b8a2 tpm: Convert to u... |
108 109 110 111 112 113 |
struct udevice *dev; u32 index, rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
114 115 116 117 118 119 120 121 |
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 Add a cli command... |
122 |
} |
abdc7b8a2 tpm: Convert to u... |
123 |
rc = tpm_extend(dev, index, in_digest, out_digest); |
8732b0700 tpm: Add TPM comm... |
124 125 126 127 |
if (!rc) { puts("PCR value after execution of the command: "); print_byte_string(out_digest, sizeof(out_digest)); |
576fb1ed3 Add a cli command... |
128 |
} |
f8f1fe1d5 tpm: Report tpm e... |
129 |
return report_return_code(rc); |
8732b0700 tpm: Add TPM comm... |
130 |
} |
c61791876 tpm: align argume... |
131 132 |
static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
133 |
{ |
b9804e5bf tpm: substitute d... |
134 |
u32 index, count, rc; |
abdc7b8a2 tpm: Convert to u... |
135 |
struct udevice *dev; |
8732b0700 tpm: Add TPM comm... |
136 |
void *data; |
abdc7b8a2 tpm: Convert to u... |
137 138 139 |
rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
140 141 142 143 144 |
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 Add a cli command... |
145 |
|
abdc7b8a2 tpm: Convert to u... |
146 |
rc = tpm_pcr_read(dev, index, data, count); |
8732b0700 tpm: Add TPM comm... |
147 148 149 150 |
if (!rc) { puts("Named PCR content: "); print_byte_string(data, count); |
576fb1ed3 Add a cli command... |
151 |
} |
f8f1fe1d5 tpm: Report tpm e... |
152 |
return report_return_code(rc); |
576fb1ed3 Add a cli command... |
153 |
} |
c61791876 tpm: align argume... |
154 155 |
static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
156 |
{ |
abdc7b8a2 tpm: Convert to u... |
157 |
struct udevice *dev; |
b9804e5bf tpm: substitute d... |
158 |
u16 presence; |
abdc7b8a2 tpm: Convert to u... |
159 160 161 162 163 |
int rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
164 165 166 |
if (argc != 2) return CMD_RET_USAGE; |
b9804e5bf tpm: substitute d... |
167 |
presence = (u16)simple_strtoul(argv[1], NULL, 0); |
eea3f4d3e tpm: Add TPM stre... |
168 |
|
abdc7b8a2 tpm: Convert to u... |
169 |
return report_return_code(tpm_tsc_physical_presence(dev, presence)); |
8732b0700 tpm: Add TPM comm... |
170 |
} |
c61791876 tpm: align argume... |
171 172 |
static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
eea3f4d3e tpm: Add TPM stre... |
173 |
{ |
abdc7b8a2 tpm: Convert to u... |
174 |
struct udevice *dev; |
b9804e5bf tpm: substitute d... |
175 |
u32 count, rc; |
8732b0700 tpm: Add TPM comm... |
176 |
void *data; |
abdc7b8a2 tpm: Convert to u... |
177 178 179 |
rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
180 181 182 183 |
if (argc != 3) return CMD_RET_USAGE; data = (void *)simple_strtoul(argv[1], NULL, 0); count = simple_strtoul(argv[2], NULL, 0); |
abdc7b8a2 tpm: Convert to u... |
184 |
rc = tpm_read_pubek(dev, data, count); |
8732b0700 tpm: Add TPM comm... |
185 186 187 188 189 |
if (!rc) { puts("pubek value: "); print_byte_string(data, count); } |
f8f1fe1d5 tpm: Report tpm e... |
190 |
return report_return_code(rc); |
eea3f4d3e tpm: Add TPM stre... |
191 |
} |
c61791876 tpm: align argume... |
192 193 |
static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
194 |
{ |
abdc7b8a2 tpm: Convert to u... |
195 |
struct udevice *dev; |
b9804e5bf tpm: substitute d... |
196 |
u8 state; |
abdc7b8a2 tpm: Convert to u... |
197 198 199 200 201 |
int rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
202 203 204 |
if (argc != 2) return CMD_RET_USAGE; |
b9804e5bf tpm: substitute d... |
205 |
state = (u8)simple_strtoul(argv[1], NULL, 0); |
eea3f4d3e tpm: Add TPM stre... |
206 |
|
abdc7b8a2 tpm: Convert to u... |
207 |
return report_return_code(tpm_physical_set_deactivated(dev, state)); |
8732b0700 tpm: Add TPM comm... |
208 |
} |
c61791876 tpm: align argume... |
209 210 |
static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
211 |
{ |
b9804e5bf tpm: substitute d... |
212 |
u32 cap_area, sub_cap, rc; |
8732b0700 tpm: Add TPM comm... |
213 214 |
void *cap; size_t count; |
abdc7b8a2 tpm: Convert to u... |
215 216 217 218 219 |
struct udevice *dev; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
220 221 222 223 224 225 226 |
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 tpm: Convert to u... |
227 |
rc = tpm_get_capability(dev, cap_area, sub_cap, cap, count); |
8732b0700 tpm: Add TPM comm... |
228 229 230 231 232 |
if (!rc) { puts("capability information: "); print_byte_string(cap, count); } |
f8f1fe1d5 tpm: Report tpm e... |
233 |
return report_return_code(rc); |
8732b0700 tpm: Add TPM comm... |
234 |
} |
eea3f4d3e tpm: Add TPM stre... |
235 |
|
c61791876 tpm: align argume... |
236 237 |
static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
238 |
{ |
c2b0f600a dm: tpm: Remove e... |
239 |
struct udevice *dev; |
8732b0700 tpm: Add TPM comm... |
240 |
void *command; |
b9804e5bf tpm: substitute d... |
241 |
u8 response[1024]; |
8732b0700 tpm: Add TPM comm... |
242 |
size_t count, response_length = sizeof(response); |
b9804e5bf tpm: substitute d... |
243 |
u32 rc; |
8732b0700 tpm: Add TPM comm... |
244 245 246 247 248 249 250 |
command = parse_byte_string(argv[1], NULL, &count); if (!command) { printf("Couldn't parse byte string %s ", argv[1]); return CMD_RET_FAILURE; } |
c8a8c5103 dm: tpm: Convert ... |
251 252 253 254 255 |
rc = get_tpm(&dev); if (rc) return rc; rc = tpm_xfer(dev, command, count, response, &response_length); |
8732b0700 tpm: Add TPM comm... |
256 257 258 259 260 261 |
free(command); if (!rc) { puts("tpm response: "); print_byte_string(response, response_length); } |
f8f1fe1d5 tpm: Report tpm e... |
262 |
return report_return_code(rc); |
8732b0700 tpm: Add TPM comm... |
263 |
} |
c61791876 tpm: align argume... |
264 265 |
static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
266 |
{ |
b9804e5bf tpm: substitute d... |
267 |
u32 index, perm, size; |
abdc7b8a2 tpm: Convert to u... |
268 269 270 271 272 273 |
struct udevice *dev; int rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
274 275 276 277 278 279 280 281 282 283 284 |
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 tpm: Convert to u... |
285 |
return report_return_code(tpm_nv_define_space(dev, index, perm, size)); |
8732b0700 tpm: Add TPM comm... |
286 |
} |
c61791876 tpm: align argume... |
287 288 |
static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
eea3f4d3e tpm: Add TPM stre... |
289 |
{ |
b9804e5bf tpm: substitute d... |
290 |
u32 index, count, err; |
abdc7b8a2 tpm: Convert to u... |
291 |
struct udevice *dev; |
8732b0700 tpm: Add TPM comm... |
292 |
void *data; |
abdc7b8a2 tpm: Convert to u... |
293 294 295 296 297 |
int rc; rc = get_tpm(&dev); if (rc) return rc; |
eea3f4d3e tpm: Add TPM stre... |
298 |
|
8732b0700 tpm: Add TPM comm... |
299 300 301 302 303 304 305 306 307 308 |
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 tpm: Add TPM stre... |
309 |
} |
abdc7b8a2 tpm: Convert to u... |
310 |
err = tpm_nv_read_value(dev, index, data, count); |
8732b0700 tpm: Add TPM comm... |
311 312 313 314 315 316 |
if (!err) { if (type_string_write_vars(argv[1], data, argv + 3)) { printf("Couldn't write to variables "); err = ~0; } |
eea3f4d3e tpm: Add TPM stre... |
317 |
} |
8732b0700 tpm: Add TPM comm... |
318 |
free(data); |
f8f1fe1d5 tpm: Report tpm e... |
319 |
return report_return_code(err); |
8732b0700 tpm: Add TPM comm... |
320 |
} |
c61791876 tpm: align argume... |
321 322 |
static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
8732b0700 tpm: Add TPM comm... |
323 |
{ |
b9804e5bf tpm: substitute d... |
324 |
u32 index, count, err; |
abdc7b8a2 tpm: Convert to u... |
325 |
struct udevice *dev; |
8732b0700 tpm: Add TPM comm... |
326 |
void *data; |
abdc7b8a2 tpm: Convert to u... |
327 328 329 330 331 |
int rc; rc = get_tpm(&dev); if (rc) return rc; |
8732b0700 tpm: Add TPM comm... |
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
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 tpm: Convert to u... |
350 |
err = tpm_nv_write_value(dev, index, data, count); |
8732b0700 tpm: Add TPM comm... |
351 |
free(data); |
f8f1fe1d5 tpm: Report tpm e... |
352 |
return report_return_code(err); |
8732b0700 tpm: Add TPM comm... |
353 |
} |
be6c1529c tpm: add AUTH1 cm... |
354 |
#ifdef CONFIG_TPM_AUTH_SESSIONS |
c61791876 tpm: align argume... |
355 356 |
static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
be6c1529c tpm: add AUTH1 cm... |
357 |
{ |
b9804e5bf tpm: substitute d... |
358 |
u32 auth_handle, err; |
abdc7b8a2 tpm: Convert to u... |
359 360 361 362 363 364 |
struct udevice *dev; int rc; rc = get_tpm(&dev); if (rc) return rc; |
be6c1529c tpm: add AUTH1 cm... |
365 |
|
abdc7b8a2 tpm: Convert to u... |
366 |
err = tpm_oiap(dev, &auth_handle); |
be6c1529c tpm: add AUTH1 cm... |
367 |
|
f8f1fe1d5 tpm: Report tpm e... |
368 |
return report_return_code(err); |
be6c1529c tpm: add AUTH1 cm... |
369 |
} |
0f4b2ba17 tpm: Add function... |
370 371 372 373 |
#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 tpm: substitute d... |
374 375 376 377 |
u32 parent_handle = 0; u32 key_len, key_handle, err; u8 usage_auth[DIGEST_LENGTH]; u8 parent_hash[DIGEST_LENGTH]; |
0f4b2ba17 tpm: Add function... |
378 |
void *key; |
abdc7b8a2 tpm: Convert to u... |
379 380 381 382 383 |
struct udevice *dev; rc = get_tpm(&dev); if (rc) return rc; |
0f4b2ba17 tpm: Add function... |
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 409 |
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 env: Rename commo... |
410 |
env_set_hex("key_handle", key_handle); |
0f4b2ba17 tpm: Add function... |
411 412 413 414 415 |
} return report_return_code(err); } #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */ |
c61791876 tpm: align argume... |
416 417 |
static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
be6c1529c tpm: add AUTH1 cm... |
418 |
{ |
b9804e5bf tpm: substitute d... |
419 420 |
u32 parent_handle, key_len, key_handle, err; u8 usage_auth[DIGEST_LENGTH]; |
be6c1529c tpm: add AUTH1 cm... |
421 |
void *key; |
abdc7b8a2 tpm: Convert to u... |
422 423 424 425 426 427 |
struct udevice *dev; int rc; rc = get_tpm(&dev); if (rc) return rc; |
be6c1529c tpm: add AUTH1 cm... |
428 429 430 431 432 433 434 435 436 437 |
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 tpm: Convert to u... |
438 |
err = tpm_load_key2_oiap(dev, parent_handle, key, key_len, usage_auth, |
c61791876 tpm: align argume... |
439 |
&key_handle); |
be6c1529c tpm: add AUTH1 cm... |
440 441 442 |
if (!err) printf("Key handle is 0x%x ", key_handle); |
f8f1fe1d5 tpm: Report tpm e... |
443 |
return report_return_code(err); |
be6c1529c tpm: add AUTH1 cm... |
444 |
} |
c61791876 tpm: align argume... |
445 446 |
static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
be6c1529c tpm: add AUTH1 cm... |
447 |
{ |
b9804e5bf tpm: substitute d... |
448 449 450 |
u32 key_handle, err; u8 usage_auth[DIGEST_LENGTH]; u8 pub_key_buffer[TPM_PUBKEY_MAX_LENGTH]; |
be6c1529c tpm: add AUTH1 cm... |
451 |
size_t pub_key_len = sizeof(pub_key_buffer); |
abdc7b8a2 tpm: Convert to u... |
452 453 454 455 456 457 |
struct udevice *dev; int rc; rc = get_tpm(&dev); if (rc) return rc; |
be6c1529c tpm: add AUTH1 cm... |
458 459 460 461 462 463 464 465 |
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 tpm: Convert to u... |
466 |
err = tpm_get_pub_key_oiap(dev, key_handle, usage_auth, pub_key_buffer, |
c61791876 tpm: align argume... |
467 |
&pub_key_len); |
be6c1529c tpm: add AUTH1 cm... |
468 469 470 471 472 |
if (!err) { printf("dump of received pub key structure: "); print_byte_string(pub_key_buffer, pub_key_len); } |
f8f1fe1d5 tpm: Report tpm e... |
473 |
return report_return_code(err); |
be6c1529c tpm: add AUTH1 cm... |
474 475 476 477 478 |
} TPM_COMMAND_NO_ARG(tpm_end_oiap) #endif /* CONFIG_TPM_AUTH_SESSIONS */ |
7690be35d lib: tpm: Add com... |
479 480 481 482 |
#ifdef CONFIG_TPM_FLUSH_RESOURCES static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { |
abdc7b8a2 tpm: Convert to u... |
483 |
struct udevice *dev; |
7690be35d lib: tpm: Add com... |
484 |
int type = 0; |
abdc7b8a2 tpm: Convert to u... |
485 486 487 488 489 |
int rc; rc = get_tpm(&dev); if (rc) return rc; |
7690be35d lib: tpm: Add com... |
490 |
|
1c08b210a cmd: tpm: Fix flu... |
491 |
if (argc != 3) |
7690be35d lib: tpm: Add com... |
492 |
return CMD_RET_USAGE; |
1c08b210a cmd: tpm: Fix flu... |
493 |
if (!strcasecmp(argv[1], "key")) |
7690be35d lib: tpm: Add com... |
494 |
type = TPM_RT_KEY; |
1c08b210a cmd: tpm: Fix flu... |
495 |
else if (!strcasecmp(argv[1], "auth")) |
7690be35d lib: tpm: Add com... |
496 |
type = TPM_RT_AUTH; |
1c08b210a cmd: tpm: Fix flu... |
497 |
else if (!strcasecmp(argv[1], "hash")) |
7690be35d lib: tpm: Add com... |
498 |
type = TPM_RT_HASH; |
1c08b210a cmd: tpm: Fix flu... |
499 |
else if (!strcasecmp(argv[1], "trans")) |
7690be35d lib: tpm: Add com... |
500 |
type = TPM_RT_TRANS; |
1c08b210a cmd: tpm: Fix flu... |
501 |
else if (!strcasecmp(argv[1], "context")) |
7690be35d lib: tpm: Add com... |
502 |
type = TPM_RT_CONTEXT; |
1c08b210a cmd: tpm: Fix flu... |
503 |
else if (!strcasecmp(argv[1], "counter")) |
7690be35d lib: tpm: Add com... |
504 |
type = TPM_RT_COUNTER; |
1c08b210a cmd: tpm: Fix flu... |
505 |
else if (!strcasecmp(argv[1], "delegate")) |
7690be35d lib: tpm: Add com... |
506 |
type = TPM_RT_DELEGATE; |
1c08b210a cmd: tpm: Fix flu... |
507 |
else if (!strcasecmp(argv[1], "daa_tpm")) |
7690be35d lib: tpm: Add com... |
508 |
type = TPM_RT_DAA_TPM; |
1c08b210a cmd: tpm: Fix flu... |
509 |
else if (!strcasecmp(argv[1], "daa_v0")) |
7690be35d lib: tpm: Add com... |
510 |
type = TPM_RT_DAA_V0; |
1c08b210a cmd: tpm: Fix flu... |
511 |
else if (!strcasecmp(argv[1], "daa_v1")) |
7690be35d lib: tpm: Add com... |
512 |
type = TPM_RT_DAA_V1; |
1c08b210a cmd: tpm: Fix flu... |
513 514 515 516 517 518 519 |
if (!type) { printf("Resource type %s unknown. ", argv[1]); return -1; } if (!strcasecmp(argv[2], "all")) { |
b9804e5bf tpm: substitute d... |
520 521 522 |
u16 res_count; u8 buf[288]; u8 *ptr; |
7690be35d lib: tpm: Add com... |
523 524 525 526 |
int err; uint i; /* fetch list of already loaded resources in the TPM */ |
abdc7b8a2 tpm: Convert to u... |
527 |
err = tpm_get_capability(dev, TPM_CAP_HANDLE, type, buf, |
7690be35d lib: tpm: Add com... |
528 |
sizeof(buf)); |
1c08b210a cmd: tpm: Fix flu... |
529 530 531 |
if (err) { printf("tpm_get_capability returned error %d. ", err); |
7690be35d lib: tpm: Add com... |
532 |
return -1; |
1c08b210a cmd: tpm: Fix flu... |
533 |
} |
7690be35d lib: tpm: Add com... |
534 535 536 |
res_count = get_unaligned_be16(buf); ptr = buf + 2; for (i = 0; i < res_count; ++i, ptr += 4) |
abdc7b8a2 tpm: Convert to u... |
537 |
tpm_flush_specific(dev, get_unaligned_be32(ptr), type); |
7690be35d lib: tpm: Add com... |
538 |
} else { |
b9804e5bf tpm: substitute d... |
539 |
u32 handle = simple_strtoul(argv[2], NULL, 0); |
7690be35d lib: tpm: Add com... |
540 |
|
1c08b210a cmd: tpm: Fix flu... |
541 542 543 |
if (!handle) { printf("Illegal resource handle %s ", argv[2]); |
7690be35d lib: tpm: Add com... |
544 |
return -1; |
1c08b210a cmd: tpm: Fix flu... |
545 |
} |
abdc7b8a2 tpm: Convert to u... |
546 |
tpm_flush_specific(dev, cpu_to_be32(handle), type); |
7690be35d lib: tpm: Add com... |
547 548 549 550 551 |
} return 0; } #endif /* CONFIG_TPM_FLUSH_RESOURCES */ |
3d1df0e36 lib: tpm: Add com... |
552 553 554 555 556 |
#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 tpm: substitute d... |
557 558 559 |
u16 res_count; u8 buf[288]; u8 *ptr; |
3d1df0e36 lib: tpm: Add com... |
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 617 |
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 tpm: disociate TP... |
618 619 620 621 622 |
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 tpm: Add TPM comm... |
623 |
|
d677bfe2f tpm: disociate TP... |
624 |
static cmd_tbl_t tpm1_commands[] = { |
3780e2d08 cmd: tpm: add a s... |
625 |
U_BOOT_CMD_MKENT(device, 0, 1, do_tpm_device, "", ""), |
ad77694e2 tpm: Add a 'tpm i... |
626 |
U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""), |
c61791876 tpm: align argume... |
627 |
U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""), |
8732b0700 tpm: Add TPM comm... |
628 |
U_BOOT_CMD_MKENT(startup, 0, 1, |
c61791876 tpm: align argume... |
629 |
do_tpm_startup, "", ""), |
8732b0700 tpm: Add TPM comm... |
630 |
U_BOOT_CMD_MKENT(self_test_full, 0, 1, |
c61791876 tpm: align argume... |
631 |
do_tpm_self_test_full, "", ""), |
8732b0700 tpm: Add TPM comm... |
632 |
U_BOOT_CMD_MKENT(continue_self_test, 0, 1, |
c61791876 tpm: align argume... |
633 |
do_tpm_continue_self_test, "", ""), |
8732b0700 tpm: Add TPM comm... |
634 |
U_BOOT_CMD_MKENT(force_clear, 0, 1, |
c61791876 tpm: align argume... |
635 |
do_tpm_force_clear, "", ""), |
8732b0700 tpm: Add TPM comm... |
636 |
U_BOOT_CMD_MKENT(physical_enable, 0, 1, |
c61791876 tpm: align argume... |
637 |
do_tpm_physical_enable, "", ""), |
8732b0700 tpm: Add TPM comm... |
638 |
U_BOOT_CMD_MKENT(physical_disable, 0, 1, |
c61791876 tpm: align argume... |
639 |
do_tpm_physical_disable, "", ""), |
8732b0700 tpm: Add TPM comm... |
640 |
U_BOOT_CMD_MKENT(nv_define_space, 0, 1, |
c61791876 tpm: align argume... |
641 |
do_tpm_nv_define_space, "", ""), |
8732b0700 tpm: Add TPM comm... |
642 |
U_BOOT_CMD_MKENT(nv_read_value, 0, 1, |
c61791876 tpm: align argume... |
643 |
do_tpm_nv_read_value, "", ""), |
8732b0700 tpm: Add TPM comm... |
644 |
U_BOOT_CMD_MKENT(nv_write_value, 0, 1, |
c61791876 tpm: align argume... |
645 |
do_tpm_nv_write_value, "", ""), |
8732b0700 tpm: Add TPM comm... |
646 |
U_BOOT_CMD_MKENT(extend, 0, 1, |
c61791876 tpm: align argume... |
647 |
do_tpm_extend, "", ""), |
8732b0700 tpm: Add TPM comm... |
648 |
U_BOOT_CMD_MKENT(pcr_read, 0, 1, |
c61791876 tpm: align argume... |
649 |
do_tpm_pcr_read, "", ""), |
8732b0700 tpm: Add TPM comm... |
650 |
U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1, |
c61791876 tpm: align argume... |
651 |
do_tpm_tsc_physical_presence, "", ""), |
8732b0700 tpm: Add TPM comm... |
652 |
U_BOOT_CMD_MKENT(read_pubek, 0, 1, |
c61791876 tpm: align argume... |
653 |
do_tpm_read_pubek, "", ""), |
8732b0700 tpm: Add TPM comm... |
654 |
U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1, |
c61791876 tpm: align argume... |
655 |
do_tpm_physical_set_deactivated, "", ""), |
8732b0700 tpm: Add TPM comm... |
656 |
U_BOOT_CMD_MKENT(get_capability, 0, 1, |
c61791876 tpm: align argume... |
657 |
do_tpm_get_capability, "", ""), |
8732b0700 tpm: Add TPM comm... |
658 |
U_BOOT_CMD_MKENT(raw_transfer, 0, 1, |
c61791876 tpm: align argume... |
659 |
do_tpm_raw_transfer, "", ""), |
8732b0700 tpm: Add TPM comm... |
660 |
U_BOOT_CMD_MKENT(nv_define, 0, 1, |
c61791876 tpm: align argume... |
661 |
do_tpm_nv_define, "", ""), |
8732b0700 tpm: Add TPM comm... |
662 |
U_BOOT_CMD_MKENT(nv_read, 0, 1, |
c61791876 tpm: align argume... |
663 |
do_tpm_nv_read, "", ""), |
8732b0700 tpm: Add TPM comm... |
664 |
U_BOOT_CMD_MKENT(nv_write, 0, 1, |
c61791876 tpm: align argume... |
665 |
do_tpm_nv_write, "", ""), |
be6c1529c tpm: add AUTH1 cm... |
666 667 668 669 670 671 672 |
#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 tpm: Add function... |
673 674 675 676 |
#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 tpm: add AUTH1 cm... |
677 678 679 |
U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1, do_tpm_get_pub_key_oiap, "", ""), #endif /* CONFIG_TPM_AUTH_SESSIONS */ |
7690be35d lib: tpm: Add com... |
680 681 682 683 |
#ifdef CONFIG_TPM_FLUSH_RESOURCES U_BOOT_CMD_MKENT(flush, 0, 1, do_tpm_flush, "", ""), #endif /* CONFIG_TPM_FLUSH_RESOURCES */ |
3d1df0e36 lib: tpm: Add com... |
684 685 686 687 |
#ifdef CONFIG_TPM_LIST_RESOURCES U_BOOT_CMD_MKENT(list, 0, 1, do_tpm_list, "", ""), #endif /* CONFIG_TPM_LIST_RESOURCES */ |
8732b0700 tpm: Add TPM comm... |
688 |
}; |
2a2096ea6 tpm: allow TPM v1... |
689 |
cmd_tbl_t *get_tpm1_commands(unsigned int *size) |
8732b0700 tpm: Add TPM comm... |
690 |
{ |
d677bfe2f tpm: disociate TP... |
691 |
*size = ARRAY_SIZE(tpm1_commands); |
eea3f4d3e tpm: Add TPM stre... |
692 |
|
d677bfe2f tpm: disociate TP... |
693 |
return tpm1_commands; |
eea3f4d3e tpm: Add TPM stre... |
694 |
} |
8732b0700 tpm: Add TPM comm... |
695 |
U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, |
d677bfe2f tpm: disociate TP... |
696 |
"Issue a TPMv1.x command", |
8732b0700 tpm: Add TPM comm... |
697 698 699 700 701 702 |
"cmd args... " " - Issue TPM command <cmd> with arguments <args...>. " "Admin Startup and State Commands: " |
3780e2d08 cmd: tpm: add a s... |
703 704 705 706 |
" device [num device] " " - Show all devices or set the specified device " |
ad77694e2 tpm: Add a 'tpm i... |
707 708 |
" info - Show information about the TPM " |
8732b0700 tpm: Add TPM comm... |
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 759 760 761 762 763 764 |
" 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 lib: tpm: Add com... |
765 |
#if defined(CONFIG_TPM_FLUSH_RESOURCES) || defined(CONFIG_TPM_LIST_RESOURCES) |
7690be35d lib: tpm: Add com... |
766 767 |
"Resource management functions " |
3d1df0e36 lib: tpm: Add com... |
768 769 |
#endif #ifdef CONFIG_TPM_FLUSH_RESOURCES |
7690be35d lib: tpm: Add com... |
770 771 772 773 774 775 776 777 778 779 780 |
" 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 lib: tpm: Add com... |
781 782 783 784 785 786 787 788 789 790 |
#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 tpm: add AUTH1 cm... |
791 792 793 794 795 796 797 798 799 800 801 |
#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 tpm: Add function... |
802 803 804 805 806 807 808 809 810 811 |
#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 tpm: add AUTH1 cm... |
812 813 814 815 816 817 818 |
" 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 tpm: Add TPM comm... |
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
"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 tpm: add AUTH1 cm... |
839 840 841 842 843 844 845 846 847 848 849 850 |
#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 tpm: Add TPM comm... |
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 889 890 891 892 893 894 |
"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 tpm: Add TPM stre... |
895 |
); |