Skip to contentSkip to conversation

EFI: Use sysreset instead of reset command

PATCH New Masami Hiramatsu 1 participant 4 messages Mar 21, 2022

lore
Share & tools
lore
#0 lore raw

v3 cover EFI: Use sysreset instead of reset command

Hi,

Here is the 3rd version of the series to use sysreset instead of do_reset command interface for resetting after capsule update on disk. This change requires EFI capsule update on disk to depends on sysreset.

This adds two fixes from the previous patch:
- [1/3] Disable 'capsule disk-update' of efidebug command when CONFIG_EFI_CAPSULE_ON_DISK is disabled.
- [2/3] Make efi_load_capsule_drivers() available even if the CONFIG_EFI_CAPSULE_ON_DISK is disabled.
And add Reviewed-by from Simon and Heinrich to [3/3].

Thank you,

---

Masami Hiramatsu (3):
cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n
efi_loader: Make efi_load_capsule_drivers() available even if EFI_CAPSULE_ON_DISK=n
efi_loader: Use sysreset instead of reset command

 cmd/efidebug.c               |    4 +++
 lib/efi_loader/Kconfig       |    1 +
 lib/efi_loader/efi_capsule.c |   65 +++++++++++++++++++++---------------------
 3 files changed, 38 insertions(+), 32 deletions(-)

--
Masami Hiramatsu <[email protected]>

#1 lore raw

PATCH v3 1/3 cmd: efidebug: Disable 'capsule disk-update' when CONFIG_EFI_CAPSULE_ON_DISK=n

Disable 'capsule disk-update' option for the efidebug command when CONFIC_EFI_CAPSULE_ON_DISK is disabled, because this option is available only when the EFI capsule update on disk is enabled.

---
 cmd/efidebug.c |    4 ++++
 1 file changed, 4 insertions(+)
cmd/efidebug.c +4 -0
index 401d13cc4c..a1a0717ecb 100644
@@ -84,6 +84,7 @@ static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int flag,
 	return CMD_RET_SUCCESS;
 }
 
