2 * Copyright (c) 2011 The Chromium OS Authors.
4 * See file CREDITS for list of people who contributed to this
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.
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.
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,
27 #define MAX_TRANSACTION_SIZE 30
30 * tpm_write() expects a variable number of parameters: the internal address
31 * followed by data to write, byte by byte.
33 * Returns 0 on success or -1 on errors (wrong arguments or TPM failure).
35 static int tpm_process(int argc, char * const argv[], cmd_tbl_t *cmdtp)
37 u8 tpm_buffer[MAX_TRANSACTION_SIZE];
38 u32 write_size, read_size;
42 for (write_size = 0; write_size < argc; write_size++) {
43 u32 datum = simple_strtoul(argv[write_size], &p, 0);
44 if (*p || (datum > 0xff)) {
45 printf("\n%s: bad data value\n\n", argv[write_size]);
49 tpm_buffer[write_size] = (u8)datum;
52 read_size = sizeof(tpm_buffer);
53 if (!tis_sendrecv(tpm_buffer, write_size, tpm_buffer, &read_size)) {
55 puts("Got TPM response:\n");
56 for (i = 0; i < read_size; i++)
57 printf(" %2.2x", tpm_buffer[i]);
61 puts("tpm command failed\n");
66 static int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71 * Verify that in case it is present, the first argument, it is
72 * exactly one character in size.
75 puts("command should be at least six bytes in size\n");
80 puts("tis_init() failed!\n");
85 puts("tis_open() failed!\n");
89 rv = tpm_process(argc - 1, argv + 1, cmdtp);
92 puts("tis_close() failed!\n");
99 U_BOOT_CMD(tpm, MAX_TRANSACTION_SIZE, 1, do_tpm,
100 "<byte> [<byte> ...] - write data and read response",
101 "send arbitrary data (at least 6 bytes) to the TPM "
102 "device and read the response"