tpm-v1.c 22 KB

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