tpm-v1.c 22 KB

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