cmd_tpm.c 20 KB

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