All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilias Apalodimas" <ilias.apalodimas@linaro.org>
To: "Balaji Selvanathan" <balaji.selvanathan@oss.qualcomm.com>,
	<u-boot@lists.u-boot-project.org>
Cc: "Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Tom Rini" <trini@konsulko.com>,
	"Michal Simek" <michal.simek@amd.com>,
	"Vincent Stehlé" <vincent.stehle@arm.com>,
	"Simon Glass" <sjg@chromium.org>,
	"Mario Six" <mario.six@gdsys.cc>
Subject: Re: [PATCH 1/2] efi_loader: firmware: decouple dfu_alt_num from image_index
Date: Fri, 28 Aug 2026 12:28:49 +0300	[thread overview]
Message-ID: <DL0GYMY2PH5B.3TCLPY0T7YFMX@linaro.org> (raw)
In-Reply-To: <20260813-efi-firmware-dfu-alt-num-v1-1-43f034253b21@oss.qualcomm.com>

Hi Balaji,


On Thu Aug 13, 2026 at 8:53 AM EEST, Balaji Selvanathan wrote:
> RAW capsule updates assume dfu_alt_num is always image_index - 1, i.e.
> that fw_images[] is a positionally-ordered mirror of the DFU alt
> settings. That holds for every board that builds its fw_images[] table
> by hand, but a platform whose image list is discovered at runtime
> (varying per board, with gaps for missing components) can't guarantee
> image_index and dfu_alt_num stay in lockstep.
>
> Move the (image_index - 1) calculation into a __weak function that
> platforms can override, following the pattern already used for
> efi_firmware_get_image_type_id(). The default keeps the
> existing behaviour, so no other board needs any change.

*efi_firmware_get_image_type_id() was always static, which funtion did you mean?
fwu_plat_get_alt_num()?

>
> Signed-off-by: Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
> ---
>  include/efi_loader.h          | 17 +++++++++++++++++
>  lib/efi_loader/efi_firmware.c | 21 +++++++++++++++++++--
>  2 files changed, 36 insertions(+), 2 deletions(-)
>
> diff --git a/include/efi_loader.h b/include/efi_loader.h
> index 3a4d502631c..6626674f738 100644
> --- a/include/efi_loader.h
> +++ b/include/efi_loader.h
> @@ -1187,11 +1187,15 @@ efi_status_t efi_capsule_authenticate(const void *capsule,
>   * @fw_name:		Name of the firmware image
>   * @image_index:	Image Index, same as value passed to SetImage FMP
>   *                      function
> + * @dfu_alt_num:	DFU alt setting number for this image. Only consulted
> + *                      by a platform's efi_firmware_get_dfu_alt_num()
> + *                      override
>   */
>  struct efi_fw_image {
>  	efi_guid_t image_type_id;
>  	u16 *fw_name;
>  	u8 image_index;
> +	u8 dfu_alt_num;

Why do we need the extra struct member? The code doesn't update it to store any updates values.
Can't we just use the runtime result every time?

>  };
>
>  /**
> @@ -1240,6 +1244,19 @@ efi_status_t efi_ecpt_register(void);
>  efi_status_t efi_esrt_populate(void);
>  efi_status_t efi_load_capsule_drivers(void);
>
> +/**
> + * efi_firmware_get_dfu_alt_num() - get the DFU alt setting number for an image
> + * @image_index:	image index
> + *
> + * Return the DFU alt setting number to use when writing the image
> + * identified by @image_index. Weak default derives it positionally as
> + * (image_index - 1); a platform whose fw_images[] is not laid out 1:1 with
> + * DFU alt numbers should override this function.
> + *
> + * Return:		DFU alt setting number
> + */
> +u8 efi_firmware_get_dfu_alt_num(u8 image_index);
> +
>  efi_status_t platform_get_eventlog(struct udevice *dev, u64 *addr, u32 *sz);
>
>  efi_status_t efi_locate_handle_buffer_int(enum efi_locate_search_type search_type,
> diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
> index b41969c70fd..c7339412055 100644
> --- a/lib/efi_loader/efi_firmware.c
> +++ b/lib/efi_loader/efi_firmware.c
> @@ -80,6 +80,22 @@ efi_guid_t *efi_firmware_get_image_type_id(u8 image_index)
>  	return NULL;
>  }
>
> +/**
> + * efi_firmware_get_dfu_alt_num - get the DFU alt setting number for an image
> + * @image_index:	image index
> + *
> + * Return the DFU alt setting number to use when writing the image
> + * identified by @image_index. The generic default derives it positionally
> + * from @image_index; a platform whose fw_images[] is not laid out 1:1 with
> + * DFU alt numbers should override this function.
> + *
> + * Return:		DFU alt setting number
> + */
> +u8 __weak efi_firmware_get_dfu_alt_num(u8 image_index)
> +{
> +	return image_index - 1;
> +}

This is one of the things you need to support swapping image indexes on the fly, but there's way
more. One of the compromises we had to make to plug in capsuile updates via DFU is that the image
index *must* match the dfu command array member. IOW if you define the array with this

{guid_a, "u-boot", 1}, {guid_b, "u-boot-env", 2}
the dfu_string *must* list u-boot first and u-boot-env second.

IIRC we already check for a mismatch of GUID/Index in FWU code, but in the normal code we only have
a check in the efi_fmp_find(). The way you are switching happens after the check so you might end up
updating the partition with the wrond kind of firmware.

[...]

Cheers
/Ilias

  reply	other threads:[~2026-08-28  9:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13  5:53 [PATCH 0/2] efi_loader: firmware: decouple dfu_alt_num from image_index Balaji Selvanathan via U-Boot
2026-08-13  5:53 ` [PATCH 1/2] " Balaji Selvanathan via U-Boot
2026-08-28  9:28   ` Ilias Apalodimas [this message]
2026-08-13  5:53 ` [PATCH 2/2] test: efi_capsule: add sandbox coverage for dfu_alt_num override Balaji Selvanathan via U-Boot
2026-08-26  9:17 ` [PATCH 0/2] efi_loader: firmware: decouple dfu_alt_num from image_index Balaji Selvanathan
2026-08-26 19:18 ` Casey Connolly

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DL0GYMY2PH5B.3TCLPY0T7YFMX@linaro.org \
    --to=ilias.apalodimas@linaro.org \
    --cc=balaji.selvanathan@oss.qualcomm.com \
    --cc=mario.six@gdsys.cc \
    --cc=michal.simek@amd.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    --cc=vincent.stehle@arm.com \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.