From: Jon Humphreys <j-humphreys@ti.com>
To: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Raymond Mao <raymond.mao@linaro.org>,
Caleb Connolly <caleb.connolly@linaro.org>,
Adriano Cordova <adrianox@gmail.com>,
"Michal Simek" <michal.simek@amd.com>,
Udit Kumar <u-kumar1@ti.com>, Simon Glass <sjg@chromium.org>,
Devarsh Thakkar <devarsht@ti.com>, Hari Nagalla <hnagalla@ti.com>,
Manorit Chawdhry <m-chawdhry@ti.com>,
Santhosh Kumar K <s-k6@ti.com>,
Neha Malcom Francis <n-francis@ti.com>,
Daniel Schultz <d.schultz@phytec.de>,
Neil Armstrong <neil.armstrong@linaro.org>,
"Aashvij Shenai" <a-shenai@ti.com>,
Roger Quadros <rogerq@kernel.org>,
"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
Bryan Brattlof <bb@ti.com>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
Wadim Egorov <w.egorov@phytec.de>, Tom Rini <trini@konsulko.com>,
Robert Nelson <robertcnelson@gmail.com>,
"Nishanth Menon" <nm@ti.com>,
Sughosh Ganu <sughosh.ganu@linaro.org>,
"Mattijs Korpershoek" <mkorpershoek@baylibre.com>,
Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
Lukasz Majewski <lukma@denx.de>, <s-vadapalli@ti.com>,
<u-boot@lists.denx.de>
Subject: Re: [PATCH v3 2/3] efi_firmware: set EFI capsule dfu_alt_info env explicitly
Date: Sun, 23 Feb 2025 20:38:14 -0600 [thread overview]
Message-ID: <86tt8knk2x.fsf@udb0321960.dhcp.ti.com> (raw)
In-Reply-To: <Z7Q8t2lCXjikVSm0@hades>
Ilias Apalodimas <ilias.apalodimas@linaro.org> writes:
> Hi Jonathan,
>
> The patch looks correct but there's a few more things to address.
>
> On Thu, Feb 13, 2025 at 01:53:50PM -0600, Jonathan Humphreys wrote:
>> The current implementation of EFI capsule update uses set_dfu_alt_info() to
>> set the dfu_alt_info environment variable with the settings it requires.
>> However, set_dfu_alt_info() is doing this for all DFU operations, even
>> those unrelated to capsule update.
>>
>> Thus other uses of DFU, such as DFU boot which sets its own value for the
>> dfu_alt_info environment variable, will have that setting overwritten with
>> the capsule update setting. Similarly, any user defined value for the
>> dfu_alt_info environment variable would get overwritten when any DFU
>> operation was performed, including simply performing a "dfu 0 list"
>> command.
>>
>> The solution is stop using the set_dfu_alt_info() mechanism to set the
>> dfu_alt_info environment variable and instead explicitly set it to the
>> capsule update's setting just before performing the capsule update's DFU
>> operation, and then restore the environment variable back to its original
>> value.
>>
>> This patch implements the explicit setting and restoring of the
>> dfu_alt_info environment variable as part of the EFI capsule update
>> operation.
>>
>> The fix is fully implemented in a subsequent patch that removes the capsule
>> update dfu_alt_info support in set_dfu_alt_info().
>>
>> Signed-off-by: Jonathan Humphreys <j-humphreys@ti.com>
>> ---
>> lib/efi_loader/efi_firmware.c | 39 ++++++++++++++++++++++++++++++++---
>> 1 file changed, 36 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
>> index 5a754c9cd03..1a1cf3b55e1 100644
>> --- a/lib/efi_loader/efi_firmware.c
>> +++ b/lib/efi_loader/efi_firmware.c
>> @@ -649,8 +649,10 @@ efi_status_t EFIAPI efi_firmware_fit_set_image(
>> efi_status_t (*progress)(efi_uintn_t completion),
>> u16 **abort_reason)
>> {
>> + int ret;
>> efi_status_t status;
>> struct fmp_state state = { 0 };
>> + char *orig_dfu_env;
>>
>> EFI_ENTRY("%p %d %p %zu %p %p %p\n", this, image_index, image,
>> image_size, vendor_code, progress, abort_reason);
>> @@ -663,7 +665,22 @@ efi_status_t EFIAPI efi_firmware_fit_set_image(
>> if (status != EFI_SUCCESS)
>> return EFI_EXIT(status);
>>
>> - if (fit_update(image))
>> + orig_dfu_env = strdup(env_get("dfu_alt_info"));
>
> strdup might fail, we need to check that the orig_dfu_env is !NULL
>
>> + if (env_set("dfu_alt_info", update_info.dfu_string)) {
>> + log_err("unable to set env variable \"dfu_alt_info\"!\n");
>> + free(orig_dfu_env);
>> + return EFI_EXIT(EFI_DEVICE_ERROR);
>> + }
>> +
>> + ret = fit_update(image);
>
>> +
>> + if (env_set("dfu_alt_info", orig_dfu_env)) {
>> + log_err("unable to set env variable \"dfu_alt_info\"!\n");
>> + ret = 1;
>
> This will work but for consistency just use an EFI defined error e.g
> ret = EFI_DEVICE_ERROR;
>
>> + }
>> + free(orig_dfu_env);
>> +
>> + if (ret)
>
> I am not 100% sure this exiting here is useful. If fit_update has succeeded
> we have updated our firmware. So I think we should just add a warning here,
> that resetting the dfu to its original value failed, and any further dfu
> ops will fail.
>
Hi Ilias, thanks for the review.
The exit here is for either fit_update() failing OR we cannot restore the
original value for the dfu_alt_info variable, so it is needed, at least in
the fit_update() failure case.
I was trying to keep the control flow simpler by handling the 2 failure
events together. Are you wanting to separate the 2 failure conditions, and
return EFI_DEVICE_ERROR if fit_update() fails, and emit a warning and
return EFI_SUCCESS if restoring the env variable fails?
Jon
>> return EFI_EXIT(EFI_DEVICE_ERROR);
>>
>> efi_firmware_set_fmp_state_var(&state, image_index);
>> @@ -717,6 +734,7 @@ efi_status_t EFIAPI efi_firmware_raw_set_image(
>> u8 dfu_alt_num;
>> efi_status_t status;
>> struct fmp_state state = { 0 };
>> + char *orig_dfu_env;
>>
>> EFI_ENTRY("%p %d %p %zu %p %p %p\n", this, image_index, image,
>> image_size, vendor_code, progress, abort_reason);
>> @@ -747,8 +765,23 @@ efi_status_t EFIAPI efi_firmware_raw_set_image(
>> }
>> }
>>
>> - if (dfu_write_by_alt(dfu_alt_num, (void *)image, image_size,
>> - NULL, NULL))
>> + orig_dfu_env = strdup(env_get("dfu_alt_info"));
>> + if (env_set("dfu_alt_info", update_info.dfu_string)) {
>> + log_err("unable to set env variable \"dfu_alt_info\"!\n");
>> + free(orig_dfu_env);
>> + return EFI_EXIT(EFI_DEVICE_ERROR);
>> + }
>> +
>> + ret = dfu_write_by_alt(dfu_alt_num, (void *)image, image_size,
>> + NULL, NULL);
>> +
>> + if (env_set("dfu_alt_info", orig_dfu_env)) {
>> + log_err("unable to set env variable \"dfu_alt_info\"!\n");
>> + ret = 1;
>> + }
>> + free(orig_dfu_env);
>> +
>> + if (ret)
>> return EFI_EXIT(EFI_DEVICE_ERROR);
>>
>> efi_firmware_set_fmp_state_var(&state, image_index);
>> --
>> 2.34.1
>>
>
> Thanks
> /Ilias
next prev parent reply other threads:[~2025-02-24 2:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 19:53 [PATCH v3 0/3] EFI Capsule update explicitly sets dfu_alt_info Jonathan Humphreys
2025-02-13 19:53 ` [PATCH v3 1/3] xilinx: dfu: Fill directly update_info.dfu_string Jonathan Humphreys
2025-02-14 16:52 ` Mattijs Korpershoek
2025-02-18 7:43 ` Ilias Apalodimas
2025-02-13 19:53 ` [PATCH v3 2/3] efi_firmware: set EFI capsule dfu_alt_info env explicitly Jonathan Humphreys
2025-02-14 16:54 ` Mattijs Korpershoek
2025-02-18 7:54 ` Ilias Apalodimas
2025-02-24 2:38 ` Jon Humphreys [this message]
2025-02-26 8:54 ` Ilias Apalodimas
2025-02-13 19:53 ` [PATCH v3 3/3] board: remove capsule update support in set_dfu_alt_info() Jonathan Humphreys
2025-02-18 8:10 ` Ilias Apalodimas
2025-02-17 7:04 ` [PATCH v3 0/3] EFI Capsule update explicitly sets dfu_alt_info Michal Simek
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=86tt8knk2x.fsf@udb0321960.dhcp.ti.com \
--to=j-humphreys@ti.com \
--cc=a-shenai@ti.com \
--cc=adrianox@gmail.com \
--cc=bb@ti.com \
--cc=caleb.connolly@linaro.org \
--cc=d.schultz@phytec.de \
--cc=devarsht@ti.com \
--cc=hnagalla@ti.com \
--cc=ilias.apalodimas@linaro.org \
--cc=lukma@denx.de \
--cc=m-chawdhry@ti.com \
--cc=michal.simek@amd.com \
--cc=mkorpershoek@baylibre.com \
--cc=n-francis@ti.com \
--cc=neil.armstrong@linaro.org \
--cc=nm@ti.com \
--cc=rasmus.villemoes@prevas.dk \
--cc=raymond.mao@linaro.org \
--cc=robertcnelson@gmail.com \
--cc=rogerq@kernel.org \
--cc=s-k6@ti.com \
--cc=s-vadapalli@ti.com \
--cc=sjg@chromium.org \
--cc=sughosh.ganu@linaro.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=u-kumar1@ti.com \
--cc=vigneshr@ti.com \
--cc=w.egorov@phytec.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox