diff mbox series

[1/2] efi_loader: Avoid using efi_update_capsule() from update capsule on disk

Message ID 164362072975.312714.5769638615920735810.stgit@localhost
State New
Headers show
Series EFI: Reset system after capsule-on-disk | expand

Commit Message

Masami Hiramatsu Jan. 31, 2022, 9:18 a.m. UTC
The efi_update_capsule() may have to handle the capsule flags as an UEFI
runtime and boottime service, but the capsule-on-disk process doesn't.
Thus, the capsule-on-disk should use the efi_capsule_update_firmware()
directly instead of efi_update_capsule(). To keep the consistency
ESRT also will be updated after all capsule updates are completed.

Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
---
 lib/efi_loader/efi_capsule.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Heinrich Schuchardt Jan. 31, 2022, 7:26 p.m. UTC | #1
On 1/31/22 10:18, Masami Hiramatsu wrote:
> The efi_update_capsule() may have to handle the capsule flags as an UEFI
> runtime and boottime service, but the capsule-on-disk process doesn't.
> Thus, the capsule-on-disk should use the efi_capsule_update_firmware()
> directly instead of efi_update_capsule(). To keep the consistency
> ESRT also will be updated after all capsule updates are completed.
>
> Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
> ---
>   lib/efi_loader/efi_capsule.c |    9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
> index 4463ae00fd..98dab1c6f5 100644
> --- a/lib/efi_loader/efi_capsule.c
> +++ b/lib/efi_loader/efi_capsule.c
> @@ -1118,7 +1118,7 @@ efi_status_t efi_launch_capsules(void)
>   			index = 0;
>   		ret = efi_capsule_read_file(files[i], &capsule);
>   		if (ret == EFI_SUCCESS) {
> -			ret = EFI_CALL(efi_update_capsule(&capsule, 1, 0));
> +			ret = efi_capsule_update_firmware(&capsule);

Thanks for the patch. This look better.

>   			if (ret != EFI_SUCCESS)
>   				log_err("Applying capsule %ls failed\n",
>   					files[i]);
> @@ -1142,6 +1142,13 @@ efi_status_t efi_launch_capsules(void)
>   		free(files[i]);
>   	free(files);
>
> +	if (IS_ENABLED(CONFIG_EFI_ESRT)) {
> +		/* Rebuild the ESRT to reflect any updated FW images. */
> +		ret = efi_esrt_populate();
> +		if (ret != EFI_SUCCESS)
> +			log_warning("ESRT update failed\n");
> +	}
> +

This is not needed as you want to reboot.

Best regards

Heinrich

>   	return ret;
>   }
>   #endif /* CONFIG_EFI_CAPSULE_ON_DISK */
>
Masami Hiramatsu Feb. 1, 2022, 2:21 a.m. UTC | #2
Hi Heinrich,

Thanks for review.

2022年2月1日(火) 4:26 Heinrich Schuchardt <xypron.glpk@gmx.de>:
>
> On 1/31/22 10:18, Masami Hiramatsu wrote:
> > The efi_update_capsule() may have to handle the capsule flags as an UEFI
> > runtime and boottime service, but the capsule-on-disk process doesn't.
> > Thus, the capsule-on-disk should use the efi_capsule_update_firmware()
> > directly instead of efi_update_capsule(). To keep the consistency
> > ESRT also will be updated after all capsule updates are completed.
> >
> > Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org>
> > ---
> >   lib/efi_loader/efi_capsule.c |    9 ++++++++-
> >   1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
> > index 4463ae00fd..98dab1c6f5 100644
> > --- a/lib/efi_loader/efi_capsule.c
> > +++ b/lib/efi_loader/efi_capsule.c
> > @@ -1118,7 +1118,7 @@ efi_status_t efi_launch_capsules(void)
> >                       index = 0;
> >               ret = efi_capsule_read_file(files[i], &capsule);
> >               if (ret == EFI_SUCCESS) {
> > -                     ret = EFI_CALL(efi_update_capsule(&capsule, 1, 0));
> > +                     ret = efi_capsule_update_firmware(&capsule);
>
> Thanks for the patch. This look better.
>
> >                       if (ret != EFI_SUCCESS)
> >                               log_err("Applying capsule %ls failed\n",
> >                                       files[i]);
> > @@ -1142,6 +1142,13 @@ efi_status_t efi_launch_capsules(void)
> >               free(files[i]);
> >       free(files);
> >
> > +     if (IS_ENABLED(CONFIG_EFI_ESRT)) {
> > +             /* Rebuild the ESRT to reflect any updated FW images. */
> > +             ret = efi_esrt_populate();
> > +             if (ret != EFI_SUCCESS)
> > +                     log_warning("ESRT update failed\n");
> > +     }
> > +
>
> This is not needed as you want to reboot.

Yes, OK. I'll drop this part.

Thank you,

>
>
> Best regards
>
> Heinrich
>
> >       return ret;
> >   }
> >   #endif /* CONFIG_EFI_CAPSULE_ON_DISK */
> >
>
diff mbox series

Patch

diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index 4463ae00fd..98dab1c6f5 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -1118,7 +1118,7 @@  efi_status_t efi_launch_capsules(void)
 			index = 0;
 		ret = efi_capsule_read_file(files[i], &capsule);
 		if (ret == EFI_SUCCESS) {
-			ret = EFI_CALL(efi_update_capsule(&capsule, 1, 0));
+			ret = efi_capsule_update_firmware(&capsule);
 			if (ret != EFI_SUCCESS)
 				log_err("Applying capsule %ls failed\n",
 					files[i]);
@@ -1142,6 +1142,13 @@  efi_status_t efi_launch_capsules(void)
 		free(files[i]);
 	free(files);
 
+	if (IS_ENABLED(CONFIG_EFI_ESRT)) {
+		/* Rebuild the ESRT to reflect any updated FW images. */
+		ret = efi_esrt_populate();
+		if (ret != EFI_SUCCESS)
+			log_warning("ESRT update failed\n");
+	}
+
 	return ret;
 }
 #endif /* CONFIG_EFI_CAPSULE_ON_DISK */