tpm-v1.c 21 KB

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