[PATCH] efi_loader: efi_var_sf: Do not fail on blank SPI Flash
Michal Simek
michal.simek at amd.com
Wed Mar 18 17:47:54 CET 2026
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");
+ ret = EFI_SUCCESS;
goto error;
}
+ if (efi_var_restore(buf, false) != EFI_SUCCESS)
+ log_err("Invalid EFI variables in SPI Flash\n");
+
ret = EFI_SUCCESS;
error:
free(buf);
--
2.43.0
base-commit: 85854708c4d707d9db8ec84c11e1686a32198d91
branch: debian-sent3
More information about the U-Boot
mailing list