diff mbox series

[v3,16/17] efi_loader: enable UEFI variables at runtime

Message ID 20200708162936.25802-17-xypron.glpk@gmx.de
State Superseded
Headers show
Series efi_loader: non-volatile and runtime variables | expand

Commit Message

Heinrich Schuchardt July 8, 2020, 4:29 p.m. UTC
Enable UEFI variables at runtime.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
v3:
	Use efi_var_mem_ins() when restoring variables from file.
	Remove EFI_VARIABLE_READ_ONLY attribute in runtime GetVariable().
---
 lib/efi_loader/efi_runtime.c  |  2 ++
 lib/efi_loader/efi_var_file.c |  6 +++---
 lib/efi_loader/efi_variable.c | 14 ++++++++++++--
 3 files changed, 17 insertions(+), 5 deletions(-)

--
2.27.0
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 5b6506fbdc..91a4551448 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -121,6 +121,8 @@  efi_status_t efi_init_runtime_supported(void)
 	rt_table->version = EFI_RT_PROPERTIES_TABLE_VERSION;
 	rt_table->length = sizeof(struct efi_rt_properties_table);
 	rt_table->runtime_services_supported =
+				EFI_RT_SUPPORTED_GET_VARIABLE |
+				EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME |
 				EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP |
 				EFI_RT_SUPPORTED_CONVERT_POINTER;

diff --git a/lib/efi_loader/efi_var_file.c b/lib/efi_loader/efi_var_file.c
index b1b7532495..880c279aef 100644
--- a/lib/efi_loader/efi_var_file.c
+++ b/lib/efi_loader/efi_var_file.c
@@ -183,9 +183,9 @@  static efi_status_t __maybe_unused efi_var_restore(struct efi_var_file *buf)
 		u16 *data = var->name + u16_strlen(var->name) + 1;

 		if (var->attr & EFI_VARIABLE_NON_VOLATILE && var->length) {
-			ret = efi_set_variable_int(var->name, &var->guid,
-						   var->attr, var->length,
-						   data, true);
+			ret = efi_var_mem_ins(var->name, &var->guid, var->attr,
+					      var->length, data, 0, NULL,
+					      var->time);
 			if (ret != EFI_SUCCESS)
 				log_err("Failed to set EFI variable %ls\n",
 					var->name);
diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 13123e7e41..c8fbcf396b 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -672,7 +672,16 @@  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_status_t ret;
+
+	ret = efi_get_variable_int(variable_name, vendor, attributes,
+				   data_size, data, NULL);
+
+	/* Remove EFI_VARIABLE_READ_ONLY flag */
+	if (attributes)
+		*attributes &= EFI_VARIABLE_MASK;
+
+	return ret;
 }

 /**
@@ -688,7 +697,8 @@  static efi_status_t __efi_runtime EFIAPI
 efi_get_next_variable_name_runtime(efi_uintn_t *variable_name_size,
 				   u16 *variable_name, efi_guid_t *vendor)
 {
-	return EFI_UNSUPPORTED;
+	return efi_get_next_variable_name_int(variable_name_size, variable_name,
+					      vendor);
 }

 /**