coreboot-gerrit
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
July 2015
- 1 participants
- 1048 discussions
New patch to review for coreboot: buildgcc: Deal with gmp on 32bit Linux on 64bit CPUs
by Patrick Georgi July 4, 2015
by Patrick Georgi July 4, 2015
July 4, 2015
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10792
-gerrit
commit 5d9f1bc10129f1ebc27a60da6d25bbb0ff0de2df
Author: Patrick Georgi <patrick(a)georgi-clan.de>
Date: Sat Jul 4 17:45:54 2015 +0200
buildgcc: Deal with gmp on 32bit Linux on 64bit CPUs
GMP is overeager to detect 64bit ABIs even if the entire running codebase is
32bit (but on a 64bit CPU). Enforce a 32bit build in that situation.
Change-Id: I23e9e57f3c8b0e3ad2e4e1e3eb106f7830aa76a1
Signed-off-by: Patrick Georgi <patrick(a)georgi-clan.de>
---
util/crossgcc/buildgcc | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/util/crossgcc/buildgcc b/util/crossgcc/buildgcc
index b78b141..e0b4ed4 100755
--- a/util/crossgcc/buildgcc
+++ b/util/crossgcc/buildgcc
@@ -615,6 +615,12 @@ if [ $UNAME = "Darwin" ]; then
if $CC -v 2>&1 | grep -q LLVM; then
CC=llvm-gcc
fi
+elif [ $UNAME = "Linux" ]; then
+ # gmp is overeager with detecting 64bit CPUs even if they run
+ # a 32bit kernel and userland.
+ if [ "$(uname -m 2>/dev/null)" = "i686" ]; then
+ OPTIONS="ABI=32"
+ fi
fi
fi # GCC
1
0
Patch merged into coreboot/master: crossgcc: Fix binutils for aarch64
by gerrit@coreboot.org July 4, 2015
by gerrit@coreboot.org July 4, 2015
July 4, 2015
the following patch was just integrated into master:
commit 630ad918d45d6dee4f114fca457af6020ab8668d
Author: Patrick Georgi <patrick(a)georgi-clan.de>
Date: Sat Jul 4 09:26:15 2015 +0200
crossgcc: Fix binutils for aarch64
The gold linker didn't build.
Change-Id: I93c26a7715e781b001a71978d8fadbf65fdfe427
Signed-off-by: Patrick Georgi <patrick(a)georgi-clan.de>
Reviewed-on: http://review.coreboot.org/10791
Reviewed-by: Stefan Reinauer <stefan.reinauer(a)coreboot.org>
Tested-by: build bot (Jenkins)
See http://review.coreboot.org/10791 for details.
-gerrit
1
0
July 4, 2015
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10791
-gerrit
commit 73b75379f8ce6407925c6b2fa762664631136577
Author: Patrick Georgi <patrick(a)georgi-clan.de>
Date: Sat Jul 4 09:26:15 2015 +0200
crossgcc: Fix binutils for aarch64
The gold linker didn't build.
Change-Id: I93c26a7715e781b001a71978d8fadbf65fdfe427
Signed-off-by: Patrick Georgi <patrick(a)georgi-clan.de>
---
util/crossgcc/patches/binutils-2.25_fix-aarch64.patch | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/util/crossgcc/patches/binutils-2.25_fix-aarch64.patch b/util/crossgcc/patches/binutils-2.25_fix-aarch64.patch
new file mode 100644
index 0000000..de6b9f2
--- /dev/null
+++ b/util/crossgcc/patches/binutils-2.25_fix-aarch64.patch
@@ -0,0 +1,14 @@
+Taken from https://sourceware.org/ml/binutils/2014-10/msg00099.html
+Authored by Andreas Schwab <schwab(a)linux-m68k.org>
+diff --git a/gold/configure.tgt b/gold/configure.tgt
+index 9a75070..59a681e 100644
+--- binutils-2.25/gold/configure.tgt
++++ binutils-2.25/gold/configure.tgt
+@@ -146,6 +146,7 @@ arm*-*-*)
+ ;;
+ aarch64*-*)
+ targ_obj=aarch64
++ targ_extra_obj=aarch64-reloc-property
+ targ_machine=EM_AARCH64
+ targ_size=64
+ targ_extra_size=32
1
0
Patch set updated for coreboot: TPM: Merge of two TPM API's into one API.
by Philipp Deppenwiese July 4, 2015
by Philipp Deppenwiese July 4, 2015
July 4, 2015
Philipp Deppenwiese (zaolin(a)das-labor.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10542
-gerrit
commit 27513f7b798889f4c3a6226cb12cf42475cb59f9
Author: Philipp Deppenwiese <zaolin(a)das-labor.org>
Date: Sat Jun 13 23:35:37 2015 +0200
TPM: Merge of two TPM API's into one API.
Currently coreboot includes two TPM software implementations.
Following changes are done:
+ Use Google's lib/tlcl.* small tpm software stack as the main one.
+ Remove the old one drivers/pc80/tpm/romstage.c which can't be used for vboot2.
+ Split & Merge implementations into TSS and TSPI.
-> Rename tlcl* files into tss which is the common name.
-> Move init_tpm(void) function from drivers/pc80/tpm/romstage.c into
the lib/tpm/tspi.c which is also the common name for highlevel tpm functions based on tss.
-> Put the tss and tspi files into tpm folders in lib/ and include/ .
-> Change header includes so that tpm.h can be found in include/pc80/
and software stack related stuff in include/tpm.
+ Revert pragma once statements from previous commit.
Compile:
VBOOT2 Feature = yes
Coreboot TPM Feature = yes
Run:
VBOOT2 Feature = not tested
Coreboot TPM Feature = yes
Change-Id: I8cbcd723d83ffcc0c1c47c58438dccdb16bb7cf7
Signed-off-by: Philipp Deppenwiese <zaolin(a)das-labor.org>
---
src/cpu/intel/haswell/romstage.c | 2 +-
src/drivers/pc80/tpm/Makefile.inc | 1 -
src/drivers/pc80/tpm/romstage.c | 255 ----------------
src/drivers/pc80/tpm/tpm.c | 2 +-
src/include/antirollback.h | 2 +-
src/include/pc80/tpm.h | 69 +++++
src/include/tpm.h | 71 -----
src/include/tpm/tspi.h | 29 ++
src/include/tpm/tss.h | 136 +++++++++
src/include/tpm/tss_constants.h | 98 ++++++
src/include/tpm_lite/tlcl.h | 137 ---------
src/include/tpm_lite/tss_constants.h | 96 ------
src/lib/Makefile.inc | 8 +-
src/lib/mocked_tlcl.c | 136 ---------
src/lib/tlcl.c | 327 --------------------
src/lib/tlcl_internal.h | 61 ----
src/lib/tlcl_structures.h | 138 ---------
src/lib/tpm/Makefile.inc | 13 +
src/lib/tpm/mocked_tss.c | 136 +++++++++
src/lib/tpm/tspi.c | 95 ++++++
src/lib/tpm/tss.c | 331 +++++++++++++++++++++
src/lib/tpm/tss_internal.h | 61 ++++
src/lib/tpm/tss_structures.h | 138 +++++++++
src/mainboard/google/link/romstage.c | 2 +-
src/mainboard/google/parrot/romstage.c | 2 +-
src/mainboard/google/stout/romstage.c | 2 +-
src/mainboard/intel/emeraldlake2/romstage.c | 2 +-
src/mainboard/lenovo/t530/Kconfig | 1 +
src/mainboard/lenovo/x201/romstage.c | 2 +-
src/mainboard/samsung/lumpy/romstage.c | 2 +-
src/mainboard/samsung/stumpy/romstage.c | 2 +-
.../intel/sandybridge/romstage_native.c | 2 +-
src/soc/intel/baytrail/romstage/romstage.c | 2 +-
src/soc/intel/braswell/romstage/romstage.c | 2 +-
src/soc/intel/broadwell/romstage/romstage.c | 2 +-
.../google/chromeos/vboot2/antirollback.c | 4 +-
36 files changed, 1124 insertions(+), 1245 deletions(-)
diff --git a/src/cpu/intel/haswell/romstage.c b/src/cpu/intel/haswell/romstage.c
index 6adb8be..c24883b 100644
--- a/src/cpu/intel/haswell/romstage.c
+++ b/src/cpu/intel/haswell/romstage.c
@@ -44,7 +44,7 @@
#include "northbridge/intel/haswell/raminit.h"
#include "southbridge/intel/lynxpoint/pch.h"
#include "southbridge/intel/lynxpoint/me.h"
-#include <tpm.h>
+#include <tpm/tspi.h>
static inline void reset_system(void)
{
diff --git a/src/drivers/pc80/tpm/Makefile.inc b/src/drivers/pc80/tpm/Makefile.inc
index 089d067..c900fe8 100644
--- a/src/drivers/pc80/tpm/Makefile.inc
+++ b/src/drivers/pc80/tpm/Makefile.inc
@@ -1,3 +1,2 @@
romstage-$(CONFIG_LPC_TPM) += tpm.c
ramstage-$(CONFIG_LPC_TPM) += tpm.c
-romstage-$(CONFIG_LPC_TPM) += romstage.c
diff --git a/src/drivers/pc80/tpm/romstage.c b/src/drivers/pc80/tpm/romstage.c
deleted file mode 100644
index 96760e2..0000000
--- a/src/drivers/pc80/tpm/romstage.c
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
- *
- * 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; version 2 of the License.
- *
- * 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.
- */
-
-#include <types.h>
-#include <console/cbmem_console.h>
-#include <console/console.h>
-#include <arch/acpi.h>
-#include <tpm.h>
-#include <reset.h>
-
-//#define EXTRA_LOGGING
-
-#define TPM_LARGE_ENOUGH_COMMAND_SIZE 256 /* saves space in the firmware */
-
-#define TPM_SUCCESS ((u32)0x00000000)
-
-#define TPM_E_IOERROR ((u32)0x0000001f)
-#define TPM_E_COMMUNICATION_ERROR ((u32)0x00005004)
-#define TPM_E_NON_FATAL ((u32)0x00000800)
-#define TPM_E_INVALID_POSTINIT ((u32)0x00000026)
-
-#define TPM_E_NEEDS_SELFTEST ((u32)(TPM_E_NON_FATAL + 1))
-#define TPM_E_DOING_SELFTEST ((u32)(TPM_E_NON_FATAL + 2))
-
-static const struct {
- u8 buffer[12];
-} tpm_resume_cmd = {
- { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x99, 0x0, 0x2 }
-};
-
-static const struct {
- u8 buffer[12];
-} tpm_startup_cmd = {
- {0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x99, 0x0, 0x1 }
-};
-
-static const struct {
- u8 buffer[12];
-} tpm_deactivate_cmd = {
- {0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x99, 0x0, 0x3 }
-};
-
-static const struct {
- u8 buffer[10];
-} tpm_continueselftest_cmd = {
- { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x53 }
-};
-
-static inline void FromTpmUint32(const u8 * buffer, u32 * x)
-{
- *x = ((buffer[0] << 24) |
- (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]);
-}
-
-static inline int TpmCommandSize(const u8 * buffer)
-{
- u32 size;
- FromTpmUint32(buffer + sizeof(u16), &size);
- return (int)size;
-}
-
-/* Gets the code field of a TPM command. */
-static inline int TpmCommandCode(const u8 * buffer)
-{
- u32 code;
- FromTpmUint32(buffer + sizeof(u16) + sizeof(u32), &code);
- return code;
-}
-
-/* Gets the return code field of a TPM result. */
-static inline int TpmReturnCode(const u8 * buffer)
-{
- return TpmCommandCode(buffer);
-}
-
-/* Like TlclSendReceive below, but do not retry if NEEDS_SELFTEST or
- * DOING_SELFTEST errors are returned.
- */
-static u32 TlclSendReceiveNoRetry(const u8 * request,
- u8 * response, int max_length)
-{
- size_t response_length = max_length;
- u32 result;
-
-#ifdef EXTRA_LOGGING
- printk(BIOS_DEBUG, "TPM: command: %x%x %x%x%x%x %x%x%x%x\n",
- request[0], request[1],
- request[2], request[3], request[4], request[5],
- request[6], request[7], request[8], request[9]);
-#endif
-
- result = TPM_SUCCESS;
- if (tis_sendrecv
- (request, TpmCommandSize(request), response, &response_length))
- result = TPM_E_IOERROR;
-
- if (0 != result) {
- /* Communication with TPM failed, so response is garbage */
- printk(BIOS_DEBUG,
- "TPM: command 0x%x send/receive failed: 0x%x\n",
- TpmCommandCode(request), result);
- return TPM_E_COMMUNICATION_ERROR;
- }
- /* Otherwise, use the result code from the response */
- result = TpmReturnCode(response);
-
-/* TODO: add paranoia about returned response_length vs. max_length
- * (and possibly expected length from the response header). See
- * crosbug.com/17017 */
-
-#ifdef EXTRA_LOGGING
- printk(BIOS_DEBUG, "TPM: response: %x%x %x%x%x%x %x%x%x%x\n",
- response[0], response[1],
- response[2], response[3], response[4], response[5],
- response[6], response[7], response[8], response[9]);
-#endif
-
- printk(BIOS_DEBUG, "TPM: command 0x%x returned 0x%x\n",
- TpmCommandCode(request), result);
-
- return result;
-}
-
-static inline u32 TlclContinueSelfTest(void)
-{
- u8 response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
- printk(BIOS_DEBUG, "TPM: Continue self test\n");
- /* Call the No Retry version of SendReceive to avoid recursion. */
- return TlclSendReceiveNoRetry(tpm_continueselftest_cmd.buffer,
- response, sizeof(response));
-}
-
-/* Sends a TPM command and gets a response. Returns 0 if success or the TPM
- * error code if error. In the firmware, waits for the self test to complete
- * if needed. In the host, reports the first error without retries. */
-static u32 TlclSendReceive(const u8 * request, u8 * response, int max_length)
-{
- u32 result = TlclSendReceiveNoRetry(request, response, max_length);
- /* When compiling for the firmware, hide command failures due to the self
- * test not having run or completed. */
- /* If the command fails because the self test has not completed, try it
- * again after attempting to ensure that the self test has completed. */
- if (result == TPM_E_NEEDS_SELFTEST || result == TPM_E_DOING_SELFTEST) {
- result = TlclContinueSelfTest();
- if (result != TPM_SUCCESS) {
- return result;
- }
-#if defined(TPM_BLOCKING_CONTINUESELFTEST) || defined(VB_RECOVERY_MODE)
- /* Retry only once */
- result = TlclSendReceiveNoRetry(request, response, max_length);
-#else
- /* This needs serious testing. The TPM specification says:
- * "iii. The caller MUST wait for the actions of
- * TPM_ContinueSelfTest to complete before reissuing the
- * command C1." But, if ContinueSelfTest is non-blocking, how
- * do we know that the actions have completed other than trying
- * again? */
- do {
- result =
- TlclSendReceiveNoRetry(request, response,
- max_length);
- } while (result == TPM_E_DOING_SELFTEST);
-#endif
- }
-
- return result;
-}
-
-void init_tpm(int s3resume)
-{
- u32 result;
- u8 response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
-
- if (CONFIG_TPM_DEACTIVATE) {
- printk(BIOS_SPEW, "TPM: Deactivate\n");
- result = TlclSendReceive(tpm_deactivate_cmd.buffer,
- response, sizeof(response));
- if (result == TPM_SUCCESS) {
- printk(BIOS_SPEW, "TPM: OK.\n");
- return;
- }
-
- printk(BIOS_ERR, "TPM: Error code 0x%x.\n", result);
- return;
- }
-
- /* Doing TPM startup when we're not coming in on the S3 resume path
- * saves us roughly 20ms in boot time only. This does not seem to
- * be worth an API change to vboot_reference-firmware right now, so
- * let's keep the code around, but just bail out early:
- */
- if (s3resume ? CONFIG_NO_TPM_RESUME
- : CONFIG_SKIP_TPM_STARTUP_ON_NORMAL_BOOT)
- return;
-
- printk(BIOS_DEBUG, "TPM initialization.\n");
-
- printk(BIOS_SPEW, "TPM: Init\n");
- if (tis_init())
- return;
-
- printk(BIOS_SPEW, "TPM: Open\n");
- if (tis_open())
- return;
-
-
- if (s3resume) {
- /* S3 Resume */
- printk(BIOS_SPEW, "TPM: Resume\n");
- result = TlclSendReceive(tpm_resume_cmd.buffer,
- response, sizeof(response));
- if (result == TPM_E_INVALID_POSTINIT) {
- /* We're on a platform where the TPM maintains power
- * in S3, so it's already initialized.
- */
- printk(BIOS_DEBUG, "TPM: Already initialized.\n");
- return;
- }
- } else {
- printk(BIOS_SPEW, "TPM: Startup\n");
- result = TlclSendReceive(tpm_startup_cmd.buffer,
- response, sizeof(response));
- }
-
- if (result == TPM_SUCCESS) {
- printk(BIOS_SPEW, "TPM: OK.\n");
- return;
- }
-
- printk(BIOS_ERR, "TPM: Error code 0x%x.\n", result);
-
- if (CONFIG_TPM_INIT_FAILURE_IS_FATAL) {
- printk(BIOS_ERR, "Hard reset!\n");
- post_code(POST_TPM_FAILURE);
- if (IS_ENABLED(CONFIG_CONSOLE_CBMEM_DUMP_TO_UART))
- cbmem_dump_console();
- hard_reset();
- }
-}
diff --git a/src/drivers/pc80/tpm/tpm.c b/src/drivers/pc80/tpm/tpm.c
index ba2561d..620a77d 100644
--- a/src/drivers/pc80/tpm/tpm.c
+++ b/src/drivers/pc80/tpm/tpm.c
@@ -32,7 +32,7 @@
#include <delay.h>
#include <arch/io.h>
#include <console/console.h>
-#include <tpm.h>
+#include <pc80/tpm.h>
#include <arch/early_variables.h>
#include <device/pnp.h>
#include "chip.h"
diff --git a/src/include/antirollback.h b/src/include/antirollback.h
index 5ba36f7..9d3c3fd 100644
--- a/src/include/antirollback.h
+++ b/src/include/antirollback.h
@@ -9,7 +9,7 @@
#ifndef ANTIROLLBACK_H_
#define ANTIROLLBACK_H_
-#include "tpm_lite/tss_constants.h"
+#include <tpm/tss_constants.h>
struct vb2_context;
enum vb2_pcr_digest;
diff --git a/src/include/pc80/tpm.h b/src/include/pc80/tpm.h
new file mode 100644
index 0000000..8923349
--- /dev/null
+++ b/src/include/pc80/tpm.h
@@ -0,0 +1,69 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2011 Google Inc.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#ifndef PC80_TPM_H
+#define PC80_TPM_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+/*
+ * tis_init()
+ *
+ * Initialize the TPM device. Returns 0 on success or -1 on
+ * failure (in case device probing did not succeed).
+ */
+int tis_init(void);
+
+/*
+ * tis_open()
+ *
+ * Requests access to locality 0 for the caller. After all commands have been
+ * completed the caller is supposed to call tis_close().
+ *
+ * Returns 0 on success, -1 on failure.
+ */
+int tis_open(void);
+
+/*
+ * tis_close()
+ *
+ * terminate the currect session with the TPM by releasing the locked
+ * locality. Returns 0 on success of -1 on failure (in case lock
+ * removal did not succeed).
+ */
+int tis_close(void);
+
+/*
+ * tis_sendrecv()
+ *
+ * Send the requested data to the TPM and then try to get its response
+ *
+ * @sendbuf - buffer of the data to send
+ * @send_size size of the data to send
+ * @recvbuf - memory to save the response to
+ * @recv_len - pointer to the size of the response buffer
+ *
+ * Returns 0 on success (and places the number of response bytes at recv_len)
+ * or -1 on failure.
+ */
+int tis_sendrecv(const u8 *sendbuf, size_t send_size, u8 *recvbuf,
+ size_t *recv_len);
+
+#endif /* PC80_TPM_H */
\ No newline at end of file
diff --git a/src/include/tpm.h b/src/include/tpm.h
deleted file mode 100644
index 9b4db4a..0000000
--- a/src/include/tpm.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright 2011 Google Inc.
- *
- * 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; version 2 of the License.
- *
- * 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.
- */
-
-#ifndef TPM_H_
-#define TPM_H_
-
-#include <stddef.h>
-#include <stdint.h>
-
-/*
- * tis_init()
- *
- * Initialize the TPM device. Returns 0 on success or -1 on
- * failure (in case device probing did not succeed).
- */
-int tis_init(void);
-
-/*
- * tis_open()
- *
- * Requests access to locality 0 for the caller. After all commands have been
- * completed the caller is supposed to call tis_close().
- *
- * Returns 0 on success, -1 on failure.
- */
-int tis_open(void);
-
-/*
- * tis_close()
- *
- * terminate the currect session with the TPM by releasing the locked
- * locality. Returns 0 on success of -1 on failure (in case lock
- * removal did not succeed).
- */
-int tis_close(void);
-
-/*
- * tis_sendrecv()
- *
- * Send the requested data to the TPM and then try to get its response
- *
- * @sendbuf - buffer of the data to send
- * @send_size size of the data to send
- * @recvbuf - memory to save the response to
- * @recv_len - pointer to the size of the response buffer
- *
- * Returns 0 on success (and places the number of response bytes at recv_len)
- * or -1 on failure.
- */
-int tis_sendrecv(const u8 *sendbuf, size_t send_size, u8 *recvbuf,
- size_t *recv_len);
-
-void init_tpm(int s3resume);
-
-#endif /* TPM_H_ */
diff --git a/src/include/tpm/tspi.h b/src/include/tpm/tspi.h
new file mode 100644
index 0000000..8e1b5f0
--- /dev/null
+++ b/src/include/tpm/tspi.h
@@ -0,0 +1,29 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2015 The Chromium OS Authors. All rights reserved.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#ifndef TPM_TSPI_H
+#define TPM_TSPI_H
+
+/**
+ * TSPI Implementation for coreboot without vboot2
+ */
+void init_tpm(int s3resume);
+
+
+#endif /* TPM_TSPI_H */
\ No newline at end of file
diff --git a/src/include/tpm/tss.h b/src/include/tpm/tss.h
new file mode 100644
index 0000000..c6c4b1a
--- /dev/null
+++ b/src/include/tpm/tss.h
@@ -0,0 +1,136 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/*
+ * TPM Lightweight Command Library.
+ *
+ * A low-level library for interfacing to TPM hardware or an emulator.
+ */
+
+#ifndef TPM_TSS_H
+#define TPM_TSS_H
+
+#include "tss_constants.h"
+
+/*****************************************************************************/
+/* Functions implemented in tlcl.c */
+
+/**
+ * Call this first. Returns 0 if success, nonzero if error.
+ */
+uint32_t tlcl_lib_init(void);
+
+/**
+ * Perform a raw TPM request/response transaction.
+ */
+uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
+ int max_length);
+
+/* Commands */
+
+/**
+ * Send a TPM_Startup(ST_CLEAR). The TPM error code is returned (0 for
+ * success).
+ */
+uint32_t tlcl_startup(void);
+
+/**
+ * Resume by sending a TPM_Startup(ST_STATE). The TPM error code is returned
+ * (0 for success).
+ */
+uint32_t tlcl_resume(void);
+
+/**
+ * Run the self test.
+ *
+ * Note---this is synchronous. To run this in parallel with other firmware,
+ * use ContinueSelfTest(). The TPM error code is returned.
+ */
+uint32_t tlcl_self_test_full(void);
+
+/**
+ * Run the self test in the background.
+ */
+uint32_t tlcl_continue_self_test(void);
+
+/**
+ * Define a space with permission [perm]. [index] is the index for the space,
+ * [size] the usable data size. The TPM error code is returned.
+ */
+uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size);
+
+/**
+ * Write [length] bytes of [data] to space at [index]. The TPM error code is
+ * returned.
+ */
+uint32_t tlcl_write(uint32_t index, const void *data, uint32_t length);
+
+/**
+ * Read [length] bytes from space at [index] into [data]. The TPM error code
+ * is returned.
+ */
+uint32_t tlcl_read(uint32_t index, void *data, uint32_t length);
+
+/**
+ * Assert physical presence in software. The TPM error code is returned.
+ */
+uint32_t tlcl_assert_physical_presence(void);
+
+/**
+ * Enable the physical presence command. The TPM error code is returned.
+ */
+uint32_t tlcl_physical_presence_cmd_enable(void);
+
+/**
+ * Finalize the physical presence settings: sofware PP is enabled, hardware PP
+ * is disabled, and the lifetime lock is set. The TPM error code is returned.
+ */
+uint32_t tlcl_finalize_physical_presence(void);
+
+/**
+ * Set the nvLocked bit. The TPM error code is returned.
+ */
+uint32_t tlcl_set_nv_locked(void);
+
+/**
+ * Issue a ForceClear. The TPM error code is returned.
+ */
+uint32_t tlcl_force_clear(void);
+
+/**
+ * Issue a PhysicalEnable. The TPM error code is returned.
+ */
+uint32_t tlcl_set_enable(void);
+
+/**
+ * Issue a SetDeactivated. Pass 0 to activate. Returns result code.
+ */
+uint32_t tlcl_set_deactivated(uint8_t flag);
+
+/**
+ * Get flags of interest. Pointers for flags you aren't interested in may
+ * be NULL. The TPM error code is returned.
+ */
+uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
+ uint8_t *nvlocked);
+
+/**
+ * Set the bGlobalLock flag, which only a reboot can clear. The TPM error
+ * code is returned.
+ */
+uint32_t tlcl_set_global_lock(void);
+
+/**
+ * Perform a TPM_Extend.
+ */
+uint32_t tlcl_extend(int pcr_num, const uint8_t *in_digest,
+ uint8_t *out_digest);
+
+/**
+ * Get the entire set of permanent flags.
+ */
+uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags);
+
+#endif
\ No newline at end of file
diff --git a/src/include/tpm/tss_constants.h b/src/include/tpm/tss_constants.h
new file mode 100644
index 0000000..9cfbe2d
--- /dev/null
+++ b/src/include/tpm/tss_constants.h
@@ -0,0 +1,98 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Some TPM constants and type definitions for standalone compilation for use
+ * in the firmware
+ */
+
+#ifndef TPM_TSS_CONSTANTS_H
+#define TPM_TSS_CONSTANTS_H
+
+#include <stdint.h>
+
+#define TPM_MAX_COMMAND_SIZE 4096
+#define TPM_LARGE_ENOUGH_COMMAND_SIZE 256 /* saves space in the firmware */
+#define TPM_PUBEK_SIZE 256
+#define TPM_PCR_DIGEST 20
+
+#define TPM_E_NON_FATAL 0x800
+
+#define TPM_SUCCESS ((uint32_t)0x00000000)
+
+#define TPM_E_AREA_LOCKED ((uint32_t)0x0000003c)
+#define TPM_E_BADINDEX ((uint32_t)0x00000002)
+#define TPM_E_BAD_PRESENCE ((uint32_t)0x0000002d)
+#define TPM_E_IOERROR ((uint32_t)0x0000001f)
+#define TPM_E_INVALID_POSTINIT ((uint32_t)0x00000026)
+#define TPM_E_MAXNVWRITES ((uint32_t)0x00000048)
+#define TPM_E_OWNER_SET ((uint32_t)0x00000014)
+
+#define TPM_E_NEEDS_SELFTEST ((uint32_t)(TPM_E_NON_FATAL + 1))
+#define TPM_E_DOING_SELFTEST ((uint32_t)(TPM_E_NON_FATAL + 2))
+
+#define TPM_E_ALREADY_INITIALIZED ((uint32_t)0x00005000) /* vboot local */
+#define TPM_E_INTERNAL_INCONSISTENCY ((uint32_t)0x00005001) /* vboot local */
+#define TPM_E_MUST_REBOOT ((uint32_t)0x00005002) /* vboot local */
+#define TPM_E_CORRUPTED_STATE ((uint32_t)0x00005003) /* vboot local */
+#define TPM_E_COMMUNICATION_ERROR ((uint32_t)0x00005004) /* vboot local */
+#define TPM_E_RESPONSE_TOO_LARGE ((uint32_t)0x00005005) /* vboot local */
+#define TPM_E_NO_DEVICE ((uint32_t)0x00005006) /* vboot local */
+#define TPM_E_INPUT_TOO_SMALL ((uint32_t)0x00005007) /* vboot local */
+#define TPM_E_WRITE_FAILURE ((uint32_t)0x00005008) /* vboot local */
+#define TPM_E_READ_EMPTY ((uint32_t)0x00005009) /* vboot local */
+#define TPM_E_READ_FAILURE ((uint32_t)0x0000500a) /* vboot local */
+
+#define TPM_NV_INDEX0 ((uint32_t)0x00000000)
+#define TPM_NV_INDEX_LOCK ((uint32_t)0xffffffff)
+#define TPM_NV_PER_GLOBALLOCK (((uint32_t)1)<<15)
+#define TPM_NV_PER_PPWRITE (((uint32_t)1)<<0)
+#define TPM_NV_PER_READ_STCLEAR (((uint32_t)1)<<31)
+#define TPM_NV_PER_WRITE_STCLEAR (((uint32_t)1)<<14)
+
+#define TPM_TAG_RQU_COMMAND ((uint16_t) 0xc1)
+#define TPM_TAG_RQU_AUTH1_COMMAND ((uint16_t) 0xc2)
+#define TPM_TAG_RQU_AUTH2_COMMAND ((uint16_t) 0xc3)
+
+#define TPM_TAG_RSP_COMMAND ((uint16_t) 0xc4)
+#define TPM_TAG_RSP_AUTH1_COMMAND ((uint16_t) 0xc5)
+#define TPM_TAG_RSP_AUTH2_COMMAND ((uint16_t) 0xc6)
+
+typedef uint8_t TSS_BOOL;
+typedef uint16_t TPM_STRUCTURE_TAG;
+
+typedef struct tdTPM_PERMANENT_FLAGS
+{
+ TPM_STRUCTURE_TAG tag;
+ TSS_BOOL disable;
+ TSS_BOOL ownership;
+ TSS_BOOL deactivated;
+ TSS_BOOL readPubek;
+ TSS_BOOL disableOwnerClear;
+ TSS_BOOL allowMaintenance;
+ TSS_BOOL physicalPresenceLifetimeLock;
+ TSS_BOOL physicalPresenceHWEnable;
+ TSS_BOOL physicalPresenceCMDEnable;
+ TSS_BOOL CEKPUsed;
+ TSS_BOOL TPMpost;
+ TSS_BOOL TPMpostLock;
+ TSS_BOOL FIPS;
+ TSS_BOOL Operator;
+ TSS_BOOL enableRevokeEK;
+ TSS_BOOL nvLocked;
+ TSS_BOOL readSRKPub;
+ TSS_BOOL tpmEstablished;
+ TSS_BOOL maintenanceDone;
+ TSS_BOOL disableFullDALogicInfo;
+} TPM_PERMANENT_FLAGS;
+
+typedef struct tdTPM_STCLEAR_FLAGS{
+ TPM_STRUCTURE_TAG tag;
+ TSS_BOOL deactivated;
+ TSS_BOOL disableForceClear;
+ TSS_BOOL physicalPresence;
+ TSS_BOOL physicalPresenceLock;
+ TSS_BOOL bGlobalLock;
+} TPM_STCLEAR_FLAGS;
+
+#endif /* TPM_TSS_CONSTANTS_H */
\ No newline at end of file
diff --git a/src/include/tpm_lite/tlcl.h b/src/include/tpm_lite/tlcl.h
deleted file mode 100644
index 7724592..0000000
--- a/src/include/tpm_lite/tlcl.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/*
- * TPM Lightweight Command Library.
- *
- * A low-level library for interfacing to TPM hardware or an emulator.
- */
-
-#ifndef TPM_LITE_TLCL_H_
-#define TPM_LITE_TLCL_H_
-#include <stdint.h>
-
-#include "tss_constants.h"
-
-/*****************************************************************************/
-/* Functions implemented in tlcl.c */
-
-/**
- * Call this first. Returns 0 if success, nonzero if error.
- */
-uint32_t tlcl_lib_init(void);
-
-/**
- * Perform a raw TPM request/response transaction.
- */
-uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
- int max_length);
-
-/* Commands */
-
-/**
- * Send a TPM_Startup(ST_CLEAR). The TPM error code is returned (0 for
- * success).
- */
-uint32_t tlcl_startup(void);
-
-/**
- * Resume by sending a TPM_Startup(ST_STATE). The TPM error code is returned
- * (0 for success).
- */
-uint32_t tlcl_resume(void);
-
-/**
- * Run the self test.
- *
- * Note---this is synchronous. To run this in parallel with other firmware,
- * use ContinueSelfTest(). The TPM error code is returned.
- */
-uint32_t tlcl_self_test_full(void);
-
-/**
- * Run the self test in the background.
- */
-uint32_t tlcl_continue_self_test(void);
-
-/**
- * Define a space with permission [perm]. [index] is the index for the space,
- * [size] the usable data size. The TPM error code is returned.
- */
-uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size);
-
-/**
- * Write [length] bytes of [data] to space at [index]. The TPM error code is
- * returned.
- */
-uint32_t tlcl_write(uint32_t index, const void *data, uint32_t length);
-
-/**
- * Read [length] bytes from space at [index] into [data]. The TPM error code
- * is returned.
- */
-uint32_t tlcl_read(uint32_t index, void *data, uint32_t length);
-
-/**
- * Assert physical presence in software. The TPM error code is returned.
- */
-uint32_t tlcl_assert_physical_presence(void);
-
-/**
- * Enable the physical presence command. The TPM error code is returned.
- */
-uint32_t tlcl_physical_presence_cmd_enable(void);
-
-/**
- * Finalize the physical presence settings: sofware PP is enabled, hardware PP
- * is disabled, and the lifetime lock is set. The TPM error code is returned.
- */
-uint32_t tlcl_finalize_physical_presence(void);
-
-/**
- * Set the nvLocked bit. The TPM error code is returned.
- */
-uint32_t tlcl_set_nv_locked(void);
-
-/**
- * Issue a ForceClear. The TPM error code is returned.
- */
-uint32_t tlcl_force_clear(void);
-
-/**
- * Issue a PhysicalEnable. The TPM error code is returned.
- */
-uint32_t tlcl_set_enable(void);
-
-/**
- * Issue a SetDeactivated. Pass 0 to activate. Returns result code.
- */
-uint32_t tlcl_set_deactivated(uint8_t flag);
-
-/**
- * Get flags of interest. Pointers for flags you aren't interested in may
- * be NULL. The TPM error code is returned.
- */
-uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
- uint8_t *nvlocked);
-
-/**
- * Set the bGlobalLock flag, which only a reboot can clear. The TPM error
- * code is returned.
- */
-uint32_t tlcl_set_global_lock(void);
-
-/**
- * Perform a TPM_Extend.
- */
-uint32_t tlcl_extend(int pcr_num, const uint8_t *in_digest,
- uint8_t *out_digest);
-
-/**
- * Get the entire set of permanent flags.
- */
-uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags);
-
-#endif /* TPM_LITE_TLCL_H_ */
diff --git a/src/include/tpm_lite/tss_constants.h b/src/include/tpm_lite/tss_constants.h
deleted file mode 100644
index 883a5ad..0000000
--- a/src/include/tpm_lite/tss_constants.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Some TPM constants and type definitions for standalone compilation for use
- * in the firmware
- */
-#ifndef VBOOT_REFERENCE_TSS_CONSTANTS_H_
-#define VBOOT_REFERENCE_TSS_CONSTANTS_H_
-#include <stdint.h>
-
-#define TPM_MAX_COMMAND_SIZE 4096
-#define TPM_LARGE_ENOUGH_COMMAND_SIZE 256 /* saves space in the firmware */
-#define TPM_PUBEK_SIZE 256
-#define TPM_PCR_DIGEST 20
-
-#define TPM_E_NON_FATAL 0x800
-
-#define TPM_SUCCESS ((uint32_t)0x00000000)
-
-#define TPM_E_AREA_LOCKED ((uint32_t)0x0000003c)
-#define TPM_E_BADINDEX ((uint32_t)0x00000002)
-#define TPM_E_BAD_PRESENCE ((uint32_t)0x0000002d)
-#define TPM_E_IOERROR ((uint32_t)0x0000001f)
-#define TPM_E_INVALID_POSTINIT ((uint32_t)0x00000026)
-#define TPM_E_MAXNVWRITES ((uint32_t)0x00000048)
-#define TPM_E_OWNER_SET ((uint32_t)0x00000014)
-
-#define TPM_E_NEEDS_SELFTEST ((uint32_t)(TPM_E_NON_FATAL + 1))
-#define TPM_E_DOING_SELFTEST ((uint32_t)(TPM_E_NON_FATAL + 2))
-
-#define TPM_E_ALREADY_INITIALIZED ((uint32_t)0x00005000) /* vboot local */
-#define TPM_E_INTERNAL_INCONSISTENCY ((uint32_t)0x00005001) /* vboot local */
-#define TPM_E_MUST_REBOOT ((uint32_t)0x00005002) /* vboot local */
-#define TPM_E_CORRUPTED_STATE ((uint32_t)0x00005003) /* vboot local */
-#define TPM_E_COMMUNICATION_ERROR ((uint32_t)0x00005004) /* vboot local */
-#define TPM_E_RESPONSE_TOO_LARGE ((uint32_t)0x00005005) /* vboot local */
-#define TPM_E_NO_DEVICE ((uint32_t)0x00005006) /* vboot local */
-#define TPM_E_INPUT_TOO_SMALL ((uint32_t)0x00005007) /* vboot local */
-#define TPM_E_WRITE_FAILURE ((uint32_t)0x00005008) /* vboot local */
-#define TPM_E_READ_EMPTY ((uint32_t)0x00005009) /* vboot local */
-#define TPM_E_READ_FAILURE ((uint32_t)0x0000500a) /* vboot local */
-
-#define TPM_NV_INDEX0 ((uint32_t)0x00000000)
-#define TPM_NV_INDEX_LOCK ((uint32_t)0xffffffff)
-#define TPM_NV_PER_GLOBALLOCK (((uint32_t)1)<<15)
-#define TPM_NV_PER_PPWRITE (((uint32_t)1)<<0)
-#define TPM_NV_PER_READ_STCLEAR (((uint32_t)1)<<31)
-#define TPM_NV_PER_WRITE_STCLEAR (((uint32_t)1)<<14)
-
-#define TPM_TAG_RQU_COMMAND ((uint16_t) 0xc1)
-#define TPM_TAG_RQU_AUTH1_COMMAND ((uint16_t) 0xc2)
-#define TPM_TAG_RQU_AUTH2_COMMAND ((uint16_t) 0xc3)
-
-#define TPM_TAG_RSP_COMMAND ((uint16_t) 0xc4)
-#define TPM_TAG_RSP_AUTH1_COMMAND ((uint16_t) 0xc5)
-#define TPM_TAG_RSP_AUTH2_COMMAND ((uint16_t) 0xc6)
-
-typedef uint8_t TSS_BOOL;
-typedef uint16_t TPM_STRUCTURE_TAG;
-
-typedef struct tdTPM_PERMANENT_FLAGS
-{
- TPM_STRUCTURE_TAG tag;
- TSS_BOOL disable;
- TSS_BOOL ownership;
- TSS_BOOL deactivated;
- TSS_BOOL readPubek;
- TSS_BOOL disableOwnerClear;
- TSS_BOOL allowMaintenance;
- TSS_BOOL physicalPresenceLifetimeLock;
- TSS_BOOL physicalPresenceHWEnable;
- TSS_BOOL physicalPresenceCMDEnable;
- TSS_BOOL CEKPUsed;
- TSS_BOOL TPMpost;
- TSS_BOOL TPMpostLock;
- TSS_BOOL FIPS;
- TSS_BOOL Operator;
- TSS_BOOL enableRevokeEK;
- TSS_BOOL nvLocked;
- TSS_BOOL readSRKPub;
- TSS_BOOL tpmEstablished;
- TSS_BOOL maintenanceDone;
- TSS_BOOL disableFullDALogicInfo;
-} TPM_PERMANENT_FLAGS;
-
-typedef struct tdTPM_STCLEAR_FLAGS{
- TPM_STRUCTURE_TAG tag;
- TSS_BOOL deactivated;
- TSS_BOOL disableForceClear;
- TSS_BOOL physicalPresence;
- TSS_BOOL physicalPresenceLock;
- TSS_BOOL bGlobalLock;
-} TPM_STCLEAR_FLAGS;
-
-#endif /* VBOOT_REFERENCE_TSS_CONSTANTS_H_ */
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index bda7586..6e6ba3c 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -16,7 +16,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc.
#
-subdirs-y += loaders
+subdirs-y += loaders tpm
bootblock-y += assets.c
bootblock-y += prog_loaders.c
@@ -54,12 +54,6 @@ verstage-y += boot_device.c
verstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
verstage-$(CONFIG_COMMON_CBFS_SPI_WRAPPER) += cbfs_spi.c
-ifeq ($(MOCK_TPM),1)
-libverstage-y += mocked_tlcl.c
-else
-libverstage-y += tlcl.c
-endif
-
verstage-$(CONFIG_GENERIC_UDELAY) += timer.c
verstage-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
verstage-y += mem_pool.c
diff --git a/src/lib/mocked_tlcl.c b/src/lib/mocked_tlcl.c
deleted file mode 100644
index c5c12bf..0000000
--- a/src/lib/mocked_tlcl.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2015 The ChromiumOS Authors. All rights reserved.
- *
- * 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; version 2 of the License.
- *
- * 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.
- */
-
-#include <tpm_lite/tlcl.h>
-
-#ifdef FOR_TEST
-#include <stdio.h>
-#define VBDEBUG(format, args...) printf(format, ## args)
-#else
-#include <console/console.h>
-#define VBDEBUG(format, args...) printk(BIOS_DEBUG, format, ## args)
-#endif
-
-uint32_t tlcl_lib_init(void) {
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_startup(void) {
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_resume(void) {
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_self_test_full(void)
-{
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_continue_self_test(void)
-{
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size)
-{
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_write(uint32_t index, const void* data, uint32_t length)
-{
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_read(uint32_t index, void* data, uint32_t length)
-{
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-
-uint32_t tlcl_assert_physical_presence(void) {
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_physical_presence_cmd_enable(void) {
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_finalize_physical_presence(void) {
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_set_nv_locked(void) {
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_force_clear(void) {
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_set_enable(void) {
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_set_deactivated(uint8_t flag)
-{
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS* pflags)
-{
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_get_flags(uint8_t* disable, uint8_t* deactivated,
- uint8_t *nvlocked)
-{
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_set_global_lock(void)
-{
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
-
-uint32_t tlcl_extend(int pcr_num, const uint8_t* in_digest,
- uint8_t* out_digest)
-{
- VBDEBUG("MOCK_TPM: %s\n", __func__);
- return TPM_E_NO_DEVICE;
-}
diff --git a/src/lib/tlcl.c b/src/lib/tlcl.c
deleted file mode 100644
index ccf4e80..0000000
--- a/src/lib/tlcl.c
+++ /dev/null
@@ -1,327 +0,0 @@
-/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* A lightweight TPM command library.
- *
- * The general idea is that TPM commands are array of bytes whose
- * fields are mostly compile-time constant. The goal is to build much
- * of the commands at compile time (or build time) and change some of
- * the fields at run time as needed. The code in
- * utility/tlcl_generator.c builds structures containing the commands,
- * as well as the offsets of the fields that need to be set at run
- * time.
- */
-
-#include <assert.h>
-#include <string.h>
-#include <tpm_lite/tlcl.h>
-#include <tpm.h>
-#include <vb2_api.h>
-#include "tlcl_internal.h"
-#include "tlcl_structures.h"
-
-#ifdef FOR_TEST
-#include <stdio.h>
-#define VBDEBUG(format, args...) printf(format, ## args)
-#else
-#include <console/console.h>
-#define VBDEBUG(format, args...) printk(BIOS_DEBUG, format, ## args)
-#endif
-
-static int tpm_send_receive(const uint8_t *request,
- uint32_t request_length,
- uint8_t *response,
- uint32_t *response_length)
-{
- size_t len = *response_length;
- if (tis_sendrecv(request, request_length, response, &len))
- return VB2_ERROR_UNKNOWN;
- /* check 64->32bit overflow and (re)check response buffer overflow */
- if (len > *response_length)
- return VB2_ERROR_UNKNOWN;
- *response_length = len;
- return VB2_SUCCESS;
-}
-
-/* Sets the size field of a TPM command. */
-static inline void set_tpm_command_size(uint8_t* buffer, uint32_t size) {
- to_tpm_uint32(buffer + sizeof(uint16_t), size);
-}
-
-/* Gets the size field of a TPM command. */
-__attribute__((unused))
-static inline int tpm_command_size(const uint8_t* buffer) {
- uint32_t size;
- from_tpm_uint32(buffer + sizeof(uint16_t), &size);
- return (int) size;
-}
-
-/* Gets the code field of a TPM command. */
-static inline int tpm_command_code(const uint8_t* buffer) {
- uint32_t code;
- from_tpm_uint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &code);
- return code;
-}
-
-/* Gets the return code field of a TPM result. */
-static inline int tpm_return_code(const uint8_t* buffer) {
- return tpm_command_code(buffer);
-}
-
-/* Like TlclSendReceive below, but do not retry if NEEDS_SELFTEST or
- * DOING_SELFTEST errors are returned.
- */
-static uint32_t tlcl_send_receive_no_retry(const uint8_t* request,
- uint8_t* response, int max_length) {
- uint32_t response_length = max_length;
- uint32_t result;
-
- result = tpm_send_receive(request, tpm_command_size(request),
- response, &response_length);
- if (0 != result) {
- /* Communication with TPM failed, so response is garbage */
- VBDEBUG("TPM: command 0x%x send/receive failed: 0x%x\n",
- tpm_command_code(request), result);
- return result;
- }
- /* Otherwise, use the result code from the response */
- result = tpm_return_code(response);
-
- /* TODO: add paranoia about returned response_length vs. max_length
- * (and possibly expected length from the response header). See
- * crosbug.com/17017 */
-
- VBDEBUG("TPM: command 0x%x returned 0x%x\n",
- tpm_command_code(request), result);
-
-return result;
-}
-
-
-/* Sends a TPM command and gets a response. Returns 0 if success or the TPM
- * error code if error. Waits for the self test to complete if needed. */
-uint32_t tlcl_send_receive(const uint8_t* request, uint8_t* response,
- int max_length) {
- uint32_t result = tlcl_send_receive_no_retry(request, response,
- max_length);
- /* If the command fails because the self test has not completed, try it
- * again after attempting to ensure that the self test has completed. */
- if (result == TPM_E_NEEDS_SELFTEST || result == TPM_E_DOING_SELFTEST) {
- result = tlcl_continue_self_test();
- if (result != TPM_SUCCESS)
- return result;
-#if defined(TPM_BLOCKING_CONTINUESELFTEST) || defined(VB_RECOVERY_MODE)
- /* Retry only once */
- result = tlcl_send_receive_no_retry(request, response,
- max_length);
-#else
- /* This needs serious testing. The TPM specification says: "iii.
- * The caller MUST wait for the actions of TPM_ContinueSelfTest
- * to complete before reissuing the command C1." But, if
- * ContinueSelfTest is non-blocking, how do we know that the
- * actions have completed other than trying again? */
- do {
- result = tlcl_send_receive_no_retry(request, response,
- max_length);
- } while (result == TPM_E_DOING_SELFTEST);
-#endif
- }
- return result;
-}
-
-/* Sends a command and returns the error code. */
-static uint32_t send(const uint8_t* command) {
- uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
- return tlcl_send_receive(command, response, sizeof(response));
-}
-
-/* Exported functions. */
-
-uint32_t tlcl_lib_init(void) {
- if (tis_init())
- return VB2_ERROR_UNKNOWN;
- if (tis_open())
- return VB2_ERROR_UNKNOWN;
- return VB2_SUCCESS;
-}
-
-uint32_t tlcl_startup(void) {
- VBDEBUG("TPM: Startup\n");
- return send(tpm_startup_cmd.buffer);
-}
-
-uint32_t tlcl_resume(void) {
- VBDEBUG("TPM: Resume\n");
- return send(tpm_resume_cmd.buffer);
-}
-
-uint32_t tlcl_self_test_full(void)
-{
- VBDEBUG("TPM: Self test full\n");
- return send(tpm_selftestfull_cmd.buffer);
-}
-
-uint32_t tlcl_continue_self_test(void)
-{
- uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
- VBDEBUG("TPM: Continue self test\n");
- /* Call the No Retry version of SendReceive to avoid recursion. */
- return tlcl_send_receive_no_retry(tpm_continueselftest_cmd.buffer,
- response, sizeof(response));
-}
-
-uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size)
-{
- struct s_tpm_nv_definespace_cmd cmd;
- VBDEBUG("TPM: TlclDefineSpace(0x%x, 0x%x, %d)\n", index, perm, size);
- memcpy(&cmd, &tpm_nv_definespace_cmd, sizeof(cmd));
- to_tpm_uint32(cmd.buffer + tpm_nv_definespace_cmd.index, index);
- to_tpm_uint32(cmd.buffer + tpm_nv_definespace_cmd.perm, perm);
- to_tpm_uint32(cmd.buffer + tpm_nv_definespace_cmd.size, size);
- return send(cmd.buffer);
-}
-
-uint32_t tlcl_write(uint32_t index, const void* data, uint32_t length)
-{
- struct s_tpm_nv_write_cmd cmd;
- uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
- const int total_length =
- kTpmRequestHeaderLength + kWriteInfoLength + length;
-
- VBDEBUG("TPM: tlcl_write(0x%x, %d)\n", index, length);
- memcpy(&cmd, &tpm_nv_write_cmd, sizeof(cmd));
- assert(total_length <= TPM_LARGE_ENOUGH_COMMAND_SIZE);
- set_tpm_command_size(cmd.buffer, total_length);
-
- to_tpm_uint32(cmd.buffer + tpm_nv_write_cmd.index, index);
- to_tpm_uint32(cmd.buffer + tpm_nv_write_cmd.length, length);
- memcpy(cmd.buffer + tpm_nv_write_cmd.data, data, length);
-
- return tlcl_send_receive(cmd.buffer, response, sizeof(response));
-}
-
-uint32_t tlcl_read(uint32_t index, void* data, uint32_t length)
-{
- struct s_tpm_nv_read_cmd cmd;
- uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
- uint32_t result_length;
- uint32_t result;
-
- VBDEBUG("TPM: tlcl_read(0x%x, %d)\n", index, length);
- memcpy(&cmd, &tpm_nv_read_cmd, sizeof(cmd));
- to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.index, index);
- to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.length, length);
-
- result = tlcl_send_receive(cmd.buffer, response, sizeof(response));
- if (result == TPM_SUCCESS && length > 0) {
- uint8_t* nv_read_cursor = response + kTpmResponseHeaderLength;
- from_tpm_uint32(nv_read_cursor, &result_length);
- nv_read_cursor += sizeof(uint32_t);
- memcpy(data, nv_read_cursor, result_length);
- }
-
- return result;
-}
-
-
-uint32_t tlcl_assert_physical_presence(void) {
- VBDEBUG("TPM: Asserting physical presence\n");
- return send(tpm_ppassert_cmd.buffer);
-}
-
-uint32_t tlcl_physical_presence_cmd_enable(void) {
- VBDEBUG("TPM: Enable the physical presence command\n");
- return send(tpm_ppenable_cmd.buffer);
-}
-
-uint32_t tlcl_finalize_physical_presence(void) {
- VBDEBUG("TPM: Enable PP cmd, disable HW pp, and set lifetime lock\n");
- return send(tpm_finalizepp_cmd.buffer);
-}
-
-uint32_t tlcl_set_nv_locked(void) {
- VBDEBUG("TPM: Set NV locked\n");
- return tlcl_define_space(TPM_NV_INDEX_LOCK, 0, 0);
-}
-
-uint32_t tlcl_force_clear(void) {
- VBDEBUG("TPM: Force clear\n");
- return send(tpm_forceclear_cmd.buffer);
-}
-
-uint32_t tlcl_set_enable(void) {
- VBDEBUG("TPM: Enabling TPM\n");
- return send(tpm_physicalenable_cmd.buffer);
-}
-
-uint32_t tlcl_set_deactivated(uint8_t flag)
-{
- struct s_tpm_physicalsetdeactivated_cmd cmd;
- VBDEBUG("TPM: SetDeactivated(%d)\n", flag);
- memcpy(&cmd, &tpm_physicalsetdeactivated_cmd, sizeof(cmd));
- *(cmd.buffer + cmd.deactivated) = flag;
- return send(cmd.buffer);
-}
-
-uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS* pflags)
-{
- uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
- uint32_t size;
- uint32_t result = tlcl_send_receive(tpm_getflags_cmd.buffer, response,
- sizeof(response));
- if (result != TPM_SUCCESS)
- return result;
- from_tpm_uint32(response + kTpmResponseHeaderLength, &size);
- assert(size == sizeof(TPM_PERMANENT_FLAGS));
- memcpy(pflags, response + kTpmResponseHeaderLength + sizeof(size),
- sizeof(TPM_PERMANENT_FLAGS));
- return result;
-}
-
-uint32_t tlcl_get_flags(uint8_t* disable, uint8_t* deactivated,
- uint8_t *nvlocked)
-{
- TPM_PERMANENT_FLAGS pflags;
- uint32_t result = tlcl_get_permanent_flags(&pflags);
- if (result == TPM_SUCCESS) {
- if (disable)
- *disable = pflags.disable;
- if (deactivated)
- *deactivated = pflags.deactivated;
- if (nvlocked)
- *nvlocked = pflags.nvLocked;
- VBDEBUG("TPM: flags disable=%d, deactivated=%d, nvlocked=%d\n",
- pflags.disable, pflags.deactivated, pflags.nvLocked);
- }
- return result;
-}
-
-uint32_t tlcl_set_global_lock(void)
-{
- uint32_t x;
- VBDEBUG("TPM: Set global lock\n");
- return tlcl_write(TPM_NV_INDEX0, (uint8_t*) &x, 0);
-}
-
-uint32_t tlcl_extend(int pcr_num, const uint8_t* in_digest,
- uint8_t* out_digest)
-{
- struct s_tpm_extend_cmd cmd;
- uint8_t response[kTpmResponseHeaderLength + kPcrDigestLength];
- uint32_t result;
-
- memcpy(&cmd, &tpm_extend_cmd, sizeof(cmd));
- to_tpm_uint32(cmd.buffer + tpm_extend_cmd.pcrNum, pcr_num);
- memcpy(cmd.buffer + cmd.inDigest, in_digest, kPcrDigestLength);
-
- result = tlcl_send_receive(cmd.buffer, response, sizeof(response));
- if (result != TPM_SUCCESS)
- return result;
-
- if (out_digest)
- memcpy(out_digest, response + kTpmResponseHeaderLength,
- kPcrDigestLength);
- return result;
-}
diff --git a/src/lib/tlcl_internal.h b/src/lib/tlcl_internal.h
deleted file mode 100644
index 8261b0d..0000000
--- a/src/lib/tlcl_internal.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef TPM_LITE_TLCL_INTERNAL_H_
-#define TPM_LITE_TLCL_INTERNAL_H_
-
-/*
- * These numbers derive from adding the sizes of command fields as shown in the
- * TPM commands manual.
- */
-#define kTpmRequestHeaderLength 10
-#define kTpmResponseHeaderLength 10
-#define kTpmReadInfoLength 12
-#define kEncAuthLength 20
-#define kPcrDigestLength 20
-
-
-/*
- * Conversion functions. to_tpm_TYPE puts a value of type TYPE into a TPM
- * command buffer. from_tpm_TYPE gets a value of type TYPE from a TPM command
- * buffer into a variable.
- */
-__attribute__((unused))
-static inline void to_tpm_uint32(uint8_t *buffer, uint32_t x) {
- buffer[0] = (uint8_t)(x >> 24);
- buffer[1] = (uint8_t)((x >> 16) & 0xff);
- buffer[2] = (uint8_t)((x >> 8) & 0xff);
- buffer[3] = (uint8_t)(x & 0xff);
-}
-
-/*
- * See comment for above function.
- */
-__attribute__((unused))
-static inline void from_tpm_uint32(const uint8_t *buffer, uint32_t *x) {
- *x = ((buffer[0] << 24) |
- (buffer[1] << 16) |
- (buffer[2] << 8) |
- buffer[3]);
-}
-
-/*
- * See comment for above function.
- */
-__attribute__((unused))
-static inline void to_tpm_uint16(uint8_t *buffer, uint16_t x) {
- buffer[0] = (uint8_t)(x >> 8);
- buffer[1] = (uint8_t)(x & 0xff);
-}
-
-/*
- * See comment for above function.
- */
-__attribute__((unused))
-static inline void from_tpm_uint16(const uint8_t *buffer, uint16_t *x) {
- *x = (buffer[0] << 8) | buffer[1];
-}
-
-#endif /* TPM_LITE_TLCL_INTERNAL_H_ */
diff --git a/src/lib/tlcl_structures.h b/src/lib/tlcl_structures.h
deleted file mode 100644
index 36c1bb9..0000000
--- a/src/lib/tlcl_structures.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/* This file is automatically generated */
-
-const struct s_tpm_extend_cmd{
- uint8_t buffer[34];
- uint16_t pcrNum;
- uint16_t inDigest;
-} tpm_extend_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x22, 0x0, 0x0, 0x0, 0x14, },
-10, 14, };
-
-const struct s_tpm_get_random_cmd{
- uint8_t buffer[14];
- uint16_t bytesRequested;
-} tpm_get_random_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x46, },
-10, };
-
-const struct s_tpm_getownership_cmd{
- uint8_t buffer[22];
-} tpm_getownership_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x1, 0x11, },
-};
-
-const struct s_tpm_getpermissions_cmd{
- uint8_t buffer[22];
- uint16_t index;
-} tpm_getpermissions_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0x11, 0x0, 0x0, 0x0, 0x4, },
-18, };
-
-const struct s_tpm_getstclearflags_cmd{
- uint8_t buffer[22];
-} tpm_getstclearflags_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x1, 0x9, },
-};
-
-const struct s_tpm_getflags_cmd{
- uint8_t buffer[22];
-} tpm_getflags_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x1, 0x8, },
-};
-
-const struct s_tpm_physicalsetdeactivated_cmd{
- uint8_t buffer[11];
- uint16_t deactivated;
-} tpm_physicalsetdeactivated_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xb, 0x0, 0x0, 0x0, 0x72, },
-10, };
-
-const struct s_tpm_physicalenable_cmd{
- uint8_t buffer[10];
-} tpm_physicalenable_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x6f, },
-};
-
-const struct s_tpm_physicaldisable_cmd{
- uint8_t buffer[10];
-} tpm_physicaldisable_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x70, },
-};
-
-const struct s_tpm_forceclear_cmd{
- uint8_t buffer[10];
-} tpm_forceclear_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x5d, },
-};
-
-const struct s_tpm_readpubek_cmd{
- uint8_t buffer[30];
-} tpm_readpubek_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x1e, 0x0, 0x0, 0x0, 0x7c, },
-};
-
-const struct s_tpm_continueselftest_cmd{
- uint8_t buffer[10];
-} tpm_continueselftest_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x53, },
-};
-
-const struct s_tpm_selftestfull_cmd{
- uint8_t buffer[10];
-} tpm_selftestfull_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50, },
-};
-
-const struct s_tpm_resume_cmd{
- uint8_t buffer[12];
-} tpm_resume_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x99, 0x0, 0x2, },
-};
-
-const struct s_tpm_savestate_cmd{
- uint8_t buffer[10];
-} tpm_savestate_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x98, },
-};
-
-const struct s_tpm_startup_cmd{
- uint8_t buffer[12];
-} tpm_startup_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x99, 0x0, 0x1, },
-};
-
-const struct s_tpm_finalizepp_cmd{
- uint8_t buffer[12];
-} tpm_finalizepp_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x2, 0xa0, },
-};
-
-const struct s_tpm_pplock_cmd{
- uint8_t buffer[12];
-} tpm_pplock_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x4, },
-};
-
-const struct s_tpm_ppenable_cmd{
- uint8_t buffer[12];
-} tpm_ppenable_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x20, },
-};
-
-const struct s_tpm_ppassert_cmd{
- uint8_t buffer[12];
-} tpm_ppassert_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x8, },
-};
-
-const struct s_tpm_pcr_read_cmd{
- uint8_t buffer[14];
- uint16_t pcrNum;
-} tpm_pcr_read_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x15, },
-10, };
-
-const struct s_tpm_nv_read_cmd{
- uint8_t buffer[22];
- uint16_t index;
- uint16_t length;
-} tpm_nv_read_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0xcf, },
-10, 18, };
-
-const struct s_tpm_nv_write_cmd{
- uint8_t buffer[256];
- uint16_t index;
- uint16_t length;
- uint16_t data;
-} tpm_nv_write_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xcd, },
-10, 18, 22, };
-
-const struct s_tpm_nv_definespace_cmd{
- uint8_t buffer[101];
- uint16_t index;
- uint16_t perm;
- uint16_t size;
-} tpm_nv_definespace_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0xcc, 0x0, 0x18, 0, 0, 0, 0, 0x0, 0x3, 0, 0, 0, 0x1f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0, 0x3, 0, 0, 0, 0x1f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0, 0x17, },
-12, 70, 77, };
-
-const int kWriteInfoLength = 12;
-const int kNvDataPublicPermissionsOffset = 60;
diff --git a/src/lib/tpm/Makefile.inc b/src/lib/tpm/Makefile.inc
new file mode 100644
index 0000000..81a3eb9
--- /dev/null
+++ b/src/lib/tpm/Makefile.inc
@@ -0,0 +1,13 @@
+ifneq ($(CONFIG_CHROMEOS),y)
+romstage-$(CONFIG_LPC_TPM) += tss.c tspi.c
+ramstage-$(CONFIG_LPC_TPM) += tss.c tspi.c
+else
+romstage-$(CONFIG_LPC_TPM) += tspi.c
+endif
+
+ifeq ($(MOCK_TPM),1)
+libverstage-y += mocked_tss.c
+else
+libverstage-y += tss.c
+endif
+
diff --git a/src/lib/tpm/mocked_tss.c b/src/lib/tpm/mocked_tss.c
new file mode 100644
index 0000000..ce956ad
--- /dev/null
+++ b/src/lib/tpm/mocked_tss.c
@@ -0,0 +1,136 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2015 The ChromiumOS Authors. All rights reserved.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#include <tpm/tss.h>
+
+#ifdef FOR_TEST
+#include <stdio.h>
+#define VBDEBUG(format, args...) printf(format, ## args)
+#else
+#include <console/console.h>
+#define VBDEBUG(format, args...) printk(BIOS_DEBUG, format, ## args)
+#endif
+
+uint32_t tlcl_lib_init(void) {
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_startup(void) {
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_resume(void) {
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_self_test_full(void)
+{
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_continue_self_test(void)
+{
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size)
+{
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_write(uint32_t index, const void* data, uint32_t length)
+{
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_read(uint32_t index, void* data, uint32_t length)
+{
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+
+uint32_t tlcl_assert_physical_presence(void) {
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_physical_presence_cmd_enable(void) {
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_finalize_physical_presence(void) {
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_set_nv_locked(void) {
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_force_clear(void) {
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_set_enable(void) {
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_set_deactivated(uint8_t flag)
+{
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS* pflags)
+{
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_get_flags(uint8_t* disable, uint8_t* deactivated,
+ uint8_t *nvlocked)
+{
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_set_global_lock(void)
+{
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
+
+uint32_t tlcl_extend(int pcr_num, const uint8_t* in_digest,
+ uint8_t* out_digest)
+{
+ VBDEBUG("MOCK_TPM: %s\n", __func__);
+ return TPM_E_NO_DEVICE;
+}
diff --git a/src/lib/tpm/tspi.c b/src/lib/tpm/tspi.c
new file mode 100644
index 0000000..00848f1
--- /dev/null
+++ b/src/lib/tpm/tspi.c
@@ -0,0 +1,95 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2015 The Chromium OS Authors. All rights reserved.
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#include <console/cbmem_console.h>
+#include <console/console.h>
+#include <reset.h>
+
+#include <tpm/tss.h>
+#include <tpm/tspi.h>
+
+void init_tpm(int s3resume)
+{
+ u32 result = 0;
+
+ if (CONFIG_TPM_DEACTIVATE) {
+ printk(BIOS_SPEW, "TPM: Deactivate\n");
+
+ result = tlcl_set_deactivated(1);
+ if(result != TPM_SUCCESS) {
+ printk(BIOS_ERR, "TPM: Error code 0x%x.\n", result);
+ return;
+ }
+ }
+
+ /* Doing TPM startup when we're not coming in on the S3 resume path
+ * saves us roughly 20ms in boot time only. This does not seem to
+ * be worth an API change to vboot_reference-firmware right now, so
+ * let's keep the code around, but just bail out early:
+ */
+ if (s3resume ? CONFIG_NO_TPM_RESUME
+ : CONFIG_SKIP_TPM_STARTUP_ON_NORMAL_BOOT)
+ return;
+
+ printk(BIOS_DEBUG, "TPM initialization.\n");
+
+ if(tlcl_lib_init() != TPM_SUCCESS) {
+ printk(BIOS_ERR, "TPM: Error code 0x%x.\n", result);
+ return;
+ }
+
+ if (s3resume) {
+ /* S3 Resume */
+ printk(BIOS_SPEW, "TPM: Resume\n");
+
+ result = tlcl_resume();
+ if(result == TPM_E_INVALID_POSTINIT) {
+ /* We're on a platform where the TPM maintains power
+ * in S3, so it's already initialized.
+ */
+ printk(BIOS_DEBUG, "TPM: Already initialized.\n");
+ return;
+ } else if(result != TPM_SUCCESS) {
+ printk(BIOS_ERR, "TPM: Error code 0x%x.\n", result);
+ return;
+ }
+ } else {
+ printk(BIOS_SPEW, "TPM: Startup\n");
+ result = tlcl_startup();
+ if(result != TPM_SUCCESS) {
+ printk(BIOS_ERR, "TPM: Error code 0x%x.\n", result);
+ return;
+ }
+ }
+
+ if (result == TPM_SUCCESS) {
+ printk(BIOS_SPEW, "TPM: OK.\n");
+ return;
+ }
+
+ printk(BIOS_ERR, "TPM: Error code 0x%x.\n", result);
+
+ if (CONFIG_TPM_INIT_FAILURE_IS_FATAL) {
+ printk(BIOS_ERR, "Hard reset!\n");
+ post_code(POST_TPM_FAILURE);
+ if (IS_ENABLED(CONFIG_CONSOLE_CBMEM_DUMP_TO_UART))
+ cbmem_dump_console();
+ hard_reset();
+ }
+}
\ No newline at end of file
diff --git a/src/lib/tpm/tss.c b/src/lib/tpm/tss.c
new file mode 100644
index 0000000..fed9d45
--- /dev/null
+++ b/src/lib/tpm/tss.c
@@ -0,0 +1,331 @@
+/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* A lightweight TPM command library.
+ *
+ * The general idea is that TPM commands are array of bytes whose
+ * fields are mostly compile-time constant. The goal is to build much
+ * of the commands at compile time (or build time) and change some of
+ * the fields at run time as needed. The code in
+ * utility/tlcl_generator.c builds structures containing the commands,
+ * as well as the offsets of the fields that need to be set at run
+ * time.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <tpm/tss.h>
+#include <pc80/tpm.h>
+#include <console/cbmem_console.h>
+#include <console/console.h>
+#include <reset.h>
+#include "tss_internal.h"
+#include "tss_structures.h"
+
+#ifdef FOR_TEST
+#include <stdio.h>
+#define VBDEBUG(format, args...) printf(format, ## args)
+#else
+#include <console/console.h>
+#define VBDEBUG(format, args...) printk(BIOS_DEBUG, format, ## args)
+#endif
+
+#define UNKNOWN_ERROR 0x10000001 // see VBOOT2 error codes..
+
+static int tpm_send_receive(const uint8_t *request,
+ uint32_t request_length,
+ uint8_t *response,
+ uint32_t *response_length)
+{
+ size_t len = *response_length;
+ if (tis_sendrecv(request, request_length, response, &len))
+ return UNKNOWN_ERROR;
+ /* check 64->32bit overflow and (re)check response buffer overflow */
+ if (len > *response_length)
+ return UNKNOWN_ERROR;
+ *response_length = len;
+ return TPM_SUCCESS;
+}
+
+/* Sets the size field of a TPM command. */
+static inline void set_tpm_command_size(uint8_t* buffer, uint32_t size) {
+ to_tpm_uint32(buffer + sizeof(uint16_t), size);
+}
+
+/* Gets the size field of a TPM command. */
+__attribute__((unused))
+static inline int tpm_command_size(const uint8_t* buffer) {
+ uint32_t size;
+ from_tpm_uint32(buffer + sizeof(uint16_t), &size);
+ return (int) size;
+}
+
+/* Gets the code field of a TPM command. */
+static inline int tpm_command_code(const uint8_t* buffer) {
+ uint32_t code;
+ from_tpm_uint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &code);
+ return code;
+}
+
+/* Gets the return code field of a TPM result. */
+static inline int tpm_return_code(const uint8_t* buffer) {
+ return tpm_command_code(buffer);
+}
+
+/* Like TlclSendReceive below, but do not retry if NEEDS_SELFTEST or
+ * DOING_SELFTEST errors are returned.
+ */
+static uint32_t tlcl_send_receive_no_retry(const uint8_t* request,
+ uint8_t* response, int max_length) {
+ uint32_t response_length = max_length;
+ uint32_t result;
+
+ result = tpm_send_receive(request, tpm_command_size(request),
+ response, &response_length);
+ if (0 != result) {
+ /* Communication with TPM failed, so response is garbage */
+ VBDEBUG("TPM: command 0x%x send/receive failed: 0x%x\n",
+ tpm_command_code(request), result);
+ return result;
+ }
+ /* Otherwise, use the result code from the response */
+ result = tpm_return_code(response);
+
+ /* TODO: add paranoia about returned response_length vs. max_length
+ * (and possibly expected length from the response header). See
+ * crosbug.com/17017 */
+
+ VBDEBUG("TPM: command 0x%x returned 0x%x\n",
+ tpm_command_code(request), result);
+
+return result;
+}
+
+
+/* Sends a TPM command and gets a response. Returns 0 if success or the TPM
+ * error code if error. Waits for the self test to complete if needed. */
+uint32_t tlcl_send_receive(const uint8_t* request, uint8_t* response,
+ int max_length) {
+ uint32_t result = tlcl_send_receive_no_retry(request, response,
+ max_length);
+ /* If the command fails because the self test has not completed, try it
+ * again after attempting to ensure that the self test has completed. */
+ if (result == TPM_E_NEEDS_SELFTEST || result == TPM_E_DOING_SELFTEST) {
+ result = tlcl_continue_self_test();
+ if (result != TPM_SUCCESS)
+ return result;
+#if defined(TPM_BLOCKING_CONTINUESELFTEST) || defined(VB_RECOVERY_MODE)
+ /* Retry only once */
+ result = tlcl_send_receive_no_retry(request, response,
+ max_length);
+#else
+ /* This needs serious testing. The TPM specification says: "iii.
+ * The caller MUST wait for the actions of TPM_ContinueSelfTest
+ * to complete before reissuing the command C1." But, if
+ * ContinueSelfTest is non-blocking, how do we know that the
+ * actions have completed other than trying again? */
+ do {
+ result = tlcl_send_receive_no_retry(request, response,
+ max_length);
+ } while (result == TPM_E_DOING_SELFTEST);
+#endif
+ }
+ return result;
+}
+
+/* Sends a command and returns the error code. */
+static uint32_t send(const uint8_t* command) {
+ uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
+ return tlcl_send_receive(command, response, sizeof(response));
+}
+
+/* Exported functions. */
+
+uint32_t tlcl_lib_init(void) {
+ if (tis_init())
+ return UNKNOWN_ERROR;
+ if (tis_open())
+ return UNKNOWN_ERROR;
+ return TPM_SUCCESS;
+}
+
+uint32_t tlcl_startup(void) {
+ VBDEBUG("TPM: Startup\n");
+ return send(tpm_startup_cmd.buffer);
+}
+
+uint32_t tlcl_resume(void) {
+ VBDEBUG("TPM: Resume\n");
+ return send(tpm_resume_cmd.buffer);
+}
+
+uint32_t tlcl_self_test_full(void)
+{
+ VBDEBUG("TPM: Self test full\n");
+ return send(tpm_selftestfull_cmd.buffer);
+}
+
+uint32_t tlcl_continue_self_test(void)
+{
+ uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
+ VBDEBUG("TPM: Continue self test\n");
+ /* Call the No Retry version of SendReceive to avoid recursion. */
+ return tlcl_send_receive_no_retry(tpm_continueselftest_cmd.buffer,
+ response, sizeof(response));
+}
+
+uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size)
+{
+ struct s_tpm_nv_definespace_cmd cmd;
+ VBDEBUG("TPM: TlclDefineSpace(0x%x, 0x%x, %d)\n", index, perm, size);
+ memcpy(&cmd, &tpm_nv_definespace_cmd, sizeof(cmd));
+ to_tpm_uint32(cmd.buffer + tpm_nv_definespace_cmd.index, index);
+ to_tpm_uint32(cmd.buffer + tpm_nv_definespace_cmd.perm, perm);
+ to_tpm_uint32(cmd.buffer + tpm_nv_definespace_cmd.size, size);
+ return send(cmd.buffer);
+}
+
+uint32_t tlcl_write(uint32_t index, const void* data, uint32_t length)
+{
+ struct s_tpm_nv_write_cmd cmd;
+ uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
+ const int total_length =
+ kTpmRequestHeaderLength + kWriteInfoLength + length;
+
+ VBDEBUG("TPM: tlcl_write(0x%x, %d)\n", index, length);
+ memcpy(&cmd, &tpm_nv_write_cmd, sizeof(cmd));
+ assert(total_length <= TPM_LARGE_ENOUGH_COMMAND_SIZE);
+ set_tpm_command_size(cmd.buffer, total_length);
+
+ to_tpm_uint32(cmd.buffer + tpm_nv_write_cmd.index, index);
+ to_tpm_uint32(cmd.buffer + tpm_nv_write_cmd.length, length);
+ memcpy(cmd.buffer + tpm_nv_write_cmd.data, data, length);
+
+ return tlcl_send_receive(cmd.buffer, response, sizeof(response));
+}
+
+uint32_t tlcl_read(uint32_t index, void* data, uint32_t length)
+{
+ struct s_tpm_nv_read_cmd cmd;
+ uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
+ uint32_t result_length;
+ uint32_t result;
+
+ VBDEBUG("TPM: tlcl_read(0x%x, %d)\n", index, length);
+ memcpy(&cmd, &tpm_nv_read_cmd, sizeof(cmd));
+ to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.index, index);
+ to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.length, length);
+
+ result = tlcl_send_receive(cmd.buffer, response, sizeof(response));
+ if (result == TPM_SUCCESS && length > 0) {
+ uint8_t* nv_read_cursor = response + kTpmResponseHeaderLength;
+ from_tpm_uint32(nv_read_cursor, &result_length);
+ nv_read_cursor += sizeof(uint32_t);
+ memcpy(data, nv_read_cursor, result_length);
+ }
+
+ return result;
+}
+
+
+uint32_t tlcl_assert_physical_presence(void) {
+ VBDEBUG("TPM: Asserting physical presence\n");
+ return send(tpm_ppassert_cmd.buffer);
+}
+
+uint32_t tlcl_physical_presence_cmd_enable(void) {
+ VBDEBUG("TPM: Enable the physical presence command\n");
+ return send(tpm_ppenable_cmd.buffer);
+}
+
+uint32_t tlcl_finalize_physical_presence(void) {
+ VBDEBUG("TPM: Enable PP cmd, disable HW pp, and set lifetime lock\n");
+ return send(tpm_finalizepp_cmd.buffer);
+}
+
+uint32_t tlcl_set_nv_locked(void) {
+ VBDEBUG("TPM: Set NV locked\n");
+ return tlcl_define_space(TPM_NV_INDEX_LOCK, 0, 0);
+}
+
+uint32_t tlcl_force_clear(void) {
+ VBDEBUG("TPM: Force clear\n");
+ return send(tpm_forceclear_cmd.buffer);
+}
+
+uint32_t tlcl_set_enable(void) {
+ VBDEBUG("TPM: Enabling TPM\n");
+ return send(tpm_physicalenable_cmd.buffer);
+}
+
+uint32_t tlcl_set_deactivated(uint8_t flag)
+{
+ struct s_tpm_physicalsetdeactivated_cmd cmd;
+ VBDEBUG("TPM: SetDeactivated(%d)\n", flag);
+ memcpy(&cmd, &tpm_physicalsetdeactivated_cmd, sizeof(cmd));
+ *(cmd.buffer + cmd.deactivated) = flag;
+ return send(cmd.buffer);
+}
+
+uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS* pflags)
+{
+ uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
+ uint32_t size;
+ uint32_t result = tlcl_send_receive(tpm_getflags_cmd.buffer, response,
+ sizeof(response));
+ if (result != TPM_SUCCESS)
+ return result;
+ from_tpm_uint32(response + kTpmResponseHeaderLength, &size);
+ assert(size == sizeof(TPM_PERMANENT_FLAGS));
+ memcpy(pflags, response + kTpmResponseHeaderLength + sizeof(size),
+ sizeof(TPM_PERMANENT_FLAGS));
+ return result;
+}
+
+uint32_t tlcl_get_flags(uint8_t* disable, uint8_t* deactivated,
+ uint8_t *nvlocked)
+{
+ TPM_PERMANENT_FLAGS pflags;
+ uint32_t result = tlcl_get_permanent_flags(&pflags);
+ if (result == TPM_SUCCESS) {
+ if (disable)
+ *disable = pflags.disable;
+ if (deactivated)
+ *deactivated = pflags.deactivated;
+ if (nvlocked)
+ *nvlocked = pflags.nvLocked;
+ VBDEBUG("TPM: flags disable=%d, deactivated=%d, nvlocked=%d\n",
+ pflags.disable, pflags.deactivated, pflags.nvLocked);
+ }
+ return result;
+}
+
+uint32_t tlcl_set_global_lock(void)
+{
+ uint32_t x;
+ VBDEBUG("TPM: Set global lock\n");
+ return tlcl_write(TPM_NV_INDEX0, (uint8_t*) &x, 0);
+}
+
+uint32_t tlcl_extend(int pcr_num, const uint8_t* in_digest,
+ uint8_t* out_digest)
+{
+ struct s_tpm_extend_cmd cmd;
+ uint8_t response[kTpmResponseHeaderLength + kPcrDigestLength];
+ uint32_t result;
+
+ memcpy(&cmd, &tpm_extend_cmd, sizeof(cmd));
+ to_tpm_uint32(cmd.buffer + tpm_extend_cmd.pcrNum, pcr_num);
+ memcpy(cmd.buffer + cmd.inDigest, in_digest, kPcrDigestLength);
+
+ result = tlcl_send_receive(cmd.buffer, response, sizeof(response));
+ if (result != TPM_SUCCESS)
+ return result;
+
+ if (out_digest)
+ memcpy(out_digest, response + kTpmResponseHeaderLength,
+ kPcrDigestLength);
+ return result;
+}
\ No newline at end of file
diff --git a/src/lib/tpm/tss_internal.h b/src/lib/tpm/tss_internal.h
new file mode 100644
index 0000000..bc56b12
--- /dev/null
+++ b/src/lib/tpm/tss_internal.h
@@ -0,0 +1,61 @@
+/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef LIB_TPM_TSS_INTERNAL_H
+#define LIB_TPM_TSS_INTERNAL_H
+
+/*
+ * These numbers derive from adding the sizes of command fields as shown in the
+ * TPM commands manual.
+ */
+#define kTpmRequestHeaderLength 10
+#define kTpmResponseHeaderLength 10
+#define kTpmReadInfoLength 12
+#define kEncAuthLength 20
+#define kPcrDigestLength 20
+
+
+/*
+ * Conversion functions. to_tpm_TYPE puts a value of type TYPE into a TPM
+ * command buffer. from_tpm_TYPE gets a value of type TYPE from a TPM command
+ * buffer into a variable.
+ */
+__attribute__((unused))
+static inline void to_tpm_uint32(uint8_t *buffer, uint32_t x) {
+ buffer[0] = (uint8_t)(x >> 24);
+ buffer[1] = (uint8_t)((x >> 16) & 0xff);
+ buffer[2] = (uint8_t)((x >> 8) & 0xff);
+ buffer[3] = (uint8_t)(x & 0xff);
+}
+
+/*
+ * See comment for above function.
+ */
+__attribute__((unused))
+static inline void from_tpm_uint32(const uint8_t *buffer, uint32_t *x) {
+ *x = ((buffer[0] << 24) |
+ (buffer[1] << 16) |
+ (buffer[2] << 8) |
+ buffer[3]);
+}
+
+/*
+ * See comment for above function.
+ */
+__attribute__((unused))
+static inline void to_tpm_uint16(uint8_t *buffer, uint16_t x) {
+ buffer[0] = (uint8_t)(x >> 8);
+ buffer[1] = (uint8_t)(x & 0xff);
+}
+
+/*
+ * See comment for above function.
+ */
+__attribute__((unused))
+static inline void from_tpm_uint16(const uint8_t *buffer, uint16_t *x) {
+ *x = (buffer[0] << 8) | buffer[1];
+}
+
+#endif /* LIB_TPM_TSS_INTERNAL_H */
\ No newline at end of file
diff --git a/src/lib/tpm/tss_structures.h b/src/lib/tpm/tss_structures.h
new file mode 100644
index 0000000..36c1bb9
--- /dev/null
+++ b/src/lib/tpm/tss_structures.h
@@ -0,0 +1,138 @@
+/* This file is automatically generated */
+
+const struct s_tpm_extend_cmd{
+ uint8_t buffer[34];
+ uint16_t pcrNum;
+ uint16_t inDigest;
+} tpm_extend_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x22, 0x0, 0x0, 0x0, 0x14, },
+10, 14, };
+
+const struct s_tpm_get_random_cmd{
+ uint8_t buffer[14];
+ uint16_t bytesRequested;
+} tpm_get_random_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x46, },
+10, };
+
+const struct s_tpm_getownership_cmd{
+ uint8_t buffer[22];
+} tpm_getownership_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x1, 0x11, },
+};
+
+const struct s_tpm_getpermissions_cmd{
+ uint8_t buffer[22];
+ uint16_t index;
+} tpm_getpermissions_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0x11, 0x0, 0x0, 0x0, 0x4, },
+18, };
+
+const struct s_tpm_getstclearflags_cmd{
+ uint8_t buffer[22];
+} tpm_getstclearflags_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x1, 0x9, },
+};
+
+const struct s_tpm_getflags_cmd{
+ uint8_t buffer[22];
+} tpm_getflags_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x1, 0x8, },
+};
+
+const struct s_tpm_physicalsetdeactivated_cmd{
+ uint8_t buffer[11];
+ uint16_t deactivated;
+} tpm_physicalsetdeactivated_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xb, 0x0, 0x0, 0x0, 0x72, },
+10, };
+
+const struct s_tpm_physicalenable_cmd{
+ uint8_t buffer[10];
+} tpm_physicalenable_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x6f, },
+};
+
+const struct s_tpm_physicaldisable_cmd{
+ uint8_t buffer[10];
+} tpm_physicaldisable_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x70, },
+};
+
+const struct s_tpm_forceclear_cmd{
+ uint8_t buffer[10];
+} tpm_forceclear_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x5d, },
+};
+
+const struct s_tpm_readpubek_cmd{
+ uint8_t buffer[30];
+} tpm_readpubek_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x1e, 0x0, 0x0, 0x0, 0x7c, },
+};
+
+const struct s_tpm_continueselftest_cmd{
+ uint8_t buffer[10];
+} tpm_continueselftest_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x53, },
+};
+
+const struct s_tpm_selftestfull_cmd{
+ uint8_t buffer[10];
+} tpm_selftestfull_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50, },
+};
+
+const struct s_tpm_resume_cmd{
+ uint8_t buffer[12];
+} tpm_resume_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x99, 0x0, 0x2, },
+};
+
+const struct s_tpm_savestate_cmd{
+ uint8_t buffer[10];
+} tpm_savestate_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x98, },
+};
+
+const struct s_tpm_startup_cmd{
+ uint8_t buffer[12];
+} tpm_startup_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x99, 0x0, 0x1, },
+};
+
+const struct s_tpm_finalizepp_cmd{
+ uint8_t buffer[12];
+} tpm_finalizepp_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x2, 0xa0, },
+};
+
+const struct s_tpm_pplock_cmd{
+ uint8_t buffer[12];
+} tpm_pplock_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x4, },
+};
+
+const struct s_tpm_ppenable_cmd{
+ uint8_t buffer[12];
+} tpm_ppenable_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x20, },
+};
+
+const struct s_tpm_ppassert_cmd{
+ uint8_t buffer[12];
+} tpm_ppassert_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x8, },
+};
+
+const struct s_tpm_pcr_read_cmd{
+ uint8_t buffer[14];
+ uint16_t pcrNum;
+} tpm_pcr_read_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x15, },
+10, };
+
+const struct s_tpm_nv_read_cmd{
+ uint8_t buffer[22];
+ uint16_t index;
+ uint16_t length;
+} tpm_nv_read_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0xcf, },
+10, 18, };
+
+const struct s_tpm_nv_write_cmd{
+ uint8_t buffer[256];
+ uint16_t index;
+ uint16_t length;
+ uint16_t data;
+} tpm_nv_write_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xcd, },
+10, 18, 22, };
+
+const struct s_tpm_nv_definespace_cmd{
+ uint8_t buffer[101];
+ uint16_t index;
+ uint16_t perm;
+ uint16_t size;
+} tpm_nv_definespace_cmd = {{0x0, 0xc1, 0x0, 0x0, 0x0, 0x65, 0x0, 0x0, 0x0, 0xcc, 0x0, 0x18, 0, 0, 0, 0, 0x0, 0x3, 0, 0, 0, 0x1f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0, 0x3, 0, 0, 0, 0x1f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0, 0x17, },
+12, 70, 77, };
+
+const int kWriteInfoLength = 12;
+const int kNvDataPublicPermissionsOffset = 60;
diff --git a/src/mainboard/google/link/romstage.c b/src/mainboard/google/link/romstage.c
index e9b4a09..1837d50 100644
--- a/src/mainboard/google/link/romstage.c
+++ b/src/mainboard/google/link/romstage.c
@@ -41,7 +41,7 @@
#include <cpu/x86/msr.h>
#include <halt.h>
#include "gpio.h"
-#include <tpm.h>
+#include <tpm/tspi.h>
#include <cbfs.h>
#include <southbridge/intel/bd82x6x/chip.h>
diff --git a/src/mainboard/google/parrot/romstage.c b/src/mainboard/google/parrot/romstage.c
index a947c48..209611e 100644
--- a/src/mainboard/google/parrot/romstage.c
+++ b/src/mainboard/google/parrot/romstage.c
@@ -40,7 +40,7 @@
#include <halt.h>
#include "gpio.h"
#include <cbfs.h>
-#include <tpm.h>
+#include <tpm/tspi.h>
#include "ec/compal/ene932/ec.h"
static void pch_enable_lpc(void)
diff --git a/src/mainboard/google/stout/romstage.c b/src/mainboard/google/stout/romstage.c
index 31b61e2..9d9f761 100644
--- a/src/mainboard/google/stout/romstage.c
+++ b/src/mainboard/google/stout/romstage.c
@@ -40,7 +40,7 @@
#include <halt.h>
#include "gpio.h"
#include <bootmode.h>
-#include <tpm.h>
+#include <tpm/tspi.h>
#include <cbfs.h>
#include <ec/quanta/it8518/ec.h>
#include "ec.h"
diff --git a/src/mainboard/intel/emeraldlake2/romstage.c b/src/mainboard/intel/emeraldlake2/romstage.c
index bcf498b..d612d67 100644
--- a/src/mainboard/intel/emeraldlake2/romstage.c
+++ b/src/mainboard/intel/emeraldlake2/romstage.c
@@ -39,7 +39,7 @@
#include <cpu/x86/bist.h>
#include <cpu/x86/msr.h>
#include <halt.h>
-#include <tpm.h>
+#include <tpm/tspi.h>
#include "gpio.h"
#define SIO_PORT 0x164e
diff --git a/src/mainboard/lenovo/t530/Kconfig b/src/mainboard/lenovo/t530/Kconfig
index f144afb..6aef758 100644
--- a/src/mainboard/lenovo/t530/Kconfig
+++ b/src/mainboard/lenovo/t530/Kconfig
@@ -23,6 +23,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy
select MAINBOARD_DO_NATIVE_VGA_INIT # default to native vga init
select ENABLE_VMX
select MAINBOARD_HAS_LPC_TPM
+ select MAINBOARD_HAS_CHROMEOS
# Workaround for EC/KBC IRQ1.
select SERIRQ_CONTINUOUS_MODE
diff --git a/src/mainboard/lenovo/x201/romstage.c b/src/mainboard/lenovo/x201/romstage.c
index 1e335d3..bb49b49 100644
--- a/src/mainboard/lenovo/x201/romstage.c
+++ b/src/mainboard/lenovo/x201/romstage.c
@@ -37,7 +37,7 @@
#include <timestamp.h>
#include <arch/acpi.h>
#include <cbmem.h>
-#include <tpm.h>
+#include <tpm/tspi.h>
#include "gpio.h"
#include "dock.h"
diff --git a/src/mainboard/samsung/lumpy/romstage.c b/src/mainboard/samsung/lumpy/romstage.c
index 015ae08..cea088d 100644
--- a/src/mainboard/samsung/lumpy/romstage.c
+++ b/src/mainboard/samsung/lumpy/romstage.c
@@ -32,7 +32,7 @@
#include <cbmem.h>
#include <console/console.h>
#include <bootmode.h>
-#include <tpm.h>
+#include <tpm/tspi.h>
#include <northbridge/intel/sandybridge/sandybridge.h>
#include <northbridge/intel/sandybridge/raminit.h>
#include <southbridge/intel/bd82x6x/pch.h>
diff --git a/src/mainboard/samsung/stumpy/romstage.c b/src/mainboard/samsung/stumpy/romstage.c
index 161c8d1..2906815 100644
--- a/src/mainboard/samsung/stumpy/romstage.c
+++ b/src/mainboard/samsung/stumpy/romstage.c
@@ -41,7 +41,7 @@
#include <cpu/x86/bist.h>
#include <cpu/x86/msr.h>
#include <halt.h>
-#include <tpm.h>
+#include <tpm/tspi.h>
#include "gpio.h"
#if CONFIG_DRIVERS_UART_8250IO
#include <superio/smsc/lpc47n207/lpc47n207.h>
diff --git a/src/northbridge/intel/sandybridge/romstage_native.c b/src/northbridge/intel/sandybridge/romstage_native.c
index 45f671c..13696bd 100644
--- a/src/northbridge/intel/sandybridge/romstage_native.c
+++ b/src/northbridge/intel/sandybridge/romstage_native.c
@@ -32,7 +32,7 @@
#include <device/pci_def.h>
#include <device/device.h>
#include <halt.h>
-#include <tpm.h>
+#include <tpm/tspi.h>
#include "raminit_native.h"
#include <northbridge/intel/sandybridge/chip.h>
#include "southbridge/intel/bd82x6x/pch.h"
diff --git a/src/soc/intel/baytrail/romstage/romstage.c b/src/soc/intel/baytrail/romstage/romstage.c
index 1b93eb6..108faf3 100644
--- a/src/soc/intel/baytrail/romstage/romstage.c
+++ b/src/soc/intel/baytrail/romstage/romstage.c
@@ -33,7 +33,7 @@
#include <romstage_handoff.h>
#include <stage_cache.h>
#include <timestamp.h>
-#include <tpm.h>
+#include <tpm/tspi.h>
#include <vendorcode/google/chromeos/chromeos.h>
#include <soc/gpio.h>
#include <soc/iomap.h>
diff --git a/src/soc/intel/braswell/romstage/romstage.c b/src/soc/intel/braswell/romstage/romstage.c
index df6efd8..db2fd92 100644
--- a/src/soc/intel/braswell/romstage/romstage.c
+++ b/src/soc/intel/braswell/romstage/romstage.c
@@ -50,7 +50,7 @@
#include <soc/romstage.h>
#include <soc/smm.h>
#include <soc/spi.h>
-#include <tpm.h>
+#include <tpm/tsṕi.h>
void program_base_addresses(void)
{
diff --git a/src/soc/intel/broadwell/romstage/romstage.c b/src/soc/intel/broadwell/romstage/romstage.c
index 27fb0f2..166ee30 100644
--- a/src/soc/intel/broadwell/romstage/romstage.c
+++ b/src/soc/intel/broadwell/romstage/romstage.c
@@ -29,7 +29,7 @@
#include <cbmem.h>
#include <cpu/x86/mtrr.h>
#include <elog.h>
-#include <tpm.h>
+#include <tpm/tspi.h>
#include <romstage_handoff.h>
#include <stage_cache.h>
#include <timestamp.h>
diff --git a/src/vendorcode/google/chromeos/vboot2/antirollback.c b/src/vendorcode/google/chromeos/vboot2/antirollback.c
index 407b19c..f947c35 100644
--- a/src/vendorcode/google/chromeos/vboot2/antirollback.c
+++ b/src/vendorcode/google/chromeos/vboot2/antirollback.c
@@ -9,8 +9,8 @@
#include <antirollback.h>
#include <stdlib.h>
#include <string.h>
-#include <tpm_lite/tlcl.h>
-#include <tpm_lite/tss_constants.h>
+#include <tpm/tss.h>
+#include <tpm/tss_constants.h>
#include <vb2_api.h>
#ifndef offsetof
1
0
July 4, 2015
Aaron Durbin (adurbin(a)chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10790
-gerrit
commit df613580f26c955431fed7432b104e8965e8220f
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Fri Jul 3 17:04:21 2015 -0500
timestamp: add generic cache region
In order to accommodate tracking timestamps in all the
__PRE_RAM__ stages (bootblock, verstage, romstage, etc)
of a platform one needs to provide a way to specify
a persistent region of SRAM or cache-as-ram to store
the timestamps until cbmem comes online. Provide that
infrastructure.
Based on original patches from chromium.org:
Original-Change-Id: I4d78653c0595523eeeb02115423e7fecceea5e1e
Original-Signed-off-by: Furquan Shaikh <furquan(a)google.com>
Original-Reviewed-on: https://chromium-review.googlesource.com/223348
Original-Reviewed-by: Aaron Durbin <adurbin(a)chromium.org>
Original-Reviewed-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Tested-by: Furquan Shaikh <furquan(a)chromium.org>
Original-Commit-Queue: Furquan Shaikh <furquan(a)chromium.org>
Original-Change-Id: Ie5ffda3112d626068bd1904afcc5a09bc4916d16
Original-Signed-off-by: Furquan Shaikh <furquan(a)google.com>
Original-Reviewed-on: https://chromium-review.googlesource.com/224024
Original-Reviewed-by: Furquan Shaikh <furquan(a)chromium.org>
Original-Commit-Queue: Furquan Shaikh <furquan(a)chromium.org>
Original-Tested-by: Furquan Shaikh <furquan(a)chromium.org>
Change-Id: I8779526136e89ae61a6f177ce5c74a6530469ae1
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/Kconfig | 9 ++
src/arch/x86/Makefile.inc | 3 +-
src/arch/x86/init/romstage.ld | 5 +
src/include/memlayout.h | 3 +
src/include/symbols.h | 4 +
src/include/timestamp.h | 13 +++
src/lib/timestamp.c | 261 +++++++++++++++++++++++++++++-------------
7 files changed, 218 insertions(+), 80 deletions(-)
diff --git a/src/Kconfig b/src/Kconfig
index 269f7d2..84523a2 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -200,6 +200,15 @@ config COLLECT_TIMESTAMPS
Make coreboot create a table of timer-ID/timer-value pairs to
allow measuring time spent at different phases of the boot process.
+config HAS_PRECBMEM_TIMESTAMP_REGION
+ bool "Timestamp region exists for pre-cbmem timestamps"
+ default y if ARCH_ROMSTAGE_X86_32 && CACHE_AS_RAM
+ depends on COLLECT_TIMESTAMPS
+ help
+ A separate region is maintained to allow storing of timestamps before
+ cbmem comes up. This is useful for storing timestamps across different
+ stage boundaries.
+
config USE_BLOBS
bool "Allow use of binary-only repository"
default n
diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc
index f502bbe..dcb9ff0 100644
--- a/src/arch/x86/Makefile.inc
+++ b/src/arch/x86/Makefile.inc
@@ -225,7 +225,8 @@ $(objgenerated)/romstage_null.ld: $(obj)/config.h $$(filter %.ld,$$(romstage-src
rm -f $@
printf "ROMSTAGE_BASE = 0x0;\n" > $@.tmp
printf '$(foreach ldscript,$(^),#include "$(ldscript)"\n)' >> $@.tmp
- $(CC_romstage) $(PREPROCESS_ONLY) $@.tmp > $@
+ $(CC_romstage) $(PREPROCESS_ONLY) $(CPPFLAGS_common) $@.tmp > $@
+
$(objgenerated)/romstage.ld: $(objgenerated)/romstage_null.ld $(objcbfs)/base_xip.txt
@printf " GEN $(subst $(obj)/,,$(@))\n"
diff --git a/src/arch/x86/init/romstage.ld b/src/arch/x86/init/romstage.ld
index 7b9cb6a..951ca65 100644
--- a/src/arch/x86/init/romstage.ld
+++ b/src/arch/x86/init/romstage.ld
@@ -52,6 +52,11 @@ SECTIONS
. = CONFIG_DCACHE_RAM_BASE;
.car.data . (NOLOAD) : {
_car_data_start = .;
+#if IS_ENABLED(CONFIG_HAS_PRECBMEM_TIMESTAMP_REGION)
+ _timestamp = .;
+ . = . + 0x100;
+ _etimestamp = .;
+#endif
*(.car.global_data);
_car_data_end = .;
/* The preram cbmem console area comes last to take advantage
diff --git a/src/include/memlayout.h b/src/include/memlayout.h
index 2771f2f..a529628 100644
--- a/src/include/memlayout.h
+++ b/src/include/memlayout.h
@@ -47,6 +47,9 @@
#define DRAM_START(addr) SYMBOL(dram, addr)
+#define TIMESTAMP(addr, size) \
+ REGION(timestamp, addr, size, 8)
+
#define PRERAM_CBMEM_CONSOLE(addr, size) \
REGION(preram_cbmem_console, addr, size, 4)
diff --git a/src/include/symbols.h b/src/include/symbols.h
index 9102e82..3fbf819 100644
--- a/src/include/symbols.h
+++ b/src/include/symbols.h
@@ -28,6 +28,10 @@ extern u8 _esram[];
extern u8 _dram[];
+extern u8 _timestamp[];
+extern u8 _etimestamp[];
+#define _timestamp_size (_etimestamp - _timestamp)
+
extern u8 _preram_cbmem_console[];
extern u8 _epreram_cbmem_console[];
#define _preram_cbmem_console_size \
diff --git a/src/include/timestamp.h b/src/include/timestamp.h
index a248ea4..54d69ce 100644
--- a/src/include/timestamp.h
+++ b/src/include/timestamp.h
@@ -89,8 +89,21 @@ enum timestamp_id {
};
#if CONFIG_COLLECT_TIMESTAMPS && (CONFIG_EARLY_CBMEM_INIT || !defined(__PRE_RAM__))
+/*
+ * timestamp_init() needs to be called once for each of these cases:
+ * 1. __PRE_RAM__ (bootblock, romstage, verstage, etc) and
+ * 2. !__PRE_RAM__ (ramstage)
+ * The latter is taken care of by the generic coreboot infrastructure so
+ * it's up to the chipset/arch to call timestamp_init() in *one* of
+ * the __PRE_RAM__ stages. If multiple calls are made timestamps will be lost.
+ */
void timestamp_init(uint64_t base);
+/*
+ * Add a new timestamp. Depending on cbmem is available or not, this timestamp
+ * will be stored to cbmem / timestamp cache.
+ */
void timestamp_add(enum timestamp_id id, uint64_t ts_time);
+/* Calls timestamp_add with current timestamp. */
void timestamp_add_now(enum timestamp_id id);
#else
#define timestamp_init(base)
diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c
index 0c41ea2..51e63b2 100644
--- a/src/lib/timestamp.c
+++ b/src/lib/timestamp.c
@@ -17,10 +17,12 @@
* Foundation, Inc.
*/
+#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <console/console.h>
#include <cbmem.h>
+#include <symbols.h>
#include <timer.h>
#include <timestamp.h>
#include <arch/early_variables.h>
@@ -29,12 +31,65 @@
#define MAX_TIMESTAMPS 60
-static struct timestamp_table* ts_table_p CAR_GLOBAL = NULL;
-static uint64_t ts_basetime CAR_GLOBAL = 0;
+#define MAX_TIMESTAMP_CACHE 16
-static void timestamp_stash(enum timestamp_id id, uint64_t ts_time);
+struct __attribute__((__packed__)) timestamp_cache {
+ int cache_state;
+ struct timestamp_table table;
+ /* The struct timestamp_table has a 0 length array as its last field.
+ * The following 'entries' array serves as the storage space for the
+ * cache. */
+ struct timestamp_entry entries[MAX_TIMESTAMP_CACHE];
+};
-static void timestamp_real_init(uint64_t base)
+#if (IS_ENABLED(CONFIG_HAS_PRECBMEM_TIMESTAMP_REGION) && defined(__PRE_RAM__))
+#define USE_TIMESTAMP_REGION 1
+#else
+#define USE_TIMESTAMP_REGION 0
+#endif
+
+/* The cache location will sit in BSS when in ramstage. */
+#define TIMESTAMP_CACHE_IN_BSS ENV_RAMSTAGE
+
+#define HAS_CBMEM (ENV_ROMSTAGE || ENV_RAMSTAGE)
+
+/* Storage of cache entries during ramstage prior to cbmem coming online. */
+static struct timestamp_cache timestamp_cache;
+
+enum {
+ TIMESTAMP_CACHE_UNINITIALIZED = 0,
+ TIMESTAMP_CACHE_INITIALIZED,
+ TIMESTAMP_CACHE_NOT_NEEDED,
+};
+
+static void timestamp_cache_init(struct timestamp_cache *ts_cache,
+ uint64_t base)
+{
+ ts_cache->table.num_entries = 0;
+ ts_cache->table.max_entries = MAX_TIMESTAMP_CACHE;
+ ts_cache->table.base_time = base;
+ ts_cache->cache_state = TIMESTAMP_CACHE_INITIALIZED;
+}
+
+static struct timestamp_cache *timestamp_cache_get(void)
+{
+ struct timestamp_cache *ts_cache = NULL;
+
+ if (TIMESTAMP_CACHE_IN_BSS) {
+ ts_cache = ×tamp_cache;
+ } else if (USE_TIMESTAMP_REGION) {
+ if (_timestamp_size < sizeof(*ts_cache))
+ BUG();
+ ts_cache = car_get_var_ptr((void *)_timestamp);
+ }
+
+ if (ts_cache && ts_cache->cache_state == TIMESTAMP_CACHE_UNINITIALIZED)
+ timestamp_cache_init(ts_cache, 0);
+
+ return ts_cache;
+}
+
+static struct timestamp_table *timestamp_alloc_cbmem_table(void)
{
struct timestamp_table* tst;
@@ -43,13 +98,13 @@ static void timestamp_real_init(uint64_t base)
MAX_TIMESTAMPS * sizeof(struct timestamp_entry));
if (!tst)
- return;
+ return NULL;
- tst->base_time = base;
+ tst->base_time = 0;
tst->max_entries = MAX_TIMESTAMPS;
tst->num_entries = 0;
- car_set_var(ts_table_p, tst);
+ return tst;
}
/* Determine if one should proceed into timestamp code. This is for protecting
@@ -64,117 +119,165 @@ static int timestamp_should_run(void)
return 1;
}
-void timestamp_add(enum timestamp_id id, uint64_t ts_time)
+static struct timestamp_table *timestamp_table_get(void)
{
- struct timestamp_entry *tse;
- struct timestamp_table *ts_table = NULL;
+ MAYBE_STATIC struct timestamp_table *ts_table = NULL;
+ struct timestamp_cache *ts_cache;
if (!timestamp_should_run())
- return;
+ return NULL;
- ts_table = car_get_var(ts_table_p);
- if (!ts_table) {
- timestamp_stash(id, ts_time);
- return;
+ if (ts_table != NULL)
+ return ts_table;
+
+ ts_cache = timestamp_cache_get();
+
+ if (ts_cache == NULL) {
+ if (HAS_CBMEM)
+ ts_table = cbmem_find(CBMEM_ID_TIMESTAMP);
+ return ts_table;
}
- if (ts_table->num_entries == ts_table->max_entries)
+
+ /* Cache is required. */
+ if (ts_cache->cache_state != TIMESTAMP_CACHE_NOT_NEEDED)
+ return &ts_cache->table;
+
+ /* Cache shouldn't be used but there's no backing store. */
+ if (!HAS_CBMEM)
+ return NULL;
+
+ ts_table = cbmem_find(CBMEM_ID_TIMESTAMP);
+
+ return ts_table;
+}
+
+static void timestamp_add_table_entry(struct timestamp_table *ts_table,
+ enum timestamp_id id, uint64_t ts_time)
+{
+ struct timestamp_entry *tse;
+
+ if (ts_table->num_entries == ts_table->max_entries) {
+ printk(BIOS_ERR, "ERROR: Timestamp table full\n");
return;
+ }
tse = &ts_table->entries[ts_table->num_entries++];
tse->entry_id = id;
tse->entry_stamp = ts_time - ts_table->base_time;
}
-void timestamp_add_now(enum timestamp_id id)
+void timestamp_add(enum timestamp_id id, uint64_t ts_time)
{
- timestamp_add(id, timestamp_get());
-}
-
-#define MAX_TIMESTAMP_CACHE 8
-struct timestamp_cache {
- enum timestamp_id id;
- uint64_t time;
-} timestamp_cache[MAX_TIMESTAMP_CACHE] CAR_GLOBAL;
-
-static int timestamp_entries CAR_GLOBAL = 0;
-
-/**
- * timestamp_stash() allows to temporarily cache timestamps.
- * This is needed when timestamping before the CBMEM area
- * is initialized. The function timestamp_do_sync() is used to
- * write the timestamps to the CBMEM area and this is done as
- * part of CAR migration for romstage, and in ramstage main().
- */
+ struct timestamp_table *ts_table;
-static void timestamp_stash(enum timestamp_id id, uint64_t ts_time)
-{
- struct timestamp_cache *ts_cache = car_get_var(timestamp_cache);
- int ts_entries = car_get_var(timestamp_entries);
+ ts_table = timestamp_table_get();
- if (ts_entries >= MAX_TIMESTAMP_CACHE) {
- printk(BIOS_ERR, "ERROR: failed to add timestamp to cache\n");
+ if (!ts_table) {
+ printk(BIOS_ERR, "ERROR: No timestamp table found\n");
return;
}
- ts_cache[ts_entries].id = id;
- ts_cache[ts_entries].time = ts_time;
- car_set_var(timestamp_entries, ++ts_entries);
+
+ timestamp_add_table_entry(ts_table, id, ts_time);
}
-static void timestamp_do_sync(void)
+void timestamp_add_now(enum timestamp_id id)
{
- struct timestamp_cache *ts_cache = car_get_var(timestamp_cache);
- int ts_entries = car_get_var(timestamp_entries);
-
- int i;
- for (i = 0; i < ts_entries; i++)
- timestamp_add(ts_cache[i].id, ts_cache[i].time);
- car_set_var(timestamp_entries, 0);
+ timestamp_add(id, timestamp_get());
}
void timestamp_init(uint64_t base)
{
+ struct timestamp_cache *ts_cache;
+
if (!timestamp_should_run())
return;
-#ifdef __PRE_RAM__
- /* Copy of basetime, it is too early for CBMEM. */
- car_set_var(ts_basetime, base);
-#else
- struct timestamp_table *tst = NULL;
-
- /* Locate and use an already existing table. */
- if (!IS_ENABLED(CONFIG_LATE_CBMEM_INIT))
- tst = cbmem_find(CBMEM_ID_TIMESTAMP);
+ ts_cache = timestamp_cache_get();
- if (tst) {
- car_set_var(ts_table_p, tst);
+ if (!ts_cache) {
+ printk(BIOS_ERR, "ERROR: No timestamp cache to init\n");
return;
}
- /* Copy of basetime, may be too early for CBMEM. */
- car_set_var(ts_basetime, base);
- timestamp_real_init(base);
-#endif
+ timestamp_cache_init(ts_cache, base);
}
-static void timestamp_reinit(int is_recovery)
+static void timestamp_sync_cache_to_cbmem(int is_recovery)
{
+ uint32_t i;
+ struct timestamp_cache *ts_cache;
+ struct timestamp_table *ts_cache_table;
+ struct timestamp_table *ts_cbmem_table = NULL;
+
if (!timestamp_should_run())
return;
-#ifdef __PRE_RAM__
- timestamp_real_init(car_get_var(ts_basetime));
-#else
- if (!car_get_var(ts_table_p))
- timestamp_init(car_get_var(ts_basetime));
-#endif
- if (car_get_var(ts_table_p))
- timestamp_do_sync();
+ ts_cache = timestamp_cache_get();
+
+ /* No timestamp cache found */
+ if (ts_cache == NULL) {
+ printk(BIOS_ERR, "ERROR: No timestamp cache found\n");
+ return;
+ }
+
+ ts_cache_table = &ts_cache->table;
+
+ /* cbmem is being recovered. */
+ if (is_recovery) {
+ /* x86 resume path expects timestamps to be reset. */
+ if (IS_ENABLED(CONFIG_ARCH_ROMSTAGE_X86_32) && ENV_ROMSTAGE)
+ ts_cbmem_table = timestamp_alloc_cbmem_table();
+ else {
+ /* Find existing table in cbmem. */
+ ts_cbmem_table = cbmem_find(CBMEM_ID_TIMESTAMP);
+ /* No existing timestamp table. */
+ if (ts_cbmem_table == NULL)
+ ts_cbmem_table = timestamp_alloc_cbmem_table();
+ }
+ } else
+ /* First time sync. Add new table. */
+ ts_cbmem_table = timestamp_alloc_cbmem_table();
+
+ if (ts_cbmem_table == NULL) {
+ printk(BIOS_ERR, "ERROR: No timestamp table allocated\n");
+ return;
+ }
+
+ /*
+ * There's no need to worry about the base_time fields being out of
+ * sync because the following configurations are used/supported:
+ *
+ * 1. CONFIG_HAS_PRECBMEM_TIMESTAMP_REGION is enabled. This
+ * implies CONFIG_EARLY_CBMEM_INIT so once cbmem comes
+ * online we sync the timestamps to the cbmem storage while
+ * running in romstage. In ramstage the cbmem area is
+ * recovered and utilized.
+ *
+ * 2. CONFIG_LATE_CBMEM_INIT (!CONFIG_EARLY_CBMEM_INIT) is
+ * being used. That means the only cache that exists is
+ * in ramstage. Once cbmem comes online in ramstage those
+ * values are sync'd over.
+ *
+ * Any other combinations will result in inconsistent base_time
+ * values including bizarre timestamp values.
+ */
+ for (i = 0; i < ts_cache_table->num_entries; i++) {
+ struct timestamp_entry *tse = &ts_cache_table->entries[i];
+ timestamp_add_table_entry(ts_cbmem_table, tse->entry_id,
+ tse->entry_stamp);
+ }
+
+ /* Freshly added cbmem table has base_time 0. Inherit cache base_time */
+ if (ts_cbmem_table->base_time == 0)
+ ts_cbmem_table->base_time = ts_cache_table->base_time;
+
+ /* Cache no longer required. */
+ ts_cache_table->num_entries = 0;
+ ts_cache->cache_state = TIMESTAMP_CACHE_NOT_NEEDED;
}
-/* Call timestamp_reinit CBMEM init hooks. */
-ROMSTAGE_CBMEM_INIT_HOOK(timestamp_reinit)
-RAMSTAGE_CBMEM_INIT_HOOK(timestamp_reinit)
+ROMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem)
+RAMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem)
/* Provide default timestamp implementation using monotonic timer. */
uint64_t __attribute__((weak)) timestamp_get(void)
1
0
Patch merged into coreboot/master: hp/pavilion_m6_1035dx: Remove 'select USBDEBUG_IN_ROMSTAGE'
by gerrit@coreboot.org July 4, 2015
by gerrit@coreboot.org July 4, 2015
July 4, 2015
the following patch was just integrated into master:
commit caa599507f64a368facabf6da132cc3bc84b1bb2
Author: Kimarie Hoot <kimarie.hoot(a)se-eng.com>
Date: Tue Jun 23 16:45:10 2015 -0600
hp/pavilion_m6_1035dx: Remove 'select USBDEBUG_IN_ROMSTAGE'
Since USBDEBUG is not selected by this platform, there is no
benefit to selecting USBDEBUG_IN_ROMSTAGE in the mainboard
Kconfig. Further, using a 'select' for USBDEBUG_IN_ROMSTAGE
prevents the value from being modified by a user in menuconfig.
Change-Id: I67b71a724a8614882cff4bb43b042f0c092d11d2
Signed-off-by: Kimarie Hoot <kimarie.hoot(a)se-eng.com>
Reviewed-on: http://review.coreboot.org/10671
Tested-by: build bot (Jenkins)
Reviewed-by: Marc Jones <marc.jones(a)se-eng.com>
See http://review.coreboot.org/10671 for details.
-gerrit
1
0
Patch merged into coreboot/master: Kconfig whitespace cleanup: Change leading spaces to tabs
by gerrit@coreboot.org July 4, 2015
by gerrit@coreboot.org July 4, 2015
July 4, 2015
the following patch was just integrated into master:
commit 45895f1e7dcce9fdeb8b18afb1cf78f0aa4a9c08
Author: Martin Roth <gaumless(a)gmail.com>
Date: Wed Jul 1 19:38:29 2015 -0600
Kconfig whitespace cleanup: Change leading spaces to tabs
Change-Id: Icab6bd9f55f086da7b51ae463f34e29366d50e1a
Signed-off-by: Martin Roth <gaumless(a)gmail.com>
Reviewed-on: http://review.coreboot.org/10764
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter(a)users.sourceforge.net>
Reviewed-by: Patrick Georgi <pgeorgi(a)google.com>
See http://review.coreboot.org/10764 for details.
-gerrit
1
0
Patch set updated for coreboot: timestamps: remove intermediate function in sync code path
by Patrick Georgi July 4, 2015
by Patrick Georgi July 4, 2015
July 4, 2015
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10786
-gerrit
commit 10f878eec8efc679036597cdcc4a5be529767c65
Author: Patrick Georgi <pgeorgi(a)google.com>
Date: Fri Jul 3 16:07:38 2015 +0200
timestamps: remove intermediate function in sync code path
No need to have a simple stub function call another. Just do the deed.
Change-Id: I37d6fb24468e911f041caa4944ef906dc2ecb1b7
Signed-off-by: Patrick Georgi <pgeorgi(a)google.com>
---
src/lib/timestamp.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c
index c845757..7a4a6ae 100644
--- a/src/lib/timestamp.c
+++ b/src/lib/timestamp.c
@@ -198,7 +198,7 @@ void timestamp_early_init(uint64_t base)
timestamp_cache_init(ts_cache, base, TIMESTAMP_CBMEM_RESET_REQD);
}
-static void timestamp_do_sync(void)
+static void timestamp_do_sync_to_cbmem(int is_recovery)
{
uint32_t i;
@@ -206,6 +206,9 @@ static void timestamp_do_sync(void)
struct timestamp_table *ts_cache_table;
struct timestamp_table *ts_cbmem_table = NULL;
+ if (!timestamp_should_run())
+ return;
+
ts_cache = timestamp_cache_get();
/* No timestamp cache found */
@@ -292,18 +295,9 @@ void timestamp_init(uint64_t base)
tst->base_time = base;
}
-/* moves timestamp data from cache to cbmem region */
-static void timestamp_reinit(int is_recovery)
-{
- if (!timestamp_should_run())
- return;
-
- timestamp_do_sync();
-}
-
-/* Call timestamp_reinit CBMEM init hooks. */
-ROMSTAGE_CBMEM_INIT_HOOK(timestamp_reinit)
-RAMSTAGE_CBMEM_INIT_HOOK(timestamp_reinit)
+/* Call timestamp_do_sync_to_cbmem CBMEM init hook. */
+ROMSTAGE_CBMEM_INIT_HOOK(timestamp_do_sync_to_cbmem)
+RAMSTAGE_CBMEM_INIT_HOOK(timestamp_do_sync_to_cbmem)
/* Provide default timestamp implementation using monotonic timer. */
uint64_t __attribute__((weak)) timestamp_get(void)
1
0
July 4, 2015
Patrick Rudolph (siro(a)das-labor.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10789
-gerrit
commit 185c81de95d36de6a05ca338b73e9435a9cc6ead
Author: Patrick Rudolph <siro(a)das-labor.org>
Date: Fri Jul 3 21:11:25 2015 +0200
intel raminit: rename register
Found while doing code review.
Rename reg_4004_b30 to cmd_stretch.
Found in 4th-gen-core-family-desktop-vol-2-datasheet.pdf chapter 4.2.1.
Change-Id: Ib07059625ed458332708562e836803f2b587d5d8
Signed-off-by: Patrick Rudolph <siro(a)das-labor.org>
---
src/northbridge/intel/sandybridge/raminit_native.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/northbridge/intel/sandybridge/raminit_native.c b/src/northbridge/intel/sandybridge/raminit_native.c
index 8d1fecc..3740a02 100644
--- a/src/northbridge/intel/sandybridge/raminit_native.c
+++ b/src/northbridge/intel/sandybridge/raminit_native.c
@@ -136,7 +136,7 @@ typedef struct ramctr_timing_st {
int ref_card_offset[NUM_CHANNELS];
u32 mad_dimm[NUM_CHANNELS];
int channel_size_mb[NUM_CHANNELS];
- u32 reg_4004_b30[NUM_CHANNELS];
+ u32 cmd_stretch[NUM_CHANNELS];
int reg_c14_offset;
int reg_320c_range_threshold;
@@ -2683,7 +2683,7 @@ static void reprogram_320c(ramctr_timing * ctrl)
#define MIN_C320C_LEN 13
-static int try_reg_4004_b30(ramctr_timing * ctrl, int r4004b30)
+static int try_cmd_stretch(ramctr_timing * ctrl, int cmd_stretch)
{
struct ram_rank_timings saved_timings[NUM_CHANNELS][NUM_SLOTRANKS];
int channel, slotrank;
@@ -2695,7 +2695,7 @@ static int try_reg_4004_b30(ramctr_timing * ctrl, int r4004b30)
}
FOR_ALL_POPULATED_CHANNELS {
- ctrl->reg_4004_b30[channel] = r4004b30;
+ ctrl->cmd_stretch[channel] = cmd_stretch;
}
FOR_ALL_POPULATED_CHANNELS
@@ -2706,14 +2706,14 @@ static int try_reg_4004_b30(ramctr_timing * ctrl, int r4004b30)
| (ctrl->tWTR << 12)
| (ctrl->tFAW << 16)
| (ctrl->tWR << 24)
- | (ctrl->reg_4004_b30[channel] << 30);
+ | (ctrl->cmd_stretch[channel] << 30);
FOR_ALL_CHANNELS {
int delta = 0;
- if (ctrl->reg_4004_b30[channel] == 2)
+ if (ctrl->cmd_stretch[channel] == 2)
delta = 2;
- else if (ctrl->reg_4004_b30[channel] == 0)
+ else if (ctrl->cmd_stretch[channel] == 0)
delta = 4;
FOR_ALL_POPULATED_RANKS {
@@ -2764,7 +2764,8 @@ static void command_training(ramctr_timing * ctrl)
write32(DEFAULT_MCHBAR + 0x4288 + 0x400 * channel, 0x1f);
}
- if (!try_reg_4004_b30(ctrl, 0) && !try_reg_4004_b30(ctrl, 2))
+ /* try command rate 1T and 2T */
+ if (!try_cmd_stretch(ctrl, 0) && !try_cmd_stretch(ctrl, 2))
die("c320c discovery failed");
FOR_ALL_POPULATED_CHANNELS {
@@ -3621,7 +3622,7 @@ static void restore_timings(ramctr_timing * ctrl)
| (ctrl->tWTR << 12)
| (ctrl->tFAW << 16)
| (ctrl->tWR << 24)
- | (ctrl->reg_4004_b30[channel] << 30);
+ | (ctrl->cmd_stretch[channel] << 30);
udelay(1);
1
0
Patch set updated for coreboot: Update crossgcc Makefile for new buildgcc arguments
by Martin Roth July 4, 2015
by Martin Roth July 4, 2015
July 4, 2015
Martin Roth (gaumless(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10679
-gerrit
commit 32da9f00010b04505518afc1353821b7427614bb
Author: Martin Roth <gaumless(a)gmail.com>
Date: Sat Jun 27 19:09:05 2015 -0600
Update crossgcc Makefile for new buildgcc arguments
The script `util/crossgcc/buildgcc` was rewritten in commit 85b07d68
(buildgcc: move to a package centric user interface) and the switches
changed. This patch does the following:
- IASL was split out of the gcc builds, so needs a target of its own.
- Add clang build target
- Update the build-ARCH targets as buildgcc -G no longer builds gcc.
- Rework all the targets to use common targets to call buildgcc
- Split the tempfile clean from the regular clean
- Change the 'all' target to leave the tempfiles until all architectures
are built so that if one fails and needs a rebuild, it doesn't have to
start from scratch.
- Add an all_without_gdb target
- Add clang build to all
Change-Id: I4ff720eab6d9b72d00757fd2b632e6d9a6c25aa3
Signed-off-by: Martin Roth <gaumless(a)gmail.com>
---
util/crossgcc/Makefile | 77 +++++++++++++++++++++++++++++++++++---------------
1 file changed, 55 insertions(+), 22 deletions(-)
diff --git a/util/crossgcc/Makefile b/util/crossgcc/Makefile
index ae9177c..b4b0223 100644
--- a/util/crossgcc/Makefile
+++ b/util/crossgcc/Makefile
@@ -1,56 +1,89 @@
-all: build-i386 build-x64 build-armv7a build-aarch64 build-mips build-riscv
+# if no architecture is specified, set a default
+BUILD_PLATFORM ?= i386-elf
+all:
+ $(MAKE) BUILDGCC_OPTIONS=-t build-i386 build-x64 build-armv7a build-mips build-riscv build-aarch64 \
+ build_clang
+ $(MAKE) clean_tempfiles
+
+all_without_gdb:
+ $(MAKE) BUILDGCC_OPTIONS=-t build-i386-without-gdb build-x64-without-gdb build-armv7a-without-gdb \
+ build-mips-without-gdb build-riscv-without-gdb build-aarch64-without-gdb build_clang
+ $(MAKE) clean_tempfiles
+
+build_tools: build_gcc build_iasl build_gdb
+
+build_tools_without_gdb: build_gcc build_iasl
+
+###########################################################
+### targets to do buildgcc builds
+
+build_gcc:
+ bash ./buildgcc -p $(BUILD_PLATFORM) $(if $(BUILDJOBS),-j $(BUILDJOBS)) $(BUILDGCC_OPTIONS)
+
+build_gdb:
+ bash ./buildgcc -p $(BUILD_PLATFORM) -P gdb $(if $(BUILDJOBS),-j $(BUILDJOBS)) $(BUILDGCC_OPTIONS)
+
+build_iasl:
+ bash ./buildgcc -P iasl $(if $(BUILDJOBS),-j $(BUILDJOBS)) $(BUILDGCC_OPTIONS)
+
+build_clang:
+ bash ./buildgcc -P clang $(if $(BUILDJOBS),-j $(BUILDJOBS)) $(BUILDGCC_OPTIONS)
+
+###########################################################
+### Build with GDB ###
build-i386:
- bash ./buildgcc -G -p i386-elf $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools BUILD_PLATFORM=i386-elf
build-x64:
- bash ./buildgcc -G -p x86_64-elf $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools BUILD_PLATFORM=x86_64-elf
build-armv7a:
- bash ./buildgcc -G -p armv7a-eabi $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools BUILD_PLATFORM=armv7a-eabi
build-aarch64:
- bash ./buildgcc -G -p aarch64-elf $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools BUILD_PLATFORM=aarch64-elf
build-mips:
- bash ./buildgcc -G -p mipsel-elf $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools BUILD_PLATFORM=mipsel-elf
build-riscv:
- bash ./buildgcc -G -p riscv-elf $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools BUILD_PLATFORM=riscv-elf
-.PHONY: build-i386-without-gdb
+###########################################################
+### Build without GDB
build-i386-without-gdb:
- bash ./buildgcc -p i386-elf $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools_without_gdb BUILD_PLATFORM=i386-elf
-.PHONY: build-x64-without-gdb
build-x64-without-gdb:
- bash ./buildgcc -p x86_64-elf $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools_without_gdb BUILD_PLATFORM=x86_64-elf
-.PHONY: build-armv7a-without-gdb
build-armv7a-without-gdb:
- bash ./buildgcc -p armv7a-eabi $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools_without_gdb BUILD_PLATFORM=armv7a-eabi
-.PHONY: build-aarch64-without-gdb
build-aarch64-without-gdb:
- bash ./buildgcc -p aarch64-elf $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools_without_gdb BUILD_PLATFORM=aarch64-elf
-.PHONY: build-mips-without-gdb
build-mips-without-gdb:
- bash ./buildgcc -p mipsel-elf $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools_without_gdb BUILD_PLATFORM=mipsel-elf
-.PHONY: build-riscv-without-gdb
build-riscv-without-gdb:
- bash ./buildgcc -p riscv-elf $(if $(BUILDJOBS),-j $(BUILDJOBS))
+ @$(MAKE) build_tools_without_gdb BUILD_PLATFORM=riscv-elf
-clean:
- rm -rf xgcc
+clean_tempfiles:
rm -rf build-*
rm -rf binutils-* gcc-* gmp-* libelf-* mpc-* mpfr-*
rm -rf llvm-* clang-tools-* cfe-* compiler-rt-*
rm -rf acpica-*
rm -rf gdb-*
+clean: clean_tempfiles
+ rm -rf xgcc
+
distclean: clean
rm -rf tarballs
-.PHONY: all build clean distclean
+.PHONY: build_gcc build_iasl build_gdb build_tools build_tools_without_gdb \
+ build-i386-without-gdb build-x64-without-gdb build-armv7a-without-gdb \
+ build-aarch64-without-gdb build-mips-without-gdb build-riscv-without-gdb \
+ all build clean distclean clean_tempfiles all_without_gdb
1
0