[PATCH v2] efi_loader: efi_var_sf: Do not fail on blank SPI Flash
Ilias Apalodimas
ilias.apalodimas at linaro.org
Mon Mar 23 16:29:44 CET 2026
On Thu, 19 Mar 2026 at 09:15, Michal Simek <michal.simek at amd.com> wrote:
>
> When SPI Flash is blank (first boot or erased), efi_var_from_storage()
> returns EFI_DEVICE_ERROR because efi_var_restore() fails on invalid
> magic/CRC. This prevents the EFI subsystem from initializing.
>
> Check the magic value before attempting to restore variables. If
> the magic does not match EFI_VAR_FILE_MAGIC, treat it as an empty
> store and return EFI_SUCCESS, matching the behavior of the file-based
> efi_var_file.c which deliberately returns EFI_SUCCESS on missing or
> corrupted variable files to avoid blocking the boot process.
>
> Similarly, if the magic matches but efi_var_restore() fails (e.g.
> corrupted CRC), log the error but still return EFI_SUCCESS.
>
> Suggested-by: John Toomey <john.toomey at amd.com>
> Signed-off-by: Michal Simek <michal.simek at amd.com>
> ---
Reviewed-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
>
> Changes in v2:
> - Remove magic checking which is the part of efi_var_restore() already
>
> lib/efi_loader/efi_var_sf.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/lib/efi_loader/efi_var_sf.c b/lib/efi_loader/efi_var_sf.c
> index 6eae8d464645..b84ec8e67dce 100644
> --- a/lib/efi_loader/efi_var_sf.c
> +++ b/lib/efi_loader/efi_var_sf.c
> @@ -98,11 +98,8 @@ efi_status_t efi_var_from_storage(void)
> goto error;
> }
>
> - if (efi_var_restore(buf, false) != EFI_SUCCESS) {
> + if (efi_var_restore(buf, false) != EFI_SUCCESS)
> log_err("No valid EFI variables in SPI Flash\n");
> - ret = EFI_DEVICE_ERROR;
> - goto error;
> - }
>
> ret = EFI_SUCCESS;
> error:
> --
> 2.43.0
>
> base-commit: 85854708c4d707d9db8ec84c11e1686a32198d91
> branch: debian-sent3
More information about the U-Boot
mailing list