X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ftpm.c;h=8a622162740f9863b76b2cddfc80dee4886c1c7a;hb=3a85e4362aa830c0beb2b0253c0e70102b42f066;hp=f0b4f59eafc73d77e13c1d6d5ca775a081409296;hpb=be6c1529c1ce9718cc955f23fdaa5891d15b6551;p=oweals%2Fu-boot.git diff --git a/lib/tpm.c b/lib/tpm.c index f0b4f59eaf..8a62216274 100644 --- a/lib/tpm.c +++ b/lib/tpm.c @@ -2,30 +2,14 @@ * Copyright (c) 2013 The Chromium OS Authors. * Coypright (c) 2013 Guntermann & Drunck GmbH * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ #include -#include -#include +#include #include #include +#include /* Internal error of TPM command library */ #define TPM_LIB_ERROR ((uint32_t)~0u) @@ -33,7 +17,6 @@ /* Useful constants */ enum { COMMAND_BUFFER_SIZE = 256, - TPM_PUBEK_SIZE = 256, TPM_REQUEST_HEADER_LENGTH = 10, TPM_RESPONSE_HEADER_LENGTH = 10, PCR_DIGEST_LENGTH = 20, @@ -246,6 +229,8 @@ static uint32_t tpm_return_code(const void *response) static uint32_t tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr) { + struct udevice *dev; + int ret; uint8_t response_buffer[COMMAND_BUFFER_SIZE]; size_t response_length; uint32_t err; @@ -256,9 +241,14 @@ static uint32_t tpm_sendrecv_command(const void *command, response = response_buffer; response_length = sizeof(response_buffer); } - err = tis_sendrecv(command, tpm_command_size(command), - response, &response_length); - if (err) + + ret = uclass_first_device(UCLASS_TPM, &dev); + if (ret) + return ret; + err = tpm_xfer(dev, command, tpm_command_size(command), + response, &response_length); + + if (err < 0) return TPM_LIB_ERROR; if (size_ptr) *size_ptr = response_length; @@ -266,15 +256,15 @@ static uint32_t tpm_sendrecv_command(const void *command, return tpm_return_code(response); } -uint32_t tpm_init(void) +int tpm_init(void) { - uint32_t err; + int err; + struct udevice *dev; - err = tis_init(); + err = uclass_first_device(UCLASS_TPM, &dev); if (err) return err; - - return tis_open(); + return tpm_open(dev); } uint32_t tpm_startup(enum tpm_startup_type mode) @@ -605,6 +595,56 @@ uint32_t tpm_get_capability(uint32_t cap_area, uint32_t sub_cap, return 0; } +uint32_t tpm_get_permanent_flags(struct tpm_permanent_flags *pflags) +{ + const uint8_t command[22] = { + 0x0, 0xc1, /* TPM_TAG */ + 0x0, 0x0, 0x0, 0x16, /* parameter size */ + 0x0, 0x0, 0x0, 0x65, /* TPM_COMMAND_CODE */ + 0x0, 0x0, 0x0, 0x4, /* TPM_CAP_FLAG_PERM */ + 0x0, 0x0, 0x0, 0x4, /* subcap size */ + 0x0, 0x0, 0x1, 0x8, /* subcap value */ + }; + uint8_t response[COMMAND_BUFFER_SIZE]; + size_t response_length = sizeof(response); + uint32_t err; + + err = tpm_sendrecv_command(command, response, &response_length); + if (err) + return err; + memcpy(pflags, response + TPM_HEADER_SIZE, sizeof(*pflags)); + + return 0; +} + +uint32_t tpm_get_permissions(uint32_t index, uint32_t *perm) +{ + const uint8_t command[22] = { + 0x0, 0xc1, /* TPM_TAG */ + 0x0, 0x0, 0x0, 0x16, /* parameter size */ + 0x0, 0x0, 0x0, 0x65, /* TPM_COMMAND_CODE */ + 0x0, 0x0, 0x0, 0x11, + 0x0, 0x0, 0x0, 0x4, + }; + const size_t index_offset = 18; + const size_t perm_offset = 60; + uint8_t buf[COMMAND_BUFFER_SIZE], response[COMMAND_BUFFER_SIZE]; + size_t response_length = sizeof(response); + uint32_t err; + + if (pack_byte_string(buf, sizeof(buf), "d", 0, command, sizeof(command), + index_offset, index)) + return TPM_LIB_ERROR; + err = tpm_sendrecv_command(buf, response, &response_length); + if (err) + return err; + if (unpack_byte_string(response, response_length, "d", + perm_offset, perm)) + return TPM_LIB_ERROR; + + return 0; +} + #ifdef CONFIG_TPM_AUTH_SESSIONS /**