From 4191dbf0c9a57088e7a7323d8bf02a8708eacdb9 Mon Sep 17 00:00:00 2001
From: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Date: Sun, 23 Oct 2022 00:34:32 +0300
Subject: security/tpm: add TPM log format as per 1.2 spec
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Used by default for all boards with TPM1 which don't specify log format
explicitly.

Ticket: https://ticket.coreboot.org/issues/423
Change-Id: I89720615a75573d44dd0a39ad3d7faa78f125843
Signed-off-by: Michał Żygowski <michal.zygowski@3mdeb.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/68747
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
---
 src/commonlib/bsd/include/commonlib/bsd/cbmem_id.h |  6 ++--
 .../bsd/include/commonlib/bsd/tpm_log_defs.h       | 42 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 3 deletions(-)
 create mode 100644 src/commonlib/bsd/include/commonlib/bsd/tpm_log_defs.h

(limited to 'src/commonlib')

diff --git a/src/commonlib/bsd/include/commonlib/bsd/cbmem_id.h b/src/commonlib/bsd/include/commonlib/bsd/cbmem_id.h
index 89f88b7709..fa5c8d9e94 100644
--- a/src/commonlib/bsd/include/commonlib/bsd/cbmem_id.h
+++ b/src/commonlib/bsd/include/commonlib/bsd/cbmem_id.h
@@ -60,10 +60,10 @@
 #define CBMEM_ID_STAGEx_CACHE	0x57a9e100
 #define CBMEM_ID_STAGEx_RAW	0x57a9e200
 #define CBMEM_ID_STORAGE_DATA	0x53746f72
-#define CBMEM_ID_TPM_CB_LOG	0x54435041
-#define CBMEM_ID_TCPA_TCG_LOG	0x54445041
+#define CBMEM_ID_TPM_CB_LOG	0x54435041 /* TPM log in coreboot-specific format */
+#define CBMEM_ID_TCPA_TCG_LOG	0x54445041 /* TPM log per TPM 1.2 specification */
 #define CBMEM_ID_TIMESTAMP	0x54494d45
-#define CBMEM_ID_TPM2_TCG_LOG	0x54504d32
+#define CBMEM_ID_TPM2_TCG_LOG	0x54504d32 /* TPM log per TPM 2.0 specification */
 #define CBMEM_ID_TPM_PPI	0x54505049
 #define CBMEM_ID_VBOOT_HANDOFF	0x780074f0  /* deprecated */
 #define CBMEM_ID_VBOOT_SEL_REG	0x780074f1  /* deprecated */
diff --git a/src/commonlib/bsd/include/commonlib/bsd/tpm_log_defs.h b/src/commonlib/bsd/include/commonlib/bsd/tpm_log_defs.h
new file mode 100644
index 0000000000..a45a212746
--- /dev/null
+++ b/src/commonlib/bsd/include/commonlib/bsd/tpm_log_defs.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef COMMONLIB_BSD_TPM_LOG_DEFS_H
+#define COMMONLIB_BSD_TPM_LOG_DEFS_H
+
+#include <commonlib/helpers.h>
+#include <stdint.h>
+
+#define TCPA_SPEC_ID_EVENT_SIGNATURE    "Spec ID Event00"
+#define TCG_EFI_SPEC_ID_EVENT_SIGNATURE "Spec ID Event03"
+
+#define EV_PREBOOT_CERT			0x00000000
+#define EV_POST_CODE			0x00000001
+#define EV_UNUSED			0x00000002
+#define EV_NO_ACTION			0x00000003
+#define EV_SEPARATOR			0x00000004
+#define EV_ACTION			0x00000005
+#define EV_EVENT_TAG			0x00000006
+#define EV_S_CRTM_CONTENTS		0x00000007
+#define EV_S_CRTM_VERSION		0x00000008
+#define EV_CPU_MICROCODE		0x00000009
+#define EV_PLATFORM_CONFIG_FLAGS	0x0000000A
+#define EV_TABLE_OF_DEVICES		0x0000000B
+#define EV_COMPACT_HASH			0x0000000C
+#define EV_IPL				0x0000000D
+#define EV_IPL_PARTITION_DATA		0x0000000E
+#define EV_NONHOST_CODE			0x0000000F
+#define EV_NONHOST_CONFIG		0x00000010
+#define EV_NONHOST_INFO			0x00000011
+#define EV_OMIT_BOOT_DEVICE_EVENTS	0x00000012
+
+struct spec_id_event_data {
+	char signature[16];
+	uint32_t platform_class;
+	uint8_t spec_version_minor;
+	uint8_t spec_version_major;
+	uint8_t spec_errata;
+	uint8_t reserved;
+	uint8_t vendor_info_size;
+} __packed;
+
+#endif
-- 
cgit v1.2.3