[PATCH] efi_loader: efi_var_sf: Do not fail on blank SPI Flash
Heinrich Schuchardt
xypron.glpk at gmx.de
Wed Mar 18 20:59:33 CET 2026
Am 18. März 2026 17:47:54 MEZ schrieb Michal Simek <michal.simek at amd.com>:
>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>
>---
>
> lib/efi_loader/efi_var_sf.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
>diff --git a/lib/efi_loader/efi_var_sf.c b/lib/efi_loader/efi_var_sf.c
>index 6eae8d464645..a1dc81e17434 100644
>--- a/lib/efi_loader/efi_var_sf.c
>+++ b/lib/efi_loader/efi_var_sf.c
>@@ -98,12 +98,15 @@ efi_status_t efi_var_from_storage(void)
> goto error;
> }
>
>- if (efi_var_restore(buf, false) != EFI_SUCCESS) {
>- log_err("No valid EFI variables in SPI Flash\n");
>- ret = EFI_DEVICE_ERROR;
>+ if (buf->magic != EFI_VAR_FILE_MAGIC) {
>+ log_info("No EFI variables in SPI Flash\n")
If the SPI flash is erased, I would expect magic == 0. A incorrect non-zero magic is similar to an incorrect crc32.
If magic == 0 is an expected state, why write a non-debug message?
>+ ret = EFI_SUCCESS;
> goto error;
> }
>
>+ if (efi_var_restore(buf, false) != EFI_SUCCESS)
Yes, we must always return EFI_SUCESS.
Best regards
Heinrich
>+ log_err("Invalid EFI variables in SPI Flash\n");
>+
> ret = EFI_SUCCESS;
> error:
> free(buf);
More information about the U-Boot
mailing list