[U-Boot] [PATCH 2/7] efi_debug: make variable support customizable

Heinrich Schuchardt xypron.glpk at gmx.de
Mon Jun 24 05:31:03 UTC 2019


Provide a customization option to define how UEFI variables are
implemented.

This patch provides a dummy implementation without any variable support and
provides the choice between this dummy and the legacy implementation.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 lib/efi_loader/Kconfig             | 18 ++++++
 lib/efi_loader/Makefile            |  3 +-
 lib/efi_loader/efi_setup.c         | 10 +++-
 lib/efi_loader/efi_variable_null.c | 96 ++++++++++++++++++++++++++++++
 lib/efi_selftest/Makefile          |  5 +-
 5 files changed, 128 insertions(+), 4 deletions(-)
 create mode 100644 lib/efi_loader/efi_variable_null.c

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index cd5436c576..97c2ca9820 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -34,6 +34,24 @@ config EFI_SET_TIME
 	  Provide the SetTime() runtime service at boottime. This service
 	  can be used by an EFI application to adjust the real time clock.

+choice
+	prompt "Variable storage"
+	default EFI_VARIABLES_UBOOT
+	help
+	  Define where UEFI variables are stored.
+
+config EFI_VARIABLES_UBOOT
+	bool "U-Boot environment"
+	help
+	  UEFI variables are stored in the U-Boot environment.
+
+config EFI_VARIABLES_NULL
+	bool "UEFI variables are not available"
+	help
+	  UEFI variables are not supported.
+
+endchoice
+
 config EFI_DEVICE_PATH_TO_TEXT
 	bool "Device path to text protocol"
 	default y
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 01769ea58b..e244aee2f5 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -31,7 +31,8 @@ obj-y += efi_root_node.o
 obj-y += efi_runtime.o
 obj-y += efi_setup.o
 obj-$(CONFIG_EFI_UNICODE_COLLATION_PROTOCOL2) += efi_unicode_collation.o
-obj-y += efi_variable.o
+obj-$(CONFIG_EFI_VARIABLES_UBOOT) += efi_variable.o
+obj-$(CONFIG_EFI_VARIABLES_NULL) += efi_variable_null.o
 obj-y += efi_watchdog.o
 obj-$(CONFIG_LCD) += efi_gop.o
 obj-$(CONFIG_DM_VIDEO) += efi_gop.o
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index bfb57836fa..a3f59506d8 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -22,6 +22,8 @@ void __weak allow_unaligned(void)
 {
 }

