]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
ArmPlatformPkg/NorFlashDxe: initialize varstore headers eagerly
[mirror_edk2.git] / ArmPlatformPkg / Drivers / NorFlashDxe / NorFlashFvbDxe.c
index 4f56bae330229404100ae448f4e1d4a27702e399..c3e6489f398f896811d16999cb3a09292425329f 100644 (file)
@@ -59,10 +59,6 @@ InitializeFvAndVariableStoreHeaders (
   EFI_FIRMWARE_VOLUME_HEADER          *FirmwareVolumeHeader;\r
   VARIABLE_STORE_HEADER               *VariableStoreHeader;\r
 \r
-  if (!Instance->Initialized && Instance->Initialize) {\r
-    Instance->Initialize (Instance);\r
-  }\r
-\r
   HeadersLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(VARIABLE_STORE_HEADER);\r
   Headers = AllocateZeroPool(HeadersLength);\r
 \r
@@ -111,7 +107,7 @@ InitializeFvAndVariableStoreHeaders (
   // VARIABLE_STORE_HEADER\r
   //\r
   VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINTN)Headers + FirmwareVolumeHeader->HeaderLength);\r
-  CopyGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid);\r
+  CopyGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid);\r
   VariableStoreHeader->Size = PcdGet32(PcdFlashNvStorageVariableSize) - FirmwareVolumeHeader->HeaderLength;\r
   VariableStoreHeader->Format            = VARIABLE_STORE_FORMATTED;\r
   VariableStoreHeader->State             = VARIABLE_STORE_HEALTHY;\r
@@ -158,34 +154,40 @@ ValidateFvHeader (
       || (FwVolHeader->FvLength  != FvLength)\r
       )\r
   {\r
-    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: No Firmware Volume header present\n"));\r
+    DEBUG ((EFI_D_INFO, "%a: No Firmware Volume header present\n",\r
+      __FUNCTION__));\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
   // Check the Firmware Volume Guid\r
   if( CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid) == FALSE ) {\r
-    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Firmware Volume Guid non-compatible\n"));\r
+    DEBUG ((EFI_D_INFO, "%a: Firmware Volume Guid non-compatible\n",\r
+      __FUNCTION__));\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
   // Verify the header checksum\r
   Checksum = CalculateSum16((UINT16*)FwVolHeader, FwVolHeader->HeaderLength);\r
   if (Checksum != 0) {\r
-    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: FV checksum is invalid (Checksum:0x%X)\n",Checksum));\r
+    DEBUG ((EFI_D_INFO, "%a: FV checksum is invalid (Checksum:0x%X)\n",\r
+      __FUNCTION__, Checksum));\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
   VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINTN)FwVolHeader + FwVolHeader->HeaderLength);\r
 \r
   // Check the Variable Store Guid\r
