From: Laszlo Ersek Date: Wed, 11 Apr 2018 20:18:24 +0000 (+0200) Subject: ArmPlatformPkg/NorFlashDxe: initialize varstore headers eagerly X-Git-Tag: edk2-stable201903~1920 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=0f87c53d0d0eb7e7c003e209705ec79264e0852b;hp=7ab26d51808bd4ffab2510091b062a91cf6a8c81 ArmPlatformPkg/NorFlashDxe: initialize varstore headers eagerly The lazy initialization of the varstore FVB makes no longer sense at this point: - "mNorFlashInstanceTemplate.Initialize" is NULL; - in NorFlashCreateInstance(), we only set Instance->Initialize to non-NULL -- namely NorFlashFvbInitialize() -- if the FVB stands for the variable store (see "ContainVariableStorage" / "SupportFvb"); - we call Instance->Initialize() from three places: - from NorFlashWriteSingleBlock(), which is too late for the variable read service ("variable write" depends on "variable read"); - from InitializeFvAndVariableStoreHeaders(), but that is only reachable from NorFlashFvbInitialize(), i.e. recursively from Instance->Initialize() itself; - and from FvbRead(), which is never called by the variable driver, only by the FTW driver. However, the variable driver may read (not write) the memory-mapped varstore flash chip before the FTW driver is dispatched. Therefore the lazy initialization is both superfluous and insufficient. Initialize the varstore headers eagerly, before we install the FVB protocol interface. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Steve Capper Cc: Supreeth Venkatesh Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Ard Biesheuvel Tested-by: Steve Capper Reviewed-by: Leif Lindholm --- diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c index 1098d9501c..46e815beb3 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c @@ -32,9 +32,6 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = { NOR_FLASH_SIGNATURE, // Signature NULL, // Handle ... NEED TO BE FILLED - FALSE, // Initialized - NULL, // Initialize - 0, // DeviceBaseAddress ... NEED TO BE FILLED 0, // RegionBaseAddress ... NEED TO BE FILLED 0, // Size ... NEED TO BE FILLED @@ -69,7 +66,6 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = { NorFlashDiskIoWriteDisk // WriteDisk }, - FALSE, // SupportFvb ... NEED TO BE FILLED { FvbGetAttributes, // GetAttributes FvbSetAttributes, // SetAttributes @@ -137,8 +133,7 @@ NorFlashCreateInstance ( } if (SupportFvb) { - Instance->SupportFvb = TRUE; - Instance->Initialize = NorFlashFvbInitialize; + NorFlashFvbInitialize (Instance); Status = gBS->InstallMultipleProtocolInterfaces ( &Instance->Handle, @@ -152,8 +147,6 @@ NorFlashCreateInstance ( return Status; } } else { - Instance->Initialized = TRUE; - Status = gBS->InstallMultipleProtocolInterfaces ( &Instance->Handle, &gEfiDevicePathProtocolGuid, &Instance->DevicePath, @@ -924,10 +917,6 @@ NorFlashWriteSingleBlock ( PrevBlockAddress = 0; - if (!Instance->Initialized && Instance->Initialize) { - Instance->Initialize(Instance); - } - DEBUG ((DEBUG_BLKIO, "NorFlashWriteSingleBlock(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes, Buffer)); // Detect WriteDisabled state diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h index c24680098f..5c07694fbf 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h @@ -122,8 +122,6 @@ typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE; -typedef EFI_STATUS (*NOR_FLASH_INITIALIZE) (NOR_FLASH_INSTANCE* Instance); - typedef struct { VENDOR_DEVICE_PATH Vendor; EFI_DEVICE_PATH_PROTOCOL End; @@ -133,9 +131,6 @@ struct _NOR_FLASH_INSTANCE { UINT32 Signature; EFI_HANDLE Handle; - BOOLEAN Initialized; - NOR_FLASH_INITIALIZE Initialize; - UINTN DeviceBaseAddress; UINTN RegionBaseAddress; UINTN Size; @@ -145,7 +140,6 @@ struct _NOR_FLASH_INSTANCE { EFI_BLOCK_IO_MEDIA Media; EFI_DISK_IO_PROTOCOL DiskIoProtocol; - BOOLEAN SupportFvb; EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol; VOID* ShadowBuffer; diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c index 3ea858f46f..c3e6489f39 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c @@ -59,10 +59,6 @@ InitializeFvAndVariableStoreHeaders ( EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumeHeader; VARIABLE_STORE_HEADER *VariableStoreHeader; - if (!Instance->Initialized && Instance->Initialize) { - Instance->Initialize (Instance); - } - HeadersLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(VARIABLE_STORE_HEADER); Headers = AllocateZeroPool(HeadersLength); @@ -431,10 +427,6 @@ FvbRead ( DEBUG ((DEBUG_BLKIO, "FvbRead(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer)); - if (!Instance->Initialized && Instance->Initialize) { - Instance->Initialize(Instance); - } - TempStatus = EFI_SUCCESS; // Cache the block size to avoid de-referencing pointers all the time @@ -749,7 +741,6 @@ NorFlashFvbInitialize ( EFI_MEMORY_UC | EFI_MEMORY_RUNTIME); ASSERT_EFI_ERROR (Status); - Instance->Initialized = TRUE; mFlashNvStorageVariableBase = FixedPcdGet32 (PcdFlashNvStorageVariableBase); // Set the index of the first LBA for the FVB