+#ifndef CONFIG_EFI_VARIABLES_NULL
+
 /**
  * efi_init_platform_lang() - define supported languages
  *
@@ -82,6 +84,8 @@ out:
 	return ret;
 }

+#endif
+
 /**
  * efi_init_obj_list() - Initialize and populate EFI object list
  *
@@ -89,7 +93,9 @@ out:
  */
 efi_status_t efi_init_obj_list(void)
 {
+#ifndef CONFIG_EFI_VARIABLES_NULL
 	u64 os_indications_supported = 0; /* None */
+#endif
 	efi_status_t ret = EFI_SUCCESS;

 	/* Initialize once only */
@@ -101,7 +107,7 @@ efi_status_t efi_init_obj_list(void)

 	/* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */
 	switch_to_non_secure_mode();
-
+#ifndef CONFIG_EFI_VARIABLES_NULL
 	/* Define supported languages */
 	ret = efi_init_platform_lang();
 	if (ret != EFI_SUCCESS)
@@ -121,7 +127,7 @@ efi_status_t efi_init_obj_list(void)
 	ret = efi_init_runtime_supported();
 	if (ret != EFI_SUCCESS)
 		goto out;
-
+#endif
 	/* Initialize system table */
 	ret = efi_initialize_system_table();
 	if (ret != EFI_SUCCESS)
diff --git a/lib/efi_loader/efi_variable_null.c b/lib/efi_loader/efi_variable_null.c
new file mode 100644
index 0000000000..f4c96c90a3
--- /dev/null
+++ b/lib/efi_loader/efi_variable_null.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Dummy driver for UEFI variables. None of the variable services is supported.
+ *
+ * Copyright (c) 2019 Heinrich Schuchardt
+ */
+
+#include <efi_loader.h>
+
+/**
+ * efi_get_variable() - retrieve value of a UEFI variable
+ *
+ * This function implements the GetVariable runtime service.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @variable_name:	name of the variable
+ * @vendor:		vendor GUID
+ * @attributes:		attributes of the variable
+ * @data_size:		size of the buffer to which the variable value is copied
+ * @data:		buffer to which the variable value is copied
+ * Return:		status code
+ */
+efi_status_t __efi_runtime EFIAPI
+efi_get_variable(u16 *variable_name, const efi_guid_t *vendor, u32 *attributes,
+		 efi_uintn_t *data_size, void *data)
+{
+	return EFI_UNSUPPORTED;
+}
+
+/**
+ * efi_get_next_variable_name() - enumerate the current variable names
+ * @variable_name_size:	size of variable_name buffer in byte
+ * @variable_name:	name of uefi variable's name in u16
+ * @vendor:		vendor's guid
+ *
+ * This function implements the GetNextVariableName service.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details: http://wiki.phoenix.com/wiki/index.php/
+ *		EFI_RUNTIME_SERVICES#GetNextVariableName.28.29
+ *
+ * Return: status code
+ */
+efi_status_t __efi_runtime EFIAPI
+efi_get_next_variable_name(efi_uintn_t *variable_name_size, u16 *variable_name,
+			   const efi_guid_t *vendor)
+{
+	return EFI_UNSUPPORTED;
+}
+
+/**
+ * efi_set_variable() - set value of a UEFI variable
+ *
+ * This function implements the SetVariable runtime service.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @variable_name:	name of the variable
+ * @vendor:		vendor GUID
+ * @attributes:		attributes of the variable
+ * @data_size:		size of the buffer with the variable value
+ * @data:		buffer with the variable value
+ * Return:		status code
+ */
+efi_status_t __efi_runtime EFIAPI
+efi_set_variable(u16 *variable_name, const efi_guid_t *vendor, u32 attributes,
+		 efi_uintn_t data_size, const void *data)
+{
+	return EFI_UNSUPPORTED;
+}
+
+/**
+ * efi_query_variable_info() - query information the variable store
+ *
+ * This function implements the QueryVariableInfo runtime service.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @attributes:				type of variables for which info shall
+ *					be provided
+ * @maximum_variable_storage_size:	total available storage for variables
+ * @remaining_variable_storage_size:	remaining available storage
+ * @maximum_variable_size:		maximum size of a variable
+ * Return:				status code
+ */
+efi_status_t __efi_runtime  EFIAPI
+efi_query_variable_info(u32 attributes, u64 *maximum_variable_storage_size,
+			u64 *remaining_variable_storage_size,
+			u64 *maximum_variable_size)
+{
+	return EFI_UNSUPPORTED;
+}
diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile
index 3bebd0f573..bb3ebd7fa7 100644
--- a/lib/efi_selftest/Makefile
+++ b/lib/efi_selftest/Makefile
@@ -34,7 +34,6 @@ efi_selftest_textinputex.o \
 efi_selftest_textoutput.o \
 efi_selftest_tpl.o \
 efi_selftest_util.o \
-efi_selftest_variables.o \
 efi_selftest_watchdog.o

 obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_selftest_devicepath.o
@@ -45,6 +44,10 @@ obj-$(CONFIG_CPU_V7) += efi_selftest_unaligned.o
 obj-$(CONFIG_EFI_LOADER_HII) += efi_selftest_hii.o
 obj-$(CONFIG_EFI_GET_TIME) += efi_selftest_rtc.o

+ifeq ($(CONFIG_EFI_VARIABLES_NULL),)
+obj-y += efi_selftest_variables.o
+endif
+
 ifeq ($(CONFIG_GENERATE_ACPI_TABLE),)
 obj-y += efi_selftest_fdt.o
 endif
--
2.20.1



More information about the U-Boot mailing list