diff options
author | Heinrich Schuchardt <xypron.glpk@gmx.de> | 2020-11-12 19:53:10 +0100 |
---|---|---|
committer | Heinrich Schuchardt <xypron.glpk@gmx.de> | 2020-11-14 05:05:46 +0100 |
commit | af69267c3208e33378241f282a26ea7d50ec691f (patch) | |
tree | d768e1994e43a2b5a1c78961b4a435f41e5ac2a9 /lib | |
parent | c1c021052c7a03ed0226b4ce3e9b20c0498e2ccb (diff) | |
download | u-boot-af69267c3208e33378241f282a26ea7d50ec691f.tar.gz |
efi_selftest: provide unit test for the EFI_TCG2_PROTOCOL
Provide a minimal test for the EFI_TCG2_PROTOCOL.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/efi_selftest/Makefile | 1 | ||||
-rw-r--r-- | lib/efi_selftest/efi_selftest_tcg2.c | 75 |
2 files changed, 76 insertions, 0 deletions
diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index aabb743ecbb..58fb43fcdfc 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 00000000000..1399309cec7 --- /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, +}; |