tpm-v1.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2013 The Chromium OS Authors.
  4. */
  5. #include <common.h>
  6. #include <malloc.h>
  7. #include <asm/unaligned.h>
  8. #include <tpm-common.h>
  9. #include <tpm-v1.h>
  10. #include "tpm-user-utils.h"
  11. static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag, int argc,
  12. char * const argv[])
  13. {
  14. enum tpm_startup_type mode;
  15. if (argc != 2)
  16. return CMD_RET_USAGE;
  17. if (!strcasecmp("TPM_ST_CLEAR", argv[1])) {
  18. mode = TPM_ST_CLEAR;
  19. } else if (!strcasecmp("TPM_ST_STATE", argv[1])) {
  20. mode = TPM_ST_STATE;
  21. } else if (!strcasecmp("TPM_ST_DEACTIVATED", argv[1])) {
  22. mode = TPM_ST_DEACTIVATED;
  23. } else {
  24. printf("Couldn't recognize mode string: %s\n", argv[1]);
  25. return CMD_RET_FAILURE;
  26. }
  27. return report_return_code(tpm_startup(mode));
  28. }
  29. static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag, int argc,
  30. char * const argv[])
  31. {
  32. u32 index, perm, size;
  33. if (argc != 4)
  34. return CMD_RET_USAGE;
  35. index = simple_strtoul(argv[1], NULL, 0);
  36. perm = simple_strtoul(argv[2], NULL, 0);
  37. size = simple_strtoul(argv[3], NULL, 0);
  38. return report_return_code(tpm_nv_define_space(index, perm, size));
  39. }
  40. static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag, int argc,
  41. char * const argv[])
  42. {
  43. u32 index, count, rc;
  44. void *data;
  45. if (argc != 4)
  46. return CMD_RET_USAGE;
  47. index = simple_strtoul(argv[1], NULL, 0);
  48. data = (void *)simple_strtoul(argv[2], NULL, 0);
  49. count = simple_strtoul(argv[3], NULL, 0);
  50. rc = tpm_nv_read_value(index, data, count);
  51. if (!rc) {
  52. puts("area content:\n");
  53. print_byte_string(data, count);
  54. }
  55. return report_return_code(rc);
  56. }
  57. static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag, int argc,
  58. char * const argv[])
  59. {
  60. u32 index, rc;
  61. size_t count;
  62. void *data;
  63. if (argc != 3)
  64. return CMD_RET_USAGE;
  65. index = simple_strtoul(argv[1], NULL, 0);
  66. data = parse_byte_string(argv[2], NULL, &count);
  67. if (!data) {
  68. printf("Couldn't parse byte string %s\n", argv[2]);
  69. return CMD_RET_FAILURE;
  70. }
  71. rc = tpm_nv_write_value(index, data, count);
  72. free(data);
  73. return report_return_code(rc);
  74. }
  75. static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag, int argc,
  76. char * const argv[])
  77. {
  78. u32 index, rc;
  79. u8 in_digest[20], out_digest[20];
  80. if (argc != 3)
  81. return CMD_RET_USAGE;
  82. index = simple_strtoul(argv[1], NULL, 0);
  83. if (!parse_byte_string(argv[2], in_digest, NULL)) {
  84. printf("Couldn't parse byte string %s\n", argv[2]);
  85. return CMD_RET_FAILURE;
  86. }
  87. rc = tpm_extend(index, in_digest, out_digest);
  88. if (!rc) {
  89. puts("PCR value after execution of the command:\n");
  90. print_byte_string(out_digest, sizeof(out_digest));
  91. }
  92. return report_return_code(rc);
  93. }
  94. static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
  95. char * const argv[])
  96. {
  97. u32 index, count, rc;
  98. void *data;
  99. if (argc != 4)
  100. return CMD_RET_USAGE;
  101. index = simple_strtoul(argv[1], NULL, 0);
  102. data = (void *)simple_strtoul(argv[2], NULL, 0);
  103. count = simple_strtoul(argv[3], NULL, 0);
  104. rc = tpm_pcr_read(index, data, count);
  105. if (!rc) {
  106. puts("Named PCR content:\n");
  107. print_byte_string(data, count);
  108. }
  109. return report_return_code(rc);
  110. }
  111. static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag, int argc,
  112. char * const argv[])
  113. {
  114. u16 presence;
  115. if (argc != 2)
  116. return CMD_RET_USAGE;
  117. presence = (u16)simple_strtoul(argv[1], NULL, 0);
  118. return report_return_code(tpm_tsc_physical_presence(presence));
  119. }
  120. static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag, int argc,
  121. char * const argv[])
  122. {
  123. u32 count, rc;
  124. void *data;
  125. if (argc != 3)
  126. return CMD_RET_USAGE;
  127. data = (void *)simple_strtoul(argv[1], NULL, 0);
  128. count = simple_strtoul(argv[2], NULL, 0);
  129. rc = tpm_read_pubek(data, count);
  130. if (!rc) {
  131. puts("pubek value:\n");
  132. print_byte_string(data, count);
  133. }
  134. return report_return_code(rc);
  135. }
  136. static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag, int argc,
  137. char * const argv[])
  138. {
  139. u8 state;
  140. if (argc != 2)
  141. return CMD_RET_USAGE;
  142. state = (u8)simple_strtoul(argv[1], NULL, 0);
  143. return report_return_code(tpm_physical_set_deactivated(state));
  144. }
  145. static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
  146. char * const argv[])
  147. {
  148. u32 cap_area, sub_cap, rc;
  149. void *cap;
  150. size_t count;
  151. if (argc != 5)
  152. return CMD_RET_USAGE;
  153. cap_area = simple_strtoul(argv[1], NULL, 0);
  154. sub_cap = simple_strtoul(argv[2], NULL, 0);
  155. cap = (void *)simple_strtoul(argv[3], NULL, 0);
  156. count = simple_strtoul(argv[4], NULL, 0);
  157. rc = tpm_get_capability(cap_area, sub_cap, cap, count);
  158. if (!rc) {
  159. puts("capability information:\n");
  160. print_byte_string(cap, count);
  161. }
  162. return report_return_code(rc);
  163. }
  164. static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag, int argc,
  165. char * const argv[])
  166. {
  167. struct udevice *dev;
  168. void *command;
  169. u8 response[1024];
  170. size_t count, response_length = sizeof(response);
  171. u32 rc;
  172. command = parse_byte_string(argv[1], NULL, &count);
  173. if (!command) {
  174. printf("Couldn't parse byte string %s\n", argv[1]);
  175. return CMD_RET_FAILURE;
  176. }
  177. rc = get_tpm(&dev);
  178. if (rc)
  179. return rc;
  180. rc = tpm_xfer(dev, command, count, response, &response_length);
  181. free(command);
  182. if (!rc) {
  183. puts("tpm response:\n");
  184. print_byte_string(response, response_length);
  185. }
  186. return report_return_code(rc);
  187. }
  188. static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag, int argc,
  189. char * const argv[])
  190. {
  191. u32 index, perm, size;
  192. if (argc != 4)
  193. return CMD_RET_USAGE;
  194. size = type_string_get_space_size(argv[1]);
  195. if (!size) {
  196. printf("Couldn't parse arguments\n");
  197. return CMD_RET_USAGE;
  198. }
  199. index = simple_strtoul(argv[2], NULL, 0);
  200. perm = simple_strtoul(argv[3], NULL, 0);
  201. return report_return_code(tpm_nv_define_space(index, perm, size));
  202. }
  203. static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag, int argc,
  204. char * const argv[])
  205. {
  206. u32 index, count, err;
  207. void *data;
  208. if (argc < 3)
  209. return CMD_RET_USAGE;
  210. if (argc != 3 + type_string_get_num_values(argv[1]))
  211. return CMD_RET_USAGE;
  212. index = simple_strtoul(argv[2], NULL, 0);
  213. data = type_string_alloc(argv[1], &count);
  214. if (!data) {
  215. printf("Couldn't parse arguments\n");
  216. return CMD_RET_USAGE;
  217. }
  218. err = tpm_nv_read_value(index, data, count);
  219. if (!err) {
  220. if (type_string_write_vars(argv[1], data, argv + 3)) {
  221. printf("Couldn't write to variables\n");
  222. err = ~0;
  223. }
  224. }
  225. free(data);
  226. return report_return_code(err);
  227. }
  228. static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag, int argc,
  229. char * const argv[])
  230. {
  231. u32 index, count, err;
  232. void *data;
  233. if (argc < 3)
  234. return CMD_RET_USAGE;
  235. if (argc != 3 + type_string_get_num_values(argv[1]))
  236. return CMD_RET_USAGE;
  237. index = simple_strtoul(argv[2], NULL, 0);
  238. data = type_string_alloc(argv[1], &count);
  239. if (!data) {
  240. printf("Couldn't parse arguments\n");
  241. return CMD_RET_USAGE;
  242. }
  243. if (type_string_pack(argv[1], argv + 3, data)) {
  244. printf("Couldn't parse arguments\n");
  245. free(data);
  246. return CMD_RET_USAGE;
  247. }
  248. err = tpm_nv_write_value(index, data, count);
  249. free(data);
  250. return report_return_code(err);
  251. }
  252. #ifdef CONFIG_TPM_AUTH_SESSIONS
  253. static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
  254. char * const argv[])
  255. {
  256. u32 auth_handle, err;
  257. err = tpm_oiap(&auth_handle);
  258. return report_return_code(err);
  259. }
  260. #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
  261. static int do_tpm_load_key_by_sha1(cmd_tbl_t *cmdtp, int flag, int argc, char *
  262. const argv[])
  263. {
  264. u32 parent_handle = 0;
  265. u32 key_len, key_handle, err;
  266. u8 usage_auth[DIGEST_LENGTH];
  267. u8 parent_hash[DIGEST_LENGTH];
  268. void *key;
  269. if (argc < 5)
  270. return CMD_RET_USAGE;
  271. parse_byte_string(argv[1], parent_hash, NULL);
  272. key = (void *)simple_strtoul(argv[2], NULL, 0);
  273. key_len = simple_strtoul(argv[3], NULL, 0);
  274. if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
  275. return CMD_RET_FAILURE;
  276. parse_byte_string(argv[4], usage_auth, NULL);
  277. err = tpm_find_key_sha1(usage_auth, parent_hash, &parent_handle);
  278. if (err) {
  279. printf("Could not find matching parent key (err = %d)\n", err);
  280. return CMD_RET_FAILURE;
  281. }
  282. printf("Found parent key %08x\n", parent_handle);
  283. err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth,
  284. &key_handle);
  285. if (!err) {
  286. printf("Key handle is 0x%x\n", key_handle);
  287. env_set_hex("key_handle", key_handle);
  288. }
  289. return report_return_code(err);
  290. }
  291. #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
  292. static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
  293. char * const argv[])
  294. {
  295. u32 parent_handle, key_len, key_handle, err;
  296. u8 usage_auth[DIGEST_LENGTH];
  297. void *key;
  298. if (argc < 5)
  299. return CMD_RET_USAGE;
  300. parent_handle = simple_strtoul(argv[1], NULL, 0);
  301. key = (void *)simple_strtoul(argv[2], NULL, 0);
  302. key_len = simple_strtoul(argv[3], NULL, 0);
  303. if (strlen(argv[4]) != 2 * DIGEST_LENGTH)
  304. return CMD_RET_FAILURE;
  305. parse_byte_string(argv[4], usage_auth, NULL);
  306. err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth,
  307. &key_handle);
  308. if (!err)
  309. printf("Key handle is 0x%x\n", key_handle);
  310. return report_return_code(err);
  311. }
  312. static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
  313. char * const argv[])
  314. {
  315. u32 key_handle, err;
  316. u8 usage_auth[DIGEST_LENGTH];
  317. u8 pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
  318. size_t pub_key_len = sizeof(pub_key_buffer);
  319. if (argc < 3)
  320. return CMD_RET_USAGE;
  321. key_handle = simple_strtoul(argv[1], NULL, 0);
  322. if (strlen(argv[2]) != 2 * DIGEST_LENGTH)
  323. return CMD_RET_FAILURE;
  324. parse_byte_string(argv[2], usage_auth, NULL);
  325. err = tpm_get_pub_key_oiap(key_handle, usage_auth, pub_key_buffer,
  326. &pub_key_len);
  327. if (!err) {
  328. printf("dump of received pub key structure:\n");
  329. print_byte_string(pub_key_buffer, pub_key_len);
  330. }
  331. return report_return_code(err);
  332. }
  333. TPM_COMMAND_NO_ARG(tpm_end_oiap)
  334. #endif /* CONFIG_TPM_AUTH_SESSIONS */
  335. #ifdef CONFIG_TPM_FLUSH_RESOURCES
  336. static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc,
  337. char * const argv[])
  338. {
  339. int type = 0;
  340. if (argc != 3)
  341. return CMD_RET_USAGE;
  342. if (!strcasecmp(argv[1], "key"))
  343. type = TPM_RT_KEY;
  344. else if (!strcasecmp(argv[1], "auth"))
  345. type = TPM_RT_AUTH;
  346. else if (!strcasecmp(argv[1], "hash"))
  347. type = TPM_RT_HASH;
  348. else if (!strcasecmp(argv[1], "trans"))
  349. type = TPM_RT_TRANS;
  350. else if (!strcasecmp(argv[1], "context"))
  351. type = TPM_RT_CONTEXT;
  352. else if (!strcasecmp(argv[1], "counter"))
  353. type = TPM_RT_COUNTER;
  354. else if (!strcasecmp(argv[1], "delegate"))
  355. type = TPM_RT_DELEGATE;
  356. else if (!strcasecmp(argv[1], "daa_tpm"))
  357. type = TPM_RT_DAA_TPM;
  358. else if (!strcasecmp(argv[1], "daa_v0"))
  359. type = TPM_RT_DAA_V0;
  360. else if (!strcasecmp(argv[1], "daa_v1"))
  361. type = TPM_RT_DAA_V1;
  362. if (!type) {
  363. printf("Resource type %s unknown.\n", argv[1]);
  364. return -1;
  365. }
  366. if (!strcasecmp(argv[2], "all")) {
  367. u16 res_count;
  368. u8 buf[288];
  369. u8 *ptr;
  370. int err;
  371. uint i;
  372. /* fetch list of already loaded resources in the TPM */
  373. err = tpm_get_capability(TPM_CAP_HANDLE, type, buf,
  374. sizeof(buf));
  375. if (err) {
  376. printf("tpm_get_capability returned error %d.\n", err);
  377. return -1;
  378. }
  379. res_count = get_unaligned_be16(buf);
  380. ptr = buf + 2;
  381. for (i = 0; i < res_count; ++i, ptr += 4)
  382. tpm_flush_specific(get_unaligned_be32(ptr), type);
  383. } else {
  384. u32 handle = simple_strtoul(argv[2], NULL, 0);
  385. if (!handle) {
  386. printf("Illegal resource handle %s\n", argv[2]);
  387. return -1;
  388. }
  389. tpm_flush_specific(cpu_to_be32(handle), type);
  390. }
  391. return 0;
  392. }
  393. #endif /* CONFIG_TPM_FLUSH_RESOURCES */
  394. #ifdef CONFIG_TPM_LIST_RESOURCES
  395. static int do_tpm_list(cmd_tbl_t *cmdtp, int flag, int argc,
  396. char * const argv[])
  397. {
  398. int type = 0;
  399. u16 res_count;
  400. u8 buf[288];
  401. u8 *ptr;
  402. int err;
  403. uint i;
  404. if (argc != 2)
  405. return CMD_RET_USAGE;
  406. if (!strcasecmp(argv[1], "key"))
  407. type = TPM_RT_KEY;
  408. else if (!strcasecmp(argv[1], "auth"))
  409. type = TPM_RT_AUTH;
  410. else if (!strcasecmp(argv[1], "hash"))
  411. type = TPM_RT_HASH;
  412. else if (!strcasecmp(argv[1], "trans"))
  413. type = TPM_RT_TRANS;
  414. else if (!strcasecmp(argv[1], "context"))
  415. type = TPM_RT_CONTEXT;
  416. else if (!strcasecmp(argv[1], "counter"))
  417. type = TPM_RT_COUNTER;
  418. else if (!strcasecmp(argv[1], "delegate"))
  419. type = TPM_RT_DELEGATE;
  420. else if (!strcasecmp(argv[1], "daa_tpm"))
  421. type = TPM_RT_DAA_TPM;
  422. else if (!strcasecmp(argv[1], "daa_v0"))
  423. type = TPM_RT_DAA_V0;
  424. else if (!strcasecmp(argv[1], "daa_v1"))
  425. type = TPM_RT_DAA_V1;
  426. if (!type) {
  427. printf("Resource type %s unknown.\n", argv[1]);
  428. return -1;
  429. }
  430. /* fetch list of already loaded resources in the TPM */
  431. err = tpm_get_capability(TPM_CAP_HANDLE, type, buf,
  432. sizeof(buf));
  433. if (err) {
  434. printf("tpm_get_capability returned error %d.\n", err);
  435. return -1;
  436. }
  437. res_count = get_unaligned_be16(buf);
  438. ptr = buf + 2;
  439. printf("Resources of type %s (%02x):\n", argv[1], type);
  440. if (!res_count) {
  441. puts("None\n");
  442. } else {
  443. for (i = 0; i < res_count; ++i, ptr += 4)
  444. printf("Index %d: %08x\n", i, get_unaligned_be32(ptr));
  445. }
  446. return 0;
  447. }
  448. #endif /* CONFIG_TPM_LIST_RESOURCES */
  449. TPM_COMMAND_NO_ARG(tpm_self_test_full)
  450. TPM_COMMAND_NO_ARG(tpm_continue_self_test)
  451. TPM_COMMAND_NO_ARG(tpm_force_clear)
  452. TPM_COMMAND_NO_ARG(tpm_physical_enable)
  453. TPM_COMMAND_NO_ARG(tpm_physical_disable)
  454. static cmd_tbl_t tpm1_commands[] = {
  455. U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
  456. U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
  457. U_BOOT_CMD_MKENT(startup, 0, 1,
  458. do_tpm_startup, "", ""),
  459. U_BOOT_CMD_MKENT(self_test_full, 0, 1,
  460. do_tpm_self_test_full, "", ""),
  461. U_BOOT_CMD_MKENT(continue_self_test, 0, 1,
  462. do_tpm_continue_self_test, "", ""),
  463. U_BOOT_CMD_MKENT(force_clear, 0, 1,
  464. do_tpm_force_clear, "", ""),
  465. U_BOOT_CMD_MKENT(physical_enable, 0, 1,
  466. do_tpm_physical_enable, "", ""),
  467. U_BOOT_CMD_MKENT(physical_disable, 0, 1,
  468. do_tpm_physical_disable, "", ""),
  469. U_BOOT_CMD_MKENT(nv_define_space, 0, 1,
  470. do_tpm_nv_define_space, "", ""),
  471. U_BOOT_CMD_MKENT(nv_read_value, 0, 1,
  472. do_tpm_nv_read_value, "", ""),
  473. U_BOOT_CMD_MKENT(nv_write_value, 0, 1,
  474. do_tpm_nv_write_value, "", ""),
  475. U_BOOT_CMD_MKENT(extend, 0, 1,
  476. do_tpm_extend, "", ""),
  477. U_BOOT_CMD_MKENT(pcr_read, 0, 1,
  478. do_tpm_pcr_read, "", ""),
  479. U_BOOT_CMD_MKENT(tsc_physical_presence, 0, 1,
  480. do_tpm_tsc_physical_presence, "", ""),
  481. U_BOOT_CMD_MKENT(read_pubek, 0, 1,
  482. do_tpm_read_pubek, "", ""),
  483. U_BOOT_CMD_MKENT(physical_set_deactivated, 0, 1,
  484. do_tpm_physical_set_deactivated, "", ""),
  485. U_BOOT_CMD_MKENT(get_capability, 0, 1,
  486. do_tpm_get_capability, "", ""),
  487. U_BOOT_CMD_MKENT(raw_transfer, 0, 1,
  488. do_tpm_raw_transfer, "", ""),
  489. U_BOOT_CMD_MKENT(nv_define, 0, 1,
  490. do_tpm_nv_define, "", ""),
  491. U_BOOT_CMD_MKENT(nv_read, 0, 1,
  492. do_tpm_nv_read, "", ""),
  493. U_BOOT_CMD_MKENT(nv_write, 0, 1,
  494. do_tpm_nv_write, "", ""),
  495. #ifdef CONFIG_TPM_AUTH_SESSIONS
  496. U_BOOT_CMD_MKENT(oiap, 0, 1,
  497. do_tpm_oiap, "", ""),
  498. U_BOOT_CMD_MKENT(end_oiap, 0, 1,
  499. do_tpm_end_oiap, "", ""),
  500. U_BOOT_CMD_MKENT(load_key2_oiap, 0, 1,
  501. do_tpm_load_key2_oiap, "", ""),
  502. #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
  503. U_BOOT_CMD_MKENT(load_key_by_sha1, 0, 1,
  504. do_tpm_load_key_by_sha1, "", ""),
  505. #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
  506. U_BOOT_CMD_MKENT(get_pub_key_oiap, 0, 1,
  507. do_tpm_get_pub_key_oiap, "", ""),
  508. #endif /* CONFIG_TPM_AUTH_SESSIONS */
  509. #ifdef CONFIG_TPM_FLUSH_RESOURCES
  510. U_BOOT_CMD_MKENT(flush, 0, 1,
  511. do_tpm_flush, "", ""),
  512. #endif /* CONFIG_TPM_FLUSH_RESOURCES */
  513. #ifdef CONFIG_TPM_LIST_RESOURCES
  514. U_BOOT_CMD_MKENT(list, 0, 1,
  515. do_tpm_list, "", ""),
  516. #endif /* CONFIG_TPM_LIST_RESOURCES */
  517. };
  518. cmd_tbl_t *get_tpm1_commands(unsigned int *size)
  519. {
  520. *size = ARRAY_SIZE(tpm1_commands);
  521. return tpm1_commands;
  522. }
  523. U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
  524. "Issue a TPMv1.x command",
  525. "cmd args...\n"
  526. " - Issue TPM command <cmd> with arguments <args...>.\n"
  527. "Admin Startup and State Commands:\n"
  528. " info - Show information about the TPM\n"
  529. " init\n"
  530. " - Put TPM into a state where it waits for 'startup' command.\n"
  531. " startup mode\n"
  532. " - Issue TPM_Starup command. <mode> is one of TPM_ST_CLEAR,\n"
  533. " TPM_ST_STATE, and TPM_ST_DEACTIVATED.\n"
  534. "Admin Testing Commands:\n"
  535. " self_test_full\n"
  536. " - Test all of the TPM capabilities.\n"
  537. " continue_self_test\n"
  538. " - Inform TPM that it should complete the self-test.\n"
  539. "Admin Opt-in Commands:\n"
  540. " physical_enable\n"
  541. " - Set the PERMANENT disable flag to FALSE using physical presence as\n"
  542. " authorization.\n"
  543. " physical_disable\n"
  544. " - Set the PERMANENT disable flag to TRUE using physical presence as\n"
  545. " authorization.\n"
  546. " physical_set_deactivated 0|1\n"
  547. " - Set deactivated flag.\n"
  548. "Admin Ownership Commands:\n"
  549. " force_clear\n"
  550. " - Issue TPM_ForceClear command.\n"
  551. " tsc_physical_presence flags\n"
  552. " - Set TPM device's Physical Presence flags to <flags>.\n"
  553. "The Capability Commands:\n"
  554. " get_capability cap_area sub_cap addr count\n"
  555. " - Read <count> bytes of TPM capability indexed by <cap_area> and\n"
  556. " <sub_cap> to memory address <addr>.\n"
  557. #if defined(CONFIG_TPM_FLUSH_RESOURCES) || defined(CONFIG_TPM_LIST_RESOURCES)
  558. "Resource management functions\n"
  559. #endif
  560. #ifdef CONFIG_TPM_FLUSH_RESOURCES
  561. " flush resource_type id\n"
  562. " - flushes a resource of type <resource_type> (may be one of key, auth,\n"
  563. " hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1),\n"
  564. " and id <id> from the TPM. Use an <id> of \"all\" to flush all\n"
  565. " resources of that type.\n"
  566. #endif /* CONFIG_TPM_FLUSH_RESOURCES */
  567. #ifdef CONFIG_TPM_LIST_RESOURCES
  568. " list resource_type\n"
  569. " - lists resources of type <resource_type> (may be one of key, auth,\n"
  570. " hash, trans, context, counter, delegate, daa_tpm, daa_v0, daa_v1),\n"
  571. " contained in the TPM.\n"
  572. #endif /* CONFIG_TPM_LIST_RESOURCES */
  573. #ifdef CONFIG_TPM_AUTH_SESSIONS
  574. "Storage functions\n"
  575. " loadkey2_oiap parent_handle key_addr key_len usage_auth\n"
  576. " - loads a key data from memory address <key_addr>, <key_len> bytes\n"
  577. " into TPM using the parent key <parent_handle> with authorization\n"
  578. " <usage_auth> (20 bytes hex string).\n"
  579. #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
  580. " load_key_by_sha1 parent_hash key_addr key_len usage_auth\n"
  581. " - loads a key data from memory address <key_addr>, <key_len> bytes\n"
  582. " into TPM using the parent hash <parent_hash> (20 bytes hex string)\n"
  583. " with authorization <usage_auth> (20 bytes hex string).\n"
  584. #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
  585. " get_pub_key_oiap key_handle usage_auth\n"
  586. " - get the public key portion of a loaded key <key_handle> using\n"
  587. " authorization <usage auth> (20 bytes hex string)\n"
  588. #endif /* CONFIG_TPM_AUTH_SESSIONS */
  589. "Endorsement Key Handling Commands:\n"
  590. " read_pubek addr count\n"
  591. " - Read <count> bytes of the public endorsement key to memory\n"
  592. " address <addr>\n"
  593. "Integrity Collection and Reporting Commands:\n"
  594. " extend index digest_hex_string\n"
  595. " - Add a new measurement to a PCR. Update PCR <index> with the 20-bytes\n"
  596. " <digest_hex_string>\n"
  597. " pcr_read index addr count\n"
  598. " - Read <count> bytes from PCR <index> to memory address <addr>.\n"
  599. #ifdef CONFIG_TPM_AUTH_SESSIONS
  600. "Authorization Sessions\n"
  601. " oiap\n"
  602. " - setup an OIAP session\n"
  603. " end_oiap\n"
  604. " - terminates an active OIAP session\n"
  605. #endif /* CONFIG_TPM_AUTH_SESSIONS */
  606. "Non-volatile Storage Commands:\n"
  607. " nv_define_space index permission size\n"
  608. " - Establish a space at index <index> with <permission> of <size> bytes.\n"
  609. " nv_read_value index addr count\n"
  610. " - Read <count> bytes from space <index> to memory address <addr>.\n"
  611. " nv_write_value index addr count\n"
  612. " - Write <count> bytes from memory address <addr> to space <index>.\n"
  613. "Miscellaneous helper functions:\n"
  614. " raw_transfer byte_string\n"
  615. " - Send a byte string <byte_string> to TPM and print the response.\n"
  616. " Non-volatile storage helper functions:\n"
  617. " These helper functions treat a non-volatile space as a non-padded\n"
  618. " sequence of integer values. These integer values are defined by a type\n"
  619. " string, which is a text string of 'bwd' characters: 'b' means a 8-bit\n"
  620. " value, 'w' 16-bit value, 'd' 32-bit value. All helper functions take\n"
  621. " a type string as their first argument.\n"
  622. " nv_define type_string index perm\n"
  623. " - Define a space <index> with permission <perm>.\n"
  624. " nv_read types_string index vars...\n"
  625. " - Read from space <index> to environment variables <vars...>.\n"
  626. " nv_write types_string index values...\n"
  627. " - Write to space <index> from values <values...>.\n"
  628. );