cmd_tpm.c 19 KB

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