efi_selftest: provide unit test for the EFI_TCG2_PROTOCOL
PATCH 1/1 efi_selftest: provide unit test for the EFI_TCG2_PROTOCOL
Provide a minimal test for the EFI_TCG2_PROTOCOL.
Signed-off-by Heinrich Schuchardt <[email protected]>
--- 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
lib/efi_selftest/Makefile +1 -0
@@ -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
lib/efi_selftest/efi_selftest_tcg2.c new file +75 -0
75 lines not on this page · raw message
--
2.29.2
PATCH 1/1 efi_selftest: provide unit test for the EFI_TCG2_PROTOCOL
Quoted 66 lines · Heinrich Schuchardt
Provide a minimal test for the
EFI_TCG2_PROTOCOL.Signed-off-by Heinrich Schuchardt <[email protected]>--- 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.clib/efi_selftest/Makefile +1
-0@@ -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.olib/efi_selftest/efi_selftest_tcg2.c new file +39
-0@@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* efi_selftest_devicepath +* +* Copyright (c) 2020 Heinrich Schuchardt <[email protected]> +* +* 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 ) +{
lib/efi_selftest/efi_selftest_tcg2.c line 49
Quoted 10 lines
lib/efi_selftest/efi_selftest_tcg2.c new file +10
-0+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 ;
Nit pick sizeof(capability)
lib/efi_selftest/efi_selftest_tcg2.c line 55
Quoted 6 lines
lib/efi_selftest/efi_selftest_tcg2.c new file +6
-0+ 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 );
ditto
Quoted 21 lines
lib/efi_selftest/efi_selftest_tcg2.c new file +20
-1+ 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, +}; --
Quoted 2 lines
2.29.2
Acked-by Ilias Apalodimas <[email protected]>