[PATCH] efi_loader: efi_var_sf: Do not fail on blank SPI Flash

Michal Simek michal.simek at amd.com
Thu Mar 19 08:12:36 CET 2026



On 3/18/26 20:59, Heinrich Schuchardt wrote:
> 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?

Erased flash is 0xffffffff. Log below.

And yes I can remove that above check completely because it is the part of 
efi_var_restore() anyway.

> 
>> +		ret = EFI_SUCCESS;
>> 		goto error;
>> 	}
>>
>> +	if (efi_var_restore(buf, false) != EFI_SUCCESS)
> 
> Yes, we must always return EFI_SUCESS.

M


ZynqMP> mtd list
List of MTD devices:
* nor0
   - device: flash at 0
   - parent: spi at ff0f0000
   - driver: jedec_spi_nor
   - path: /axi/spi at ff0f0000/flash at 0
   - type: NOR flash
   - block size: 0x10000 bytes
   - min I/O: 0x1 bytes
   - 0x000000000000-0x000004000000 : "nor0"
	  - 0x000000000000-0x000000080000 : "Image Selector"
	  - 0x000000080000-0x000000100000 : "Image Selector Golden"
	  - 0x000000100000-0x000000120000 : "Persistent Register"
	  - 0x000000120000-0x000000140000 : "Persistent Register Backup"
	  - 0x000000140000-0x000000200000 : "Open_1"
	  - 0x000000200000-0x000000f00000 : "Image A (FSBL, PMU, ATF, U-Boot)"
	  - 0x000000f00000-0x000000f80000 : "ImgSel Image A Catch"
	  - 0x000000f80000-0x000001c80000 : "Image B (FSBL, PMU, ATF, U-Boot)"
	  - 0x000001c80000-0x000001d00000 : "ImgSel Image B Catch"
	  - 0x000001d00000-0x000001e00000 : "Open_2"
	  - 0x000001e00000-0x000002000000 : "Recovery Image"
	  - 0x000002000000-0x000002200000 : "Recovery Image Backup"
	  - 0x000002200000-0x000002220000 : "U-Boot storage variables"
	  - 0x000002220000-0x000002240000 : "U-Boot storage variables backup"
	  - 0x000002240000-0x000002280000 : "SHA256"
	  - 0x000002280000-0x0000022a0000 : "Secure OS Storage"
	  - 0x0000022a0000-0x000004000000 : "User"
ZynqMP> mtd erase User
Erasing 0x00000000 ... 0x01d5ffff (470 eraseblock(s))
ZynqMP> mtd read User 10000000 0 1000
Reading 4096 byte(s) at offset 0x00000000
ZynqMP> md 10000000
10000000: ffffffff ffffffff ffffffff ffffffff  ................
10000010: ffffffff ffffffff ffffffff ffffffff  ................
10000020: ffffffff ffffffff ffffffff ffffffff  ................
10000030: ffffffff ffffffff ffffffff ffffffff  ................
10000040: ffffffff ffffffff ffffffff ffffffff  ................
10000050: ffffffff ffffffff ffffffff ffffffff  ................
10000060: ffffffff ffffffff ffffffff ffffffff  ................

ZynqMP> pri -e
No EFI variables in SPI Flash
SecureBoot:
     8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID)
     BS|RT|RO, DataSize = 0x1
     00000000: 00                                               .
SetupMode:
     8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID)
     BS|RT|RO, DataSize = 0x1
     00000000: 01                                               .
AuditMode:
     8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID)
     BS|RT|RO, DataSize = 0x1
     00000000: 00                                               .
DeployedMode:
     8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID)
     BS|RT|RO, DataSize = 0x1
     00000000: 00                                               .
VendorKeys:
     8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID)
     BS|RT|RO, DataSize = 0x1
     00000000: 00                                               .
Boot0000:
     8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID)
     NV|BS|RT, DataSize = 0xb0
     00000000: 01 00 00 00 8e 00 75 00 73 00 62 00 20 00 30 00  ......u.s.b. .0.
     00000010: 00 00 01 04 1c 00 b9 73 1d e6 84 a3 cc 4a ae ab  .......s.....J..
     00000020: 82 e8 28 f3 62 8b 00 00 00 00 00 00 00 00 01 04  ..(.b...........
     00000030: 1c 00 b9 73 1d e6 84 a3 cc 4a ae ab 82 e8 28 f3  ...s.....J....(.
     00000040: 62 8b 72 00 00 00 00 00 00 00 01 04 1c 00 b9 73  b.r............s
     00000050: 1d e6 84 a3 cc 4a ae ab 82 e8 28 f3 62 8b 51 00  .....J....(.b.Q.
     00000060: 00 00 01 00 00 00 01 04 1c 00 b9 73 1d e6 84 a3  ...........s....
     00000070: cc 4a ae ab 82 e8 28 f3 62 8b 83 00 00 00 02 00  .J....(.b.......
     00000080: 00 00 03 05 06 00 00 00 03 05 06 00 01 00 03 05  ................
     00000090: 06 00 01 00 01 05 08 00 00 00 00 00 7f ff 04 00  ................
     000000a0: 4e ac 08 81 11 9f 59 4d 85 0e e2 1a 52 2c 59 b2  N.....YM....R,Y.
BootOrder:
     8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID)
     NV|BS|RT, DataSize = 0x2
     00000000: 00 00                                            ..
PlatformLangCodes:
     8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID)
     BS|RT|RO, DataSize = 0x6
     00000000: 65 6e 2d 55 53 00                                en-US.
PlatformLang:
     8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID)
     NV|BS|RT, DataSize = 0x6
     00000000: 65 6e 2d 55 53 00                                en-US.
OsIndicationsSupported:
     8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID)
     BS|RT|RO, DataSize = 0x8
     00000000: 1c 00 00 00 00 00 00 00                          ........
CapsuleMax:
     39b68c46-f7fb-441b-b6ec-16b0f69821f3 (39b68c46-f7fb-441b-b6ec-16b0f69821f3)
     BS|RT|RO, DataSize = 0x16
     00000000: 43 00 61 00 70 00 73 00 75 00 6c 00 65 00 30 00  C.a.p.s.u.l.e.0.
     00000010: 30 00 30 00 46 00                                0.0.F.
ZynqMP> mtd read User 10000000 0 1000
Reading 4096 byte(s) at offset 0x00000000
ZynqMP> md 10000000
10000000: 00000000 00000000 66456255 01615669  ........UbEfiVa.
10000010: 00000178 dc88842b 000000b0 00000007  x...+...........
10000020: 00000000 00000000 8be4df61 11d293ca  ........a.......
10000030: e0000daa 8c2b0398 006f0042 0074006f  ......+.B.o.o.t.
10000040: 00300030 00300030 00010000 008e0000  0.0.0.0.........
10000050: 00730075 00200062 00000030 001c0401  u.s.b. .0.......
10000060: e61d73b9 4acca384 e882abae 8b62f328  .s.....J....(.b.
10000070: 00000000 00000000 001c0401 e61d73b9  .............s..
10000080: 4acca384 e882abae 8b62f328 00000072  ...J....(.b.r...
10000090: 00000000 001c0401 e61d73b9 4acca384  .........s.....J
100000a0: e882abae 8b62f328 00000051 00000001  ....(.b.Q.......
100000b0: 001c0401 e61d73b9 4acca384 e882abae  .....s.....J....





More information about the U-Boot mailing list