// 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
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
VARIABLE_STORE_HEADER *VariableStoreHeader;\r
UINTN VariableStoreLength;\r
- UINTN FvLength;\r
+ UINTN FvLength;\r
\r
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Instance->RegionBaseAddress;\r
\r
|| (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
IN UINT8 *Buffer\r
)\r
{\r
- EFI_STATUS TempStatus;\r
- UINT32 Tmp;\r
- UINT32 TmpBuf;\r
- UINT32 WordToWrite;\r
- UINT32 Mask;\r
- UINTN DoErase;\r
- UINTN BytesToWrite;\r
- UINTN CurOffset;\r
- UINTN WordAddr;\r
- UINTN BlockSize;\r
NOR_FLASH_INSTANCE *Instance;\r
- UINTN BlockAddress;\r
- UINTN PrevBlockAddress;\r
\r
- PrevBlockAddress = 0;\r
+ Instance = INSTANCE_FROM_FVB_THIS (This);\r
\r
- Instance = INSTANCE_FROM_FVB_THIS(This);\r
-\r
- if (!Instance->Initialized && Instance->Initialize) {\r
- Instance->Initialize(Instance);\r
- }\r
-\r
- DEBUG ((DEBUG_BLKIO, "FvbWrite(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer));\r
-\r
- // Detect WriteDisabled state\r
- if (Instance->Media.ReadOnly == TRUE) {\r
- DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Can not write: Device is in WriteDisabled state.\n"));\r
- // It is in WriteDisabled state, return an error right away\r
- return EFI_ACCESS_DENIED;\r
- }\r
-\r
- // Cache the block size to avoid de-referencing pointers all the time\r
- BlockSize = Instance->Media.BlockSize;\r
-\r
- // The write must not span block boundaries.\r
- // We need to check each variable individually because adding two large values together overflows.\r
- if ( ( Offset >= BlockSize ) ||\r
- ( *NumBytes > BlockSize ) ||\r
- ( (Offset + *NumBytes) > BlockSize ) ) {\r
- DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));\r
- return EFI_BAD_BUFFER_SIZE;\r
- }\r
-\r
- // We must have some bytes to write\r
- if (*NumBytes == 0) {\r
- DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));\r
- return EFI_BAD_BUFFER_SIZE;\r
- }\r
-\r
- // Pick 128bytes as a good start for word operations as opposed to erasing the\r
- // block and writing the data regardless if an erase is really needed.\r
- // It looks like most individual NV variable writes are smaller than 128bytes.\r
- if (*NumBytes <= 128) {\r
- // Check to see if we need to erase before programming the data into NOR.\r
- // If the destination bits are only changing from 1s to 0s we can just write.\r
- // After a block is erased all bits in the block is set to 1.\r
- // If any byte requires us to erase we just give up and rewrite all of it.\r
- DoErase = 0;\r
- BytesToWrite = *NumBytes;\r
- CurOffset = Offset;\r
-\r
- while (BytesToWrite > 0) {\r
- // Read full word from NOR, splice as required. A word is the smallest\r
- // unit we can write.\r
- TempStatus = NorFlashRead (Instance, Instance->StartLba + Lba,\r
- CurOffset & ~(0x3), sizeof(Tmp), &Tmp);\r
- if (EFI_ERROR (TempStatus)) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- // Physical address of word in NOR to write.\r
- WordAddr = (CurOffset & ~(0x3)) + GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,\r
- Lba, BlockSize);\r
- // The word of data that is to be written.\r
- TmpBuf = *((UINT32*)(Buffer + (*NumBytes - BytesToWrite)));\r
-\r
- // First do word aligned chunks.\r
- if ((CurOffset & 0x3) == 0) {\r
- if (BytesToWrite >= 4) {\r
- // Is the destination still in 'erased' state?\r
- if (~Tmp != 0) {\r
- // Check to see if we are only changing bits to zero.\r
- if ((Tmp ^ TmpBuf) & TmpBuf) {\r
- DoErase = 1;\r
- break;\r
- }\r
- }\r
- // Write this word to NOR\r
- WordToWrite = TmpBuf;\r
- CurOffset += sizeof(TmpBuf);\r
- BytesToWrite -= sizeof(TmpBuf);\r
- } else {\r
- // BytesToWrite < 4. Do small writes and left-overs\r
- Mask = ~((~0) << (BytesToWrite * 8));\r
- // Mask out the bytes we want.\r
- TmpBuf &= Mask;\r
- // Is the destination still in 'erased' state?\r
- if ((Tmp & Mask) != Mask) {\r
- // Check to see if we are only changing bits to zero.\r
- if ((Tmp ^ TmpBuf) & TmpBuf) {\r
- DoErase = 1;\r
- break;\r
- }\r
- }\r
- // Merge old and new data. Write merged word to NOR\r
- WordToWrite = (Tmp & ~Mask) | TmpBuf;\r
- CurOffset += BytesToWrite;\r
- BytesToWrite = 0;\r
- }\r
- } else {\r
- // Do multiple words, but starting unaligned.\r
- if (BytesToWrite > (4 - (CurOffset & 0x3))) {\r
- Mask = ~((~0) << ((CurOffset & 0x3) * 8));\r
- // Mask out the bytes we want.\r
- TmpBuf = (TmpBuf << ((CurOffset & 0x3) * 8)) & Mask;\r
- // Is the destination still in 'erased' state?\r
- if ((Tmp & Mask) != Mask) {\r
- // Check to see if we are only changing bits to zero.\r
- if ((Tmp ^ TmpBuf) & TmpBuf) {\r
- DoErase = 1;\r
- break;\r
- }\r
- }\r
- // Merge old and new data. Write merged word to NOR\r
- WordToWrite = (Tmp & ~Mask) | TmpBuf;\r
- BytesToWrite -= (4 - (CurOffset & 0x3));\r
- CurOffset += (4 - (CurOffset & 0x3));\r
- } else {\r
- // Unaligned and fits in one word.\r
- Mask = (~((~0) << (BytesToWrite * 8))) << ((CurOffset & 0x3) * 8);\r
- // Mask out the bytes we want.\r
- TmpBuf = (TmpBuf << ((CurOffset & 0x3) * 8)) & Mask;\r
- // Is the destination still in 'erased' state?\r
- if ((Tmp & Mask) != Mask) {\r
- // Check to see if we are only changing bits to zero.\r
- if ((Tmp ^ TmpBuf) & TmpBuf) {\r
- DoErase = 1;\r
- break;\r
- }\r
- }\r
- // Merge old and new data. Write merged word to NOR\r
- WordToWrite = (Tmp & ~Mask) | TmpBuf;\r
- CurOffset += BytesToWrite;\r
- BytesToWrite = 0;\r
- }\r
- }\r
-\r
- //\r
- // Write the word to NOR.\r
- //\r
-\r
- BlockAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, BlockSize);\r
- if (BlockAddress != PrevBlockAddress) {\r
- TempStatus = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress);\r
- if (EFI_ERROR (TempStatus)) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- PrevBlockAddress = BlockAddress;\r
- }\r
- TempStatus = NorFlashWriteSingleWord (Instance, WordAddr, WordToWrite);\r
- if (EFI_ERROR (TempStatus)) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- }\r
- // Exit if we got here and could write all the data. Otherwise do the\r
- // Erase-Write cycle.\r
- if (!DoErase) {\r
- return EFI_SUCCESS;\r
- }\r
- }\r
-\r
- // Check we did get some memory. Buffer is BlockSize.\r
- if (Instance->FvbBuffer == NULL) {\r
- DEBUG ((EFI_D_ERROR, "FvbWrite: ERROR - Buffer not ready\n"));\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- // Read NOR Flash data into shadow buffer\r
- TempStatus = NorFlashReadBlocks (Instance, Instance->StartLba + Lba, BlockSize, Instance->FvbBuffer);\r
- if (EFI_ERROR (TempStatus)) {\r
- // Return one of the pre-approved error statuses\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- // Put the data at the appropriate location inside the buffer area\r
- CopyMem ((VOID*)((UINTN)Instance->FvbBuffer + Offset), Buffer, *NumBytes);\r
-\r
- // Write the modified buffer back to the NorFlash\r
- TempStatus = NorFlashWriteBlocks (Instance, Instance->StartLba + Lba, BlockSize, Instance->FvbBuffer);\r
- if (EFI_ERROR (TempStatus)) {\r
- // Return one of the pre-approved error statuses\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- return EFI_SUCCESS;\r
+ return NorFlashWriteSingleBlock (Instance, Instance->StartLba + Lba, Offset, NumBytes, Buffer);\r
}\r
\r
/**\r
}\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
}\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
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
Status = ValidateFvHeader (Instance);\r
}\r
\r
- // Install the Default FVB header if required \r
+ // 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
}\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