tpm-v1.c 22 KB

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