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