[U-Boot] [PATCH 5/7] efi_loader: let the variable driver patch out the runtime

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


Our variable services are only provided at boottime. Therefore when
leaving boottime the variable function are replaced by dummy functions
returning EFI_UNSUPPORTED. Move this patching of the runtime table to the
variable services implementation. Executed it in ExitBootServices().

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 include/efi_loader.h               |  2 ++
 lib/efi_loader/efi_boottime.c      |  3 +-
 lib/efi_loader/efi_runtime.c       |  9 ------
 lib/efi_loader/efi_variable.c      | 44 ++++++++++++++++++++++++++++++
 lib/efi_loader/efi_variable_null.c | 17 ++++++++++++
 5 files changed, 65 insertions(+), 10 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index d30c4e8ef3..8d75dde569 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -327,6 +327,8 @@ extern struct list_head efi_register_notify_events;
 efi_status_t efi_init_obj_list(void);
 /* Initialize variable services */
 efi_status_t efi_init_variables(void);
+/* Notify ExitBootServices() is called */
+void efi_variables_boot_exit_notify(void);
 /* Called by bootefi to initialize root node */
 efi_status_t efi_root_node_register(void);
 /* Called by bootefi to initialize runtime */
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index d104cc6b31..a929bbb671 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -1968,7 +1968,8 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle,
 	/* Make sure that notification functions are not called anymore */
 	efi_tpl = TPL_HIGH_LEVEL;

-	/* TODO: Should persist EFI variables here */
+	/* Notify variable services */
+	efi_variables_boot_exit_notify();

 	board_quiesce_devices();

diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 1c8f9b8218..551470b9ac 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -424,15 +424,6 @@ static const struct efi_runtime_detach_list_struct efi_runtime_detach_list[] = {
 		/* Clean up system table */
 		.ptr = &systab.boottime,
 		.patchto = NULL,
-	}, {
-		.ptr = &efi_runtime_services.get_variable,
-		.patchto = &efi_device_error,
-	}, {
-		.ptr = &efi_runtime_services.get_next_variable_name,
-		.patchto = &efi_device_error,
-	}, {
-		.ptr = &efi_runtime_services.set_variable,
-		.patchto = &efi_device_error,
 	}
 };

diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 6210425f5e..bc8ed678c9 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -548,6 +548,50 @@ efi_status_t __efi_runtime EFIAPI efi_query_variable_info(
 	return EFI_UNSUPPORTED;
 }

+/**
+ * efi_get_variable_runtime() - runtime implementation of GetVariable()
+ */
+static efi_status_t __efi_runtime EFIAPI
+efi_get_variable_runtime(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_runtime() - runtime implementation of
+ *					  GetNextVariable()
+ */
+static efi_status_t __efi_runtime EFIAPI
+efi_get_next_variable_name_runtime(efi_uintn_t *variable_name_size,
+				   u16 *variable_name, const efi_guid_t *vendor)
+{
+	return EFI_UNSUPPORTED;
+}
+
+/**
+ * efi_set_variable_runtime() - runtime implementation of SetVariable()
+ */
+static efi_status_t __efi_runtime EFIAPI
+efi_set_variable_runtime(u16 *variable_name, const efi_guid_t *vendor,
+			 u32 attributes, efi_uintn_t data_size,
+			 const void *data)
+{
+	return EFI_UNSUPPORTED;
+}
+
+/**
+ * efi_variables_boot_exit_notify() - notify ExitBootServices() is called
+ */
+void efi_variables_boot_exit_notify(void)
+{
+	efi_runtime_services.get_variable = efi_get_variable_runtime;
+	efi_runtime_services.get_next_variable_name =
+				efi_get_next_variable_name_runtime;
+	efi_runtime_services.set_variable = efi_set_variable_runtime;
+	efi_update_table_header_crc32(&efi_runtime_services.hdr);
+}
+
 /**
  * efi_init_variables() - initialize variable services
  *
diff --git a/lib/efi_loader/efi_variable_null.c b/lib/efi_loader/efi_variable_null.c
index f4c96c90a3..1cbfe4d8a0 100644
--- a/lib/efi_loader/efi_variable_null.c
+++ b/lib/efi_loader/efi_variable_null.c
@@ -94,3 +94,20 @@ efi_query_variable_info(u32 attributes, u64 *maximum_variable_storage_size,
 {
 	return EFI_UNSUPPORTED;
 }
+
+/**
+ * efi_variables_boot_exit_notify() - notify ExitBootServices() is called
+ */
+void efi_variables_boot_exit_notify(void);
+{
+}
+
+/**
+ * efi_init_variables() - initialize variable services
+ *
+ * Return:	status code
+ */
+efi_status_t efi_init_variables(void)
+{
+	return EFI_SUCCESS;
+}
--
2.20.1



More information about the U-Boot mailing list