diff mbox series

[07/14] efi_loader: Add config option to indicate fmp header presence

Message ID 20201126184110.30521-8-sughosh.ganu@linaro.org
State New
Headers show
Series qemu: arm64: Add support for uefi capsule update on qemu arm64 platform | expand

Commit Message

Sughosh Ganu Nov. 26, 2020, 6:41 p.m. UTC
When building the capsule using scripts in edk2, an fmp header is
added on top of the binary payload. Add a config option to indicate
the presence of the header. When enabled, the pointer to the image
needs to be adjusted as per the size of the header to point to the
actual binary payload.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

---
 lib/efi_loader/Kconfig        |  7 +++++++
 lib/efi_loader/efi_firmware.c | 12 ++++++++++++
 2 files changed, 19 insertions(+)

-- 
2.17.1

Comments

Heinrich Schuchardt Dec. 5, 2020, 10:34 a.m. UTC | #1
On 11/26/20 7:41 PM, Sughosh Ganu wrote:
> When building the capsule using scripts in edk2, an fmp header is

> added on top of the binary payload. Add a config option to indicate

> the presence of the header. When enabled, the pointer to the image

> needs to be adjusted as per the size of the header to point to the

> actual binary payload.


Why do we need a config option? Can't we detect the header?

Can we harmonize the capsule format in EDK II and U-Boot?

Best regards

Heinrich

>

> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

> ---

>   lib/efi_loader/Kconfig        |  7 +++++++

>   lib/efi_loader/efi_firmware.c | 12 ++++++++++++

>   2 files changed, 19 insertions(+)

>

> diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig

> index 0d1b1b5356..55e4787e32 100644

> --- a/lib/efi_loader/Kconfig

> +++ b/lib/efi_loader/Kconfig

> @@ -138,6 +138,13 @@ config EFI_CAPSULE_FIRMWARE_MANAGEMENT

>   	  Select this option if you want to enable capsule-based

>   	  firmware update using Firmware Management Protocol.

>

> +config EFI_CAPSULE_FMP_HEADER

> +	bool "Capsule uses FMP header"

> +	depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT

> +	help

> +	  Select this option if the capsule is built using the

> +	  scripts in edk2.

> +

>   config EFI_CAPSULE_FIRMWARE_FIT

>   	bool "FMP driver for FIT image"

>   	depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT

> diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c

> index 7e56077383..6c97604d8b 100644

> --- a/lib/efi_loader/efi_firmware.c

> +++ b/lib/efi_loader/efi_firmware.c

> @@ -385,10 +385,22 @@ efi_status_t EFIAPI efi_firmware_raw_set_image(

>   	if (!image)

>   		return EFI_EXIT(EFI_INVALID_PARAMETER);

>

> +	if (CONFIG_IS_ENABLED(EFI_CAPSULE_FMP_HEADER)) {

> +		/*

> +		 * When building the capsule with the scripts in

> +		 * edk2, a FMP header is inserted above the capsule

> +		 * payload. Compensate for this header to get the

> +		 * actual payload that is to be updated.

> +		 */

> +		image += 0x10;

> +		image_size -= 0x10;

> +	}

> +

>   	if (dfu_write_by_alt(image_index - 1, (void *)image, image_size,

>   			     NULL, NULL))

>   		return EFI_EXIT(EFI_DEVICE_ERROR);

>

> +	printf("%s: Capsule update complete!\n", __func__);

>   	return EFI_EXIT(EFI_SUCCESS);

>   }

>

>
Sughosh Ganu Dec. 7, 2020, 6:02 a.m. UTC | #2
On Sat, 5 Dec 2020 at 16:04, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:

> On 11/26/20 7:41 PM, Sughosh Ganu wrote:

> > When building the capsule using scripts in edk2, an fmp header is

> > added on top of the binary payload. Add a config option to indicate

> > the presence of the header. When enabled, the pointer to the image

> > needs to be adjusted as per the size of the header to point to the

> > actual binary payload.

>

> Why do we need a config option? Can't we detect the header?

>


We do have a header signature that can be read, so yes this can be detected
at runtime.


>

> Can we harmonize the capsule format in EDK II and U-Boot?

