All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [PATCH 1/1] efi_selftest: provide unit test for the EFI_TCG2_PROTOCOL
Date: Sat, 14 Nov 2020 04:45:18 +0100	[thread overview]
Message-ID: <20201114034518.3776-1-xypron.glpk@gmx.de> (raw)

Provide a minimal test for the EFI_TCG2_PROTOCOL.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 lib/efi_selftest/Makefile            |  1 +
 lib/efi_selftest/efi_selftest_tcg2.c | 75 ++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
 create mode 100644 lib/efi_selftest/efi_selftest_tcg2.c

diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile
index aabb743ecb..58fb43fcdf 100644
--- a/lib/efi_selftest/Makefile
+++ b/lib/efi_selftest/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_EFI_LOADER_HII) += efi_selftest_hii.o
 obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_selftest_rng.o
 obj-$(CONFIG_EFI_GET_TIME) += efi_selftest_rtc.o
 obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_selftest_load_initrd.o
+obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_selftest_tcg2.o

 ifeq ($(CONFIG_GENERATE_ACPI_TABLE),)
 obj-y += efi_selftest_fdt.o
diff --git a/lib/efi_selftest/efi_selftest_tcg2.c b/lib/efi_selftest/efi_selftest_tcg2.c
new file mode 100644
index 0000000000..dcaac34618
--- /dev/null
+++ b/lib/efi_selftest/efi_selftest_tcg2.c
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * efi_selftest_devicepath
+ *
+ * Copyright (c) 2020 Heinrich Schuchardt <xypron.glpk@gmx.de>
+ *
+ * Test the EFI_TCG2_PROTOCOL
+ */
+
+#include <efi_selftest.h>
+#include <efi_tcg2.h>
+
+static struct efi_boot_services *boottime;
+static const efi_guid_t guid_tcg2 = EFI_TCG2_PROTOCOL_GUID;
+
+/**
+ * efi_st_tcg2_setup() - setup test
+ *
+ * @handle:	handle of the loaded image
+ * @systable:	system table
+ * @return:	status code
+ */
+static int efi_st_tcg2_setup(const efi_handle_t img_handle,
+			     const struct efi_system_table *systable)
+{
+	boottime = systable->boottime;
+
+	return EFI_ST_SUCCESS;
+}
+
+/**
+ * efi_st_tcg2_execute() - execute test
+ *
+ * Call the GetCapability service of the EFI_TCG2_PROTOCOL.
+ *
+ * Return:	status code
+ */
+static int efi_st_tcg2_execute(void)
+{
+	struct efi_tcg2_protocol *tcg2;
+	struct efi_tcg2_boot_service_capability capability;
+	efi_status_t ret;
+
+	ret = boottime->locate_protocol(&guid_tcg2, NULL, (void **)&tcg2);
+	if (ret != EFI_SUCCESS) {
+		efi_st_error("TCG2 protocol is not available.\n");
+		return EFI_ST_FAILURE;
+	}
+	capability.size = sizeof(struct efi_tcg2_boot_service_capability) - 1;
+	ret = tcg2->get_capability(tcg2, &capability);
+	if (ret != EFI_BUFFER_TOO_SMALL) {
+		efi_st_error("tcg2->get_capability on small buffer failed\n");
+		return EFI_ST_FAILURE;
+	}
+	capability.size = sizeof(struct efi_tcg2_boot_service_capability);
+	ret = tcg2->get_capability(tcg2, &capability);
+	if (ret != EFI_SUCCESS) {
+		efi_st_error("tcg2->get_capability failed\n");
+		return EFI_ST_FAILURE;
+	}
+	if (!capability.tpm_present_flag) {
+		efi_st_error("TPM not present\n");
+		return EFI_ST_FAILURE;
+	}
+	efi_st_printf("TPM supports 0x%.8x event logs\n",
+		      capability.supported_event_logs);
+	return EFI_ST_SUCCESS;
+}
+
+EFI_UNIT_TEST(tcg2) = {
+	.name = "tcg2",
+	.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
+	.execute = efi_st_tcg2_execute,
+	.setup = efi_st_tcg2_setup,
+};
--
2.29.2

             reply	other threads:[~2020-11-14  3:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-14  3:45 Heinrich Schuchardt [this message]
2020-11-14  7:21 ` [PATCH 1/1] efi_selftest: provide unit test for the EFI_TCG2_PROTOCOL Ilias Apalodimas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201114034518.3776-1-xypron.glpk@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.