+#ifdef CONFIG_EFI_CAPSULE_ON_DISK
 static int do_efi_capsule_on_disk_update(struct cmd_tbl *cmdtp, int flag,
 					 int argc, char * const argv[])
 {
@@ -93,6 +94,7 @@ static int do_efi_capsule_on_disk_update(struct cmd_tbl *cmdtp, int flag,
 
 	return ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
 }
+#endif
 
 /**
  * do_efi_capsule_show() - show capsule information
@@ -303,8 +305,10 @@ static struct cmd_tbl cmd_efidebug_capsule_sub[] = {
 	U_BOOT_CMD_MKENT(esrt, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_esrt,
 			 "", ""),
 #endif
+#ifdef CONFIG_EFI_CAPSULE_ON_DISK
 	U_BOOT_CMD_MKENT(disk-update, 0, 0, do_efi_capsule_on_disk_update,
 			 "", ""),
+#endif
 	U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res,
 			 "", ""),
 };
#2 lore raw

PATCH v3 2/3 efi_loader: Make efi_load_capsule_drivers() available even if EFI_CAPSULE_ON_DISK=n

In reply to Masami Hiramatsu

Make efi_load_capsule_drivers() available even if EFI_CAPSULE_ON_DISK is disabled because the caller (efi_init_obj_list()) expects it only relays on EFI_HAVE_CAPSULE_SUPPORT.

---
 lib/efi_loader/efi_capsule.c |   60 +++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 30 deletions(-)
lib/efi_loader/efi_capsule.c +30 -30
index 613b531b82..9fd6f78ad9 100644
@@ -619,6 +619,36 @@ out:
 	return EFI_EXIT(ret);
 }
 
+/**
+ * efi_load_capsule_drivers - initialize capsule drivers
+ *
+ * Generic FMP drivers backed by DFU
+ *
+ * Return:	status code
+ */
+efi_status_t __weak efi_load_capsule_drivers(void)
+{
+	__maybe_unused efi_handle_t handle;
+	efi_status_t ret = EFI_SUCCESS;
+
+	if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)) {
+		handle = NULL;
+		ret = EFI_CALL(efi_install_multiple_protocol_interfaces(
+				&handle, &efi_guid_firmware_management_protocol,
+				&efi_fmp_fit, NULL));
+	}
+
+	if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)) {
+		handle = NULL;
+		ret = EFI_CALL(efi_install_multiple_protocol_interfaces(
+				&handle,
+				&efi_guid_firmware_management_protocol,
+				&efi_fmp_raw, NULL));
+	}
+
+	return ret;
+}
+
 #ifdef CONFIG_EFI_CAPSULE_ON_DISK
 /**
  * get_dp_device - retrieve a device  path from boot variable
@@ -1007,36 +1037,6 @@ static void efi_capsule_scan_done(void)
 	bootdev_root = NULL;
 }
 
-/**
- * efi_load_capsule_drivers - initialize capsule drivers
- *
- * Generic FMP drivers backed by DFU
- *
- * Return:	status code
- */
-efi_status_t __weak efi_load_capsule_drivers(void)
-{
-	__maybe_unused efi_handle_t handle;
-	efi_status_t ret = EFI_SUCCESS;
-
-	if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)) {
-		handle = NULL;
-		ret = EFI_CALL(efi_install_multiple_protocol_interfaces(
-				&handle, &efi_guid_firmware_management_protocol,
-				&efi_fmp_fit, NULL));
-	}
-
-	if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)) {
-		handle = NULL;
-		ret = EFI_CALL(efi_install_multiple_protocol_interfaces(
-				&handle,
-				&efi_guid_firmware_management_protocol,
-				&efi_fmp_raw, NULL));
-	}
-
-	return ret;
-}
-
 /**
  * check_run_capsules() - check whether capsule update should run
  *
#3 lore raw

PATCH v3 3/3 efi_loader: Use sysreset instead of reset command

In reply to Masami Hiramatsu

Use sysreset_walk_halt() directly from reset-after-capsule-on-disk feature to reboot (cold reset) machine instead of using reset command interface, since this is not a command.
Note that this will make CONFIG_EFI_CAPSULE_ON_DISK depending on the CONFIG_SYSRESET.

---
Changes in v2:
- Add CONFIG_SYSRESET dependency.
- Fix to add #include <sysreset.h>

---
 lib/efi_loader/Kconfig       |    1 +
 lib/efi_loader/efi_capsule.c |    5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
lib/efi_loader/Kconfig +1 -0
index e5e35fe51f..33138237cc 100644
@@ -130,6 +130,7 @@ config EFI_RUNTIME_UPDATE_CAPSULE
 
 config EFI_CAPSULE_ON_DISK
 	bool "Enable capsule-on-disk support"
+	depends on SYSRESET
 	select EFI_HAVE_CAPSULE_SUPPORT
 	help
 	  Select this option if you want to use capsule-on-disk feature,
lib/efi_loader/efi_capsule.c +3 -2
index 9fd6f78ad9..c6585cb113 100644
@@ -18,6 +18,7 @@
 #include <malloc.h>
 #include <mapmem.h>
 #include <sort.h>
+#include <sysreset.h>
 #include <asm/global_data.h>
 
 #include <crypto/pkcs7.h>
@@ -1150,9 +1151,9 @@ efi_status_t efi_launch_capsules(void)
 	 * UEFI spec requires to reset system after complete processing capsule
 	 * update on the storage.
 	 */
-	log_info("Reboot after firmware update");
+	log_info("Reboot after firmware update.\n");
 	/* Cold reset is required for loading the new firmware. */
-	do_reset(NULL, 0, 0, NULL);
+	sysreset_walk_halt(SYSRESET_COLD);
 	hang();
 	/* not reach here */