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