>


I am not sure about this though. The FMP payload header that gets added by
the edk2 scripts is not defined by the uefi specification but is a edk2
specific structure. I am not sure if defining it in u-boot would make sense.

-sughosh


> Best regards

>

> Heinrich

>

> >

> > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>

> > ---

> >   lib/efi_loader/Kconfig        |  7 +++++++

> >   lib/efi_loader/efi_firmware.c | 12 ++++++++++++

> >   2 files changed, 19 insertions(+)

> >

> > diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig

> > index 0d1b1b5356..55e4787e32 100644

> > --- a/lib/efi_loader/Kconfig

> > +++ b/lib/efi_loader/Kconfig

> > @@ -138,6 +138,13 @@ config EFI_CAPSULE_FIRMWARE_MANAGEMENT

> >         Select this option if you want to enable capsule-based

> >         firmware update using Firmware Management Protocol.

> >

> > +config EFI_CAPSULE_FMP_HEADER

> > +     bool "Capsule uses FMP header"

> > +     depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT

> > +     help

> > +       Select this option if the capsule is built using the

> > +       scripts in edk2.

> > +

> >   config EFI_CAPSULE_FIRMWARE_FIT

> >       bool "FMP driver for FIT image"

> >       depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT

> > diff --git a/lib/efi_loader/efi_firmware.c

> b/lib/efi_loader/efi_firmware.c

> > index 7e56077383..6c97604d8b 100644

> > --- a/lib/efi_loader/efi_firmware.c

> > +++ b/lib/efi_loader/efi_firmware.c

> > @@ -385,10 +385,22 @@ efi_status_t EFIAPI efi_firmware_raw_set_image(

> >       if (!image)

> >               return EFI_EXIT(EFI_INVALID_PARAMETER);

> >

> > +     if (CONFIG_IS_ENABLED(EFI_CAPSULE_FMP_HEADER)) {

> > +             /*

> > +              * When building the capsule with the scripts in

> > +              * edk2, a FMP header is inserted above the capsule

> > +              * payload. Compensate for this header to get the

> > +              * actual payload that is to be updated.

> > +              */

> > +             image += 0x10;

> > +             image_size -= 0x10;

> > +     }

> > +

> >       if (dfu_write_by_alt(image_index - 1, (void *)image, image_size,

> >                            NULL, NULL))

> >               return EFI_EXIT(EFI_DEVICE_ERROR);

> >

> > +     printf("%s: Capsule update complete!\n", __func__);

> >       return EFI_EXIT(EFI_SUCCESS);

> >   }

> >

> >

>

>
diff mbox series

Patch

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 0d1b1b5356..55e4787e32 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -138,6 +138,13 @@  config EFI_CAPSULE_FIRMWARE_MANAGEMENT
 	  Select this option if you want to enable capsule-based
 	  firmware update using Firmware Management Protocol.
 
+config EFI_CAPSULE_FMP_HEADER
+	bool "Capsule uses FMP header"
+	depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
+	help
+	  Select this option if the capsule is built using the
+	  scripts in edk2.
+
 config EFI_CAPSULE_FIRMWARE_FIT
 	bool "FMP driver for FIT image"
 	depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT
diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index 7e56077383..6c97604d8b 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -385,10 +385,22 @@  efi_status_t EFIAPI efi_firmware_raw_set_image(
 	if (!image)
 		return EFI_EXIT(EFI_INVALID_PARAMETER);
 
+	if (CONFIG_IS_ENABLED(EFI_CAPSULE_FMP_HEADER)) {
+		/*
+		 * When building the capsule with the scripts in
+		 * edk2, a FMP header is inserted above the capsule
+		 * payload. Compensate for this header to get the
+		 * actual payload that is to be updated.
+		 */
+		image += 0x10;
+		image_size -= 0x10;
+	}
+
 	if (dfu_write_by_alt(image_index - 1, (void *)image, image_size,
 			     NULL, NULL))
 		return EFI_EXIT(EFI_DEVICE_ERROR);
 
+	printf("%s: Capsule update complete!\n", __func__);
 	return EFI_EXIT(EFI_SUCCESS);
 }