-  if( CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) == FALSE ) {\r
-    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Variable Store Guid non-compatible\n"));\r
+  if (!CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) &&\r
+      !CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid)) {\r
+    DEBUG ((EFI_D_INFO, "%a: Variable Store Guid non-compatible\n",\r
+      __FUNCTION__));\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
   VariableStoreLength = PcdGet32 (PcdFlashNvStorageVariableSize) - FwVolHeader->HeaderLength;\r
   if (VariableStoreHeader->Size != VariableStoreLength) {\r
-    DEBUG ((EFI_D_ERROR, "ValidateFvHeader: Variable Store Length does not match\n"));\r
+    DEBUG ((EFI_D_INFO, "%a: Variable Store Length does not match\n",\r
+      __FUNCTION__));\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -425,10 +427,6 @@ FvbRead (
 \r
   DEBUG ((DEBUG_BLKIO, "FvbRead(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer));\r
 \r
-  if (!Instance->Initialized && Instance->Initialize) {\r
-    Instance->Initialize(Instance);\r
-  }\r
-\r
   TempStatus = EFI_SUCCESS;\r
 \r
   // Cache the block size to avoid de-referencing pointers all the time\r
@@ -622,10 +620,16 @@ FvbEraseBlocks (
     }\r
 \r
     // How many Lba blocks are we requested to erase?\r
-    NumOfLba = VA_ARG (Args, UINT32);\r
+    NumOfLba = VA_ARG (Args, UINTN);\r
 \r
     // All blocks must be within range\r
-    DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Check if: ( StartingLba=%ld + NumOfLba=%d - 1 ) > LastBlock=%ld.\n", Instance->StartLba + StartingLba, NumOfLba, Instance->Media.LastBlock));\r
+    DEBUG ((\r
+      DEBUG_BLKIO,\r
+      "FvbEraseBlocks: Check if: ( StartingLba=%ld + NumOfLba=%Lu - 1 ) > LastBlock=%ld.\n",\r
+      Instance->StartLba + StartingLba,\r
+      (UINT64)NumOfLba,\r
+      Instance->Media.LastBlock\r
+      ));\r
     if ((NumOfLba == 0) || ((Instance->StartLba + StartingLba + NumOfLba - 1) > Instance->Media.LastBlock)) {\r
       VA_END (Args);\r
       DEBUG ((EFI_D_ERROR, "FvbEraseBlocks: ERROR - Lba range goes past the last Lba.\n"));\r
@@ -650,7 +654,7 @@ FvbEraseBlocks (
     }\r
 \r
     // How many Lba blocks are we requested to erase?\r
-    NumOfLba = VA_ARG (Args, UINT32);\r
+    NumOfLba = VA_ARG (Args, UINTN);\r
 \r
     // Go through each one and erase it\r
     while (NumOfLba > 0) {\r
@@ -713,8 +717,30 @@ NorFlashFvbInitialize (
   UINTN       RuntimeMmioRegionSize;\r
 \r
   DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n"));\r
+  ASSERT((Instance != NULL));\r
+\r
+  //\r
+  // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME\r
+  //\r
+\r
+  // Note: all the NOR Flash region needs to be reserved into the UEFI Runtime memory;\r
+  //       even if we only use the small block region at the top of the NOR Flash.\r
+  //       The reason is when the NOR Flash memory is set into program mode, the command\r
+  //       is written as the base of the flash region (ie: Instance->DeviceBaseAddress)\r
+  RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size;\r
+\r
+  Status = gDS->AddMemorySpace (\r
+      EfiGcdMemoryTypeMemoryMappedIo,\r
+      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,\r
+      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME\r
+      );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gDS->SetMemorySpaceAttributes (\r
+      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,\r
+      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
-  Instance->Initialized = TRUE;\r
   mFlashNvStorageVariableBase = FixedPcdGet32 (PcdFlashNvStorageVariableBase);\r
 \r
   // Set the index of the first LBA for the FVB\r
@@ -731,7 +757,9 @@ NorFlashFvbInitialize (
   // Install the Default FVB header if required\r
   if (EFI_ERROR(Status)) {\r
     // There is no valid header, so time to install one.\r
-    DEBUG((EFI_D_ERROR,"NorFlashFvbInitialize: ERROR - The FVB Header is not valid. Installing a correct one for this volume.\n"));\r
+    DEBUG ((EFI_D_INFO, "%a: The FVB Header is not valid.\n", __FUNCTION__));\r
+    DEBUG ((EFI_D_INFO, "%a: Installing a correct one for this volume.\n",\r
+      __FUNCTION__));\r
 \r
     // Erase all the NorFlash that is reserved for variable storage\r
     FvbNumLba = (PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32(PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;\r
@@ -748,28 +776,6 @@ NorFlashFvbInitialize (
     }\r
   }\r
 \r
-  //\r
-  // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME\r
-  //\r
-\r
-  // Note: all the NOR Flash region needs to be reserved into the UEFI Runtime memory;\r
-  //       even if we only use the small block region at the top of the NOR Flash.\r
-  //       The reason is when the NOR Flash memory is set into program mode, the command\r
-  //       is written as the base of the flash region (ie: Instance->DeviceBaseAddress)\r
-  RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size;\r
-\r
-  Status = gDS->AddMemorySpace (\r
-      EfiGcdMemoryTypeMemoryMappedIo,\r
-      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,\r
-      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME\r
-      );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  Status = gDS->SetMemorySpaceAttributes (\r
-      Instance->DeviceBaseAddress, RuntimeMmioRegionSize,\r
-      EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   //\r
   // Register for the virtual address change event\r
   //\r