Hi Graeme,
The issue lies in the way the Flash1 is laid out. At offset 0x0 - UEFI Compact binary At offset 0x40000 - NorFlash Variable storage with EFI_VOLUME_HEADER
So the Arm NorFlash driver looks for EFI_VOLUME_HEADER at 0x0 offset but we have the UEFI binary present hence it couldn't find it and proceeded to reinitialize the flash region at 0x40000, hence all the EFI variables were lost.
I have created the following patch in edk2: (This is a hack to get it to work, would need to find a way a more generic way to fix this issue)
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c index e248fdf6db..d8cee8ca24 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c @@ -134,7 +134,8 @@ ValidateFvHeader ( UINTN VariableStoreLength; UINTN FvLength;
- FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Instance->RegionBaseAddress; + FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER*)(Instance->RegionBaseAddress + + (Instance->StartLba * Instance->Media.BlockSize));
FvLength = PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32(PcdFlashNvStorageFtwSpareSize);
This patch makes the header checking code to look at the right offset.
Also the following patch in edk2-platforms (This patch is just to make it match the ArmVirt Flash layout)
diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.fdf b/Platform/Qemu/SbsaQemu/SbsaQemu.fdf index 7f1a60e3ee..9ccfe7f1fa 100644 --- a/Platform/Qemu/SbsaQemu/SbsaQemu.fdf +++ b/Platform/Qemu/SbsaQemu/SbsaQemu.fdf @@ -58,10 +58,10 @@ FILE = Platform/Qemu/Sbsa/fip.bin
[FD.SBSA_FLASH1] BaseAddress = 0x10000000|gArmTokenSpaceGuid.PcdFdBaseAddress -Size = 0x002C0000|gArmTokenSpaceGuid.PcdFdSize +Size = 0x00300000|gArmTokenSpaceGuid.PcdFdSize ErasePolarity = 1 -BlockSize = 0x00001000 -NumBlocks = 0x2C0 +BlockSize = 0x00040000 +NumBlocks = 0xB
## Place for EFI (BL33) # This offset (if any as it is 0x0 currently) + BaseAddress (0x10000000) must be set in PRELOADED_BL33_BASE at ATF @@ -90,8 +90,8 @@ DATA = { 0x5f, 0x46, 0x56, 0x48, 0xff, 0xfe, 0x04, 0x00, # HeaderLength # CheckSum # ExtHeaderOffset #Reserved #Revision 0x48, 0x00, 0x28, 0x09, 0x00, 0x00, 0x00, 0x02, - # Blockmap[0]: 0x3 Blocks * 0x40000 Bytes / Block - 0x3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, + # Blockmap[0]: 0x4 Blocks * 0x40000 Bytes / Block + 0x4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, # Blockmap[1]: End 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ## This is the VARIABLE_STORE_HEADER
With the above 2 patches, I'm able to store the EFI variables persistently.
Can you please let me know what you think about these patches ?
With Regards, Tanmay
On Thu, 11 Jun 2020 at 16:55, Graeme Gregory via Asa-dev < asa-dev@op-lists.linaro.org> wrote:
Hi Tanmay,
I was doing some checking and we are causing these errors in log.
ValidateFvHeader: No Firmware Volume header present NorFlashFvbInitialize: The FVB Header is not valid. NorFlashFvbInitialize: Installing a correct one for this volume. Which is resetting all the variables
Graeme
Asa-dev mailing list Asa-dev@op-lists.linaro.org https://op-lists.linaro.org/mailman/listinfo/asa-dev