From 001e57a103fce87245bfb7ae9c32ffb499a64135 Mon Sep 17 00:00:00 2001 From: Guo Mang Date: Thu, 27 Apr 2017 11:03:56 +0800 Subject: IntelFrameworkModulePkg: Move to new location Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Guo Mang --- .../Universal/FirmwareVolume/FwVolDxe/Ffs.c | 608 -------- .../Universal/FirmwareVolume/FwVolDxe/FwPadFile.c | 1228 --------------- .../Universal/FirmwareVolume/FwVolDxe/FwVol.c | 798 ---------- .../FirmwareVolume/FwVolDxe/FwVolAttrib.c | 220 --- .../FirmwareVolume/FwVolDxe/FwVolDriver.h | 761 ---------- .../Universal/FirmwareVolume/FwVolDxe/FwVolDxe.inf | 74 - .../Universal/FirmwareVolume/FwVolDxe/FwVolDxe.uni | 23 - .../FirmwareVolume/FwVolDxe/FwVolDxeExtra.uni | 20 - .../Universal/FirmwareVolume/FwVolDxe/FwVolRead.c | 632 -------- .../Universal/FirmwareVolume/FwVolDxe/FwVolWrite.c | 1586 -------------------- .../FirmwareVolume/UpdateDriverDxe/FlashUpdate.c | 1218 --------------- .../UpdateDriverDxe/ParseUpdateProfile.c | 1133 -------------- .../UpdateDriverDxe/UpdateDispatcher.c | 846 ----------- .../FirmwareVolume/UpdateDriverDxe/UpdateDriver.h | 213 --- .../UpdateDriverDxe/UpdateDriverDxe.inf | 76 - .../UpdateDriverDxe/UpdateDriverDxe.uni | 24 - .../UpdateDriverDxe/UpdateDriverDxeExtra.uni | 20 - .../UpdateDriverDxe/UpdateStrings.uni | 25 - 18 files changed, 9505 deletions(-) delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/Ffs.c delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwPadFile.c delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVol.c delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolAttrib.c delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDriver.h delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxe.inf delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxe.uni delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxeExtra.uni delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolRead.c delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolWrite.c delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/FlashUpdate.c delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/ParseUpdateProfile.c delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDispatcher.c delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriver.h delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxe.inf delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxe.uni delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxeExtra.uni delete mode 100644 IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateStrings.uni (limited to 'IntelFrameworkModulePkg/Universal/FirmwareVolume') diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/Ffs.c b/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/Ffs.c deleted file mode 100644 index 12508b4335..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/Ffs.c +++ /dev/null @@ -1,608 +0,0 @@ -/** @file - FFS file access utilities. - - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "FwVolDriver.h" - -#define PHYSICAL_ADDRESS_TO_POINTER(Address) ((VOID *) ((UINTN) Address)) - -/** - Set File State in the FfsHeader. - - @param State File state to be set into FFS header. - @param FfsHeader Points to the FFS file header - -**/ -VOID -SetFileState ( - IN UINT8 State, - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -{ - // - // Set File State in the FfsHeader - // - FfsHeader->State = (EFI_FFS_FILE_STATE) (FfsHeader->State ^ State); - return ; -} - -/** - Get the FFS file state by checking the highest bit set in the header's state field. - - @param ErasePolarity Erase polarity attribute of the firmware volume - @param FfsHeader Points to the FFS file header - - @return FFS File state - -**/ -EFI_FFS_FILE_STATE -GetFileState ( - IN UINT8 ErasePolarity, - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -{ - EFI_FFS_FILE_STATE FileState; - UINT8 HighestBit; - - FileState = FfsHeader->State; - - if (ErasePolarity != 0) { - FileState = (EFI_FFS_FILE_STATE)~FileState; - } - - HighestBit = 0x80; - while (HighestBit != 0 && ((HighestBit & FileState) == 0)) { - HighestBit >>= 1; - } - - return (EFI_FFS_FILE_STATE) HighestBit; -} - -/** - Convert the Buffer Address to LBA Entry Address. - - @param FvDevice Cached FvDevice - @param BufferAddress Address of Buffer - @param LbaListEntry Pointer to the got LBA entry that contains the address. - - @retval EFI_NOT_FOUND Buffer address is out of FvDevice. - @retval EFI_SUCCESS LBA entry is found for Buffer address. - -**/ -EFI_STATUS -Buffer2LbaEntry ( - IN FV_DEVICE *FvDevice, - IN EFI_PHYSICAL_ADDRESS BufferAddress, - OUT LBA_ENTRY **LbaListEntry - ) -{ - LBA_ENTRY *LbaEntry; - LIST_ENTRY *Link; - - Link = FvDevice->LbaHeader.ForwardLink; - LbaEntry = (LBA_ENTRY *) Link; - - // - // Locate LBA which contains the address - // - while (&LbaEntry->Link != &FvDevice->LbaHeader) { - if ((EFI_PHYSICAL_ADDRESS) (UINTN) (LbaEntry->StartingAddress) > BufferAddress) { - break; - } - - Link = LbaEntry->Link.ForwardLink; - LbaEntry = (LBA_ENTRY *) Link; - } - - if (&LbaEntry->Link == &FvDevice->LbaHeader) { - return EFI_NOT_FOUND; - } - - Link = LbaEntry->Link.BackLink; - LbaEntry = (LBA_ENTRY *) Link; - - if (&LbaEntry->Link == &FvDevice->LbaHeader) { - return EFI_NOT_FOUND; - } - - *LbaListEntry = LbaEntry; - - return EFI_SUCCESS; -} - -/** - Convert the Buffer Address to LBA Address & Offset. - - @param FvDevice Cached FvDevice - @param BufferAddress Address of Buffer - @param Lba Pointer to the gob Lba value - @param Offset Pointer to the got Offset - - @retval EFI_NOT_FOUND Buffer address is out of FvDevice. - @retval EFI_SUCCESS LBA and Offset is found for Buffer address. - -**/ -EFI_STATUS -Buffer2Lba ( - IN FV_DEVICE *FvDevice, - IN EFI_PHYSICAL_ADDRESS BufferAddress, - OUT EFI_LBA *Lba, - OUT UINTN *Offset - ) -{ - LBA_ENTRY *LbaEntry; - EFI_STATUS Status; - - LbaEntry = NULL; - - Status = Buffer2LbaEntry ( - FvDevice, - BufferAddress, - &LbaEntry - ); - if (EFI_ERROR (Status)) { - return Status; - } - - *Lba = LbaEntry->LbaIndex; - *Offset = (UINTN) BufferAddress - (UINTN) LbaEntry->StartingAddress; - - return EFI_SUCCESS; -} - -/** - Check if a block of buffer is erased. - - @param ErasePolarity Erase polarity attribute of the firmware volume - @param Buffer The buffer to be checked - @param BufferSize Size of the buffer in bytes - - @retval TRUE The block of buffer is erased - @retval FALSE The block of buffer is not erased - -**/ -BOOLEAN -IsBufferErased ( - IN UINT8 ErasePolarity, - IN UINT8 *Buffer, - IN UINTN BufferSize - ) -{ - UINTN Count; - UINT8 EraseByte; - - if (ErasePolarity == 1) { - EraseByte = 0xFF; - } else { - EraseByte = 0; - } - - for (Count = 0; Count < BufferSize; Count++) { - if (Buffer[Count] != EraseByte) { - return FALSE; - } - } - - return TRUE; -} - -/** - Verify checksum of the firmware volume header. - - @param FvHeader Points to the firmware volume header to be checked - - @retval TRUE Checksum verification passed - @retval FALSE Checksum verification failed - -**/ -BOOLEAN -VerifyFvHeaderChecksum ( - IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader - ) -{ - UINT16 Checksum; - - Checksum = CalculateSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength); - - if (Checksum == 0) { - return TRUE; - } else { - return FALSE; - } -} - -/** - Verify checksum of the FFS file header. - - @param FfsHeader Points to the FFS file header to be checked - - @retval TRUE Checksum verification passed - @retval FALSE Checksum verification failed - -**/ -BOOLEAN -VerifyHeaderChecksum ( - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -{ - UINT8 HeaderChecksum; - - if (IS_FFS_FILE2 (FfsHeader)) { - HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER2)); - } else { - HeaderChecksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER)); - } - HeaderChecksum = (UINT8) (HeaderChecksum - FfsHeader->State - FfsHeader->IntegrityCheck.Checksum.File); - - if (HeaderChecksum == 0) { - return TRUE; - } else { - return FALSE; - } -} - -/** - Verify checksum of the FFS file data. - - @param FfsHeader Points to the FFS file header to be checked - - @retval TRUE Checksum verification passed - @retval FALSE Checksum verification failed - -**/ -BOOLEAN -VerifyFileChecksum ( - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -{ - UINT8 FileChecksum; - EFI_FV_FILE_ATTRIBUTES Attributes; - - Attributes = FfsHeader->Attributes; - - if ((Attributes & FFS_ATTRIB_CHECKSUM) != 0) { - - // - // Check checksum of FFS data - // - if (IS_FFS_FILE2 (FfsHeader)) { - FileChecksum = CalculateSum8 ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2), FFS_FILE2_SIZE (FfsHeader) - sizeof (EFI_FFS_FILE_HEADER2)); - } else { - FileChecksum = CalculateSum8 ((UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER), FFS_FILE_SIZE (FfsHeader) - sizeof (EFI_FFS_FILE_HEADER)); - } - FileChecksum = (UINT8) (FileChecksum + FfsHeader->IntegrityCheck.Checksum.File); - - if (FileChecksum == 0) { - return TRUE; - } else { - return FALSE; - } - - } else { - - if (FfsHeader->IntegrityCheck.Checksum.File != FFS_FIXED_CHECKSUM) { - return FALSE; - } else { - return TRUE; - } - } - -} - -/** - Check if it's a valid FFS file header. - - @param ErasePolarity Erase polarity attribute of the firmware volume - @param FfsHeader Points to the FFS file header to be checked - - @retval TRUE Valid FFS file header - @retval FALSE Invalid FFS file header - -**/ -BOOLEAN -IsValidFFSHeader ( - IN UINT8 ErasePolarity, - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -{ - EFI_FFS_FILE_STATE FileState; - - // - // Check if it is a free space - // - if (IsBufferErased ( - ErasePolarity, - (UINT8 *) FfsHeader, - sizeof (EFI_FFS_FILE_HEADER) - )) { - return FALSE; - } - - FileState = GetFileState (ErasePolarity, FfsHeader); - - switch (FileState) { - case EFI_FILE_HEADER_CONSTRUCTION: - // - // fall through - // - case EFI_FILE_HEADER_INVALID: - return FALSE; - - case EFI_FILE_HEADER_VALID: - // - // fall through - // - case EFI_FILE_DATA_VALID: - // - // fall through - // - case EFI_FILE_MARKED_FOR_UPDATE: - // - // fall through - // - case EFI_FILE_DELETED: - // - // Here we need to verify header checksum - // - if (!VerifyHeaderChecksum (FfsHeader)) { - return FALSE; - } - break; - - default: - // - // return - // - return FALSE; - } - - return TRUE; -} - -/** - Get next possible of Firmware File System Header. - - @param ErasePolarity Erase polarity attribute of the firmware volume - @param FfsHeader Points to the FFS file header to be skipped. - - @return Pointer to next FFS header. - -**/ -EFI_PHYSICAL_ADDRESS -GetNextPossibleFileHeader ( - IN UINT8 ErasePolarity, - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -{ - UINT32 FileLength; - UINT32 SkipLength; - - if (!IsValidFFSHeader (ErasePolarity, FfsHeader)) { - // - // Skip this header - // - if (IS_FFS_FILE2 (FfsHeader)) { - return (EFI_PHYSICAL_ADDRESS) (UINTN) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2); - } else { - return (EFI_PHYSICAL_ADDRESS) (UINTN) FfsHeader + sizeof (EFI_FFS_FILE_HEADER); - } - } - - if (IS_FFS_FILE2 (FfsHeader)) { - FileLength = FFS_FILE2_SIZE (FfsHeader); - } else { - FileLength = FFS_FILE_SIZE (FfsHeader); - } - - // - // Since FileLength is not multiple of 8, we need skip some bytes - // to get next possible header - // - SkipLength = FileLength; - while ((SkipLength & 0x07) != 0) { - SkipLength++; - } - - return (EFI_PHYSICAL_ADDRESS) (UINTN) FfsHeader + SkipLength; -} - -/** - Search FFS file with the same FFS name in FV Cache. - - @param FvDevice Cached FV image. - @param FfsHeader Points to the FFS file header to be skipped. - @param StateBit FFS file state bit to be checked. - - @return Pointer to next found FFS header. NULL will return if no found. - -**/ -EFI_FFS_FILE_HEADER * -DuplicateFileExist ( - IN FV_DEVICE *FvDevice, - IN EFI_FFS_FILE_HEADER *FfsHeader, - IN EFI_FFS_FILE_STATE StateBit - ) -{ - UINT8 *Ptr; - EFI_FFS_FILE_HEADER *NextFfsFile; - - // - // Search duplicate file, not from the beginning of FV, - // just search the next ocurrence of this file - // - NextFfsFile = FfsHeader; - - do { - Ptr = (UINT8 *) PHYSICAL_ADDRESS_TO_POINTER ( - GetNextPossibleFileHeader (FvDevice->ErasePolarity, - NextFfsFile) - ); - NextFfsFile = (EFI_FFS_FILE_HEADER *) Ptr; - - if ((UINT8 *) PHYSICAL_ADDRESS_TO_POINTER (FvDevice->CachedFv) + FvDevice->FwVolHeader->FvLength - Ptr < - sizeof (EFI_FFS_FILE_HEADER) - ) { - break; - } - - if (!IsValidFFSHeader (FvDevice->ErasePolarity, NextFfsFile)) { - continue; - } - - if (!VerifyFileChecksum (NextFfsFile)) { - continue; - } - - if (CompareGuid (&NextFfsFile->Name, &FfsHeader->Name)) { - if (GetFileState (FvDevice->ErasePolarity, NextFfsFile) == StateBit) { - return NextFfsFile; - } - } - } while (Ptr < (UINT8 *) PHYSICAL_ADDRESS_TO_POINTER (FvDevice->CachedFv) + FvDevice->FwVolHeader->FvLength); - - return NULL; -} - -/** - Change FFS file header state and write to FV. - - @param FvDevice Cached FV image. - @param FfsHeader Points to the FFS file header to be updated. - @param State FFS file state to be set. - - @retval EFI_SUCCESS File state is writen into FV. - @retval others File state can't be writen into FV. - -**/ -EFI_STATUS -UpdateHeaderBit ( - IN FV_DEVICE *FvDevice, - IN EFI_FFS_FILE_HEADER *FfsHeader, - IN EFI_FFS_FILE_STATE State - ) -{ - EFI_STATUS Status; - EFI_LBA Lba; - UINTN Offset; - UINTN NumBytesWritten; - - Lba = 0; - Offset = 0; - - SetFileState (State, FfsHeader); - - Buffer2Lba ( - FvDevice, - (EFI_PHYSICAL_ADDRESS) (UINTN) (&FfsHeader->State), - &Lba, - &Offset - ); - // - // Write the state byte into FV - // - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvDevice->Fvb->Write ( - FvDevice->Fvb, - Lba, - Offset, - &NumBytesWritten, - &FfsHeader->State - ); - return Status; -} - -/** - Check if it's a valid FFS file. - Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first. - - @param FvDevice Cached FV image. - @param FfsHeader Points to the FFS file to be checked - - @retval TRUE Valid FFS file - @retval FALSE Invalid FFS file - -**/ -BOOLEAN -IsValidFFSFile ( - IN FV_DEVICE *FvDevice, - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -{ - EFI_FFS_FILE_STATE FileState; - UINT8 ErasePolarity; - - ErasePolarity = FvDevice->ErasePolarity; - - FileState = GetFileState (ErasePolarity, FfsHeader); - - switch (FileState) { - case EFI_FILE_DATA_VALID: - if (!VerifyFileChecksum (FfsHeader)) { - return FALSE; - } - - if (FfsHeader->Type == EFI_FV_FILETYPE_FFS_PAD) { - break; - } - // - // Check if there is another duplicated file with the EFI_FILE_DATA_VALID - // - if (DuplicateFileExist (FvDevice, FfsHeader, EFI_FILE_DATA_VALID) != NULL) { - return FALSE; - } - - break; - - case EFI_FILE_MARKED_FOR_UPDATE: - if (!VerifyFileChecksum (FfsHeader)) { - return FALSE; - } - - if (FfsHeader->Type == EFI_FV_FILETYPE_FFS_PAD) { - // - // since its data area is not unperturbed, it cannot be reclaimed, - // marked it as deleted - // - UpdateHeaderBit (FvDevice, FfsHeader, EFI_FILE_DELETED); - return TRUE; - - } else if (DuplicateFileExist (FvDevice, FfsHeader, EFI_FILE_DATA_VALID) != NULL) { - // - // Here the found file is more recent than this file, - // mark it as deleted - // - UpdateHeaderBit (FvDevice, FfsHeader, EFI_FILE_DELETED); - return TRUE; - - } else { - return TRUE; - } - - break; - - case EFI_FILE_DELETED: - if (!VerifyFileChecksum (FfsHeader)) { - return FALSE; - } - - break; - - default: - return FALSE; - } - - return TRUE; -} - diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwPadFile.c b/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwPadFile.c deleted file mode 100644 index 8d53d879bd..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwPadFile.c +++ /dev/null @@ -1,1228 +0,0 @@ -/** @file - Implements functions to pad firmware file. - - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "FwVolDriver.h" - -/** - Calculate the checksum for a PAD file. - - @param PadFileHeader The Pad File to be caculeted the checksum. - -**/ -VOID -SetPadFileChecksum ( - IN EFI_FFS_FILE_HEADER *PadFileHeader - ) -{ - if ((PadFileHeader->Attributes & FFS_ATTRIB_CHECKSUM) != 0) { - - if (IS_FFS_FILE2 (PadFileHeader)) { - // - // Calculate checksum of Pad File Data - // - PadFileHeader->IntegrityCheck.Checksum.File = - CalculateCheckSum8 ((UINT8 *) PadFileHeader + sizeof (EFI_FFS_FILE_HEADER2), FFS_FILE2_SIZE (PadFileHeader) - sizeof (EFI_FFS_FILE_HEADER2)); - - } else { - // - // Calculate checksum of Pad File Data - // - PadFileHeader->IntegrityCheck.Checksum.File = - CalculateCheckSum8 ((UINT8 *) PadFileHeader + sizeof (EFI_FFS_FILE_HEADER), FFS_FILE_SIZE (PadFileHeader) - sizeof (EFI_FFS_FILE_HEADER)); - } - - } else { - - PadFileHeader->IntegrityCheck.Checksum.File = FFS_FIXED_CHECKSUM; - - } - - return ; -} - -/** - Create a PAD File in the Free Space. - - @param FvDevice Firmware Volume Device. - @param FreeSpaceEntry Indicating in which Free Space(Cache) the Pad file will be inserted. - @param Size Pad file Size, not include the header. - @param PadFileEntry The Ffs File Entry that points to this Pad File. - - @retval EFI_SUCCESS Successfully create a PAD file. - @retval EFI_OUT_OF_RESOURCES No enough free space to create a PAD file. - @retval EFI_INVALID_PARAMETER Size is not 8 byte alignment. - @retval EFI_DEVICE_ERROR Free space is not erased. -**/ -EFI_STATUS -FvCreatePadFileInFreeSpace ( - IN FV_DEVICE *FvDevice, - IN FREE_SPACE_ENTRY *FreeSpaceEntry, - IN UINTN Size, - OUT FFS_FILE_LIST_ENTRY **PadFileEntry - ) -{ - EFI_STATUS Status; - EFI_FFS_FILE_HEADER *PadFileHeader; - UINTN Offset; - UINTN NumBytesWritten; - UINTN StateOffset; - UINT8 *StartPos; - FFS_FILE_LIST_ENTRY *FfsFileEntry; - UINTN HeaderSize; - UINTN FileSize; - - HeaderSize = sizeof (EFI_FFS_FILE_HEADER); - FileSize = Size + HeaderSize; - if (FileSize > 0x00FFFFFF) { - HeaderSize = sizeof (EFI_FFS_FILE_HEADER2); - FileSize = Size + HeaderSize; - } - - if (FreeSpaceEntry->Length < FileSize) { - return EFI_OUT_OF_RESOURCES; - } - - if ((Size & 0x07) != 0) { - return EFI_INVALID_PARAMETER; - } - - StartPos = FreeSpaceEntry->StartingAddress; - - // - // First double check the space - // - if (!IsBufferErased ( - FvDevice->ErasePolarity, - StartPos, - FileSize - )) { - return EFI_DEVICE_ERROR; - } - - PadFileHeader = (EFI_FFS_FILE_HEADER *) StartPos; - - // - // Create File Step 1 - // - SetFileState (EFI_FILE_HEADER_CONSTRUCTION, PadFileHeader); - - Offset = (UINTN) (StartPos - FvDevice->CachedFv); - StateOffset = Offset + (UINT8 *) &PadFileHeader->State - (UINT8 *) PadFileHeader; - - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvcWrite ( - FvDevice, - StateOffset, - &NumBytesWritten, - &PadFileHeader->State - ); - if (EFI_ERROR (Status)) { - SetFileState (EFI_FILE_HEADER_CONSTRUCTION, PadFileHeader); - return Status; - } - // - // Update Free Space Entry, since header is allocated - // - FreeSpaceEntry->Length -= HeaderSize; - FreeSpaceEntry->StartingAddress += HeaderSize; - - // - // Fill File Name Guid, here we assign a NULL-GUID to Pad files - // - ZeroMem (&PadFileHeader->Name, sizeof (EFI_GUID)); - - // - // Fill File Type, checksum(0), Attributes(0), Size - // - PadFileHeader->Type = EFI_FV_FILETYPE_FFS_PAD; - PadFileHeader->Attributes = 0; - if ((FileSize) > 0x00FFFFFF) { - ((EFI_FFS_FILE_HEADER2 *) PadFileHeader)->ExtendedSize = (UINT32) FileSize; - *(UINT32 *) PadFileHeader->Size &= 0xFF000000; - PadFileHeader->Attributes |= FFS_ATTRIB_LARGE_FILE; - } else { - *(UINT32 *) PadFileHeader->Size &= 0xFF000000; - *(UINT32 *) PadFileHeader->Size |= FileSize; - } - - SetHeaderChecksum (PadFileHeader); - SetPadFileChecksum (PadFileHeader); - - Offset = (UINTN) (StartPos - FvDevice->CachedFv); - - NumBytesWritten = HeaderSize; - Status = FvcWrite ( - FvDevice, - Offset, - &NumBytesWritten, - (UINT8 *) PadFileHeader - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Step 2, then Mark header valid, since no data write, - // mark the data valid at the same time. - // - SetFileState (EFI_FILE_HEADER_VALID, PadFileHeader); - SetFileState (EFI_FILE_DATA_VALID, PadFileHeader); - - Offset = (UINTN) (StartPos - FvDevice->CachedFv); - StateOffset = Offset + (UINT8 *) &PadFileHeader->State - (UINT8 *) PadFileHeader; - - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvcWrite ( - FvDevice, - StateOffset, - &NumBytesWritten, - &PadFileHeader->State - ); - if (EFI_ERROR (Status)) { - SetFileState (EFI_FILE_HEADER_VALID, PadFileHeader); - SetFileState (EFI_FILE_DATA_VALID, PadFileHeader); - return Status; - } - // - // Update Free Space Entry, since header is allocated - // - FreeSpaceEntry->Length -= Size; - FreeSpaceEntry->StartingAddress += Size; - - // - // If successfully, insert an FfsFileEntry at the end of ffs file list - // - FfsFileEntry = AllocateZeroPool (sizeof (FFS_FILE_LIST_ENTRY)); - ASSERT (FfsFileEntry != NULL); - - FfsFileEntry->FfsHeader = (UINT8 *) (UINTN) StartPos; - InsertTailList (&FvDevice->FfsFileListHeader, &FfsFileEntry->Link); - - *PadFileEntry = FfsFileEntry; - FvDevice->CurrentFfsFile = FfsFileEntry; - - return EFI_SUCCESS; -} - -/** - Fill pad file header within firmware cache. - - @param PadFileHeader The start of the Pad File Buffer. - @param PadFileLength The length of the pad file including the header. - -**/ -VOID -FvFillPadFile ( - IN EFI_FFS_FILE_HEADER *PadFileHeader, - IN UINTN PadFileLength - ) -{ - // - // Fill File Name Guid, here we assign a NULL-GUID to Pad files - // - ZeroMem (&PadFileHeader->Name, sizeof (EFI_GUID)); - - // - // Fill File Type, checksum(0), Attributes(0), Size - // - PadFileHeader->Type = EFI_FV_FILETYPE_FFS_PAD; - PadFileHeader->Attributes = 0; - if (PadFileLength > 0x00FFFFFF) { - ((EFI_FFS_FILE_HEADER2 *) PadFileHeader)->ExtendedSize = (UINT32) PadFileLength; - *(UINT32 *) PadFileHeader->Size &= 0xFF000000; - PadFileHeader->Attributes |= FFS_ATTRIB_LARGE_FILE; - } else { - *(UINT32 *) PadFileHeader->Size &= 0xFF000000; - *(UINT32 *) PadFileHeader->Size |= PadFileLength; - } - - SetHeaderChecksum (PadFileHeader); - SetPadFileChecksum (PadFileHeader); - - // - // Set File State to 0x00000111 - // - SetFileState (EFI_FILE_HEADER_CONSTRUCTION, PadFileHeader); - SetFileState (EFI_FILE_HEADER_VALID, PadFileHeader); - SetFileState (EFI_FILE_DATA_VALID, PadFileHeader); - - return ; -} - -/** - Create entire FFS file. - - @param FileHeader Starting Address of a Buffer that hold the FFS File image. - @param FfsFileBuffer The source buffer that contains the File Data. - @param BufferSize The length of FfsFileBuffer. - @param ActualFileSize Size of FFS file. - @param FileName The Guid of Ffs File. - @param FileType The type of the written Ffs File. - @param FileAttributes The attributes of the written Ffs File. - - @retval EFI_INVALID_PARAMETER File type is not valid. - @retval EFI_SUCCESS FFS file is successfully created. - -**/ -EFI_STATUS -FvFillFfsFile ( - OUT EFI_FFS_FILE_HEADER *FileHeader, - IN UINT8 *FfsFileBuffer, - IN UINTN BufferSize, - IN UINTN ActualFileSize, - IN EFI_GUID *FileName, - IN EFI_FV_FILETYPE FileType, - IN EFI_FV_FILE_ATTRIBUTES FileAttributes - ) -{ - EFI_FFS_FILE_ATTRIBUTES TmpFileAttribute; - EFI_FFS_FILE_HEADER *TmpFileHeader; - - // - // File Type value 0x0E~0xE0 are reserved - // - if ((FileType > EFI_FV_FILETYPE_SMM_CORE) && (FileType < 0xE0)) { - return EFI_INVALID_PARAMETER; - } - - TmpFileHeader = (EFI_FFS_FILE_HEADER *) FfsFileBuffer; - // - // First fill all fields ready in FfsFileBuffer - // - CopyGuid (&TmpFileHeader->Name, FileName); - TmpFileHeader->Type = FileType; - - // - // Convert the FileAttributes to FFSFileAttributes - // - FvFileAttrib2FfsFileAttrib (FileAttributes, &TmpFileAttribute); - - TmpFileHeader->Attributes = TmpFileAttribute; - - if (ActualFileSize > 0x00FFFFFF) { - ((EFI_FFS_FILE_HEADER2 *) FileHeader)->ExtendedSize = (UINT32) ActualFileSize; - *(UINT32 *) FileHeader->Size &= 0xFF000000; - FileHeader->Attributes |= FFS_ATTRIB_LARGE_FILE; - } else { - *(UINT32 *) FileHeader->Size &= 0xFF000000; - *(UINT32 *) FileHeader->Size |= ActualFileSize; - } - - SetHeaderChecksum (TmpFileHeader); - SetFileChecksum (TmpFileHeader, ActualFileSize); - - SetFileState (EFI_FILE_HEADER_CONSTRUCTION, TmpFileHeader); - SetFileState (EFI_FILE_HEADER_VALID, TmpFileHeader); - SetFileState (EFI_FILE_DATA_VALID, TmpFileHeader); - - // - // Copy data from FfsFileBuffer to FileHeader(cache) - // - CopyMem (FileHeader, FfsFileBuffer, BufferSize); - - return EFI_SUCCESS; -} - -/** - Fill some other extra space using 0xFF(Erase Value). - - @param ErasePolarity Fv erase value. - @param FileHeader Point to the start of FFS File. - @param ExtraLength The pading length. - -**/ -VOID -FvAdjustFfsFile ( - IN UINT8 ErasePolarity, - IN EFI_FFS_FILE_HEADER *FileHeader, - IN UINTN ExtraLength - ) -{ - UINT8 *Ptr; - UINT8 PadingByte; - - if (IS_FFS_FILE2 (FileHeader)) { - Ptr = (UINT8 *) FileHeader + FFS_FILE2_SIZE (FileHeader); - } else { - Ptr = (UINT8 *) FileHeader + FFS_FILE_SIZE (FileHeader); - } - - if (ErasePolarity == 0) { - PadingByte = 0; - } else { - PadingByte = 0xFF; - } - // - // Fill the non-used space with Padding Byte - // - SetMem (Ptr, ExtraLength, PadingByte); - - return ; -} - -/** - Free File List entry pointed by FileListHead. - - @param FileListHeader FileListEntry Header. - -**/ -VOID -FreeFileList ( - IN LIST_ENTRY *FileListHead - ) -{ - FFS_FILE_LIST_ENTRY *FfsFileEntry; - LIST_ENTRY *NextEntry; - - FfsFileEntry = (FFS_FILE_LIST_ENTRY *) (FileListHead->ForwardLink); - - // - // Loop the whole list entry to free resources - // - while (&FfsFileEntry->Link != FileListHead) { - NextEntry = (&FfsFileEntry->Link)->ForwardLink; - FreePool (FfsFileEntry); - FfsFileEntry = (FFS_FILE_LIST_ENTRY *) NextEntry; - } - - return ; -} - -/** - Create a new file within a PAD file area. - - @param FvDevice Firmware Volume Device. - @param FfsFileBuffer A buffer that holds an FFS file,(it contains a File Header which is in init state). - @param BufferSize The size of FfsFileBuffer. - @param ActualFileSize The actual file length, it may not be multiples of 8. - @param FileName The FFS File Name. - @param FileType The FFS File Type. - @param FileAttributes The Attributes of the FFS File to be created. - - @retval EFI_SUCCESS Successfully create a new file within the found PAD file area. - @retval EFI_OUT_OF_RESOURCES No suitable PAD file is found. - @retval other errors New file is created failed. - -**/ -EFI_STATUS -FvCreateNewFileInsidePadFile ( - IN FV_DEVICE *FvDevice, - IN UINT8 *FfsFileBuffer, - IN UINTN BufferSize, - IN UINTN ActualFileSize, - IN EFI_GUID *FileName, - IN EFI_FV_FILETYPE FileType, - IN EFI_FV_FILE_ATTRIBUTES FileAttributes - ) -{ - UINTN RequiredAlignment; - FFS_FILE_LIST_ENTRY *PadFileEntry; - EFI_STATUS Status; - UINTN PadAreaLength; - UINTN PadSize; - EFI_FFS_FILE_HEADER *FileHeader; - EFI_FFS_FILE_HEADER *OldPadFileHeader; - EFI_FFS_FILE_HEADER *PadFileHeader; - EFI_FFS_FILE_HEADER *TailPadFileHeader; - UINTN StateOffset; - UINTN Offset; - UINTN NumBytesWritten; - UINT8 *StartPos; - LIST_ENTRY NewFileList; - FFS_FILE_LIST_ENTRY *NewFileListEntry; - FFS_FILE_LIST_ENTRY *FfsEntry; - FFS_FILE_LIST_ENTRY *NextFfsEntry; - - // - // First get the required alignment from the File Attributes - // - RequiredAlignment = GetRequiredAlignment (FileAttributes); - - // - // Find a suitable PAD File - // - Status = FvLocatePadFile ( - FvDevice, - BufferSize, - RequiredAlignment, - &PadSize, - &PadFileEntry - ); - - if (EFI_ERROR (Status)) { - return EFI_OUT_OF_RESOURCES; - } - - OldPadFileHeader = (EFI_FFS_FILE_HEADER *) PadFileEntry->FfsHeader; - - // - // Step 1: Update Pad File Header - // - SetFileState (EFI_FILE_MARKED_FOR_UPDATE, OldPadFileHeader); - - StartPos = PadFileEntry->FfsHeader; - - Offset = (UINTN) (StartPos - FvDevice->CachedFv); - StateOffset = Offset + (UINT8 *) &OldPadFileHeader->State - (UINT8 *) OldPadFileHeader; - - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvcWrite ( - FvDevice, - StateOffset, - &NumBytesWritten, - &OldPadFileHeader->State - ); - if (EFI_ERROR (Status)) { - SetFileState (EFI_FILE_HEADER_CONSTRUCTION, OldPadFileHeader); - return Status; - } - - // - // Step 2: Update Pad area - // - InitializeListHead (&NewFileList); - - if (IS_FFS_FILE2 (OldPadFileHeader)) { - PadAreaLength = FFS_FILE2_SIZE (OldPadFileHeader) - sizeof (EFI_FFS_FILE_HEADER); - PadFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) OldPadFileHeader + sizeof (EFI_FFS_FILE_HEADER2)); - } else { - PadAreaLength = FFS_FILE_SIZE (OldPadFileHeader) - sizeof (EFI_FFS_FILE_HEADER); - PadFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) OldPadFileHeader + sizeof (EFI_FFS_FILE_HEADER)); - } - - if (PadSize != 0) { - // - // Insert a PAD file before to achieve required alignment - // - FvFillPadFile (PadFileHeader, PadSize); - NewFileListEntry = AllocatePool (sizeof (FFS_FILE_LIST_ENTRY)); - ASSERT (NewFileListEntry != NULL); - NewFileListEntry->FfsHeader = (UINT8 *) PadFileHeader; - InsertTailList (&NewFileList, &NewFileListEntry->Link); - } - - FileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) PadFileHeader + PadSize); - - Status = FvFillFfsFile ( - FileHeader, - FfsFileBuffer, - BufferSize, - ActualFileSize, - FileName, - FileType, - FileAttributes - ); - if (EFI_ERROR (Status)) { - FreeFileList (&NewFileList); - return Status; - } - - NewFileListEntry = AllocatePool (sizeof (FFS_FILE_LIST_ENTRY)); - ASSERT (NewFileListEntry != NULL); - - NewFileListEntry->FfsHeader = (UINT8 *) FileHeader; - InsertTailList (&NewFileList, &NewFileListEntry->Link); - - FvDevice->CurrentFfsFile = NewFileListEntry; - - if (PadAreaLength > (BufferSize + PadSize)) { - if ((PadAreaLength - BufferSize - PadSize) >= sizeof (EFI_FFS_FILE_HEADER)) { - // - // we can insert another PAD file - // - TailPadFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FileHeader + BufferSize); - FvFillPadFile (TailPadFileHeader, PadAreaLength - BufferSize - PadSize); - - NewFileListEntry = AllocatePool (sizeof (FFS_FILE_LIST_ENTRY)); - ASSERT (NewFileListEntry != NULL); - - NewFileListEntry->FfsHeader = (UINT8 *) TailPadFileHeader; - InsertTailList (&NewFileList, &NewFileListEntry->Link); - } else { - // - // because left size cannot hold another PAD file header, - // adjust the writing file size (just in cache) - // - FvAdjustFfsFile ( - FvDevice->ErasePolarity, - FileHeader, - PadAreaLength - BufferSize - PadSize - ); - } - } - // - // Start writing to FV - // - if (IS_FFS_FILE2 (OldPadFileHeader)) { - StartPos = (UINT8 *) OldPadFileHeader + sizeof (EFI_FFS_FILE_HEADER2); - } else { - StartPos = (UINT8 *) OldPadFileHeader + sizeof (EFI_FFS_FILE_HEADER); - } - - Offset = (UINTN) (StartPos - FvDevice->CachedFv); - - NumBytesWritten = PadAreaLength; - Status = FvcWrite ( - FvDevice, - Offset, - &NumBytesWritten, - StartPos - ); - if (EFI_ERROR (Status)) { - FreeFileList (&NewFileList); - FvDevice->CurrentFfsFile = NULL; - return Status; - } - - // - // Step 3: Mark Pad file header as EFI_FILE_HEADER_INVALID - // - SetFileState (EFI_FILE_HEADER_INVALID, OldPadFileHeader); - - StartPos = PadFileEntry->FfsHeader; - - Offset = (UINTN) (StartPos - FvDevice->CachedFv); - StateOffset = Offset + (UINT8 *) &OldPadFileHeader->State - (UINT8 *) OldPadFileHeader; - - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvcWrite ( - FvDevice, - StateOffset, - &NumBytesWritten, - &OldPadFileHeader->State - ); - if (EFI_ERROR (Status)) { - SetFileState (EFI_FILE_HEADER_INVALID, OldPadFileHeader); - FreeFileList (&NewFileList); - FvDevice->CurrentFfsFile = NULL; - return Status; - } - - // - // If all successfully, update FFS_FILE_LIST - // - - // - // Delete old pad file entry - // - FfsEntry = (FFS_FILE_LIST_ENTRY *) PadFileEntry->Link.BackLink; - NextFfsEntry = (FFS_FILE_LIST_ENTRY *) PadFileEntry->Link.ForwardLink; - - FreePool (PadFileEntry); - - FfsEntry->Link.ForwardLink = NewFileList.ForwardLink; - (NewFileList.ForwardLink)->BackLink = &FfsEntry->Link; - NextFfsEntry->Link.BackLink = NewFileList.BackLink; - (NewFileList.BackLink)->ForwardLink = &NextFfsEntry->Link; - - return EFI_SUCCESS; -} - -/** - Free all FfsBuffer. - - @param NumOfFiles Number of FfsBuffer. - @param FfsBuffer An array of pointer to an FFS File Buffer - -**/ -VOID -FreeFfsBuffer ( - IN UINTN NumOfFiles, - IN UINT8 **FfsBuffer - ) -{ - UINTN Index; - for (Index = 0; Index < NumOfFiles; Index++) { - if (FfsBuffer[Index] != NULL) { - FreePool (FfsBuffer[Index]); - } - } -} - -/** - Create multiple files within a PAD File area. - - @param FvDevice Firmware Volume Device. - @param PadFileEntry The pad file entry to be written in. - @param NumOfFiles Total File number to be written. - @param BufferSize The array of buffer size of each FfsBuffer. - @param ActualFileSize The array of actual file size. - @param PadSize The array of leading pad file size for each FFS File - @param FfsBuffer The array of Ffs Buffer pointer. - @param FileData The array of EFI_FV_WRITE_FILE_DATA structure, - used to get name, attributes, type, etc. - - @retval EFI_SUCCESS Add the input multiple files into PAD file area. - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval other error Files can't be added into PAD file area. - -**/ -EFI_STATUS -FvCreateMultipleFilesInsidePadFile ( - IN FV_DEVICE *FvDevice, - IN FFS_FILE_LIST_ENTRY *PadFileEntry, - IN UINTN NumOfFiles, - IN UINTN *BufferSize, - IN UINTN *ActualFileSize, - IN UINTN *PadSize, - IN UINT8 **FfsBuffer, - IN EFI_FV_WRITE_FILE_DATA *FileData - ) -{ - EFI_STATUS Status; - EFI_FFS_FILE_HEADER *OldPadFileHeader; - UINTN Index; - EFI_FFS_FILE_HEADER *PadFileHeader; - EFI_FFS_FILE_HEADER *FileHeader; - EFI_FFS_FILE_HEADER *TailPadFileHeader; - UINTN TotalSize; - UINTN PadAreaLength; - LIST_ENTRY NewFileList; - FFS_FILE_LIST_ENTRY *NewFileListEntry; - UINTN Offset; - UINTN NumBytesWritten; - UINT8 *StartPos; - FFS_FILE_LIST_ENTRY *FfsEntry; - FFS_FILE_LIST_ENTRY *NextFfsEntry; - - InitializeListHead (&NewFileList); - - NewFileListEntry = NULL; - - OldPadFileHeader = (EFI_FFS_FILE_HEADER *) PadFileEntry->FfsHeader; - if (IS_FFS_FILE2 (OldPadFileHeader)) { - PadAreaLength = FFS_FILE2_SIZE (OldPadFileHeader) - sizeof (EFI_FFS_FILE_HEADER2); - } else { - PadAreaLength = FFS_FILE_SIZE (OldPadFileHeader) - sizeof (EFI_FFS_FILE_HEADER); - } - - Status = UpdateHeaderBit ( - FvDevice, - OldPadFileHeader, - EFI_FILE_MARKED_FOR_UPDATE - ); - if (EFI_ERROR (Status)) { - return Status; - } - // - // Update PAD area - // - TotalSize = 0; - if (IS_FFS_FILE2 (OldPadFileHeader)) { - PadFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) OldPadFileHeader + sizeof (EFI_FFS_FILE_HEADER2)); - } else { - PadFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) OldPadFileHeader + sizeof (EFI_FFS_FILE_HEADER)); - } - FileHeader = PadFileHeader; - - for (Index = 0; Index < NumOfFiles; Index++) { - if (PadSize[Index] != 0) { - FvFillPadFile (PadFileHeader, PadSize[Index]); - NewFileListEntry = AllocatePool (sizeof (FFS_FILE_LIST_ENTRY)); - if (NewFileListEntry == NULL) { - FreeFileList (&NewFileList); - return EFI_OUT_OF_RESOURCES; - } - - NewFileListEntry->FfsHeader = (UINT8 *) PadFileHeader; - InsertTailList (&NewFileList, &NewFileListEntry->Link); - } - - FileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) PadFileHeader + PadSize[Index]); - Status = FvFillFfsFile ( - FileHeader, - FfsBuffer[Index], - BufferSize[Index], - ActualFileSize[Index], - FileData[Index].NameGuid, - FileData[Index].Type, - FileData[Index].FileAttributes - ); - if (EFI_ERROR (Status)) { - FreeFileList (&NewFileList); - return Status; - } - - NewFileListEntry = AllocatePool (sizeof (FFS_FILE_LIST_ENTRY)); - if (NewFileListEntry == NULL) { - FreeFileList (&NewFileList); - return EFI_OUT_OF_RESOURCES; - } - - NewFileListEntry->FfsHeader = (UINT8 *) FileHeader; - InsertTailList (&NewFileList, &NewFileListEntry->Link); - - PadFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FileHeader + BufferSize[Index]); - TotalSize += PadSize[Index]; - TotalSize += BufferSize[Index]; - } - - FvDevice->CurrentFfsFile = NewFileListEntry; - // - // Maybe we need a tail pad file - // - if (PadAreaLength > TotalSize) { - if ((PadAreaLength - TotalSize) >= sizeof (EFI_FFS_FILE_HEADER)) { - // - // we can insert another PAD file - // - TailPadFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FileHeader + BufferSize[NumOfFiles - 1]); - FvFillPadFile (TailPadFileHeader, PadAreaLength - TotalSize); - - NewFileListEntry = AllocatePool (sizeof (FFS_FILE_LIST_ENTRY)); - if (NewFileListEntry == NULL) { - FreeFileList (&NewFileList); - FvDevice->CurrentFfsFile = NULL; - return EFI_OUT_OF_RESOURCES; - } - - NewFileListEntry->FfsHeader = (UINT8 *) TailPadFileHeader; - InsertTailList (&NewFileList, &NewFileListEntry->Link); - } else { - // - // because left size cannot hold another PAD file header, - // adjust the writing file size (just in cache) - // - FvAdjustFfsFile ( - FvDevice->ErasePolarity, - FileHeader, - PadAreaLength - TotalSize - ); - } - } - // - // Start writing to FV - // - if (IS_FFS_FILE2 (OldPadFileHeader)) { - StartPos = (UINT8 *) OldPadFileHeader + sizeof (EFI_FFS_FILE_HEADER2); - } else { - StartPos = (UINT8 *) OldPadFileHeader + sizeof (EFI_FFS_FILE_HEADER); - } - - Offset = (UINTN) (StartPos - FvDevice->CachedFv); - - NumBytesWritten = PadAreaLength; - Status = FvcWrite ( - FvDevice, - Offset, - &NumBytesWritten, - StartPos - ); - if (EFI_ERROR (Status)) { - FreeFileList (&NewFileList); - FvDevice->CurrentFfsFile = NULL; - return Status; - } - - Status = UpdateHeaderBit ( - FvDevice, - OldPadFileHeader, - EFI_FILE_HEADER_INVALID - ); - if (EFI_ERROR (Status)) { - FreeFileList (&NewFileList); - FvDevice->CurrentFfsFile = NULL; - return Status; - } - - // - // Update File List Link - // - - // - // First delete old pad file entry - // - FfsEntry = (FFS_FILE_LIST_ENTRY *) PadFileEntry->Link.BackLink; - NextFfsEntry = (FFS_FILE_LIST_ENTRY *) PadFileEntry->Link.ForwardLink; - - FreePool (PadFileEntry); - - FfsEntry->Link.ForwardLink = NewFileList.ForwardLink; - (NewFileList.ForwardLink)->BackLink = &FfsEntry->Link; - NextFfsEntry->Link.BackLink = NewFileList.BackLink; - (NewFileList.BackLink)->ForwardLink = &NextFfsEntry->Link; - - return EFI_SUCCESS; -} - -/** - Create multiple files within the Free Space. - - @param FvDevice Firmware Volume Device. - @param FreeSpaceEntry Indicating in which Free Space(Cache) the multiple files will be inserted. - @param NumOfFiles Total File number to be written. - @param BufferSize The array of buffer size of each FfsBuffer. - @param ActualFileSize The array of actual file size. - @param PadSize The array of leading pad file size for each FFS File - @param FfsBuffer The array of Ffs Buffer pointer. - @param FileData The array of EFI_FV_WRITE_FILE_DATA structure, - used to get name, attributes, type, etc. - - @retval EFI_SUCCESS Add the input multiple files into PAD file area. - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval other error Files can't be added into PAD file area. - -**/ -EFI_STATUS -FvCreateMultipleFilesInsideFreeSpace ( - IN FV_DEVICE *FvDevice, - IN FREE_SPACE_ENTRY *FreeSpaceEntry, - IN UINTN NumOfFiles, - IN UINTN *BufferSize, - IN UINTN *ActualFileSize, - IN UINTN *PadSize, - IN UINT8 **FfsBuffer, - IN EFI_FV_WRITE_FILE_DATA *FileData - ) -{ - EFI_STATUS Status; - UINTN Index; - EFI_FFS_FILE_HEADER *PadFileHeader; - EFI_FFS_FILE_HEADER *FileHeader; - UINTN TotalSize; - LIST_ENTRY NewFileList; - FFS_FILE_LIST_ENTRY *NewFileListEntry; - UINTN Offset; - UINTN NumBytesWritten; - UINT8 *StartPos; - - InitializeListHead (&NewFileList); - - NewFileListEntry = NULL; - - TotalSize = 0; - StartPos = FreeSpaceEntry->StartingAddress; - PadFileHeader = (EFI_FFS_FILE_HEADER *) StartPos; - FileHeader = PadFileHeader; - - for (Index = 0; Index < NumOfFiles; Index++) { - if (PadSize[Index] != 0) { - FvFillPadFile (PadFileHeader, PadSize[Index]); - NewFileListEntry = AllocatePool (sizeof (FFS_FILE_LIST_ENTRY)); - if (NewFileListEntry == NULL) { - FreeFileList (&NewFileList); - return EFI_OUT_OF_RESOURCES; - } - - NewFileListEntry->FfsHeader = (UINT8 *) PadFileHeader; - InsertTailList (&NewFileList, &NewFileListEntry->Link); - } - - FileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) PadFileHeader + PadSize[Index]); - Status = FvFillFfsFile ( - FileHeader, - FfsBuffer[Index], - BufferSize[Index], - ActualFileSize[Index], - FileData[Index].NameGuid, - FileData[Index].Type, - FileData[Index].FileAttributes - ); - if (EFI_ERROR (Status)) { - FreeFileList (&NewFileList); - return Status; - } - - NewFileListEntry = AllocatePool (sizeof (FFS_FILE_LIST_ENTRY)); - if (NewFileListEntry == NULL) { - FreeFileList (&NewFileList); - return EFI_OUT_OF_RESOURCES; - } - - NewFileListEntry->FfsHeader = (UINT8 *) FileHeader; - InsertTailList (&NewFileList, &NewFileListEntry->Link); - - PadFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FileHeader + BufferSize[Index]); - TotalSize += PadSize[Index]; - TotalSize += BufferSize[Index]; - } - - if (FreeSpaceEntry->Length < TotalSize) { - FreeFileList (&NewFileList); - return EFI_OUT_OF_RESOURCES; - } - - FvDevice->CurrentFfsFile = NewFileListEntry; - - // - // Start writing to FV - // - Offset = (UINTN) (StartPos - FvDevice->CachedFv); - - NumBytesWritten = TotalSize; - Status = FvcWrite ( - FvDevice, - Offset, - &NumBytesWritten, - StartPos - ); - if (EFI_ERROR (Status)) { - FreeFileList (&NewFileList); - FvDevice->CurrentFfsFile = NULL; - return Status; - } - - FreeSpaceEntry->Length -= TotalSize; - FreeSpaceEntry->StartingAddress += TotalSize; - - NewFileListEntry = (FFS_FILE_LIST_ENTRY *) (NewFileList.ForwardLink); - - while (NewFileListEntry != (FFS_FILE_LIST_ENTRY *) &NewFileList) { - InsertTailList (&FvDevice->FfsFileListHeader, &NewFileListEntry->Link); - NewFileListEntry = (FFS_FILE_LIST_ENTRY *) (NewFileListEntry->Link.ForwardLink); - } - - return EFI_SUCCESS; -} - -/** - Write multiple files into FV in reliable method. - - @param FvDevice Firmware Volume Device. - @param NumOfFiles Total File number to be written. - @param FileData The array of EFI_FV_WRITE_FILE_DATA structure, - used to get name, attributes, type, etc - @param FileOperation The array of operation for each file. - - @retval EFI_SUCCESS Files are added into FV. - @retval EFI_OUT_OF_RESOURCES No enough free PAD files to add the input files. - @retval EFI_INVALID_PARAMETER File number is less than or equal to 1. - @retval EFI_UNSUPPORTED File number exceeds the supported max numbers of files. - -**/ -EFI_STATUS -FvCreateMultipleFiles ( - IN FV_DEVICE *FvDevice, - IN UINTN NumOfFiles, - IN EFI_FV_WRITE_FILE_DATA *FileData, - IN BOOLEAN *FileOperation - ) -{ - EFI_STATUS Status; - UINT8 *FfsBuffer[MAX_FILES]; - UINTN Index1; - UINTN Index2; - UINTN BufferSize[MAX_FILES]; - UINTN ActualFileSize[MAX_FILES]; - UINTN RequiredAlignment[MAX_FILES]; - UINTN PadSize[MAX_FILES]; - FFS_FILE_LIST_ENTRY *PadFileEntry; - UINTN TotalSizeNeeded; - FREE_SPACE_ENTRY *FreeSpaceEntry; - EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; - UINTN Key; - EFI_GUID FileNameGuid; - EFI_FV_FILETYPE OldFileType; - EFI_FV_FILE_ATTRIBUTES OldFileAttributes; - UINTN OldFileSize; - FFS_FILE_LIST_ENTRY *OldFfsFileEntry[MAX_FILES]; - EFI_FFS_FILE_HEADER *OldFileHeader[MAX_FILES]; - BOOLEAN IsCreateFile; - UINTN HeaderSize; - - // - // To use this function, we must ensure that the NumOfFiles is great - // than 1 - // - if (NumOfFiles <= 1) { - return EFI_INVALID_PARAMETER; - } - - if (NumOfFiles > MAX_FILES) { - return EFI_UNSUPPORTED; - } - - Fv = &FvDevice->Fv; - - SetMem (FfsBuffer, NumOfFiles, 0); - SetMem (RequiredAlignment, NumOfFiles, 8); - SetMem (PadSize, NumOfFiles, 0); - ZeroMem (OldFfsFileEntry, sizeof (OldFfsFileEntry)); - ZeroMem (OldFileHeader, sizeof (OldFileHeader)); - - // - // Adjust file size - // - for (Index1 = 0; Index1 < NumOfFiles; Index1++) { - HeaderSize = sizeof (EFI_FFS_FILE_HEADER); - ActualFileSize[Index1] = FileData[Index1].BufferSize + HeaderSize; - if (ActualFileSize[Index1] > 0x00FFFFFF) { - HeaderSize = sizeof (EFI_FFS_FILE_HEADER2); - ActualFileSize[Index1] = FileData[Index1].BufferSize + HeaderSize; - } - BufferSize[Index1] = ActualFileSize[Index1]; - - if (BufferSize[Index1] == HeaderSize) { - // - // clear file attributes, zero-length file does not have any attributes - // - FileData[Index1].FileAttributes = 0; - } - - while ((BufferSize[Index1] & 0x07) != 0) { - BufferSize[Index1]++; - } - - FfsBuffer[Index1] = AllocateZeroPool (BufferSize[Index1]); - - // - // Copy File Data into FileBuffer - // - CopyMem ( - FfsBuffer[Index1] + HeaderSize, - FileData[Index1].Buffer, - FileData[Index1].BufferSize - ); - - if (FvDevice->ErasePolarity == 1) { - for (Index2 = 0; Index2 < HeaderSize; Index2++) { - FfsBuffer[Index1][Index2] = (UINT8)~FfsBuffer[Index1][Index2]; - } - } - - if ((FileData[Index1].FileAttributes & EFI_FV_FILE_ATTRIB_ALIGNMENT) != 0) { - RequiredAlignment[Index1] = GetRequiredAlignment (FileData[Index1].FileAttributes); - } - // - // If update file, mark the original file header to - // EFI_FILE_MARKED_FOR_UPDATE - // - IsCreateFile = FileOperation[Index1]; - if (!IsCreateFile) { - - Key = 0; - do { - OldFileType = 0; - Status = Fv->GetNextFile ( - Fv, - &Key, - &OldFileType, - &FileNameGuid, - &OldFileAttributes, - &OldFileSize - ); - if (EFI_ERROR (Status)) { - FreeFfsBuffer (NumOfFiles, FfsBuffer); - return Status; - } - } while (!CompareGuid (&FileNameGuid, FileData[Index1].NameGuid)); - - // - // Get FfsFileEntry from the search key - // - OldFfsFileEntry[Index1] = (FFS_FILE_LIST_ENTRY *) Key; - OldFileHeader[Index1] = (EFI_FFS_FILE_HEADER *) OldFfsFileEntry[Index1]->FfsHeader; - Status = UpdateHeaderBit ( - FvDevice, - OldFileHeader[Index1], - EFI_FILE_MARKED_FOR_UPDATE - ); - if (EFI_ERROR (Status)) { - FreeFfsBuffer (NumOfFiles, FfsBuffer); - return Status; - } - } - } - // - // First to search a suitable pad file that can hold so - // many files - // - Status = FvSearchSuitablePadFile ( - FvDevice, - NumOfFiles, - BufferSize, - RequiredAlignment, - PadSize, - &TotalSizeNeeded, - &PadFileEntry - ); - - if (Status == EFI_NOT_FOUND) { - // - // Try to find a free space that can hold these files - // - Status = FvSearchSuitableFreeSpace ( - FvDevice, - NumOfFiles, - BufferSize, - RequiredAlignment, - PadSize, - &TotalSizeNeeded, - &FreeSpaceEntry - ); - if (EFI_ERROR (Status)) { - FreeFfsBuffer (NumOfFiles, FfsBuffer); - return EFI_OUT_OF_RESOURCES; - } - Status = FvCreateMultipleFilesInsideFreeSpace ( - FvDevice, - FreeSpaceEntry, - NumOfFiles, - BufferSize, - ActualFileSize, - PadSize, - FfsBuffer, - FileData - ); - - } else { - // - // Create multiple files inside such a pad file - // to achieve lock-step update - // - Status = FvCreateMultipleFilesInsidePadFile ( - FvDevice, - PadFileEntry, - NumOfFiles, - BufferSize, - ActualFileSize, - PadSize, - FfsBuffer, - FileData - ); - } - - FreeFfsBuffer (NumOfFiles, FfsBuffer); - - if (EFI_ERROR (Status)) { - return Status; - } - // - // Delete those updated files - // - for (Index1 = 0; Index1 < NumOfFiles; Index1++) { - IsCreateFile = FileOperation[Index1]; - if (!IsCreateFile && OldFfsFileEntry[Index1] != NULL) { - (OldFfsFileEntry[Index1]->Link.BackLink)->ForwardLink = OldFfsFileEntry[Index1]->Link.ForwardLink; - (OldFfsFileEntry[Index1]->Link.ForwardLink)->BackLink = OldFfsFileEntry[Index1]->Link.BackLink; - FreePool (OldFfsFileEntry[Index1]); - } - } - // - // Set those files' state to EFI_FILE_DELETED - // - for (Index1 = 0; Index1 < NumOfFiles; Index1++) { - IsCreateFile = FileOperation[Index1]; - if (!IsCreateFile && OldFileHeader[Index1] != NULL) { - Status = UpdateHeaderBit (FvDevice, OldFileHeader[Index1], EFI_FILE_DELETED); - if (EFI_ERROR (Status)) { - return Status; - } - } - } - - return EFI_SUCCESS; -} diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVol.c b/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVol.c deleted file mode 100644 index 65a292db6b..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVol.c +++ /dev/null @@ -1,798 +0,0 @@ -/** @file - - Firmware File System driver that produce full Firmware Volume2 protocol. - Layers on top of Firmware Block protocol to produce a file abstraction - of FV based files. - - Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "FwVolDriver.h" - -#define KEYSIZE sizeof (UINTN) - -/** - Given the supplied FW_VOL_BLOCK_PROTOCOL, allocate a buffer for output and - copy the real length volume header into it. - - @param Fvb The FW_VOL_BLOCK_PROTOCOL instance from which to - read the volume header - @param FwVolHeader Pointer to pointer to allocated buffer in which - the volume header is returned. - - @retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated. - @retval EFI_SUCCESS Successfully read volume header to the allocated - buffer. - @retval EFI_ACCESS_DENIED Read status of FV is not enabled. - @retval EFI_INVALID_PARAMETER The FV Header signature is not as expected or - the file system could not be understood. -**/ -EFI_STATUS -GetFwVolHeader ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb, - OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader - ) -{ - EFI_STATUS Status; - EFI_FIRMWARE_VOLUME_HEADER TempFvh; - EFI_FVB_ATTRIBUTES_2 FvbAttributes; - UINTN FvhLength; - EFI_PHYSICAL_ADDRESS BaseAddress; - - // - // Determine the real length of FV header - // - Status = Fvb->GetAttributes ( - Fvb, - &FvbAttributes - ); - if (EFI_ERROR (Status)) { - return Status; - } - - if ((FvbAttributes & EFI_FVB2_READ_STATUS) == 0) { - return EFI_ACCESS_DENIED; - } - - // - // Just avoid compiling warning - // - BaseAddress = 0; - FvhLength = sizeof (EFI_FIRMWARE_VOLUME_HEADER); - - // - // memory-mapped FV and non memory-mapped has different ways to read - // - if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) { - Status = Fvb->GetPhysicalAddress ( - Fvb, - &BaseAddress - ); - if (EFI_ERROR (Status)) { - return Status; - } - CopyMem (&TempFvh, (VOID *) (UINTN) BaseAddress, FvhLength); - } else { - Status = Fvb->Read ( - Fvb, - 0, - 0, - &FvhLength, - (UINT8 *) &TempFvh - ); - } - - // - // Validate FV Header signature, if not as expected, continue. - // - if (TempFvh.Signature != EFI_FVH_SIGNATURE) { - return EFI_INVALID_PARAMETER; - } - - // - // Check to see that the file system is indeed formatted in a way we can - // understand it... - // - if ((!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) && - (!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) { - return EFI_INVALID_PARAMETER; - } - - *FwVolHeader = AllocatePool (TempFvh.HeaderLength); - if (*FwVolHeader == NULL) { - return EFI_OUT_OF_RESOURCES; - } - // - // Read the whole header - // - if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) { - CopyMem (*FwVolHeader, (VOID *) (UINTN) BaseAddress, TempFvh.HeaderLength); - } else { - // - // Assumed the first block is bigger than the length of Fv headder - // - FvhLength = TempFvh.HeaderLength; - Status = Fvb->Read ( - Fvb, - 0, - 0, - &FvhLength, - (UINT8 *) *FwVolHeader - ); - // - // Check whether Read successes. - // - if (EFI_ERROR (Status)) { - FreePool (*FwVolHeader); - *FwVolHeader = NULL; - return Status; - } - } - - return EFI_SUCCESS; -} - -/** - Free FvDevice resource when error happens. - - @param FvDevice Pointer to the FvDevice to be freed. -**/ -VOID -FreeFvDeviceResource ( - IN FV_DEVICE *FvDevice - ) -{ - LBA_ENTRY *LbaEntry; - FREE_SPACE_ENTRY *FreeSpaceEntry; - FFS_FILE_LIST_ENTRY *FfsFileEntry; - LIST_ENTRY *NextEntry; - - // - // Free LAB Entry - // - LbaEntry = (LBA_ENTRY *) FvDevice->LbaHeader.ForwardLink; - while (&LbaEntry->Link != &FvDevice->LbaHeader) { - NextEntry = (&LbaEntry->Link)->ForwardLink; - FreePool (LbaEntry); - LbaEntry = (LBA_ENTRY *) NextEntry; - } - // - // Free File List Entry - // - FfsFileEntry = (FFS_FILE_LIST_ENTRY *) FvDevice->FfsFileListHeader.ForwardLink; - while (&FfsFileEntry->Link != &FvDevice->FfsFileListHeader) { - NextEntry = (&FfsFileEntry->Link)->ForwardLink; - FreePool (FfsFileEntry); - FfsFileEntry = (FFS_FILE_LIST_ENTRY *) NextEntry; - } - // - // Free Space Entry - // - FreeSpaceEntry = (FREE_SPACE_ENTRY *) FvDevice->FreeSpaceHeader.ForwardLink; - while (&FreeSpaceEntry->Link != &FvDevice->FreeSpaceHeader) { - NextEntry = (&FreeSpaceEntry->Link)->ForwardLink; - FreePool (FreeSpaceEntry); - FreeSpaceEntry = (FREE_SPACE_ENTRY *) NextEntry; - } - // - // Free the cache - // - FreePool ((UINT8 *) (UINTN) FvDevice->CachedFv); - - return ; -} - -/** - - Firmware volume inherits authentication status from the FV image file and section(in another firmware volume) - where it came from. - - @param FvDevice A pointer to the FvDevice. - -**/ -VOID -FwVolInheritAuthenticationStatus ( - IN FV_DEVICE *FvDevice - ) -{ - EFI_STATUS Status; - EFI_FIRMWARE_VOLUME_HEADER *CachedFvHeader; - EFI_FIRMWARE_VOLUME_EXT_HEADER *CachedFvExtHeader; - EFI_FIRMWARE_VOLUME2_PROTOCOL *ParentFvProtocol; - UINTN Key; - EFI_GUID FileNameGuid; - EFI_FV_FILETYPE FileType; - EFI_FV_FILE_ATTRIBUTES FileAttributes; - UINTN FileSize; - EFI_SECTION_TYPE SectionType; - UINT32 AuthenticationStatus; - EFI_FIRMWARE_VOLUME_HEADER *FvHeader; - EFI_FIRMWARE_VOLUME_EXT_HEADER *FvExtHeader; - UINTN BufferSize; - - CachedFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FvDevice->CachedFv; - - if (FvDevice->Fv.ParentHandle != NULL) { - // - // By Parent Handle, find out the FV image file and section(in another firmware volume) where the firmware volume came from - // - Status = gBS->HandleProtocol (FvDevice->Fv.ParentHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **) &ParentFvProtocol); - if (!EFI_ERROR (Status) && (ParentFvProtocol != NULL)) { - Key = 0; - do { - FileType = EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE; - Status = ParentFvProtocol->GetNextFile ( - ParentFvProtocol, - &Key, - &FileType, - &FileNameGuid, - &FileAttributes, - &FileSize - ); - if (EFI_ERROR (Status)) { - return; - } - - SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE; - FvHeader = NULL; - BufferSize = 0; - Status = ParentFvProtocol->ReadSection ( - ParentFvProtocol, - &FileNameGuid, - SectionType, - 0, - (VOID **) &FvHeader, - &BufferSize, - &AuthenticationStatus - ); - if (!EFI_ERROR (Status)) { - if ((FvHeader->FvLength == CachedFvHeader->FvLength) && - (FvHeader->ExtHeaderOffset == CachedFvHeader->ExtHeaderOffset)) { - if (FvHeader->ExtHeaderOffset !=0) { - // - // Both FVs contain extension header, then compare their FV Name GUID - // - FvExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) ((UINTN) FvHeader + FvHeader->ExtHeaderOffset); - CachedFvExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) ((UINTN) CachedFvHeader + CachedFvHeader->ExtHeaderOffset); - if (CompareGuid (&FvExtHeader->FvName, &CachedFvExtHeader->FvName)) { - // - // Found the FV image section where the firmware volume came from, - // and then inherit authentication status from it. - // - FvDevice->AuthenticationStatus = AuthenticationStatus; - FreePool ((VOID *) FvHeader); - return; - } - } else { - // - // Both FVs don't contain extension header, then compare their whole FV Image. - // - if (CompareMem ((VOID *) FvHeader, (VOID *) CachedFvHeader, (UINTN) FvHeader->FvLength) == 0) { - // - // Found the FV image section where the firmware volume came from - // and then inherit authentication status from it. - // - FvDevice->AuthenticationStatus = AuthenticationStatus; - FreePool ((VOID *) FvHeader); - return; - } - } - } - FreePool ((VOID *) FvHeader); - } - } while (TRUE); - } - } -} - -/** - Check if an FV is consistent and allocate cache for it. - - @param FvDevice A pointer to the FvDevice to be checked. - - @retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated. - @retval EFI_VOLUME_CORRUPTED File system is corrupted. - @retval EFI_SUCCESS FV is consistent and cache is allocated. - -**/ -EFI_STATUS -FvCheck ( - IN FV_DEVICE *FvDevice - ) -{ - EFI_STATUS Status; - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; - EFI_FVB_ATTRIBUTES_2 FvbAttributes; - EFI_FV_BLOCK_MAP_ENTRY *BlockMap; - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - EFI_FIRMWARE_VOLUME_EXT_HEADER *FwVolExtHeader; - UINT8 *FwCache; - LBA_ENTRY *LbaEntry; - FREE_SPACE_ENTRY *FreeSpaceEntry; - FFS_FILE_LIST_ENTRY *FfsFileEntry; - UINT8 *LbaStart; - UINTN Index; - EFI_LBA LbaIndex; - UINT8 *Ptr; - UINTN Size; - UINT8 *FreeStart; - UINTN FreeSize; - UINT8 ErasePolarity; - EFI_FFS_FILE_STATE FileState; - UINT8 *TopFvAddress; - UINTN TestLength; - EFI_PHYSICAL_ADDRESS BaseAddress; - - Fvb = FvDevice->Fvb; - - Status = Fvb->GetAttributes (Fvb, &FvbAttributes); - if (EFI_ERROR (Status)) { - return Status; - } - - InitializeListHead (&FvDevice->LbaHeader); - InitializeListHead (&FvDevice->FreeSpaceHeader); - InitializeListHead (&FvDevice->FfsFileListHeader); - - FwVolHeader = NULL; - Status = GetFwVolHeader (Fvb, &FwVolHeader); - if (EFI_ERROR (Status)) { - return Status; - } - ASSERT (FwVolHeader != NULL); - - FvDevice->IsFfs3Fv = CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem3Guid); - - // - // Double Check firmware volume header here - // - if (!VerifyFvHeaderChecksum (FwVolHeader)) { - FreePool (FwVolHeader); - return EFI_VOLUME_CORRUPTED; - } - - BlockMap = FwVolHeader->BlockMap; - - // - // FwVolHeader->FvLength is the whole FV length including FV header - // - FwCache = AllocateZeroPool ((UINTN) FwVolHeader->FvLength); - if (FwCache == NULL) { - FreePool (FwVolHeader); - return EFI_OUT_OF_RESOURCES; - } - - FvDevice->CachedFv = (EFI_PHYSICAL_ADDRESS) (UINTN) FwCache; - - // - // Copy to memory - // - LbaStart = FwCache; - LbaIndex = 0; - Ptr = NULL; - - if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) { - // - // Get volume base address - // - Status = Fvb->GetPhysicalAddress (Fvb, &BaseAddress); - if (EFI_ERROR (Status)) { - FreePool (FwVolHeader); - return Status; - } - - Ptr = (UINT8 *) ((UINTN) BaseAddress); - - DEBUG((EFI_D_INFO, "Fv Base Address is 0x%LX\n", BaseAddress)); - } - // - // Copy whole FV into the memory - // - while ((BlockMap->NumBlocks != 0) || (BlockMap->Length != 0)) { - - for (Index = 0; Index < BlockMap->NumBlocks; Index++) { - LbaEntry = AllocatePool (sizeof (LBA_ENTRY)); - if (LbaEntry == NULL) { - FreePool (FwVolHeader); - FreeFvDeviceResource (FvDevice); - return EFI_OUT_OF_RESOURCES; - } - - LbaEntry->LbaIndex = LbaIndex; - LbaEntry->StartingAddress = LbaStart; - LbaEntry->BlockLength = BlockMap->Length; - - // - // Copy each LBA into memory - // - if ((FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) { - - CopyMem (LbaStart, Ptr, BlockMap->Length); - Ptr += BlockMap->Length; - - } else { - - Size = BlockMap->Length; - Status = Fvb->Read ( - Fvb, - LbaIndex, - 0, - &Size, - LbaStart - ); - // - // Not check EFI_BAD_BUFFER_SIZE, for Size = BlockMap->Length - // - if (EFI_ERROR (Status)) { - FreePool (FwVolHeader); - FreeFvDeviceResource (FvDevice); - return Status; - } - - } - - LbaIndex++; - LbaStart += BlockMap->Length; - - InsertTailList (&FvDevice->LbaHeader, &LbaEntry->Link); - } - - BlockMap++; - } - - FvDevice->FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) FwCache; - - // - // it is not used any more, so free FwVolHeader - // - FreePool (FwVolHeader); - - // - // Scan to check the free space & File list - // - if ((FvbAttributes & EFI_FVB2_ERASE_POLARITY) != 0) { - ErasePolarity = 1; - } else { - ErasePolarity = 0; - } - - FvDevice->ErasePolarity = ErasePolarity; - - // - // go through the whole FV cache, check the consistence of the FV - // - if (FvDevice->FwVolHeader->ExtHeaderOffset != 0) { - // - // Searching for files starts on an 8 byte aligned boundary after the end of the Extended Header if it exists. - // - FwVolExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) (UINTN) (FvDevice->CachedFv + FvDevice->FwVolHeader->ExtHeaderOffset); - Ptr = (UINT8 *) FwVolExtHeader + FwVolExtHeader->ExtHeaderSize; - Ptr = (UINT8 *) ALIGN_POINTER (Ptr, 8); - } else { - Ptr = (UINT8 *) (UINTN) (FvDevice->CachedFv + FvDevice->FwVolHeader->HeaderLength); - } - TopFvAddress = (UINT8 *) (UINTN) (FvDevice->CachedFv + FvDevice->FwVolHeader->FvLength); - - // - // Build FFS list & Free Space List here - // - while (Ptr < TopFvAddress) { - TestLength = TopFvAddress - Ptr; - - if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) { - TestLength = sizeof (EFI_FFS_FILE_HEADER); - } - - if (IsBufferErased (ErasePolarity, Ptr, TestLength)) { - // - // We found free space - // - FreeStart = Ptr; - FreeSize = 0; - - do { - TestLength = TopFvAddress - Ptr; - - if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) { - TestLength = sizeof (EFI_FFS_FILE_HEADER); - } - - if (!IsBufferErased (ErasePolarity, Ptr, TestLength)) { - break; - } - - FreeSize += TestLength; - Ptr += TestLength; - } while (Ptr < TopFvAddress); - - FreeSpaceEntry = AllocateZeroPool (sizeof (FREE_SPACE_ENTRY)); - if (FreeSpaceEntry == NULL) { - FreeFvDeviceResource (FvDevice); - return EFI_OUT_OF_RESOURCES; - } - // - // Create a Free space entry - // - FreeSpaceEntry->StartingAddress = FreeStart; - FreeSpaceEntry->Length = FreeSize; - InsertTailList (&FvDevice->FreeSpaceHeader, &FreeSpaceEntry->Link); - continue; - } - // - // double check boundary - // - if (TestLength < sizeof (EFI_FFS_FILE_HEADER)) { - break; - } - - if (!IsValidFFSHeader ( - FvDevice->ErasePolarity, - (EFI_FFS_FILE_HEADER *) Ptr - )) { - FileState = GetFileState ( - FvDevice->ErasePolarity, - (EFI_FFS_FILE_HEADER *) Ptr - ); - if ((FileState == EFI_FILE_HEADER_INVALID) || (FileState == EFI_FILE_HEADER_CONSTRUCTION)) { - if (IS_FFS_FILE2 (Ptr)) { - if (!FvDevice->IsFfs3Fv) { - DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &((EFI_FFS_FILE_HEADER *) Ptr)->Name)); - } - Ptr = Ptr + sizeof (EFI_FFS_FILE_HEADER2); - } else { - Ptr = Ptr + sizeof (EFI_FFS_FILE_HEADER); - } - - continue; - - } else { - // - // File system is corrputed, return - // - FreeFvDeviceResource (FvDevice); - return EFI_VOLUME_CORRUPTED; - } - } - - if (IS_FFS_FILE2 (Ptr)) { - ASSERT (FFS_FILE2_SIZE (Ptr) > 0x00FFFFFF); - if (!FvDevice->IsFfs3Fv) { - DEBUG ((EFI_D_ERROR, "Found a FFS3 formatted file: %g in a non-FFS3 formatted FV.\n", &((EFI_FFS_FILE_HEADER *) Ptr)->Name)); - Ptr = Ptr + FFS_FILE2_SIZE (Ptr); - // - // Adjust Ptr to the next 8-byte aligned boundary. - // - while (((UINTN) Ptr & 0x07) != 0) { - Ptr++; - } - continue; - } - } - - if (IsValidFFSFile (FvDevice, (EFI_FFS_FILE_HEADER *) Ptr)) { - FileState = GetFileState ( - FvDevice->ErasePolarity, - (EFI_FFS_FILE_HEADER *) Ptr - ); - - // - // check for non-deleted file - // - if (FileState != EFI_FILE_DELETED) { - // - // Create a FFS list entry for each non-deleted file - // - FfsFileEntry = AllocateZeroPool (sizeof (FFS_FILE_LIST_ENTRY)); - if (FfsFileEntry == NULL) { - FreeFvDeviceResource (FvDevice); - return EFI_OUT_OF_RESOURCES; - } - - FfsFileEntry->FfsHeader = Ptr; - InsertTailList (&FvDevice->FfsFileListHeader, &FfsFileEntry->Link); - } - - if (IS_FFS_FILE2 (Ptr)) { - Ptr = Ptr + FFS_FILE2_SIZE (Ptr); - } else { - Ptr = Ptr + FFS_FILE_SIZE (Ptr); - } - - // - // Adjust Ptr to the next 8-byte aligned boundary. - // - while (((UINTN) Ptr & 0x07) != 0) { - Ptr++; - } - } else { - // - // File system is corrupted, return - // - FreeFvDeviceResource (FvDevice); - return EFI_VOLUME_CORRUPTED; - } - } - - FvDevice->CurrentFfsFile = NULL; - - return EFI_SUCCESS; -} - -/** - Entry point function does install/reinstall FV2 protocol with full functionality. - - @param ImageHandle A handle for the image that is initializing this driver - @param SystemTable A pointer to the EFI system table - - @retval EFI_SUCCESS At least one Fv protocol install/reinstall successfully. - @retval EFI_NOT_FOUND No FV protocol install/reinstall successfully. -**/ -EFI_STATUS -EFIAPI -FwVolDriverInit ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_STATUS Status; - EFI_HANDLE *HandleBuffer; - UINTN HandleCount; - UINTN Index; - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; - EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; - FV_DEVICE *FvDevice; - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - BOOLEAN Reinstall; - BOOLEAN InstallFlag; - - DEBUG ((EFI_D_INFO, "=========FwVol writable driver installed\n")); - InstallFlag = FALSE; - // - // Locate all handles of Fvb protocol - // - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiFirmwareVolumeBlockProtocolGuid, - NULL, - &HandleCount, - &HandleBuffer - ); - if (EFI_ERROR (Status)) { - return EFI_NOT_FOUND; - } - - for (Index = 0; Index < HandleCount; Index += 1) { - Status = gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiFirmwareVolumeBlockProtocolGuid, - (VOID **) &Fvb - ); - if (EFI_ERROR (Status)) { - continue; - } - - FwVolHeader = NULL; - Status = GetFwVolHeader (Fvb, &FwVolHeader); - if (EFI_ERROR (Status)) { - continue; - } - ASSERT (FwVolHeader != NULL); - FreePool (FwVolHeader); - - Reinstall = FALSE; - // - // Check if there is an FV protocol already installed in that handle - // - Status = gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiFirmwareVolume2ProtocolGuid, - (VOID **) &Fv - ); - if (!EFI_ERROR (Status)) { - Reinstall = TRUE; - } - // - // FwVol protocol on the handle so create a new one - // - FvDevice = AllocateZeroPool (sizeof (FV_DEVICE)); - if (FvDevice == NULL) { - goto Done; - } - - FvDevice->Signature = FV_DEVICE_SIGNATURE; - FvDevice->Fvb = Fvb; - - // - // Firmware Volume Protocol interface - // - FvDevice->Fv.GetVolumeAttributes = FvGetVolumeAttributes; - FvDevice->Fv.SetVolumeAttributes = FvSetVolumeAttributes; - FvDevice->Fv.ReadFile = FvReadFile; - FvDevice->Fv.ReadSection = FvReadFileSection; - FvDevice->Fv.WriteFile = FvWriteFile; - FvDevice->Fv.GetNextFile = FvGetNextFile; - FvDevice->Fv.KeySize = KEYSIZE; - FvDevice->Fv.GetInfo = FvGetVolumeInfo; - FvDevice->Fv.SetInfo = FvSetVolumeInfo; - FvDevice->Fv.ParentHandle = Fvb->ParentHandle; - - Status = FvCheck (FvDevice); - if (EFI_ERROR (Status)) { - // - // The file system is not consistence - // - FreePool (FvDevice); - continue; - } - - FwVolInheritAuthenticationStatus (FvDevice); - - if (Reinstall) { - // - // Reinstall an New FV protocol - // - // FvDevice = FV_DEVICE_FROM_THIS (Fv); - // FvDevice->Fvb = Fvb; - // FreeFvDeviceResource (FvDevice); - // - Status = gBS->ReinstallProtocolInterface ( - HandleBuffer[Index], - &gEfiFirmwareVolume2ProtocolGuid, - Fv, - &FvDevice->Fv - ); - if (!EFI_ERROR (Status)) { - InstallFlag = TRUE; - } else { - FreePool (FvDevice); - } - - DEBUG ((EFI_D_INFO, "Reinstall FV protocol as writable - %r\n", Status)); - ASSERT_EFI_ERROR (Status); - } else { - // - // Install an New FV protocol - // - Status = gBS->InstallProtocolInterface ( - &FvDevice->Handle, - &gEfiFirmwareVolume2ProtocolGuid, - EFI_NATIVE_INTERFACE, - &FvDevice->Fv - ); - if (!EFI_ERROR (Status)) { - InstallFlag = TRUE; - } else { - FreePool (FvDevice); - } - - DEBUG ((EFI_D_INFO, "Install FV protocol as writable - %r\n", Status)); - ASSERT_EFI_ERROR (Status); - } - } - -Done: - // - // As long as one Fv protocol install/reinstall successfully, - // success should return to ensure this image will be not unloaded. - // Otherwise, new Fv protocols are corrupted by other loaded driver. - // - if (InstallFlag) { - return EFI_SUCCESS; - } - - // - // No FV protocol install/reinstall successfully. - // EFI_NOT_FOUND should return to ensure this image will be unloaded. - // - return EFI_NOT_FOUND; -} diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolAttrib.c b/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolAttrib.c deleted file mode 100644 index 0e4ddf8bea..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolAttrib.c +++ /dev/null @@ -1,220 +0,0 @@ -/** @file - - Implements get/set firmware volume attributes. - - Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "FwVolDriver.h" - -/** - Retrieves attributes, insures positive polarity of attribute bits, returns - resulting attributes in output parameter. - - @param This Calling context - @param Attributes output buffer which contains attributes - - @retval EFI_SUCCESS Successfully got volume attributes - -**/ -EFI_STATUS -EFIAPI -FvGetVolumeAttributes ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - OUT EFI_FV_ATTRIBUTES *Attributes - ) -{ - EFI_STATUS Status; - FV_DEVICE *FvDevice; - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; - EFI_FVB_ATTRIBUTES_2 FvbAttributes; - - FvDevice = FV_DEVICE_FROM_THIS (This); - Fvb = FvDevice->Fvb; - - // - // First get the Firmware Volume Block Attributes - // - Status = Fvb->GetAttributes (Fvb, &FvbAttributes); - FvbAttributes &= 0xfffff0ff; - - *Attributes = FvbAttributes; - *Attributes |= EFI_FV2_WRITE_POLICY_RELIABLE; - return Status; -} - -/** - Sets current attributes for volume. - - @param This Calling context - @param Attributes On input, FvAttributes is a pointer to - an EFI_FV_ATTRIBUTES containing the - desired firmware volume settings. On - successful return, it contains the new - settings of the firmware volume. On - unsuccessful return, FvAttributes is not - modified and the firmware volume - settings are not changed. - - @retval EFI_SUCCESS The requested firmware volume attributes - were set and the resulting - EFI_FV_ATTRIBUTES is returned in - FvAttributes. - @retval EFI_ACCESS_DENIED Atrribute is locked down. - @retval EFI_INVALID_PARAMETER Atrribute is not valid. - -**/ -EFI_STATUS -EFIAPI -FvSetVolumeAttributes ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN OUT EFI_FV_ATTRIBUTES *Attributes - ) -{ - EFI_STATUS Status; - FV_DEVICE *FvDevice; - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; - EFI_FVB_ATTRIBUTES_2 OldFvbAttributes; - EFI_FVB_ATTRIBUTES_2 NewFvbAttributes; - UINT64 NewStatus; - UINT32 Capabilities; - - FvDevice = FV_DEVICE_FROM_THIS (This); - Fvb = FvDevice->Fvb; - - // - // First get the current Volume Attributes - // - Status = Fvb->GetAttributes ( - Fvb, - &OldFvbAttributes - ); - - if ((OldFvbAttributes & EFI_FVB2_LOCK_STATUS) != 0) { - return EFI_ACCESS_DENIED; - } - // - // Only status attributes can be updated. - // - Capabilities = OldFvbAttributes & EFI_FVB2_CAPABILITIES; - NewStatus = (*Attributes) & EFI_FVB2_STATUS; - - // - // Test read disable - // - if ((Capabilities & EFI_FVB2_READ_DISABLED_CAP) == 0) { - if ((NewStatus & EFI_FVB2_READ_STATUS) == 0) { - return EFI_INVALID_PARAMETER; - } - } - // - // Test read enable - // - if ((Capabilities & EFI_FVB2_READ_ENABLED_CAP) == 0) { - if ((NewStatus & EFI_FVB2_READ_STATUS) != 0) { - return EFI_INVALID_PARAMETER; - } - } - // - // Test write disable - // - if ((Capabilities & EFI_FVB2_WRITE_DISABLED_CAP) == 0) { - if ((NewStatus & EFI_FVB2_WRITE_STATUS) == 0) { - return EFI_INVALID_PARAMETER; - } - } - // - // Test write enable - // - if ((Capabilities & EFI_FVB2_WRITE_ENABLED_CAP) == 0) { - if ((NewStatus & EFI_FVB2_WRITE_STATUS) != 0) { - return EFI_INVALID_PARAMETER; - } - } - // - // Test lock - // - if ((Capabilities & EFI_FVB2_LOCK_CAP) == 0) { - if ((NewStatus & EFI_FVB2_LOCK_STATUS) != 0) { - return EFI_INVALID_PARAMETER; - } - } - - NewFvbAttributes = OldFvbAttributes & (0xFFFFFFFF & (~EFI_FVB2_STATUS)); - NewFvbAttributes |= NewStatus; - Status = Fvb->SetAttributes ( - Fvb, - &NewFvbAttributes - ); - - if (EFI_ERROR (Status)) { - return Status; - } - - *Attributes = 0; - - This->GetVolumeAttributes ( - This, - Attributes - ); - - return EFI_SUCCESS; -} - -/** - Return information of type InformationType for the requested firmware - volume. - - @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL. - @param InformationType InformationType for requested. - @param BufferSize On input, size of Buffer.On output, the amount of - data returned in Buffer. - @param Buffer A poniter to the data buffer to return. - - @return EFI_UNSUPPORTED Could not get. - -**/ -EFI_STATUS -EFIAPI -FvGetVolumeInfo ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN CONST EFI_GUID *InformationType, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ) -{ - return EFI_UNSUPPORTED; -} - -/** - Set information with InformationType into the requested firmware volume. - - @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL. - @param InformationType InformationType for requested. - @param BufferSize Size of Buffer data. - @param Buffer A poniter to the data buffer to be set. - - @retval EFI_UNSUPPORTED Could not set. - -**/ -EFI_STATUS -EFIAPI -FvSetVolumeInfo ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN CONST EFI_GUID *InformationType, - IN UINTN BufferSize, - IN CONST VOID *Buffer - ) -{ - return EFI_UNSUPPORTED; -} diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDriver.h b/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDriver.h deleted file mode 100644 index b1646dd39e..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDriver.h +++ /dev/null @@ -1,761 +0,0 @@ -/** @file - Common defines and definitions for a FwVolDxe driver. - - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef _FWVOL_DRIVER_H_ -#define _FWVOL_DRIVER_H_ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define FV_DEVICE_SIGNATURE SIGNATURE_32 ('_', 'F', 'V', '_') - -// -// Define two helper macro to extract the Capability field or Status field in FVB -// bit fields -// -#define EFI_FVB2_CAPABILITIES (EFI_FVB2_READ_DISABLED_CAP | \ - EFI_FVB2_READ_ENABLED_CAP | \ - EFI_FVB2_WRITE_DISABLED_CAP | \ - EFI_FVB2_WRITE_ENABLED_CAP | \ - EFI_FVB2_LOCK_CAP \ - ) - -#define EFI_FVB2_STATUS (EFI_FVB2_READ_STATUS | EFI_FVB2_WRITE_STATUS | EFI_FVB2_LOCK_STATUS) - -#define MAX_FILES 32 - -// -// Used to calculate from address -> Lba -// -typedef struct { - LIST_ENTRY Link; - EFI_LBA LbaIndex; - UINT8 *StartingAddress; - UINTN BlockLength; -} LBA_ENTRY; - -// -// Used to track free space in the Fv -// -typedef struct { - LIST_ENTRY Link; - UINT8 *StartingAddress; - UINTN Length; -} FREE_SPACE_ENTRY; - -// -// Used to track all non-deleted files -// -typedef struct { - LIST_ENTRY Link; - UINT8 *FfsHeader; -} FFS_FILE_LIST_ENTRY; - -typedef struct { - UINTN Signature; - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; - EFI_FIRMWARE_VOLUME2_PROTOCOL Fv; - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - UINT8 *Key; - EFI_HANDLE Handle; - - UINT8 ErasePolarity; - EFI_PHYSICAL_ADDRESS CachedFv; - LIST_ENTRY LbaHeader; - LIST_ENTRY FreeSpaceHeader; - LIST_ENTRY FfsFileListHeader; - - FFS_FILE_LIST_ENTRY *CurrentFfsFile; - BOOLEAN IsFfs3Fv; - UINT32 AuthenticationStatus; -} FV_DEVICE; - -#define FV_DEVICE_FROM_THIS(a) CR (a, FV_DEVICE, Fv, FV_DEVICE_SIGNATURE) - -/** - Retrieves attributes, insures positive polarity of attribute bits, returns - resulting attributes in output parameter. - - @param This Calling context - @param Attributes output buffer which contains attributes - - @retval EFI_SUCCESS Successfully got volume attributes - -**/ -EFI_STATUS -EFIAPI -FvGetVolumeAttributes ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - OUT EFI_FV_ATTRIBUTES *Attributes - ); - -/** - Sets current attributes for volume. - - @param This Calling context - @param Attributes On input, FvAttributes is a pointer to - an EFI_FV_ATTRIBUTES containing the - desired firmware volume settings. On - successful return, it contains the new - settings of the firmware volume. On - unsuccessful return, FvAttributes is not - modified and the firmware volume - settings are not changed. - - @retval EFI_SUCCESS The requested firmware volume attributes - were set and the resulting - EFI_FV_ATTRIBUTES is returned in - FvAttributes. - @retval EFI_ACCESS_DENIED Atrribute is locked down. - @retval EFI_INVALID_PARAMETER Atrribute is not valid. - -**/ -EFI_STATUS -EFIAPI -FvSetVolumeAttributes ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN OUT EFI_FV_ATTRIBUTES *Attributes - ); - -/** - Given the input key, search for the next matching file in the volume. - - @param This Indicates the calling context. - @param Key Key is a pointer to a caller allocated - buffer that contains implementation specific - data that is used to track where to begin - the search for the next file. The size of - the buffer must be at least This->KeySize - bytes long. To reinitialize the search and - begin from the beginning of the firmware - volume, the entire buffer must be cleared to - zero. Other than clearing the buffer to - initiate a new search, the caller must not - modify the data in the buffer between calls - to GetNextFile(). - @param FileType FileType is a pointer to a caller allocated - EFI_FV_FILETYPE. The GetNextFile() API can - filter it's search for files based on the - value of *FileType input. A *FileType input - of 0 causes GetNextFile() to search for - files of all types. If a file is found, the - file's type is returned in *FileType. - *FileType is not modified if no file is - found. - @param NameGuid NameGuid is a pointer to a caller allocated - EFI_GUID. If a file is found, the file's - name is returned in *NameGuid. *NameGuid is - not modified if no file is found. - @param Attributes Attributes is a pointer to a caller - allocated EFI_FV_FILE_ATTRIBUTES. If a file - is found, the file's attributes are returned - in *Attributes. *Attributes is not modified - if no file is found. - @param Size Size is a pointer to a caller allocated - UINTN. If a file is found, the file's size - is returned in *Size. *Size is not modified - if no file is found. - - @retval EFI_SUCCESS Successfully find the file. - @retval EFI_DEVICE_ERROR Device error. - @retval EFI_ACCESS_DENIED Fv could not read. - @retval EFI_NOT_FOUND No matching file found. - @retval EFI_INVALID_PARAMETER Invalid parameter - -**/ -EFI_STATUS -EFIAPI -FvGetNextFile ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN OUT VOID *Key, - IN OUT EFI_FV_FILETYPE *FileType, - OUT EFI_GUID *NameGuid, - OUT EFI_FV_FILE_ATTRIBUTES *Attributes, - OUT UINTN *Size - ); - -/** - Locates a file in the firmware volume and - copies it to the supplied buffer. - - @param This Indicates the calling context. - @param NameGuid Pointer to an EFI_GUID, which is the - filename. - @param Buffer Buffer is a pointer to pointer to a buffer - in which the file or section contents or are - returned. - @param BufferSize BufferSize is a pointer to caller allocated - UINTN. On input *BufferSize indicates the - size in bytes of the memory region pointed - to by Buffer. On output, *BufferSize - contains the number of bytes required to - read the file. - @param FoundType FoundType is a pointer to a caller allocated - EFI_FV_FILETYPE that on successful return - from Read() contains the type of file read. - This output reflects the file type - irrespective of the value of the SectionType - input. - @param FileAttributes FileAttributes is a pointer to a caller - allocated EFI_FV_FILE_ATTRIBUTES. On - successful return from Read(), - *FileAttributes contains the attributes of - the file read. - @param AuthenticationStatus AuthenticationStatus is a pointer to a - caller allocated UINTN in which the - authentication status is returned. - - @retval EFI_SUCCESS Successfully read to memory buffer. - @retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small. - @retval EFI_NOT_FOUND Not found. - @retval EFI_DEVICE_ERROR Device error. - @retval EFI_ACCESS_DENIED Could not read. - @retval EFI_INVALID_PARAMETER Invalid parameter. - @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated. - -**/ -EFI_STATUS -EFIAPI -FvReadFile ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN CONST EFI_GUID *NameGuid, - IN OUT VOID **Buffer, - IN OUT UINTN *BufferSize, - OUT EFI_FV_FILETYPE *FoundType, - OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes, - OUT UINT32 *AuthenticationStatus - ); - -/** - Locates a section in a given FFS File and - copies it to the supplied buffer (not including section header). - - @param This Indicates the calling context. - @param NameGuid Pointer to an EFI_GUID, which is the - filename. - @param SectionType Indicates the section type to return. - @param SectionInstance Indicates which instance of sections with a - type of SectionType to return. - @param Buffer Buffer is a pointer to pointer to a buffer - in which the file or section contents or are - returned. - @param BufferSize BufferSize is a pointer to caller allocated - UINTN. - @param AuthenticationStatus AuthenticationStatus is a pointer to a - caller allocated UINT32 in which the - authentication status is returned. - - @retval EFI_SUCCESS Successfully read the file section into - buffer. - @retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small. - @retval EFI_NOT_FOUND Section not found. - @retval EFI_DEVICE_ERROR Device error. - @retval EFI_ACCESS_DENIED Could not read. - @retval EFI_INVALID_PARAMETER Invalid parameter. - -**/ -EFI_STATUS -EFIAPI -FvReadFileSection ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN CONST EFI_GUID *NameGuid, - IN EFI_SECTION_TYPE SectionType, - IN UINTN SectionInstance, - IN OUT VOID **Buffer, - IN OUT UINTN *BufferSize, - OUT UINT32 *AuthenticationStatus - ); - -/** - Writes one or more files to the firmware volume. - - @param This Indicates the calling context. - @param NumberOfFiles Number of files. - @param WritePolicy WritePolicy indicates the level of reliability - for the write in the event of a power failure or - other system failure during the write operation. - @param FileData FileData is an pointer to an array of - EFI_FV_WRITE_DATA. Each element of array - FileData represents a file to be written. - - @retval EFI_SUCCESS Files successfully written to firmware volume - @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated. - @retval EFI_DEVICE_ERROR Device error. - @retval EFI_WRITE_PROTECTED Write protected. - @retval EFI_NOT_FOUND Not found. - @retval EFI_INVALID_PARAMETER Invalid parameter. - @retval EFI_UNSUPPORTED This function not supported. - -**/ -EFI_STATUS -EFIAPI -FvWriteFile ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN UINT32 NumberOfFiles, - IN EFI_FV_WRITE_POLICY WritePolicy, - IN EFI_FV_WRITE_FILE_DATA *FileData - ); - -/** - Return information of type InformationType for the requested firmware - volume. - - @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL. - @param InformationType InformationType for requested. - @param BufferSize On input, size of Buffer.On output, the amount of - data returned in Buffer. - @param Buffer A poniter to the data buffer to return. - - @return EFI_UNSUPPORTED Could not get. - -**/ -EFI_STATUS -EFIAPI -FvGetVolumeInfo ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN CONST EFI_GUID *InformationType, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ); - - -/** - Set information with InformationType into the requested firmware volume. - - @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL. - @param InformationType InformationType for requested. - @param BufferSize Size of Buffer data. - @param Buffer A poniter to the data buffer to be set. - - @retval EFI_UNSUPPORTED Could not set. - -**/ -EFI_STATUS -EFIAPI -FvSetVolumeInfo ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN CONST EFI_GUID *InformationType, - IN UINTN BufferSize, - IN CONST VOID *Buffer - ); - -/** - Writes data beginning at Lba:Offset from FV. The write terminates either - when *NumBytes of data have been written, or when the firmware end is - reached. *NumBytes is updated to reflect the actual number of bytes - written. - - @param FvDevice Cached Firmware Volume - @param Offset Offset in the block at which to begin write - @param NumBytes At input, indicates the requested write size. - At output, indicates the actual number of bytes written. - @param Buffer Buffer containing source data for the write. - - @retval EFI_SUCCESS Data is successfully written into FV. - @return error Data is failed written. - -**/ -EFI_STATUS -FvcWrite ( - IN FV_DEVICE *FvDevice, - IN UINTN Offset, - IN OUT UINTN *NumBytes, - IN UINT8 *Buffer - ); - - -/** - Check if a block of buffer is erased. - - @param ErasePolarity Erase polarity attribute of the firmware volume - @param Buffer The buffer to be checked - @param BufferSize Size of the buffer in bytes - - @retval TRUE The block of buffer is erased - @retval FALSE The block of buffer is not erased - -**/ -BOOLEAN -IsBufferErased ( - IN UINT8 ErasePolarity, - IN UINT8 *Buffer, - IN UINTN BufferSize - ); - -/** - Get the FFS file state by checking the highest bit set in the header's state field. - - @param ErasePolarity Erase polarity attribute of the firmware volume - @param FfsHeader Points to the FFS file header - - @return FFS File state - -**/ -EFI_FFS_FILE_STATE -GetFileState ( - IN UINT8 ErasePolarity, - IN EFI_FFS_FILE_HEADER *FfsHeader - ); - -/** - Verify checksum of the firmware volume header. - - @param FvHeader Points to the firmware volume header to be checked - - @retval TRUE Checksum verification passed - @retval FALSE Checksum verification failed - -**/ -BOOLEAN -VerifyFvHeaderChecksum ( - IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader - ); - -/** - Check if it's a valid FFS file header. - - @param ErasePolarity Erase polarity attribute of the firmware volume - @param FfsHeader Points to the FFS file header to be checked - - @retval TRUE Valid FFS file header - @retval FALSE Invalid FFS file header - -**/ -BOOLEAN -IsValidFFSHeader ( - IN UINT8 ErasePolarity, - IN EFI_FFS_FILE_HEADER *FfsHeader - ); - -/** - Check if it's a valid FFS file. - Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first. - - @param FvDevice Cached FV image. - @param FfsHeader Points to the FFS file to be checked - - @retval TRUE Valid FFS file - @retval FALSE Invalid FFS file - -**/ -BOOLEAN -IsValidFFSFile ( - IN FV_DEVICE *FvDevice, - IN EFI_FFS_FILE_HEADER *FfsHeader - ); - -/** - Given the supplied FW_VOL_BLOCK_PROTOCOL, allocate a buffer for output and - copy the real length volume header into it. - - @param Fvb The FW_VOL_BLOCK_PROTOCOL instance from which to - read the volume header - @param FwVolHeader Pointer to pointer to allocated buffer in which - the volume header is returned. - - @retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated. - @retval EFI_SUCCESS Successfully read volume header to the allocated - buffer. - @retval EFI_ACCESS_DENIED Read status of FV is not enabled. - @retval EFI_INVALID_PARAMETER The FV Header signature is not as expected or - the file system could not be understood. -**/ -EFI_STATUS -GetFwVolHeader ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb, - OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader - ); - -/** - Convert the Buffer Address to LBA Entry Address. - - @param FvDevice Cached FvDevice - @param BufferAddress Address of Buffer - @param LbaListEntry Pointer to the got LBA entry that contains the address. - - @retval EFI_NOT_FOUND Buffer address is out of FvDevice. - @retval EFI_SUCCESS LBA entry is found for Buffer address. - -**/ -EFI_STATUS -Buffer2LbaEntry ( - IN FV_DEVICE *FvDevice, - IN EFI_PHYSICAL_ADDRESS BufferAddress, - OUT LBA_ENTRY **LbaListEntry - ); - -/** - Convert the Buffer Address to LBA Address & Offset. - - @param FvDevice Cached FvDevice - @param BufferAddress Address of Buffer - @param Lba Pointer to the gob Lba value - @param Offset Pointer to the got Offset - - @retval EFI_NOT_FOUND Buffer address is out of FvDevice. - @retval EFI_SUCCESS LBA and Offset is found for Buffer address. - -**/ -EFI_STATUS -Buffer2Lba ( - IN FV_DEVICE *FvDevice, - IN EFI_PHYSICAL_ADDRESS BufferAddress, - OUT EFI_LBA *Lba, - OUT UINTN *Offset - ); - -/** - Set File State in the FfsHeader. - - @param State File state to be set into FFS header. - @param FfsHeader Points to the FFS file header - -**/ -VOID -SetFileState ( - IN UINT8 State, - IN EFI_FFS_FILE_HEADER *FfsHeader - ); - -/** - Create a PAD File in the Free Space. - - @param FvDevice Firmware Volume Device. - @param FreeSpaceEntry Indicating in which Free Space(Cache) the Pad file will be inserted. - @param Size Pad file Size, not include the header. - @param PadFileEntry The Ffs File Entry that points to this Pad File. - - @retval EFI_SUCCESS Successfully create a PAD file. - @retval EFI_OUT_OF_RESOURCES No enough free space to create a PAD file. - @retval EFI_INVALID_PARAMETER Size is not 8 byte alignment. - @retval EFI_DEVICE_ERROR Free space is not erased. -**/ -EFI_STATUS -FvCreatePadFileInFreeSpace ( - IN FV_DEVICE *FvDevice, - IN FREE_SPACE_ENTRY *FreeSpaceEntry, - IN UINTN Size, - OUT FFS_FILE_LIST_ENTRY **PadFileEntry - ); - -/** - Create a new file within a PAD file area. - - @param FvDevice Firmware Volume Device. - @param FfsFileBuffer A buffer that holds an FFS file,(it contains a File Header which is in init state). - @param BufferSize The size of FfsFileBuffer. - @param ActualFileSize The actual file length, it may not be multiples of 8. - @param FileName The FFS File Name. - @param FileType The FFS File Type. - @param FileAttributes The Attributes of the FFS File to be created. - - @retval EFI_SUCCESS Successfully create a new file within the found PAD file area. - @retval EFI_OUT_OF_RESOURCES No suitable PAD file is found. - @retval other errors New file is created failed. - -**/ -EFI_STATUS -FvCreateNewFileInsidePadFile ( - IN FV_DEVICE *FvDevice, - IN UINT8 *FfsFileBuffer, - IN UINTN BufferSize, - IN UINTN ActualFileSize, - IN EFI_GUID *FileName, - IN EFI_FV_FILETYPE FileType, - IN EFI_FV_FILE_ATTRIBUTES FileAttributes - ); - -/** - Write multiple files into FV in reliable method. - - @param FvDevice Firmware Volume Device. - @param NumOfFiles Total File number to be written. - @param FileData The array of EFI_FV_WRITE_FILE_DATA structure, - used to get name, attributes, type, etc - @param FileOperation The array of operation for each file. - - @retval EFI_SUCCESS Files are added into FV. - @retval EFI_OUT_OF_RESOURCES No enough free PAD files to add the input files. - @retval EFI_INVALID_PARAMETER File number is less than or equal to 1. - @retval EFI_UNSUPPORTED File number exceeds the supported max numbers of files. - -**/ -EFI_STATUS -FvCreateMultipleFiles ( - IN FV_DEVICE *FvDevice, - IN UINTN NumOfFiles, - IN EFI_FV_WRITE_FILE_DATA *FileData, - IN BOOLEAN *FileOperation - ); - -/** - Calculate the checksum for the FFS header. - - @param FfsHeader FFS File Header which needs to calculate the checksum - -**/ -VOID -SetHeaderChecksum ( - IN EFI_FFS_FILE_HEADER *FfsHeader - ); - -/** - Calculate the checksum for the FFS File. - - @param FfsHeader FFS File Header which needs to calculate the checksum - @param ActualFileSize The whole Ffs File Length. - -**/ -VOID -SetFileChecksum ( - IN EFI_FFS_FILE_HEADER *FfsHeader, - IN UINTN ActualFileSize - ); - -/** - Get the alignment value from File Attributes. - - @param FfsAttributes FFS attribute - - @return Alignment value. - -**/ -UINTN -GetRequiredAlignment ( - IN EFI_FV_FILE_ATTRIBUTES FfsAttributes - ); - -/** - Locate Pad File for writing, this is got from FV Cache. - - @param FvDevice Cached Firmware Volume. - @param Size The required FFS file size. - @param RequiredAlignment FFS File Data alignment requirement. - @param PadSize Pointer to the size of leading Pad File. - @param PadFileEntry Pointer to the Pad File Entry that meets the requirement. - - @retval EFI_SUCCESS The required pad file is found. - @retval EFI_NOT_FOUND The required pad file can't be found. - -**/ -EFI_STATUS -FvLocatePadFile ( - IN FV_DEVICE *FvDevice, - IN UINTN Size, - IN UINTN RequiredAlignment, - OUT UINTN *PadSize, - OUT FFS_FILE_LIST_ENTRY **PadFileEntry - ); - -/** - Locate a suitable pad file for multiple file writing. - - @param FvDevice Cached Firmware Volume. - @param NumOfFiles The number of Files that needed updating - @param BufferSize The array of each file size. - @param RequiredAlignment The array of of FFS File Data alignment requirement. - @param PadSize The array of size of each leading Pad File. - @param TotalSizeNeeded The totalsize that can hold these files. - @param PadFileEntry Pointer to the Pad File Entry that meets the requirement. - - @retval EFI_SUCCESS The required pad file is found. - @retval EFI_NOT_FOUND The required pad file can't be found. - -**/ -EFI_STATUS -FvSearchSuitablePadFile ( - IN FV_DEVICE *FvDevice, - IN UINTN NumOfFiles, - IN UINTN *BufferSize, - IN UINTN *RequiredAlignment, - OUT UINTN *PadSize, - OUT UINTN *TotalSizeNeeded, - OUT FFS_FILE_LIST_ENTRY **PadFileEntry - ); - -/** - Locate a Free Space entry which can hold these files, including - meeting the alignment requirements. - - @param FvDevice Cached Firmware Volume. - @param NumOfFiles The number of Files that needed updating - @param BufferSize The array of each file size. - @param RequiredAlignment The array of of FFS File Data alignment requirement. - @param PadSize The array of size of each leading Pad File. - @param TotalSizeNeeded The got total size that can hold these files. - @param FreeSpaceEntry The Free Space Entry that can hold these files. - - @retval EFI_SUCCESS The free space entry is found. - @retval EFI_NOT_FOUND The free space entry can't be found. - -**/ -EFI_STATUS -FvSearchSuitableFreeSpace ( - IN FV_DEVICE *FvDevice, - IN UINTN NumOfFiles, - IN UINTN *BufferSize, - IN UINTN *RequiredAlignment, - OUT UINTN *PadSize, - OUT UINTN *TotalSizeNeeded, - OUT FREE_SPACE_ENTRY **FreeSpaceEntry - ); - -/** - Change FFS file header state and write to FV. - - @param FvDevice Cached FV image. - @param FfsHeader Points to the FFS file header to be updated. - @param State FFS file state to be set. - - @retval EFI_SUCCESS File state is writen into FV. - @retval others File state can't be writen into FV. - -**/ -EFI_STATUS -UpdateHeaderBit ( - IN FV_DEVICE *FvDevice, - IN EFI_FFS_FILE_HEADER *FfsHeader, - IN EFI_FFS_FILE_STATE State - ); - -/** - Convert EFI_FV_FILE_ATTRIBUTES to FFS_FILE_ATTRIBUTES. - - @param FvFileAttrib The value of EFI_FV_FILE_ATTRIBUTES - @param FfsFileAttrib Pointer to the got FFS_FILE_ATTRIBUTES value. - -**/ -VOID -FvFileAttrib2FfsFileAttrib ( - IN EFI_FV_FILE_ATTRIBUTES FvFileAttrib, - OUT UINT8 *FfsFileAttrib - ); - -#endif diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxe.inf b/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxe.inf deleted file mode 100644 index 057266bb2b..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxe.inf +++ /dev/null @@ -1,74 +0,0 @@ -## @file -# FwVolDxe Driver. -# -# This driver produces Firmware Volume2 protocol with full services -# (read/write, get/set) based on Firmware Volume Block protocol. -# -# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials are -# licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = FwVolDxe - MODULE_UNI_FILE = FwVolDxe.uni - FILE_GUID = 233C2592-1CEC-494a-A097-15DC96379777 - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - - ENTRY_POINT = FwVolDriverInit - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources] - FwVolDriver.h - FwPadFile.c - Ffs.c - FwVolWrite.c - FwVolRead.c - FwVolAttrib.c - FwVol.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - IntelFrameworkPkg/IntelFrameworkPkg.dec - - -[LibraryClasses] - UefiBootServicesTableLib - MemoryAllocationLib - BaseMemoryLib - BaseLib - UefiLib - UefiDriverEntryPoint - DebugLib - - -[Guids] - gEfiFirmwareVolumeTopFileGuid ## CONSUMES ## File # VTF file - gEfiFirmwareFileSystem2Guid ## CONSUMES ## GUID # File System Guid - gEfiFirmwareFileSystem3Guid ## CONSUMES ## GUID # File System Guid - -[Protocols] - gEfiSectionExtractionProtocolGuid ## CONSUMES - gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES - gEfiFirmwareVolume2ProtocolGuid ## PRODUCES - -[Depex] - gEfiFirmwareVolumeBlockProtocolGuid AND gEfiSectionExtractionProtocolGuid - -[UserExtensions.TianoCore."ExtraFiles"] - FwVolDxeExtra.uni diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxe.uni b/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxe.uni deleted file mode 100644 index fb77667395..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxe.uni +++ /dev/null @@ -1,23 +0,0 @@ -// /** @file -// FwVolDxe Driver. -// -// This driver produces Firmware Volume2 protocol with full services -// (read/write, get/set) based on Firmware Volume Block protocol. -// -// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
-// -// This program and the accompanying materials are -// licensed and made available under the terms and conditions of the BSD License -// which accompanies this distribution. The full text of the license may be found at -// http://opensource.org/licenses/bsd-license.php -// -// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -// -// **/ - - -#string STR_MODULE_ABSTRACT #language en-US "FwVolDxe Driver" - -#string STR_MODULE_DESCRIPTION #language en-US "This driver produces the Firmware Volume2 protocol with full services (read/write, get/set) based on Firmware Volume Block protocol." - diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxeExtra.uni b/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxeExtra.uni deleted file mode 100644 index 9af2689ec3..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolDxeExtra.uni +++ /dev/null @@ -1,20 +0,0 @@ -// /** @file -// FwVolDxe Localized Strings and Content -// -// Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
-// -// This program and the accompanying materials are -// licensed and made available under the terms and conditions of the BSD License -// which accompanies this distribution. The full text of the license may be found at -// http://opensource.org/licenses/bsd-license.php -// -// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -// -// **/ - -#string STR_PROPERTIES_MODULE_NAME -#language en-US -"Flash Storage DXE Driver v2" - - diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolRead.c b/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolRead.c deleted file mode 100644 index 0d9021914f..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolRead.c +++ /dev/null @@ -1,632 +0,0 @@ -/** @file - Implements functions to read firmware file. - - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "FwVolDriver.h" - -/** -Required Alignment Alignment Value in FFS Alignment Value in -(bytes) Attributes Field Firmware Volume Interfaces -1 0 0 -16 1 4 -128 2 7 -512 3 9 -1 KB 4 10 -4 KB 5 12 -32 KB 6 15 -64 KB 7 16 -**/ -UINT8 mFvAttributes[] = {0, 4, 7, 9, 10, 12, 15, 16}; - -/** - Convert the FFS File Attributes to FV File Attributes. - - @param FfsAttributes The attributes of UINT8 type. - - @return The attributes of EFI_FV_FILE_ATTRIBUTES - -**/ -EFI_FV_FILE_ATTRIBUTES -FfsAttributes2FvFileAttributes ( - IN EFI_FFS_FILE_ATTRIBUTES FfsAttributes - ) -{ - UINT8 DataAlignment; - EFI_FV_FILE_ATTRIBUTES FileAttribute; - - DataAlignment = (UINT8) ((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3); - ASSERT (DataAlignment < 8); - - FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes[DataAlignment]; - - if ((FfsAttributes & FFS_ATTRIB_FIXED) == FFS_ATTRIB_FIXED) { - FileAttribute |= EFI_FV_FILE_ATTRIB_FIXED; - } - - return FileAttribute; -} - -/** - Given the input key, search for the next matching file in the volume. - - @param This Indicates the calling context. - @param Key Key is a pointer to a caller allocated - buffer that contains implementation specific - data that is used to track where to begin - the search for the next file. The size of - the buffer must be at least This->KeySize - bytes long. To reinitialize the search and - begin from the beginning of the firmware - volume, the entire buffer must be cleared to - zero. Other than clearing the buffer to - initiate a new search, the caller must not - modify the data in the buffer between calls - to GetNextFile(). - @param FileType FileType is a pointer to a caller allocated - EFI_FV_FILETYPE. The GetNextFile() API can - filter it's search for files based on the - value of *FileType input. A *FileType input - of 0 causes GetNextFile() to search for - files of all types. If a file is found, the - file's type is returned in *FileType. - *FileType is not modified if no file is - found. - @param NameGuid NameGuid is a pointer to a caller allocated - EFI_GUID. If a file is found, the file's - name is returned in *NameGuid. *NameGuid is - not modified if no file is found. - @param Attributes Attributes is a pointer to a caller - allocated EFI_FV_FILE_ATTRIBUTES. If a file - is found, the file's attributes are returned - in *Attributes. *Attributes is not modified - if no file is found. - @param Size Size is a pointer to a caller allocated - UINTN. If a file is found, the file's size - is returned in *Size. *Size is not modified - if no file is found. - - @retval EFI_SUCCESS Successfully find the file. - @retval EFI_DEVICE_ERROR Device error. - @retval EFI_ACCESS_DENIED Fv could not read. - @retval EFI_NOT_FOUND No matching file found. - @retval EFI_INVALID_PARAMETER Invalid parameter - -**/ -EFI_STATUS -EFIAPI -FvGetNextFile ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN OUT VOID *Key, - IN OUT EFI_FV_FILETYPE *FileType, - OUT EFI_GUID *NameGuid, - OUT EFI_FV_FILE_ATTRIBUTES *Attributes, - OUT UINTN *Size - ) -{ - EFI_STATUS Status; - FV_DEVICE *FvDevice; - EFI_FV_ATTRIBUTES FvAttributes; - EFI_FFS_FILE_HEADER *FfsFileHeader; - UINTN *KeyValue; - LIST_ENTRY *Link; - FFS_FILE_LIST_ENTRY *FfsFileEntry; - - FvDevice = FV_DEVICE_FROM_THIS (This); - - Status = This->GetVolumeAttributes (This, &FvAttributes); - if (EFI_ERROR (Status)) { - return Status; - } - - KeyValue = (UINTN *) Key; - FfsFileHeader = NULL; - - // - // Check if read operation is enabled - // - if ((FvAttributes & EFI_FV2_READ_STATUS) == 0) { - return EFI_ACCESS_DENIED; - } - - if (*FileType > EFI_FV_FILETYPE_SMM_CORE) { - // - // File type needs to be in 0 - 0x0D - // - return EFI_NOT_FOUND; - } - - do { - if (*KeyValue == 0) { - // - // Search for 1st matching file - // - Link = &FvDevice->FfsFileListHeader; - if (Link->ForwardLink == &FvDevice->FfsFileListHeader) { - return EFI_NOT_FOUND; - } - - FfsFileEntry = (FFS_FILE_LIST_ENTRY *) Link->ForwardLink; - FfsFileHeader = (EFI_FFS_FILE_HEADER *) FfsFileEntry->FfsHeader; - - // - // remember the key - // - *KeyValue = (UINTN) FfsFileEntry; - - // - // we ignore pad files - // - if (FfsFileHeader->Type == EFI_FV_FILETYPE_FFS_PAD) { - continue; - } - - if (*FileType == 0) { - break; - } - - if (*FileType == FfsFileHeader->Type) { - break; - } - - } else { - // - // Getting link from last Ffs - // - Link = (LIST_ENTRY *) (*KeyValue); - if (Link->ForwardLink == &FvDevice->FfsFileListHeader) { - return EFI_NOT_FOUND; - } - - FfsFileEntry = (FFS_FILE_LIST_ENTRY *) Link->ForwardLink; - FfsFileHeader = (EFI_FFS_FILE_HEADER *) FfsFileEntry->FfsHeader; - - // - // remember the key - // - *KeyValue = (UINTN) FfsFileEntry; - - // - // we ignore pad files - // - if (FfsFileHeader->Type == EFI_FV_FILETYPE_FFS_PAD) { - continue; - } - - if (*FileType == EFI_FV_FILETYPE_ALL) { - break; - } - - if (*FileType == FfsFileHeader->Type) { - break; - } - } - } while (Link->ForwardLink != &FvDevice->FfsFileListHeader); - - // - // Cache this file entry - // - FvDevice->CurrentFfsFile = FfsFileEntry; - - *FileType = FfsFileHeader->Type; - CopyGuid (NameGuid, &FfsFileHeader->Name); - *Attributes = FfsAttributes2FvFileAttributes (FfsFileHeader->Attributes); - if ((FvDevice->FwVolHeader->Attributes & EFI_FVB2_MEMORY_MAPPED) == EFI_FVB2_MEMORY_MAPPED) { - *Attributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED; - } - - // - // we need to substract the header size - // - if (IS_FFS_FILE2 (FfsFileHeader)) { - *Size = FFS_FILE2_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEADER2); - } else { - *Size = FFS_FILE_SIZE (FfsFileHeader) - sizeof (EFI_FFS_FILE_HEADER); - } - - if (CompareGuid (&gEfiFirmwareVolumeTopFileGuid, NameGuid)) { - // - // specially deal with VTF file - // - UINT8 *SrcPtr; - UINT32 Tmp; - - if (IS_FFS_FILE2 (FfsFileHeader)) { - SrcPtr = ((UINT8 *) FfsFileHeader) + sizeof (EFI_FFS_FILE_HEADER2); - } else { - SrcPtr = ((UINT8 *) FfsFileHeader) + sizeof (EFI_FFS_FILE_HEADER); - } - - while (*Size >= 4) { - Tmp = *(UINT32 *) SrcPtr; - if (Tmp == 0) { - SrcPtr += 4; - (*Size) -= 4; - } else { - break; - } - } - } - - return EFI_SUCCESS; -} - -/** - Locates a file in the firmware volume and - copies it to the supplied buffer. - - @param This Indicates the calling context. - @param NameGuid Pointer to an EFI_GUID, which is the - filename. - @param Buffer Buffer is a pointer to pointer to a buffer - in which the file or section contents or are - returned. - @param BufferSize BufferSize is a pointer to caller allocated - UINTN. On input *BufferSize indicates the - size in bytes of the memory region pointed - to by Buffer. On output, *BufferSize - contains the number of bytes required to - read the file. - @param FoundType FoundType is a pointer to a caller allocated - EFI_FV_FILETYPE that on successful return - from Read() contains the type of file read. - This output reflects the file type - irrespective of the value of the SectionType - input. - @param FileAttributes FileAttributes is a pointer to a caller - allocated EFI_FV_FILE_ATTRIBUTES. On - successful return from Read(), - *FileAttributes contains the attributes of - the file read. - @param AuthenticationStatus AuthenticationStatus is a pointer to a - caller allocated UINTN in which the - authentication status is returned. - - @retval EFI_SUCCESS Successfully read to memory buffer. - @retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small. - @retval EFI_NOT_FOUND Not found. - @retval EFI_DEVICE_ERROR Device error. - @retval EFI_ACCESS_DENIED Could not read. - @retval EFI_INVALID_PARAMETER Invalid parameter. - @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated. - -**/ -EFI_STATUS -EFIAPI -FvReadFile ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN CONST EFI_GUID *NameGuid, - IN OUT VOID **Buffer, - IN OUT UINTN *BufferSize, - OUT EFI_FV_FILETYPE *FoundType, - OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes, - OUT UINT32 *AuthenticationStatus - ) -{ - EFI_STATUS Status; - FV_DEVICE *FvDevice; - UINTN Key; - EFI_GUID SearchNameGuid; - EFI_FV_ATTRIBUTES FvAttributes; - EFI_FV_FILETYPE LocalFoundType; - EFI_FV_FILE_ATTRIBUTES LocalAttributes; - UINTN FileSize; - UINT8 *SrcPtr; - FFS_FILE_LIST_ENTRY *FfsFileEntry; - EFI_FFS_FILE_HEADER *FfsHeader; - UINT8 *FileBuffer; - - if (NULL == This || NULL == NameGuid) { - return EFI_INVALID_PARAMETER; - } - - FvDevice = FV_DEVICE_FROM_THIS (This); - - Status = This->GetVolumeAttributes (This, &FvAttributes); - if (EFI_ERROR (Status)) { - return Status; - } - // - // First check to see that FV is enabled for reads... - // - if (0 == (FvAttributes & EFI_FV2_READ_STATUS)) { - return EFI_ACCESS_DENIED; - } - - FfsHeader = NULL; - - // - // Check if the file was read last time. - // - FfsFileEntry = FvDevice->CurrentFfsFile; - - if (FfsFileEntry != NULL) { - FfsHeader = (EFI_FFS_FILE_HEADER *) FfsFileEntry->FfsHeader; - } - - if ((FfsFileEntry == NULL) || (!CompareGuid (&FfsHeader->Name, NameGuid))) { - // - // If not match or no file cached, search this file - // - Key = 0; - do { - LocalFoundType = 0; - Status = This->GetNextFile ( - This, - &Key, - &LocalFoundType, - &SearchNameGuid, - &LocalAttributes, - &FileSize - ); - if (EFI_ERROR (Status)) { - return EFI_NOT_FOUND; - } - } while (!CompareGuid (&SearchNameGuid, NameGuid)); - - // - // Get file entry - // - FfsFileEntry = (FFS_FILE_LIST_ENTRY *) Key; - - // - // Update the cache - // - FvDevice->CurrentFfsFile = FfsFileEntry; - - FfsHeader = (EFI_FFS_FILE_HEADER *) FfsFileEntry->FfsHeader; - - } else { - // - // Get File Size of the cached file - // - if (IS_FFS_FILE2 (FfsHeader)) { - FileSize = FFS_FILE2_SIZE (FfsHeader) - sizeof (EFI_FFS_FILE_HEADER2); - } else { - FileSize = FFS_FILE_SIZE (FfsHeader) - sizeof (EFI_FFS_FILE_HEADER); - } - } - // - // Get file info - // - *FoundType = FfsHeader->Type; - *FileAttributes = FfsAttributes2FvFileAttributes (FfsHeader->Attributes); - if ((FvDevice->FwVolHeader->Attributes & EFI_FVB2_MEMORY_MAPPED) == EFI_FVB2_MEMORY_MAPPED) { - *FileAttributes |= EFI_FV_FILE_ATTRIB_MEMORY_MAPPED; - } - // - // Inherit the authentication status. - // - *AuthenticationStatus = FvDevice->AuthenticationStatus; - - // - // If Buffer is NULL, we only want to get some information - // - if (Buffer == NULL) { - *BufferSize = FileSize; - return EFI_SUCCESS; - } - - if (IS_FFS_FILE2 (FfsHeader)) { - SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2); - } else { - SrcPtr = ((UINT8 *) FfsHeader) + sizeof (EFI_FFS_FILE_HEADER); - } - - if (CompareGuid (&gEfiFirmwareVolumeTopFileGuid, NameGuid)) { - // - // specially deal with VTF file - // - UINT32 Tmp; - - while (FileSize >= 4) { - Tmp = *(UINT32 *) SrcPtr; - if (Tmp == 0) { - SrcPtr += 4; - FileSize -= 4; - } else { - break; - } - } - } - // - // If we drop out of the above loop, we've found the correct file header... - // - if (*Buffer == NULL) { - FileBuffer = AllocateCopyPool (FileSize, SrcPtr); - if (FileBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - *BufferSize = FileSize; - *Buffer = FileBuffer; - - return EFI_SUCCESS; - } - // - // If the user's buffer is smaller than the file size, then copy as much - // as we can and return an appropriate status. - // - if (FileSize > *BufferSize) { - CopyMem (*Buffer, SrcPtr, *BufferSize); - *BufferSize = FileSize; - return EFI_WARN_BUFFER_TOO_SMALL; - } - // - // User's buffer size is ok, so copy the entire file to their buffer. - // - *BufferSize = FileSize; - CopyMem (*Buffer, SrcPtr, *BufferSize); - - return EFI_SUCCESS; -} - -/** - Locates a section in a given FFS File and - copies it to the supplied buffer (not including section header). - - @param This Indicates the calling context. - @param NameGuid Pointer to an EFI_GUID, which is the - filename. - @param SectionType Indicates the section type to return. - @param SectionInstance Indicates which instance of sections with a - type of SectionType to return. - @param Buffer Buffer is a pointer to pointer to a buffer - in which the file or section contents or are - returned. - @param BufferSize BufferSize is a pointer to caller allocated - UINTN. - @param AuthenticationStatus AuthenticationStatus is a pointer to a - caller allocated UINT32 in which the - authentication status is returned. - - @retval EFI_SUCCESS Successfully read the file section into - buffer. - @retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small. - @retval EFI_NOT_FOUND Section not found. - @retval EFI_DEVICE_ERROR Device error. - @retval EFI_ACCESS_DENIED Could not read. - @retval EFI_INVALID_PARAMETER Invalid parameter. - -**/ -EFI_STATUS -EFIAPI -FvReadFileSection ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN CONST EFI_GUID *NameGuid, - IN EFI_SECTION_TYPE SectionType, - IN UINTN SectionInstance, - IN OUT VOID **Buffer, - IN OUT UINTN *BufferSize, - OUT UINT32 *AuthenticationStatus - ) -{ - EFI_STATUS Status; - FV_DEVICE *FvDevice; - EFI_FV_ATTRIBUTES FvAttributes; - EFI_FV_FILETYPE FileType; - EFI_FV_FILE_ATTRIBUTES FileAttributes; - UINTN FileSize; - UINT8 *FileBuffer; - EFI_SECTION_EXTRACTION_PROTOCOL *Sep; - UINTN StreamHandle; - - if (NULL == This || NULL == NameGuid || Buffer == NULL) { - return EFI_INVALID_PARAMETER; - } - - FvDevice = FV_DEVICE_FROM_THIS (This); - - Status = This->GetVolumeAttributes (This, &FvAttributes); - if (EFI_ERROR (Status)) { - return Status; - } - // - // First check to see that FV is enabled for reads... - // - if (0 == (FvAttributes & EFI_FV2_READ_STATUS)) { - return EFI_ACCESS_DENIED; - } - // - // Read the whole file into buffer - // - FileBuffer = NULL; - Status = This->ReadFile ( - This, - NameGuid, - (VOID **) &FileBuffer, - &FileSize, - &FileType, - &FileAttributes, - AuthenticationStatus - ); - - if (EFI_ERROR (Status)) { - return Status; - } - // - // Check to see that the file actually HAS sections before we go any further. - // - if (FileType == EFI_FV_FILETYPE_RAW) { - FreePool (FileBuffer); - return EFI_NOT_FOUND; - } - // - // Located the protocol - // - Status = gBS->LocateProtocol ( - &gEfiSectionExtractionProtocolGuid, - NULL, - (VOID **) &Sep - ); - if (EFI_ERROR (Status)) { - FreePool (FileBuffer); - return Status; - } - - Status = Sep->OpenSectionStream ( - Sep, - FileSize, - FileBuffer, - &StreamHandle - ); - - if (EFI_ERROR (Status)) { - FreePool (FileBuffer); - return Status; - } - - if (SectionType == 0) { - // - // We need the whole section stream - // - Status = Sep->GetSection ( - Sep, - StreamHandle, - NULL, - NULL, - 0, - Buffer, - BufferSize, - AuthenticationStatus - ); - } else { - Status = Sep->GetSection ( - Sep, - StreamHandle, - &SectionType, - NULL, - SectionInstance, - Buffer, - BufferSize, - AuthenticationStatus - ); - } - - if (!EFI_ERROR (Status)) { - // - // Inherit the authentication status. - // - *AuthenticationStatus |= FvDevice->AuthenticationStatus; - } - - // - // Handle AuthenticationStatus if necessary - // - Sep->CloseSectionStream (Sep, StreamHandle); - - FreePool (FileBuffer); - - return Status; -} diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolWrite.c b/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolWrite.c deleted file mode 100644 index 99385e0f57..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVolWrite.c +++ /dev/null @@ -1,1586 +0,0 @@ -/** @file - Implements write firmware file. - - Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "FwVolDriver.h" - -/** - Calculate the checksum for the FFS header. - - @param FfsHeader FFS File Header which needs to calculate the checksum - -**/ -VOID -SetHeaderChecksum ( - IN EFI_FFS_FILE_HEADER *FfsHeader - ) -{ - EFI_FFS_FILE_STATE State; - UINT8 FileChecksum; - - // - // The state and the File checksum are not included - // - State = FfsHeader->State; - FfsHeader->State = 0; - - FileChecksum = FfsHeader->IntegrityCheck.Checksum.File; - FfsHeader->IntegrityCheck.Checksum.File = 0; - - FfsHeader->IntegrityCheck.Checksum.Header = 0; - - if (IS_FFS_FILE2 (FfsHeader)) { - FfsHeader->IntegrityCheck.Checksum.Header = CalculateCheckSum8 ( - (UINT8 *) FfsHeader, - sizeof (EFI_FFS_FILE_HEADER2) - ); - } else { - FfsHeader->IntegrityCheck.Checksum.Header = CalculateCheckSum8 ( - (UINT8 *) FfsHeader, - sizeof (EFI_FFS_FILE_HEADER) - ); - } - - FfsHeader->State = State; - FfsHeader->IntegrityCheck.Checksum.File = FileChecksum; - - return ; -} - -/** - Calculate the checksum for the FFS File. - - @param FfsHeader FFS File Header which needs to calculate the checksum - @param ActualFileSize The whole Ffs File Length. - -**/ -VOID -SetFileChecksum ( - IN EFI_FFS_FILE_HEADER *FfsHeader, - IN UINTN ActualFileSize - ) -{ - if ((FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) != 0) { - - FfsHeader->IntegrityCheck.Checksum.File = 0; - - if (IS_FFS_FILE2 (FfsHeader)) { - FfsHeader->IntegrityCheck.Checksum.File = CalculateCheckSum8 ( - (UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER2), - ActualFileSize - sizeof (EFI_FFS_FILE_HEADER2) - ); - } else { - FfsHeader->IntegrityCheck.Checksum.File = CalculateCheckSum8 ( - (UINT8 *) FfsHeader + sizeof (EFI_FFS_FILE_HEADER), - ActualFileSize - sizeof (EFI_FFS_FILE_HEADER) - ); - } - - } else { - - FfsHeader->IntegrityCheck.Checksum.File = FFS_FIXED_CHECKSUM; - - } - - return ; -} - -/** - Get the alignment value from File Attributes. - - @param FfsAttributes FFS attribute - - @return Alignment value. - -**/ -UINTN -GetRequiredAlignment ( - IN EFI_FV_FILE_ATTRIBUTES FfsAttributes - ) -{ - UINTN AlignmentValue; - - AlignmentValue = FfsAttributes & EFI_FV_FILE_ATTRIB_ALIGNMENT; - - if (AlignmentValue <= 3) { - return 0x08; - } - - if (AlignmentValue > 16) { - // - // Anyway, we won't reach this code - // - return 0x08; - } - - return (UINTN)1 << AlignmentValue; - -} - -/** - Calculate the leading Pad file size to meet the alignment requirement. - - @param FvDevice Cached Firmware Volume. - @param StartAddress The starting address to write the FFS File. - @param BufferSize The FFS File Buffer Size. - @param RequiredAlignment FFS File Data alignment requirement. - - @return The required Pad File Size. - -**/ -UINTN -CalculatePadFileSize ( - IN FV_DEVICE *FvDevice, - IN EFI_PHYSICAL_ADDRESS StartAddress, - IN UINTN BufferSize, - IN UINTN RequiredAlignment - ) -{ - UINTN DataStartPos; - UINTN RelativePos; - UINTN PadSize; - - if (BufferSize > 0x00FFFFFF) { - DataStartPos = (UINTN) StartAddress + sizeof (EFI_FFS_FILE_HEADER2); - } else { - DataStartPos = (UINTN) StartAddress + sizeof (EFI_FFS_FILE_HEADER); - } - RelativePos = DataStartPos - (UINTN) FvDevice->CachedFv; - - PadSize = 0; - - while ((RelativePos & (RequiredAlignment - 1)) != 0) { - RelativePos++; - PadSize++; - } - // - // If padsize is 0, no pad file needed; - // If padsize is great than 24, then pad file can be created - // - if ((PadSize == 0) || (PadSize >= sizeof (EFI_FFS_FILE_HEADER))) { - return PadSize; - } - - // - // Perhaps following method can save space - // - RelativePos = DataStartPos - (UINTN) FvDevice->CachedFv + sizeof (EFI_FFS_FILE_HEADER); - PadSize = sizeof (EFI_FFS_FILE_HEADER); - - while ((RelativePos & (RequiredAlignment - 1)) != 0) { - RelativePos++; - PadSize++; - } - - return PadSize; -} - -/** - Convert EFI_FV_FILE_ATTRIBUTES to FFS_FILE_ATTRIBUTES. - - @param FvFileAttrib The value of EFI_FV_FILE_ATTRIBUTES - @param FfsFileAttrib Pointer to the got FFS_FILE_ATTRIBUTES value. - -**/ -VOID -FvFileAttrib2FfsFileAttrib ( - IN EFI_FV_FILE_ATTRIBUTES FvFileAttrib, - OUT UINT8 *FfsFileAttrib - ) -{ - UINT8 FvFileAlignment; - UINT8 FfsFileAlignment; - - FvFileAlignment = (UINT8) (FvFileAttrib & EFI_FV_FILE_ATTRIB_ALIGNMENT); - FfsFileAlignment = 0; - - switch (FvFileAlignment) { - case 0: - // - // fall through - // - case 1: - // - // fall through - // - case 2: - // - // fall through - // - case 3: - // - // fall through - // - FfsFileAlignment = 0; - break; - - case 4: - // - // fall through - // - case 5: - // - // fall through - // - case 6: - // - // fall through - // - FfsFileAlignment = 1; - break; - - case 7: - // - // fall through - // - case 8: - // - // fall through - // - FfsFileAlignment = 2; - break; - - case 9: - FfsFileAlignment = 3; - break; - - case 10: - // - // fall through - // - case 11: - // - // fall through - // - FfsFileAlignment = 4; - break; - - case 12: - // - // fall through - // - case 13: - // - // fall through - // - case 14: - // - // fall through - // - FfsFileAlignment = 5; - break; - - case 15: - FfsFileAlignment = 6; - break; - - case 16: - FfsFileAlignment = 7; - break; - } - - *FfsFileAttrib = (UINT8) (FfsFileAlignment << 3); - - return ; -} - -/** - Locate a free space entry that can hold this FFS file. - - @param FvDevice Cached Firmware Volume. - @param Size The FFS file size. - @param RequiredAlignment FFS File Data alignment requirement. - @param PadSize Pointer to the size of leading Pad File. - @param FreeSpaceEntry Pointer to the Free Space Entry that meets the requirement. - - @retval EFI_SUCCESS The free space entry is found. - @retval EFI_NOT_FOUND The free space entry can't be found. - -**/ -EFI_STATUS -FvLocateFreeSpaceEntry ( - IN FV_DEVICE *FvDevice, - IN UINTN Size, - IN UINTN RequiredAlignment, - OUT UINTN *PadSize, - OUT FREE_SPACE_ENTRY **FreeSpaceEntry - ) -{ - FREE_SPACE_ENTRY *FreeSpaceListEntry; - LIST_ENTRY *Link; - UINTN PadFileSize; - - Link = FvDevice->FreeSpaceHeader.ForwardLink; - FreeSpaceListEntry = (FREE_SPACE_ENTRY *) Link; - - // - // Loop the free space entry list to find one that can hold the - // required the file size - // - while ((LIST_ENTRY *) FreeSpaceListEntry != &FvDevice->FreeSpaceHeader) { - PadFileSize = CalculatePadFileSize ( - FvDevice, - (EFI_PHYSICAL_ADDRESS) (UINTN) FreeSpaceListEntry->StartingAddress, - Size, - RequiredAlignment - ); - if (FreeSpaceListEntry->Length >= Size + PadFileSize) { - *FreeSpaceEntry = FreeSpaceListEntry; - *PadSize = PadFileSize; - return EFI_SUCCESS; - } - - FreeSpaceListEntry = (FREE_SPACE_ENTRY *) FreeSpaceListEntry->Link.ForwardLink; - } - - return EFI_NOT_FOUND; - -} - -/** - Locate Pad File for writing, this is got from FV Cache. - - @param FvDevice Cached Firmware Volume. - @param Size The required FFS file size. - @param RequiredAlignment FFS File Data alignment requirement. - @param PadSize Pointer to the size of leading Pad File. - @param PadFileEntry Pointer to the Pad File Entry that meets the requirement. - - @retval EFI_SUCCESS The required pad file is found. - @retval EFI_NOT_FOUND The required pad file can't be found. - -**/ -EFI_STATUS -FvLocatePadFile ( - IN FV_DEVICE *FvDevice, - IN UINTN Size, - IN UINTN RequiredAlignment, - OUT UINTN *PadSize, - OUT FFS_FILE_LIST_ENTRY **PadFileEntry - ) -{ - FFS_FILE_LIST_ENTRY *FileEntry; - EFI_FFS_FILE_STATE FileState; - EFI_FFS_FILE_HEADER *FileHeader; - UINTN PadAreaLength; - UINTN PadFileSize; - UINTN HeaderSize; - - FileEntry = (FFS_FILE_LIST_ENTRY *) FvDevice->FfsFileListHeader.ForwardLink; - - // - // travel through the whole file list to get the pad file entry - // - while (FileEntry != (FFS_FILE_LIST_ENTRY *) &FvDevice->FfsFileListHeader) { - - FileHeader = (EFI_FFS_FILE_HEADER *) FileEntry->FfsHeader; - FileState = GetFileState (FvDevice->ErasePolarity, FileHeader); - - if ((FileHeader->Type == EFI_FV_FILETYPE_FFS_PAD) && (FileState == EFI_FILE_DATA_VALID)) { - // - // we find one valid pad file, check its free area length - // - if (IS_FFS_FILE2 (FileHeader)) { - HeaderSize = sizeof (EFI_FFS_FILE_HEADER2); - PadAreaLength = FFS_FILE2_SIZE (FileHeader) - HeaderSize; - } else { - HeaderSize = sizeof (EFI_FFS_FILE_HEADER); - PadAreaLength = FFS_FILE_SIZE (FileHeader) - HeaderSize; - } - - PadFileSize = CalculatePadFileSize ( - FvDevice, - (EFI_PHYSICAL_ADDRESS) (UINTN) FileHeader + HeaderSize, - Size, - RequiredAlignment - ); - if (PadAreaLength >= (Size + PadFileSize)) { - *PadSize = PadFileSize; - *PadFileEntry = FileEntry; - return EFI_SUCCESS; - } - } - - FileEntry = (FFS_FILE_LIST_ENTRY *) (FileEntry->Link.ForwardLink); - } - - return EFI_NOT_FOUND; -} - -/** - Locate a suitable pad file for multiple file writing. - - @param FvDevice Cached Firmware Volume. - @param NumOfFiles The number of Files that needed updating - @param BufferSize The array of each file size. - @param RequiredAlignment The array of of FFS File Data alignment requirement. - @param PadSize The array of size of each leading Pad File. - @param TotalSizeNeeded The totalsize that can hold these files. - @param PadFileEntry Pointer to the Pad File Entry that meets the requirement. - - @retval EFI_SUCCESS The required pad file is found. - @retval EFI_NOT_FOUND The required pad file can't be found. - -**/ -EFI_STATUS -FvSearchSuitablePadFile ( - IN FV_DEVICE *FvDevice, - IN UINTN NumOfFiles, - IN UINTN *BufferSize, - IN UINTN *RequiredAlignment, - OUT UINTN *PadSize, - OUT UINTN *TotalSizeNeeded, - OUT FFS_FILE_LIST_ENTRY **PadFileEntry - ) -{ - FFS_FILE_LIST_ENTRY *FileEntry; - EFI_FFS_FILE_STATE FileState; - EFI_FFS_FILE_HEADER *FileHeader; - UINTN PadAreaLength; - UINTN TotalSize; - UINTN Index; - UINTN HeaderSize; - - FileEntry = (FFS_FILE_LIST_ENTRY *) FvDevice->FfsFileListHeader.ForwardLink; - - // - // travel through the whole file list to get the pad file entry - // - while (FileEntry != (FFS_FILE_LIST_ENTRY *) &FvDevice->FfsFileListHeader) { - - FileHeader = (EFI_FFS_FILE_HEADER *) FileEntry->FfsHeader; - FileState = GetFileState (FvDevice->ErasePolarity, FileHeader); - - if ((FileHeader->Type == EFI_FV_FILETYPE_FFS_PAD) && (FileState == EFI_FILE_DATA_VALID)) { - // - // we find one valid pad file, check its length - // - if (IS_FFS_FILE2 (FileHeader)) { - HeaderSize = sizeof (EFI_FFS_FILE_HEADER2); - PadAreaLength = FFS_FILE2_SIZE (FileHeader) - HeaderSize; - } else { - HeaderSize = sizeof (EFI_FFS_FILE_HEADER); - PadAreaLength = FFS_FILE_SIZE (FileHeader) - HeaderSize; - } - TotalSize = 0; - - for (Index = 0; Index < NumOfFiles; Index++) { - PadSize[Index] = CalculatePadFileSize ( - FvDevice, - (EFI_PHYSICAL_ADDRESS) (UINTN) FileHeader + HeaderSize + TotalSize, - BufferSize[Index], - RequiredAlignment[Index] - ); - TotalSize += PadSize[Index]; - TotalSize += BufferSize[Index]; - - if (TotalSize > PadAreaLength) { - break; - } - } - - if (PadAreaLength >= TotalSize) { - *PadFileEntry = FileEntry; - *TotalSizeNeeded = TotalSize; - return EFI_SUCCESS; - } - } - - FileEntry = (FFS_FILE_LIST_ENTRY *) (FileEntry->Link.ForwardLink); - } - - return EFI_NOT_FOUND; -} - -/** - Locate a Free Space entry which can hold these files, including - meeting the alignment requirements. - - @param FvDevice Cached Firmware Volume. - @param NumOfFiles The number of Files that needed updating - @param BufferSize The array of each file size. - @param RequiredAlignment The array of of FFS File Data alignment requirement. - @param PadSize The array of size of each leading Pad File. - @param TotalSizeNeeded The got total size that can hold these files. - @param FreeSpaceEntry The Free Space Entry that can hold these files. - - @retval EFI_SUCCESS The free space entry is found. - @retval EFI_NOT_FOUND The free space entry can't be found. - -**/ -EFI_STATUS -FvSearchSuitableFreeSpace ( - IN FV_DEVICE *FvDevice, - IN UINTN NumOfFiles, - IN UINTN *BufferSize, - IN UINTN *RequiredAlignment, - OUT UINTN *PadSize, - OUT UINTN *TotalSizeNeeded, - OUT FREE_SPACE_ENTRY **FreeSpaceEntry - ) -{ - FREE_SPACE_ENTRY *FreeSpaceListEntry; - LIST_ENTRY *Link; - UINTN TotalSize; - UINTN Index; - UINT8 *StartAddr; - - Link = FvDevice->FreeSpaceHeader.ForwardLink; - - FreeSpaceListEntry = (FREE_SPACE_ENTRY *) Link; - - while ((LIST_ENTRY *) FreeSpaceListEntry != &FvDevice->FreeSpaceHeader) { - TotalSize = 0; - StartAddr = FreeSpaceListEntry->StartingAddress; - - // - // Calculate the totalsize we need - // - for (Index = 0; Index < NumOfFiles; Index++) { - // - // Perhaps we don't need an EFI_FFS_FILE_HEADER, the first file - // have had its leading pad file. - // - PadSize[Index] = CalculatePadFileSize ( - FvDevice, - (EFI_PHYSICAL_ADDRESS) (UINTN) StartAddr + TotalSize, - BufferSize[Index], - RequiredAlignment[Index] - ); - - TotalSize += PadSize[Index]; - TotalSize += BufferSize[Index]; - - if (TotalSize > FreeSpaceListEntry->Length) { - break; - } - } - - if (FreeSpaceListEntry->Length >= TotalSize) { - *FreeSpaceEntry = FreeSpaceListEntry; - *TotalSizeNeeded = TotalSize; - return EFI_SUCCESS; - } - - FreeSpaceListEntry = (FREE_SPACE_ENTRY *) FreeSpaceListEntry->Link.ForwardLink; - } - - return EFI_NOT_FOUND; -} - -/** - Calculate the length of the remaining space in FV. - - @param FvDevice Cached Firmware Volume - @param Offset Current offset to FV base address. - @param Lba LBA number for the current offset. - @param LOffset Offset in block for the current offset. - - @return the length of remaining space. - -**/ -UINTN -CalculateRemainingLength ( - IN FV_DEVICE *FvDevice, - IN UINTN Offset, - OUT EFI_LBA *Lba, - OUT UINTN *LOffset - ) -{ - LIST_ENTRY *Link; - LBA_ENTRY *LbaEntry; - UINTN Count; - - Count = 0; - *Lba = 0; - Link = FvDevice->LbaHeader.ForwardLink; - LbaEntry = (LBA_ENTRY *) Link; - - while (&LbaEntry->Link != &FvDevice->LbaHeader) { - if (Count > Offset) { - break; - } - - Count += LbaEntry->BlockLength; - (*Lba)++; - Link = LbaEntry->Link.ForwardLink; - LbaEntry = (LBA_ENTRY *) Link; - } - - if (Count <= Offset) { - return 0; - } - - Link = LbaEntry->Link.BackLink; - LbaEntry = (LBA_ENTRY *) Link; - - (*Lba)--; - *LOffset = (UINTN) (LbaEntry->BlockLength - (Count - Offset)); - - Count = 0; - while (&LbaEntry->Link != &FvDevice->LbaHeader) { - - Count += LbaEntry->BlockLength; - - Link = LbaEntry->Link.ForwardLink; - LbaEntry = (LBA_ENTRY *) Link; - } - - Count -= *LOffset; - - return Count; -} - -/** - Writes data beginning at Lba:Offset from FV. The write terminates either - when *NumBytes of data have been written, or when the firmware end is - reached. *NumBytes is updated to reflect the actual number of bytes - written. - - @param FvDevice Cached Firmware Volume - @param Offset Offset in the block at which to begin write - @param NumBytes At input, indicates the requested write size. - At output, indicates the actual number of bytes written. - @param Buffer Buffer containing source data for the write. - - @retval EFI_SUCCESS Data is successfully written into FV. - @return error Data is failed written. - -**/ -EFI_STATUS -FvcWrite ( - IN FV_DEVICE *FvDevice, - IN UINTN Offset, - IN OUT UINTN *NumBytes, - IN UINT8 *Buffer - ) -{ - EFI_STATUS Status; - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; - EFI_LBA Lba; - UINTN LOffset; - EFI_FVB_ATTRIBUTES_2 FvbAttributes; - UINTN RemainingLength; - UINTN WriteLength; - UINT8 *TmpBuffer; - - LOffset = 0; - RemainingLength = CalculateRemainingLength (FvDevice, Offset, &Lba, &LOffset); - if ((UINTN) (*NumBytes) > RemainingLength) { - *NumBytes = (UINTN) RemainingLength; - return EFI_INVALID_PARAMETER; - } - - Fvb = FvDevice->Fvb; - - Status = Fvb->GetAttributes ( - Fvb, - &FvbAttributes - ); - if (EFI_ERROR (Status)) { - return Status; - } - - if ((FvbAttributes & EFI_FV2_WRITE_STATUS) == 0) { - return EFI_ACCESS_DENIED; - } - - RemainingLength = *NumBytes; - WriteLength = RemainingLength; - TmpBuffer = Buffer; - - do { - Status = Fvb->Write ( - Fvb, - Lba, - LOffset, - &WriteLength, - TmpBuffer - ); - if (!EFI_ERROR (Status)) { - goto Done; - } - - if (Status == EFI_BAD_BUFFER_SIZE) { - Lba++; - LOffset = 0; - TmpBuffer += WriteLength; - RemainingLength -= WriteLength; - WriteLength = (UINTN) RemainingLength; - - continue; - } else { - return Status; - } - } while (1); - -Done: - return EFI_SUCCESS; -} - -/** - Create a new FFS file into Firmware Volume device. - - @param FvDevice Cached Firmware Volume. - @param FfsFileBuffer A buffer that holds an FFS file,(it contains - a File Header which is in init state). - @param BufferSize The size of FfsFileBuffer. - @param ActualFileSize The actual file length, it may not be multiples of 8. - @param FileName The FFS File Name. - @param FileType The FFS File Type. - @param FileAttributes The Attributes of the FFS File to be created. - - @retval EFI_SUCCESS FFS fle is added into FV. - @retval EFI_INVALID_PARAMETER File type is not valid. - @retval EFI_DEVICE_ERROR FV doesn't set writable attribute. - @retval EFI_NOT_FOUND FV has no enough space for the added file. - -**/ -EFI_STATUS -FvCreateNewFile ( - IN FV_DEVICE *FvDevice, - IN UINT8 *FfsFileBuffer, - IN UINTN BufferSize, - IN UINTN ActualFileSize, - IN EFI_GUID *FileName, - IN EFI_FV_FILETYPE FileType, - IN EFI_FV_FILE_ATTRIBUTES FileAttributes - ) -{ - EFI_STATUS Status; - EFI_FFS_FILE_HEADER *FileHeader; - EFI_PHYSICAL_ADDRESS BufferPtr; - UINTN Offset; - UINTN NumBytesWritten; - UINTN StateOffset; - FREE_SPACE_ENTRY *FreeSpaceEntry; - UINTN RequiredAlignment; - UINTN PadFileSize; - FFS_FILE_LIST_ENTRY *PadFileEntry; - EFI_FFS_FILE_ATTRIBUTES TmpFileAttribute; - FFS_FILE_LIST_ENTRY *FfsFileEntry; - UINTN HeaderSize; - - // - // File Type: 0x0E~0xE0 are reserved - // - if ((FileType > EFI_FV_FILETYPE_SMM_CORE) && (FileType < 0xE0)) { - return EFI_INVALID_PARAMETER; - } - - // - // First find a free space that can hold this image. - // Check alignment, FFS at least must be aligned at 8-byte boundary - // - RequiredAlignment = GetRequiredAlignment (FileAttributes); - - Status = FvLocateFreeSpaceEntry ( - FvDevice, - BufferSize, - RequiredAlignment, - &PadFileSize, - &FreeSpaceEntry - ); - if (EFI_ERROR (Status)) { - // - // Maybe we need to find a PAD file that can hold this image - // - Status = FvCreateNewFileInsidePadFile ( - FvDevice, - FfsFileBuffer, - BufferSize, - ActualFileSize, - FileName, - FileType, - FileAttributes - ); - - return Status; - } - - BufferPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) FreeSpaceEntry->StartingAddress; - - // - // If we need a leading PAD File, create it first. - // - if (PadFileSize != 0) { - Status = FvCreatePadFileInFreeSpace ( - FvDevice, - FreeSpaceEntry, - PadFileSize - sizeof (EFI_FFS_FILE_HEADER), - &PadFileEntry - ); - if (EFI_ERROR (Status)) { - return Status; - } - } - // - // Maybe we create a pad file, so re-get the free space starting address - // and length - // - BufferPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) FreeSpaceEntry->StartingAddress; - - // - // File creation step 1: Allocate File Header, - // Mark EFI_FILE_HEADER_CONSTRUCTION bit to TRUE, - // Write Name, IntegrityCheck.Header, Type, Attributes, and Size - // - FileHeader = (EFI_FFS_FILE_HEADER *) FfsFileBuffer; - if (ActualFileSize > 0x00FFFFFF) { - HeaderSize = sizeof (EFI_FFS_FILE_HEADER2); - } else { - HeaderSize = sizeof (EFI_FFS_FILE_HEADER); - } - SetFileState (EFI_FILE_HEADER_CONSTRUCTION, FileHeader); - - Offset = (UINTN) (BufferPtr - FvDevice->CachedFv); - StateOffset = Offset + (UINT8 *) &FileHeader->State - (UINT8 *) FileHeader; - - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvcWrite ( - FvDevice, - StateOffset, - &NumBytesWritten, - &FileHeader->State - ); - if (EFI_ERROR (Status)) { - return Status; - } - // - // update header 2 cache - // - CopyMem ( - (UINT8 *) (UINTN) BufferPtr, - FileHeader, - HeaderSize - ); - - // - // update Free Space Entry, now need to substract the file header length - // - FreeSpaceEntry->StartingAddress += HeaderSize; - FreeSpaceEntry->Length -= HeaderSize; - - CopyGuid (&FileHeader->Name, FileName); - FileHeader->Type = FileType; - - // - // Convert FvFileAttribute to FfsFileAttributes - // - FvFileAttrib2FfsFileAttrib (FileAttributes, &TmpFileAttribute); - - FileHeader->Attributes = TmpFileAttribute; - - // - // File size is including the FFS File Header. - // - if (ActualFileSize > 0x00FFFFFF) { - ((EFI_FFS_FILE_HEADER2 *) FileHeader)->ExtendedSize = (UINT32) ActualFileSize; - *(UINT32 *) FileHeader->Size &= 0xFF000000; - FileHeader->Attributes |= FFS_ATTRIB_LARGE_FILE; - } else { - *(UINT32 *) FileHeader->Size &= 0xFF000000; - *(UINT32 *) FileHeader->Size |= ActualFileSize; - } - - SetHeaderChecksum (FileHeader); - - Offset = (UINTN) (BufferPtr - FvDevice->CachedFv); - - NumBytesWritten = HeaderSize; - Status = FvcWrite ( - FvDevice, - Offset, - &NumBytesWritten, - (UINT8 *) FileHeader - ); - if (EFI_ERROR (Status)) { - return Status; - } - // - // update header 2 cache - // - CopyMem ( - (UINT8 *) (UINTN) BufferPtr, - FileHeader, - HeaderSize - ); - - // - // end of step 1 - // - // File creation step 2: - // MARK EFI_FILE_HEADER_VALID bit to TRUE, - // Write IntegrityCheck.File, File Data - // - SetFileState (EFI_FILE_HEADER_VALID, FileHeader); - - Offset = (UINTN) (BufferPtr - FvDevice->CachedFv); - StateOffset = Offset + (UINT8 *) &FileHeader->State - (UINT8 *) FileHeader; - - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvcWrite ( - FvDevice, - StateOffset, - &NumBytesWritten, - &FileHeader->State - ); - if (EFI_ERROR (Status)) { - return Status; - } - // - // update header 2 cache - // - CopyMem ( - (UINT8 *) (UINTN) BufferPtr, - FileHeader, - HeaderSize - ); - - // - // update Free Space Entry, now need to substract the file data length - // - FreeSpaceEntry->StartingAddress += (BufferSize - HeaderSize); - FreeSpaceEntry->Length -= (BufferSize - HeaderSize); - - // - // Calculate File Checksum - // - SetFileChecksum (FileHeader, ActualFileSize); - - Offset = (UINTN) (BufferPtr - FvDevice->CachedFv); - - NumBytesWritten = BufferSize; - Status = FvcWrite ( - FvDevice, - Offset, - &NumBytesWritten, - FfsFileBuffer - ); - if (EFI_ERROR (Status)) { - return Status; - } - // - // each time write block successfully, write also to cache - // - CopyMem ( - (UINT8 *) (UINTN) BufferPtr, - FfsFileBuffer, - NumBytesWritten - ); - - // - // Step 3: Mark EFI_FILE_DATA_VALID to TRUE - // - SetFileState (EFI_FILE_DATA_VALID, FileHeader); - - Offset = (UINTN) (BufferPtr - FvDevice->CachedFv); - StateOffset = Offset + (UINT8 *) &FileHeader->State - (UINT8 *) FileHeader; - - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvcWrite ( - FvDevice, - StateOffset, - &NumBytesWritten, - &FileHeader->State - ); - if (EFI_ERROR (Status)) { - return Status; - } - // - // update header 2 cache - // - CopyMem ( - (UINT8 *) (UINTN) BufferPtr, - FileHeader, - HeaderSize - ); - - // - // If successfully, insert an FfsFileEntry at the end of ffs file list - // - - FfsFileEntry = AllocateZeroPool (sizeof (FFS_FILE_LIST_ENTRY)); - ASSERT (FfsFileEntry != NULL); - FfsFileEntry->FfsHeader = (UINT8 *) (UINTN) BufferPtr; - InsertTailList (&FvDevice->FfsFileListHeader, &FfsFileEntry->Link); - - // - // Set cache file to this file - // - FvDevice->CurrentFfsFile = FfsFileEntry; - - return EFI_SUCCESS; -} - -/** - Update a File, so after successful update, there are 2 files existing - in FV, one is marked for deleted, and another one is valid. - - @param FvDevice Cached Firmware Volume. - @param FfsFileBuffer A buffer that holds an FFS file,(it contains - a File Header which is in init state). - @param BufferSize The size of FfsFileBuffer. - @param ActualFileSize The actual file length, it may not be multiples of 8. - @param FileName The FFS File Name. - @param NewFileType The FFS File Type. - @param NewFileAttributes The Attributes of the FFS File to be created. - - @retval EFI_SUCCESS FFS fle is updated into FV. - @retval EFI_INVALID_PARAMETER File type is not valid. - @retval EFI_DEVICE_ERROR FV doesn't set writable attribute. - @retval EFI_NOT_FOUND FV has no enough space for the added file. - FFS with same file name is not found in FV. - -**/ -EFI_STATUS -FvUpdateFile ( - IN FV_DEVICE *FvDevice, - IN UINT8 *FfsFileBuffer, - IN UINTN BufferSize, - IN UINTN ActualFileSize, - IN EFI_GUID *FileName, - IN EFI_FV_FILETYPE NewFileType, - IN EFI_FV_FILE_ATTRIBUTES NewFileAttributes - ) -{ - EFI_STATUS Status; - EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; - UINTN NumBytesWritten; - EFI_FV_FILETYPE OldFileType; - EFI_FV_FILE_ATTRIBUTES OldFileAttributes; - UINTN OldFileSize; - EFI_FFS_FILE_HEADER *OldFileHeader; - UINTN OldOffset; - UINTN OldStateOffset; - FFS_FILE_LIST_ENTRY *OldFfsFileEntry; - UINTN Key; - EFI_GUID FileNameGuid; - - Fv = &FvDevice->Fv; - - // - // Step 1, find old file, - // Mark EFI_FILE_MARKED_FOR_UPDATE to TRUE in the older header - // - - // - // Check if the file was read last time. - // - OldFileHeader = NULL; - OldFfsFileEntry = FvDevice->CurrentFfsFile; - - if (OldFfsFileEntry != NULL) { - OldFileHeader = (EFI_FFS_FILE_HEADER *) OldFfsFileEntry->FfsHeader; - } - - if ((OldFfsFileEntry == NULL) || (!CompareGuid (&OldFileHeader->Name, FileName))) { - Key = 0; - do { - OldFileType = 0; - Status = Fv->GetNextFile ( - Fv, - &Key, - &OldFileType, - &FileNameGuid, - &OldFileAttributes, - &OldFileSize - ); - if (EFI_ERROR (Status)) { - return Status; - } - } while (!CompareGuid (&FileNameGuid, FileName)); - - // - // Get FfsFileEntry from the search key - // - OldFfsFileEntry = (FFS_FILE_LIST_ENTRY *) Key; - - // - // Double check file state before being ready to be removed - // - OldFileHeader = (EFI_FFS_FILE_HEADER *) OldFfsFileEntry->FfsHeader; - } else { - // - // Mark the cache file to invalid - // - FvDevice->CurrentFfsFile = NULL; - } - // - // Update File: Mark EFI_FILE_MARKED_FOR_UPDATE to TRUE - // - SetFileState (EFI_FILE_MARKED_FOR_UPDATE, OldFileHeader); - - OldOffset = (UINTN) ((EFI_PHYSICAL_ADDRESS) (UINTN) OldFileHeader - FvDevice->CachedFv); - OldStateOffset = OldOffset + (UINT8 *) &OldFileHeader->State - (UINT8 *) OldFileHeader; - - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvcWrite ( - FvDevice, - OldStateOffset, - &NumBytesWritten, - &OldFileHeader->State - ); - if (EFI_ERROR (Status)) { - // - // if failed, write the bit back in the cache, its XOR operation. - // - SetFileState (EFI_FILE_MARKED_FOR_UPDATE, OldFileHeader); - - return Status; - } - - // - // Step 2, Create New Files - // - Status = FvCreateNewFile ( - FvDevice, - FfsFileBuffer, - BufferSize, - ActualFileSize, - FileName, - NewFileType, - NewFileAttributes - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // If successfully, remove this file entry, - // although delete file may fail. - // - (OldFfsFileEntry->Link.BackLink)->ForwardLink = OldFfsFileEntry->Link.ForwardLink; - (OldFfsFileEntry->Link.ForwardLink)->BackLink = OldFfsFileEntry->Link.BackLink; - FreePool (OldFfsFileEntry); - - // - // Step 3: Delete old files, - // by marking EFI_FILE_DELETED to TRUE - // - SetFileState (EFI_FILE_DELETED, OldFileHeader); - - OldOffset = (UINTN) ((EFI_PHYSICAL_ADDRESS) (UINTN) OldFileHeader - FvDevice->CachedFv); - OldStateOffset = OldOffset + (UINT8 *) &OldFileHeader->State - (UINT8 *) OldFileHeader; - - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvcWrite ( - FvDevice, - OldStateOffset, - &NumBytesWritten, - &OldFileHeader->State - ); - if (EFI_ERROR (Status)) { - // - // if failed, write the bit back in the cache, its XOR operation. - // - SetFileState (EFI_FILE_DELETED, OldFileHeader); - - return Status; - } - - return EFI_SUCCESS; -} - -/** - Deleted a given file from FV device. - - @param FvDevice Cached Firmware Volume. - @param NameGuid The FFS File Name. - - @retval EFI_SUCCESS FFS file with the specified FFS name is removed. - @retval EFI_NOT_FOUND FFS file with the specified FFS name is not found. - -**/ -EFI_STATUS -FvDeleteFile ( - IN FV_DEVICE *FvDevice, - IN EFI_GUID *NameGuid - ) -{ - EFI_STATUS Status; - UINTN Key; - EFI_GUID FileNameGuid; - EFI_FV_FILETYPE FileType; - EFI_FV_FILE_ATTRIBUTES FileAttributes; - UINTN FileSize; - EFI_FFS_FILE_HEADER *FileHeader; - FFS_FILE_LIST_ENTRY *FfsFileEntry; - EFI_FFS_FILE_STATE FileState; - EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv; - UINTN Offset; - UINTN StateOffset; - UINTN NumBytesWritten; - - Fv = &FvDevice->Fv; - - // - // Check if the file was read last time. - // - FileHeader = NULL; - FfsFileEntry = FvDevice->CurrentFfsFile; - - if (FfsFileEntry != NULL) { - FileHeader = (EFI_FFS_FILE_HEADER *) FfsFileEntry->FfsHeader; - } - - if ((FfsFileEntry == NULL) || (!CompareGuid (&FileHeader->Name, NameGuid))) { - // - // Next search for the file using GetNextFile - // - Key = 0; - do { - FileType = 0; - Status = Fv->GetNextFile ( - Fv, - &Key, - &FileType, - &FileNameGuid, - &FileAttributes, - &FileSize - ); - if (EFI_ERROR (Status)) { - return Status; - } - } while (!CompareGuid (&FileNameGuid, NameGuid)); - - // - // Get FfsFileEntry from the search key - // - FfsFileEntry = (FFS_FILE_LIST_ENTRY *) Key; - - // - // Double check file state before being ready to be removed - // - FileHeader = (EFI_FFS_FILE_HEADER *) FfsFileEntry->FfsHeader; - } else { - // - // Mark the cache file to NULL - // - FvDevice->CurrentFfsFile = NULL; - } - - FileState = GetFileState (FvDevice->ErasePolarity, FileHeader); - - if (FileState == EFI_FILE_HEADER_INVALID) { - return EFI_NOT_FOUND; - } - - if (FileState == EFI_FILE_DELETED) { - return EFI_NOT_FOUND; - } - // - // Delete File: Mark EFI_FILE_DELETED to TRUE - // - SetFileState (EFI_FILE_DELETED, FileHeader); - - Offset = (UINTN) ((EFI_PHYSICAL_ADDRESS) (UINTN) FileHeader - FvDevice->CachedFv); - StateOffset = Offset + (UINT8 *) &FileHeader->State - (UINT8 *) FileHeader; - - NumBytesWritten = sizeof (EFI_FFS_FILE_STATE); - Status = FvcWrite ( - FvDevice, - StateOffset, - &NumBytesWritten, - &FileHeader->State - ); - if (EFI_ERROR (Status)) { - // - // if failed, write the bit back in the cache, its XOR operation. - // - SetFileState (EFI_FILE_DELETED, FileHeader); - - return Status; - } - // - // If successfully, remove this file entry - // - FvDevice->CurrentFfsFile = NULL; - - (FfsFileEntry->Link.BackLink)->ForwardLink = FfsFileEntry->Link.ForwardLink; - (FfsFileEntry->Link.ForwardLink)->BackLink = FfsFileEntry->Link.BackLink; - FreePool (FfsFileEntry); - - return EFI_SUCCESS; -} - -/** - Writes one or more files to the firmware volume. - - @param This Indicates the calling context. - @param NumberOfFiles Number of files. - @param WritePolicy WritePolicy indicates the level of reliability - for the write in the event of a power failure or - other system failure during the write operation. - @param FileData FileData is an pointer to an array of - EFI_FV_WRITE_DATA. Each element of array - FileData represents a file to be written. - - @retval EFI_SUCCESS Files successfully written to firmware volume - @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated. - @retval EFI_DEVICE_ERROR Device error. - @retval EFI_WRITE_PROTECTED Write protected. - @retval EFI_NOT_FOUND Not found. - @retval EFI_INVALID_PARAMETER Invalid parameter. - @retval EFI_UNSUPPORTED This function not supported. - -**/ -EFI_STATUS -EFIAPI -FvWriteFile ( - IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This, - IN UINT32 NumberOfFiles, - IN EFI_FV_WRITE_POLICY WritePolicy, - IN EFI_FV_WRITE_FILE_DATA *FileData - ) -{ - EFI_STATUS Status; - UINTN Index1; - UINTN Index2; - UINT8 *FileBuffer; - UINTN BufferSize; - UINTN ActualSize; - UINT8 ErasePolarity; - FV_DEVICE *FvDevice; - EFI_FV_FILETYPE FileType; - EFI_FV_FILE_ATTRIBUTES FileAttributes; - UINTN Size; - BOOLEAN CreateNewFile[MAX_FILES]; - UINTN NumDelete; - EFI_FV_ATTRIBUTES FvAttributes; - UINT32 AuthenticationStatus; - UINTN HeaderSize; - - if (NumberOfFiles > MAX_FILES) { - return EFI_UNSUPPORTED; - } - - Status = EFI_SUCCESS; - - SetMem (CreateNewFile, NumberOfFiles, TRUE); - - FvDevice = FV_DEVICE_FROM_THIS (This); - - // - // First check the volume attributes. - // - Status = This->GetVolumeAttributes ( - This, - &FvAttributes - ); - if (EFI_ERROR (Status)) { - return Status; - } - // - // Can we have write right? - // - if ((FvAttributes & EFI_FV2_WRITE_STATUS) == 0) { - return EFI_WRITE_PROTECTED; - } - - ErasePolarity = FvDevice->ErasePolarity; - - // - // Loop for all files - // - NumDelete = 0; - for (Index1 = 0; Index1 < NumberOfFiles; Index1++) { - - if ((FileData[Index1].BufferSize + sizeof (EFI_FFS_FILE_HEADER) > 0x00FFFFFF) && !FvDevice->IsFfs3Fv) { - // - // Found a file needs a FFS3 formatted file to store it, but it is in a non-FFS3 formatted FV. - // - DEBUG ((EFI_D_ERROR, "FFS3 formatted file can't be written in a non-FFS3 formatted FV.\n")); - return EFI_INVALID_PARAMETER; - } - - if (FileData[Index1].BufferSize == 0) { - // - // Here we will delete this file - // - Status = This->ReadFile ( - This, - FileData[Index1].NameGuid, - NULL, - &Size, - &FileType, - &FileAttributes, - &AuthenticationStatus - ); - if (!EFI_ERROR (Status)) { - NumDelete++; - } else { - return Status; - } - } - - if (FileData[Index1].Type == EFI_FV_FILETYPE_FFS_PAD) { - // - // According to PI spec, on EFI_FV_FILETYPE_FFS_PAD: - // "Standard firmware file system services will not return the handle of any pad files, - // nor will they permit explicit creation of such files." - // - return EFI_INVALID_PARAMETER; - } - } - - if ((NumDelete != NumberOfFiles) && (NumDelete != 0)) { - // - // A delete was request with a multiple file write - // - return EFI_INVALID_PARAMETER; - } - - if (NumDelete == NumberOfFiles) { - for (Index1 = 0; Index1 < NumberOfFiles; Index1++) { - // - // Delete Files - // - Status = FvDeleteFile (FvDevice, FileData[Index1].NameGuid); - if (EFI_ERROR (Status)) { - return Status; - } - } - - return EFI_SUCCESS; - } - - for (Index1 = 0; Index1 < NumberOfFiles; Index1++) { - Status = This->ReadFile ( - This, - FileData[Index1].NameGuid, - NULL, - &Size, - &FileType, - &FileAttributes, - &AuthenticationStatus - ); - if (!EFI_ERROR (Status)) { - CreateNewFile[Index1] = FALSE; - } else if (Status == EFI_NOT_FOUND) { - CreateNewFile[Index1] = TRUE; - } else { - return Status; - } - // - // Checking alignment - // - if ((FileData[Index1].FileAttributes & EFI_FV_FILE_ATTRIB_ALIGNMENT) != 0) { - UINT8 FFSAlignmentValue; - UINT8 FvAlignmentValue; - - FFSAlignmentValue = (UINT8) (FileData[Index1].FileAttributes & EFI_FV_FILE_ATTRIB_ALIGNMENT); - FvAlignmentValue = (UINT8) (((UINT32) (FvAttributes & EFI_FV2_ALIGNMENT)) >> 16); - - if (FFSAlignmentValue > FvAlignmentValue) { - return EFI_INVALID_PARAMETER; - } - } - } - - if ((WritePolicy != EFI_FV_RELIABLE_WRITE) && (WritePolicy != EFI_FV_UNRELIABLE_WRITE)) { - return EFI_INVALID_PARAMETER; - } - // - // Checking the reliable write is supported by FV - // - - if ((WritePolicy == EFI_FV_RELIABLE_WRITE) && (NumberOfFiles > 1)) { - // - // Only for multiple files, reliable write is meaningful - // - Status = FvCreateMultipleFiles ( - FvDevice, - NumberOfFiles, - FileData, - CreateNewFile - ); - - return Status; - } - - for (Index1 = 0; Index1 < NumberOfFiles; Index1++) { - // - // Making Buffersize QWORD boundary, and add file tail. - // - HeaderSize = sizeof (EFI_FFS_FILE_HEADER); - ActualSize = FileData[Index1].BufferSize + HeaderSize; - if (ActualSize > 0x00FFFFFF) { - HeaderSize = sizeof (EFI_FFS_FILE_HEADER2); - ActualSize = FileData[Index1].BufferSize + HeaderSize; - } - BufferSize = ActualSize; - - while ((BufferSize & 0x07) != 0) { - BufferSize++; - } - - FileBuffer = AllocateZeroPool (BufferSize); - if (FileBuffer == NULL) { - return Status; - } - // - // Copy File Data into FileBuffer - // - CopyMem ( - FileBuffer + HeaderSize, - FileData[Index1].Buffer, - FileData[Index1].BufferSize - ); - - if (ErasePolarity == 1) { - // - // Fill the file header and padding byte with Erase Byte - // - for (Index2 = 0; Index2 < HeaderSize; Index2++) { - FileBuffer[Index2] = (UINT8)~FileBuffer[Index2]; - } - - for (Index2 = ActualSize; Index2 < BufferSize; Index2++) { - FileBuffer[Index2] = (UINT8)~FileBuffer[Index2]; - } - } - - if (CreateNewFile[Index1]) { - Status = FvCreateNewFile ( - FvDevice, - FileBuffer, - BufferSize, - ActualSize, - FileData[Index1].NameGuid, - FileData[Index1].Type, - FileData[Index1].FileAttributes - ); - } else { - Status = FvUpdateFile ( - FvDevice, - FileBuffer, - BufferSize, - ActualSize, - FileData[Index1].NameGuid, - FileData[Index1].Type, - FileData[Index1].FileAttributes - ); - } - - FreePool (FileBuffer); - - if (EFI_ERROR (Status)) { - return Status; - } - } - - return EFI_SUCCESS; -} diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/FlashUpdate.c b/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/FlashUpdate.c deleted file mode 100644 index 56514c9855..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/FlashUpdate.c +++ /dev/null @@ -1,1218 +0,0 @@ -/** @file - Functions in this file will program the image into flash area. - - Copyright (c) 2002 - 2010, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "UpdateDriver.h" - -/** - Write a block size data into flash. - - @param FvbProtocol Pointer to FVB protocol. - @param Lba Logic block index to be updated. - @param BlockSize Block size - @param Buffer Buffer data to be written. - - @retval EFI_SUCCESS Write data successfully. - @retval other errors Write data failed. - -**/ -EFI_STATUS -UpdateOneBlock ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN EFI_LBA Lba, - IN UINTN BlockSize, - IN UINT8 *Buffer - ) -{ - EFI_STATUS Status; - UINTN Size; - - // - // First erase the block - // - Status = FvbProtocol->EraseBlocks ( - FvbProtocol, - Lba, // Lba - 1, // NumOfBlocks - EFI_LBA_LIST_TERMINATOR - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Write the block - // - Size = BlockSize; - Status = FvbProtocol->Write ( - FvbProtocol, - Lba, // Lba - 0, // Offset - &Size, // Size - Buffer // Buffer - ); - if ((EFI_ERROR (Status)) || (Size != BlockSize)) { - return Status; - } - - return EFI_SUCCESS; -} - -/** - Write buffer data in a flash block. - - @param FvbProtocol Pointer to FVB protocol. - @param Lba Logic block index to be updated. - @param Offset The offset within the block. - @param Length Size of buffer to be updated. - @param BlockSize Block size. - @param Buffer Buffer data to be updated. - - @retval EFI_SUCCESS Write data successfully. - @retval other errors Write data failed. - -**/ -EFI_STATUS -UpdateBufferInOneBlock ( - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN EFI_LBA Lba, - IN UINTN Offset, - IN UINTN Length, - IN UINTN BlockSize, - IN UINT8 *Buffer - ) -{ - EFI_STATUS Status; - UINTN Size; - UINT8 *ReservedBuffer; - - // - // If we are going to update a whole block - // - if ((Offset == 0) && (Length == BlockSize)) { - Status = UpdateOneBlock ( - FvbProtocol, - Lba, - BlockSize, - Buffer - ); - return Status; - } - - // - // If it is not a full block update, we need to coalesce data in - // the block that is not going to be updated and new data together. - // - - // - // Allocate a reserved buffer to make up the final buffer for update - // - ReservedBuffer = NULL; - ReservedBuffer = AllocatePool (BlockSize); - if (ReservedBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - // - // First get the original content of the block - // - Size = BlockSize; - Status = FvbProtocol->Read ( - FvbProtocol, - Lba, - 0, - &Size, - ReservedBuffer - ); - if ((EFI_ERROR (Status)) || (Size != BlockSize)) { - FreePool (ReservedBuffer); - return Status; - } - - // - // Overwrite the reserved buffer with new content - // - CopyMem (ReservedBuffer + Offset, Buffer, Length); - - Status = UpdateOneBlock ( - FvbProtocol, - Lba, - BlockSize, - ReservedBuffer - ); - - FreePool (ReservedBuffer); - - return Status; -} - -/** - Get the last write log, and check the status of last write. - If not complete, restart will be taken. - - @param FvbHandle Handle of FVB protocol. - @param FtwProtocol FTW protocol instance. - @param ConfigData Config data on updating driver. - @param PrivateDataSize bytes from the private data - stored for this write. - @param PrivateData A pointer to a buffer. The function will copy. - @param Lba The logical block address of the last write. - @param Offset The offset within the block of the last write. - @param Length The length of the last write. - @param Pending A Boolean value with TRUE indicating - that the write was completed. - - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval EFI_ABORTED The FTW work space is damaged. - @retval EFI_NOT_FOUND The last write is not done by this driver. - @retval EFI_SUCCESS Last write log is got. - -**/ -EFI_STATUS -RetrieveLastWrite ( - IN EFI_HANDLE FvbHandle, - IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol, - IN UPDATE_CONFIG_DATA *ConfigData, - IN UINTN PrivateDataSize, - IN OUT UPDATE_PRIVATE_DATA *PrivateData, - IN OUT EFI_LBA *Lba, - IN OUT UINTN *Offset, - IN OUT UINTN *Length, - IN OUT BOOLEAN *Pending - ) -{ - EFI_STATUS Status; - EFI_GUID CallerId; - UINTN PrivateBufferSize; - BOOLEAN Complete; - VOID *PrivateDataBuffer; - - // - // Get the last write - // - *Pending = FALSE; - PrivateBufferSize = PrivateDataSize; - PrivateDataBuffer = NULL; - Status = FtwProtocol->GetLastWrite ( - FtwProtocol, - &CallerId, - Lba, - Offset, - Length, - &PrivateBufferSize, - PrivateData, - &Complete - ); - if (EFI_ERROR (Status)) { - // - // If there is no incompleted record, return success. - // - if ((Status == EFI_NOT_FOUND) && Complete) { - return EFI_SUCCESS; - } else if (Status == EFI_BUFFER_TOO_SMALL) { - // - // If buffer too small, reallocate buffer and call getlastwrite again - // - PrivateDataBuffer = AllocatePool (PrivateBufferSize); - - if (PrivateDataBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Status = FtwProtocol->GetLastWrite ( - FtwProtocol, - &CallerId, - Lba, - Offset, - Length, - &PrivateBufferSize, - PrivateDataBuffer, - &Complete - ); - if (EFI_ERROR (Status)) { - FreePool ( PrivateDataBuffer); - return EFI_ABORTED; - } else { - CopyMem (PrivateData, PrivateDataBuffer, PrivateDataSize); - FreePool (PrivateDataBuffer); - PrivateDataBuffer = NULL; - } - } else { - return EFI_ABORTED; - } - } - - *Pending = TRUE; - - // - // If the caller is not the update driver, then return. - // The update driver cannot continue to perform the update - // - if (CompareMem (&CallerId, &gEfiCallerIdGuid, sizeof (EFI_GUID)) != 0) { - return EFI_NOT_FOUND; - } - - // - // Check the private data and see if it is the one I need. - // - if (CompareMem (&(PrivateData->FileGuid), &(ConfigData->FileGuid), sizeof(EFI_GUID)) != 0) { - return EFI_NOT_FOUND; - } - - // - // If the caller is the update driver and complete is not true, then restart(). - // - if (!Complete) { - // - // Re-start the update - // - Status = FtwProtocol->Restart ( - FtwProtocol, - FvbHandle - ); - // - // If restart() error, then abort(). - // - if (EFI_ERROR (Status)) { - FtwProtocol->Abort (FtwProtocol); - // - // Now set Pending as FALSE as this record has been cleared - // - *Pending = FALSE; - return EFI_SUCCESS; - } - - } - - return Status; -} - -/** - Update the whole FV image in fault tolerant write method. - - @param FvbHandle Handle of FVB protocol for the updated flash range. - @param FvbProtocol FVB protocol. - @param BlockMap Block array to specify flash area. - @param ConfigData Config data on updating driver. - @param ImageBuffer Image buffer to be updated. - @param ImageSize Image size. - - @retval EFI_SUCCESS FV image is writed into flash. - @retval EFI_INVALID_PARAMETER Config data is not valid. - @retval EFI_NOT_FOUND FTW protocol doesn't exist. - @retval EFI_OUT_OF_RESOURCES No enough backup space. - @retval EFI_ABORTED Error happen when update FV. - -**/ -EFI_STATUS -FaultTolerantUpdateOnWholeFv ( - IN EFI_HANDLE FvbHandle, - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN EFI_FV_BLOCK_MAP_ENTRY *BlockMap, - IN UPDATE_CONFIG_DATA *ConfigData, - IN UINT8 *ImageBuffer, - IN UINTN ImageSize - ) -{ - EFI_STATUS Status; - EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol; - UINTN MaxBlockSize; - UINTN FtwMaxBlockSize; - BOOLEAN Pending; - UPDATE_PRIVATE_DATA PrivateData; - EFI_LBA PendingLba; - EFI_LBA Lba; - UINTN PendingOffset; - UINTN Offset; - UINTN PendingLength; - UINTN Length; - EFI_FV_BLOCK_MAP_ENTRY *PtrMap; - UINTN NumOfBlocks; - UINTN Index; - UINT8 *UpdateBuffer; - - if ((ConfigData->UpdateType != UpdateWholeFV) - || (!ConfigData->FaultTolerant)) { - return EFI_INVALID_PARAMETER; - } - - // - // Get the FTW protocol - // - Status = gBS->LocateProtocol ( - &gEfiFaultTolerantWriteProtocolGuid, - NULL, - (VOID **) &FtwProtocol - ); - if (EFI_ERROR (Status)) { - return EFI_NOT_FOUND; - } - - // - // Get the maximum block size of the FV, and number of blocks - // NumOfBlocks will be the NumOfUdpates. - // - MaxBlockSize = 0; - NumOfBlocks = 0; - PtrMap = BlockMap; - while (TRUE) { - if ((PtrMap->NumBlocks == 0) || (PtrMap->Length == 0)) { - break; - } - if (MaxBlockSize < PtrMap->Length) { - MaxBlockSize = PtrMap->Length; - } - NumOfBlocks = NumOfBlocks + PtrMap->NumBlocks; - PtrMap++; - } - - FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize); - // - // Not enough backup space. return directly - // - if (FtwMaxBlockSize < MaxBlockSize) { - return EFI_OUT_OF_RESOURCES; - } - - PendingLba = 0; - PendingOffset = 0; - PendingLength = 0; - Pending = FALSE; - - // - // Fault Tolerant Write can only support actual fault tolerance if the write - // is a reclaim operation, which means the data buffer (new and old) are - // acutally both stored in flash. But for component update write, the data - // are now in memory. So we cannot actually recover the data after power - // failure. - // - Status = RetrieveLastWrite ( - FvbHandle, - FtwProtocol, - ConfigData, - sizeof (UPDATE_PRIVATE_DATA), - &PrivateData, - &PendingLba, - &PendingOffset, - &PendingLength, - &Pending - ); - - if (Pending && (Status == EFI_NOT_FOUND)) { - // - // Cannot continue with the write operation - // - return EFI_ABORTED; - } - - if (EFI_ERROR(Status)) { - return EFI_ABORTED; - } - - // - // Currently we start from the pending write if there is any. But as we - // are going to update a whole FV, we can just abort last write and start - // from the very begining. - // - if (!Pending) { - // - // Now allocte the update private data in FTW. If there is pending - // write, it has already been allocated and no need to allocate here. - // - Status = FtwProtocol->Allocate ( - FtwProtocol, - &gEfiCallerIdGuid, - sizeof (UPDATE_PRIVATE_DATA), - NumOfBlocks - ); - if (EFI_ERROR (Status)) { - return Status; - } - } - - // - // Perform the update now. If there are pending writes, we need to - // start from the pending write instead of the very beginning. - // - PtrMap = BlockMap; - Lba = 0; - Offset = 0; - UpdateBuffer = ImageBuffer; - CopyMem ( - (VOID *) &PrivateData.FileGuid, - (VOID *) &ConfigData->FileGuid, - sizeof (EFI_GUID) - ); - - while (TRUE) { - if ((PtrMap->NumBlocks == 0) || (PtrMap->Length == 0)) { - break; - } - Length = (UINTN)PtrMap->Length; - for (Index = 0; Index < PtrMap->NumBlocks; Index++) { - - // - // Add an extra check here to see if the pending record is correct - // - if (Pending && (Lba == PendingLba)) { - if ((PendingOffset != Offset) || (PendingLength != Length)) { - // - // Error. - // - Status = EFI_ABORTED; - break; - } - } - - if ((!Pending) || (Lba >= PendingLba)) { - Status = FtwProtocol->Write ( - FtwProtocol, - Lba, // Lba - Offset, // Offset - Length, // Size - &PrivateData, // Private Data - FvbHandle, // FVB handle - UpdateBuffer // Buffer - ); - } - - if (EFI_ERROR (Status)) { - break; - } - Lba++; - UpdateBuffer = (UINT8 *) ((UINTN)UpdateBuffer + Length); - } - - if (EFI_ERROR (Status)) { - break; - } - PtrMap++; - } - - return Status; - -} - -/** - Directly update the whole FV image without fault tolerant write method. - - @param FvbHandle Handle of FVB protocol for the updated flash range. - @param FvbProtocol FVB protocol. - @param BlockMap Block array to specify flash area. - @param ConfigData Config data on updating driver. - @param ImageBuffer Image buffer to be updated. - @param ImageSize Image size. - - @retval EFI_SUCCESS FV image is writed into flash. - @retval EFI_INVALID_PARAMETER Config data is not valid. - @retval EFI_ABORTED Error happen when update FV. - -**/ -EFI_STATUS -NonFaultTolerantUpdateOnWholeFv ( - IN EFI_HANDLE FvbHandle, - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN EFI_FV_BLOCK_MAP_ENTRY *BlockMap, - IN UPDATE_CONFIG_DATA *ConfigData, - IN UINT8 *ImageBuffer, - IN UINTN ImageSize - ) -{ - EFI_STATUS Status; - EFI_FV_BLOCK_MAP_ENTRY *PtrMap; - UINTN Index; - EFI_LBA UpdateLba; - UINT8 *UpdateBuffer; - UINTN UpdateSize; - - if ((ConfigData->UpdateType != UpdateWholeFV ) - || (ConfigData->FaultTolerant)) { - return EFI_INVALID_PARAMETER; - } - - Status = EFI_SUCCESS; - PtrMap = BlockMap; - UpdateLba = 0; - UpdateBuffer = ImageBuffer; - - // - // Perform the update now - // - while (TRUE) { - if ((PtrMap->NumBlocks == 0) || (PtrMap->Length == 0)) { - break; - } - UpdateSize = (UINTN)PtrMap->Length; - for (Index = 0; Index < PtrMap->NumBlocks; Index++) { - Status = UpdateOneBlock ( - FvbProtocol, - UpdateLba, - UpdateSize, - UpdateBuffer - ); - if (EFI_ERROR (Status)) { - break; - } - - UpdateLba++; - UpdateBuffer = (UINT8 *) ((UINTN)UpdateBuffer + UpdateSize); - } - - if (EFI_ERROR (Status)) { - break; - } - PtrMap++; - } - - return Status; -} - -/** - Update the whole FV image, and reinsall FVB protocol for the updated FV image. - - @param FvbHandle Handle of FVB protocol for the updated flash range. - @param FvbProtocol FVB protocol. - @param ConfigData Config data on updating driver. - @param ImageBuffer Image buffer to be updated. - @param ImageSize Image size. - - @retval EFI_INVALID_PARAMETER Update type is not UpdateWholeFV. - Or Image size is not same to the size of whole FV. - @retval EFI_OUT_OF_RESOURCES No enoug memory is allocated. - @retval EFI_SUCCESS FV image is updated, and its FVB protocol is reinstalled. - -**/ -EFI_STATUS -PerformUpdateOnWholeFv ( - IN EFI_HANDLE FvbHandle, - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN UPDATE_CONFIG_DATA *ConfigData, - IN UINT8 *ImageBuffer, - IN UINTN ImageSize -) -{ - EFI_STATUS Status; - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - EFI_FV_BLOCK_MAP_ENTRY *BlockMap; - CHAR16 *TmpStr; - - if (ConfigData->UpdateType != UpdateWholeFV) { - return EFI_INVALID_PARAMETER; - } - - // - // Get the header of the firmware volume - // - FwVolHeader = NULL; - FwVolHeader = AllocatePool (((EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (ConfigData->BaseAddress)))->HeaderLength); - if (FwVolHeader == NULL) { - return EFI_OUT_OF_RESOURCES; - } - CopyMem ( - FwVolHeader, - (VOID *) ((UINTN) (ConfigData->BaseAddress)), - ((EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) (ConfigData->BaseAddress)))->HeaderLength - ); - - // - // Check if ImageSize is the same as the size of the whole FV - // - if ((UINT64)ImageSize != FwVolHeader->FvLength) { - FreePool (FwVolHeader); - return EFI_INVALID_PARAMETER; - } - - // - // Print on screen - // - TmpStr = HiiGetString (gHiiHandle, STRING_TOKEN(UPDATE_FIRMWARE_VOLUME), NULL); - if (TmpStr != NULL) { - Print (TmpStr, ConfigData->BaseAddress, (FwVolHeader->FvLength + ConfigData->BaseAddress)); - FreePool (TmpStr); - } - - DEBUG ((EFI_D_UPDATE, "UpdateDriver: updating whole FV from %08LX to %08LX\n", - ConfigData->BaseAddress, (FwVolHeader->FvLength + ConfigData->BaseAddress))); - - // - // Get the block map of the firmware volume - // - BlockMap = &(FwVolHeader->BlockMap[0]); - - // - // It is about the same if we are going to fault tolerantly update - // a certain FV in our current design. But we divide non-fault tolerant - // and fault tolerant udpate here for better maintenance as fault - // tolerance may change and may be done more wisely if we have space. - // - if (ConfigData->FaultTolerant) { - Status = FaultTolerantUpdateOnWholeFv ( - FvbHandle, - FvbProtocol, - BlockMap, - ConfigData, - ImageBuffer, - ImageSize - ); - } else { - Status = NonFaultTolerantUpdateOnWholeFv ( - FvbHandle, - FvbProtocol, - BlockMap, - ConfigData, - ImageBuffer, - ImageSize - ); - } - - FreePool (FwVolHeader); - - if (EFI_ERROR (Status)) { - return Status; - } - - // - // As the whole FV has been replaced, the FV driver shall re-parse the - // firmware volume. So re-install FVB protocol here - // - Status = gBS->ReinstallProtocolInterface ( - FvbHandle, - &gEfiFirmwareVolumeBlockProtocolGuid, - FvbProtocol, - FvbProtocol - ); - - return Status; -} - -/** - Update certain file in the FV. - - @param FvbHandle Handle of FVB protocol for the updated flash range. - @param FvbProtocol FVB protocol. - @param ConfigData Config data on updating driver. - @param ImageBuffer Image buffer to be updated. - @param ImageSize Image size. - @param FileType FFS file type. - @param FileAttributes FFS file attribute - - @retval EFI_INVALID_PARAMETER Update type is not UpdateFvFile. - Or Image size is not same to the size of whole FV. - @retval EFI_UNSUPPORTED PEIM FFS is unsupported to be updated. - @retval EFI_SUCCESS The FFS file is added into FV. - -**/ -EFI_STATUS -PerformUpdateOnFvFile ( - IN EFI_HANDLE FvbHandle, - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN UPDATE_CONFIG_DATA *ConfigData, - IN UINT8 *ImageBuffer, - IN UINTN ImageSize, - IN EFI_FV_FILETYPE FileType, - IN EFI_FV_FILE_ATTRIBUTES FileAttributes - ) -{ - EFI_STATUS Status; - EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVolProtocol; - EFI_FV_WRITE_FILE_DATA FileData; - CHAR16 *TmpStr; - - if (ConfigData->UpdateType != UpdateFvFile) { - return EFI_INVALID_PARAMETER; - } - - // - // Print on screen - // - TmpStr = HiiGetString (gHiiHandle, STRING_TOKEN(UPDATE_FIRMWARE_VOLUME_FILE), NULL); - if (TmpStr != NULL) { - Print (TmpStr, &(ConfigData->FileGuid)); - FreePool (TmpStr); - } - - DEBUG ((EFI_D_UPDATE, "UpdateDriver: updating file: %g\n", - &(ConfigData->FileGuid))); - - // - // Get Firmware volume protocol on this FVB protocol - // - Status = gBS->HandleProtocol ( - FvbHandle, - &gEfiFirmwareVolume2ProtocolGuid, - (VOID **) &FwVolProtocol - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // - // If it is a PEIM, we need first to rebase it before committing - // the write to target - // - if ((FileType == EFI_FV_FILETYPE_PEI_CORE) || (FileType == EFI_FV_FILETYPE_PEIM ) - || (FileType == EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER)) { - return EFI_UNSUPPORTED; - } - - FileData.NameGuid = &(ConfigData->FileGuid); - FileData.Type = FileType; - FileData.FileAttributes = FileAttributes; - FileData.Buffer = ImageBuffer; - FileData.BufferSize = (UINT32) ImageSize; - - Status = FwVolProtocol->WriteFile ( - FwVolProtocol, - 1, // NumberOfFiles - (EFI_FV_WRITE_POLICY)ConfigData->FaultTolerant, - &FileData - ); - return Status; -} - -/** - Update the buffer into flash area in fault tolerant write method. - - @param ImageBuffer Image buffer to be updated. - @param SizeLeft Size of the image buffer. - @param UpdatedSize Size of the updated buffer. - @param ConfigData Config data on updating driver. - @param FlashAddress Flash address to be updated as start address. - @param FvbProtocol FVB protocol. - @param FvbHandle Handle of FVB protocol for the updated flash range. - - @retval EFI_SUCCESS Buffer data is updated into flash. - @retval EFI_INVALID_PARAMETER Base flash address is not in FVB flash area. - @retval EFI_NOT_FOUND FTW protocol doesn't exist. - @retval EFI_OUT_OF_RESOURCES No enough backup space. - @retval EFI_ABORTED Error happen when update flash area. - -**/ -EFI_STATUS -FaultTolerantUpdateOnPartFv ( - IN UINT8 *ImageBuffer, - IN UINTN SizeLeft, - IN OUT UINTN *UpdatedSize, - IN UPDATE_CONFIG_DATA *ConfigData, - IN EFI_PHYSICAL_ADDRESS FlashAddress, - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN EFI_HANDLE FvbHandle - ) -{ - EFI_STATUS Status; - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeaderTmp; - EFI_PHYSICAL_ADDRESS BaseAddress; - EFI_PHYSICAL_ADDRESS FvBase; - EFI_PHYSICAL_ADDRESS NextBlock; - EFI_FV_BLOCK_MAP_ENTRY *BlockMap; - EFI_FV_BLOCK_MAP_ENTRY *PtrMap; - UINTN NumOfUpdates; - UINTN TotalSize; - EFI_PHYSICAL_ADDRESS StartAddress; - EFI_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol; - UINTN MaxBlockSize; - UINTN FtwMaxBlockSize; - BOOLEAN Pending; - UPDATE_PRIVATE_DATA PrivateData; - EFI_LBA PendingLba; - EFI_LBA Lba; - UINTN BlockSize; - UINTN PendingOffset; - UINTN Offset; - UINTN PendingLength; - UINTN Length; - UINTN Index; - UINT8 *Image; - - // - // Get the block map to update the block one by one - // - Status = FvbProtocol->GetPhysicalAddress ( - FvbProtocol, - &FvBase - ); - if (EFI_ERROR (Status)) { - return Status; - } - - FwVolHeaderTmp = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvBase; - if ((FlashAddress < FvBase) || (FlashAddress > (FvBase + FwVolHeaderTmp->FvLength))) { - return EFI_INVALID_PARAMETER; - } - - FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)AllocateCopyPool ( - FwVolHeaderTmp->HeaderLength, - FwVolHeaderTmp - ); - if (FwVolHeader == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // For fault tolerant write, we have to know how many blocks we need to - // update. So we will calculate number of updates and max block size first - // - NumOfUpdates = 0; - MaxBlockSize = 0; - TotalSize = SizeLeft; - StartAddress = FlashAddress; - BaseAddress = FvBase; - BlockMap = &(FwVolHeader->BlockMap[0]); - PtrMap = BlockMap; - - while (TotalSize > 0) { - if ((PtrMap->NumBlocks == 0) || (PtrMap->Length == 0)) { - break; - } - - BlockSize = PtrMap->Length; - for (Index = 0; Index < PtrMap->NumBlocks; Index++) { - NextBlock = BaseAddress + BlockSize; - // - // Check if this block need to be updated - // - if ((StartAddress >= BaseAddress) && (StartAddress < NextBlock)) { - // - // Get the maximum block size - // - if (MaxBlockSize < BlockSize) { - MaxBlockSize = BlockSize; - } - - // - // This block shall be udpated. So increment number of updates - // - NumOfUpdates++; - Offset = (UINTN) (StartAddress - BaseAddress); - Length = TotalSize; - if ((Length + Offset ) > BlockSize) { - Length = BlockSize - Offset; - } - - StartAddress = StartAddress + Length; - TotalSize = TotalSize - Length; - if (TotalSize <= 0) { - break; - } - } - BaseAddress = NextBlock; - } - PtrMap++; - } - - // - // Get the FTW protocol - // - Status = gBS->LocateProtocol ( - &gEfiFaultTolerantWriteProtocolGuid, - NULL, - (VOID **) &FtwProtocol - ); - if (EFI_ERROR (Status)) { - FreePool (FwVolHeader); - return EFI_NOT_FOUND; - } - - FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize); - - // - // Not enough backup space. return directly - // - if (FtwMaxBlockSize < MaxBlockSize) { - FreePool (FwVolHeader); - return EFI_OUT_OF_RESOURCES; - } - - PendingLba = 0; - PendingOffset = 0; - PendingLength = 0; - Pending = FALSE; - - // - // Fault Tolerant Write can only support actual fault tolerance if the write - // is a reclaim operation, which means the data buffer (new and old) are - // acutally both stored in flash. But for component update write, the data - // are now in memory. So we cannot actually recover the data after power - // failure. - // - Status = RetrieveLastWrite ( - FvbHandle, - FtwProtocol, - ConfigData, - sizeof (UPDATE_PRIVATE_DATA), - &PrivateData, - &PendingLba, - &PendingOffset, - &PendingLength, - &Pending - ); - if (Pending && (Status == EFI_NOT_FOUND)) { - // - // I'm not the owner of the pending fault tolerant write record - // Cannot continue with the write operation - // - FreePool (FwVolHeader); - return EFI_ABORTED; - } - - if (EFI_ERROR(Status)) { - FreePool (FwVolHeader); - return EFI_ABORTED; - } - - // - // Currently we start from the pending write if there is any. But if the - // caller is exactly the same, and the new data is already a in memory, (it - // cannot be stored in flash in last write,) we can just abort last write - // and start from the very begining. - // - if (!Pending) { - // - // Now allocte the update private data in FTW. If there is pending - // write, it has already been allocated and no need to allocate here. - // - Status = FtwProtocol->Allocate ( - FtwProtocol, - &gEfiCallerIdGuid, - sizeof (UPDATE_PRIVATE_DATA), - NumOfUpdates - ); - if (EFI_ERROR (Status)) { - FreePool (FwVolHeader); - return Status; - } - } - - // - // Perform the update now. If there are pending writes, we need to - // start from the pending write instead of the very beginning. - // - TotalSize = SizeLeft; - Lba = 0; - StartAddress = FlashAddress; - BaseAddress = FvBase; - PtrMap = BlockMap; - Image = ImageBuffer; - CopyMem ( - (VOID *) &PrivateData.FileGuid, - (VOID *) &ConfigData->FileGuid, - sizeof (EFI_GUID) - ); - - while (TotalSize > 0) { - if ((PtrMap->NumBlocks == 0) || (PtrMap->Length == 0)) { - break; - } - - BlockSize = (UINTN)PtrMap->Length; - for (Index = 0; Index < PtrMap->NumBlocks; Index++) { - NextBlock = BaseAddress + BlockSize; - if ((StartAddress >= BaseAddress) && (StartAddress < NextBlock)) { - // - // So we need to update this block - // - Offset = (UINTN) (StartAddress - BaseAddress); - Length = TotalSize; - if ((Length + Offset ) > BlockSize) { - Length = BlockSize - Offset; - } - - // - // Add an extra check here to see if the pending record is correct - // - if (Pending && (Lba == PendingLba)) { - if ((PendingOffset != Offset) || (PendingLength != Length)) { - // - // Error. - // - Status = EFI_ABORTED; - break; - } - } - - if ((!Pending) || (Lba >= PendingLba)) { - DEBUG ((EFI_D_UPDATE, "Update Flash area from %08LX to %08LX\n", StartAddress, (UINT64)StartAddress + Length)); - Status = FtwProtocol->Write ( - FtwProtocol, - Lba, // Lba - Offset, // Offset - Length, // Size - &PrivateData, // Private Data - FvbHandle, // FVB handle - Image // Buffer - ); - if (EFI_ERROR (Status)) { - break; - } - } - - // - // Now increment StartAddress, ImageBuffer and decrease the - // left size to prepare for the next block update. - // - StartAddress = StartAddress + Length; - Image = Image + Length; - TotalSize = TotalSize - Length; - if (TotalSize <= 0) { - break; - } - } - BaseAddress = NextBlock; - Lba++; - } - - if (EFI_ERROR (Status)) { - break; - } - PtrMap++; - } - - FreePool (FwVolHeader); - - *UpdatedSize = SizeLeft - TotalSize; - - return EFI_SUCCESS; -} - -/** - Directly update the buffer into flash area without fault tolerant write method. - - @param ImageBuffer Image buffer to be updated. - @param SizeLeft Size of the image buffer. - @param UpdatedSize Size of the updated buffer. - @param FlashAddress Flash address to be updated as start address. - @param FvbProtocol FVB protocol. - @param FvbHandle Handle of FVB protocol for the updated flash range. - - @retval EFI_SUCCESS Buffer data is updated into flash. - @retval EFI_INVALID_PARAMETER Base flash address is not in FVB flash area. - @retval EFI_OUT_OF_RESOURCES No enough backup space. - -**/ -EFI_STATUS -NonFaultTolerantUpdateOnPartFv ( - IN UINT8 *ImageBuffer, - IN UINTN SizeLeft, - IN OUT UINTN *UpdatedSize, - IN EFI_PHYSICAL_ADDRESS FlashAddress, - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN EFI_HANDLE FvbHandle - ) -{ - EFI_STATUS Status; - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeaderTmp; - EFI_PHYSICAL_ADDRESS BaseAddress; - EFI_PHYSICAL_ADDRESS NextBlock; - EFI_FV_BLOCK_MAP_ENTRY *BlockMap; - UINTN Index; - UINTN TotalSize; - UINTN BlockSize; - EFI_LBA Lba; - UINTN Offset; - UINTN Length; - UINT8 *Image; - - // - // Get the block map to update the block one by one - // - Status = FvbProtocol->GetPhysicalAddress ( - FvbProtocol, - &BaseAddress - ); - if (EFI_ERROR (Status)) { - return Status; - } - - FwVolHeaderTmp = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress; - if ((FlashAddress < BaseAddress) || (FlashAddress > ( BaseAddress + FwVolHeaderTmp->FvLength ))) { - return EFI_INVALID_PARAMETER; - } - - FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)AllocateCopyPool ( - FwVolHeaderTmp->HeaderLength, - FwVolHeaderTmp - ); - if (FwVolHeader == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Image = ImageBuffer; - TotalSize = SizeLeft; - BlockMap = &(FwVolHeader->BlockMap[0]); - Lba = 0; - - while (TotalSize > 0) { - if ((BlockMap->NumBlocks == 0) || (BlockMap->Length == 0)) { - break; - } - - BlockSize = BlockMap->Length; - for (Index = 0 ; Index < BlockMap->NumBlocks ; Index++) { - NextBlock = BaseAddress + BlockSize; - if ((FlashAddress >= BaseAddress) && (FlashAddress < NextBlock)) { - // - // So we need to update this block - // - Offset = (UINTN) FlashAddress - (UINTN) BaseAddress; - Length = TotalSize; - if ((Length + Offset ) > BlockSize) { - Length = BlockSize - Offset; - } - - DEBUG ((EFI_D_UPDATE, "Update Flash area from %08LX to %08LX\n", FlashAddress, (UINT64)FlashAddress + Length)); - // - // Update the block - // - Status = UpdateBufferInOneBlock ( - FvbProtocol, - Lba, - Offset, - Length, - BlockSize, - Image - ); - if (EFI_ERROR (Status)) { - FreePool (FwVolHeader); - return Status; - } - - // - // Now increment FlashAddress, ImageBuffer and decrease the - // left size to prepare for the next block update. - // - FlashAddress = FlashAddress + Length; - Image = Image + Length; - TotalSize = TotalSize - Length; - if (TotalSize <= 0) { - break; - } - } - BaseAddress = NextBlock; - Lba++; - } - - if (EFI_ERROR (Status)) { - break; - } - BlockMap++; - } - - FreePool (FwVolHeader); - - *UpdatedSize = SizeLeft - TotalSize; - - return EFI_SUCCESS; -} diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/ParseUpdateProfile.c b/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/ParseUpdateProfile.c deleted file mode 100644 index 023506e6ee..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/ParseUpdateProfile.c +++ /dev/null @@ -1,1133 +0,0 @@ -/** @file - Source file for the component update driver. It parse the update - configuration file and pass the information to the update driver - so that the driver can perform updates accordingly. - - Copyright (c) 2002 - 2015, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "UpdateDriver.h" - -/** - Copy one line data from buffer data to the line buffer. - - @param Buffer Buffer data. - @param BufferSize Buffer Size. - @param LineBuffer Line buffer to store the found line data. - @param LineSize On input, size of the input line buffer. - On output, size of the actual line buffer. - - @retval EFI_BUFFER_TOO_SMALL The size of input line buffer is not enough. - @retval EFI_SUCCESS Copy line data into the line buffer. - -**/ -EFI_STATUS -ProfileGetLine ( - IN UINT8 *Buffer, - IN UINTN BufferSize, - IN OUT UINT8 *LineBuffer, - IN OUT UINTN *LineSize - ) -{ - UINTN Length; - UINT8 *PtrBuf; - UINTN PtrEnd; - - PtrBuf = Buffer; - PtrEnd = (UINTN)Buffer + BufferSize; - - // - // 0x0D indicates a line break. Otherwise there is no line break - // - while ((UINTN)PtrBuf < PtrEnd) { - if (*PtrBuf == 0x0D) { - break; - } - PtrBuf++; - } - - if ((UINTN)PtrBuf >= (PtrEnd - 1)) { - // - // The buffer ends without any line break - // or it is the last character of the buffer - // - Length = BufferSize; - } else if (*(PtrBuf + 1) == 0x0A) { - // - // Further check if a 0x0A follows. If yes, count 0xA - // - Length = (UINTN) PtrBuf - (UINTN) Buffer + 2; - } else { - Length = (UINTN) PtrBuf - (UINTN) Buffer + 1; - } - - if (Length > (*LineSize)) { - *LineSize = Length; - return EFI_BUFFER_TOO_SMALL; - } - - SetMem (LineBuffer, *LineSize, 0x0); - *LineSize = Length; - CopyMem (LineBuffer, Buffer, Length); - - return EFI_SUCCESS; -} - -/** - Trim Buffer by removing all CR, LF, TAB, and SPACE chars in its head and tail. - - @param Buffer On input, buffer data to be trimed. - On output, the trimmed buffer. - @param BufferSize On input, size of original buffer data. - On output, size of the trimmed buffer. - -**/ -VOID -ProfileTrim ( - IN OUT UINT8 *Buffer, - IN OUT UINTN *BufferSize - ) -{ - UINTN Length; - UINT8 *PtrBuf; - UINT8 *PtrEnd; - - if (*BufferSize == 0) { - return; - } - - // - // Trim the tail first, include CR, LF, TAB, and SPACE. - // - Length = *BufferSize; - PtrBuf = (UINT8 *) ((UINTN) Buffer + Length - 1); - while (PtrBuf >= Buffer) { - if ((*PtrBuf != 0x0D) && (*PtrBuf != 0x0A ) - && (*PtrBuf != 0x20) && (*PtrBuf != 0x09)) { - break; - } - PtrBuf --; - } - - // - // all spaces, a blank line, return directly; - // - if (PtrBuf < Buffer) { - *BufferSize = 0; - return; - } - - Length = (UINTN)PtrBuf - (UINTN)Buffer + 1; - PtrEnd = PtrBuf; - PtrBuf = Buffer; - - // - // Now skip the heading CR, LF, TAB and SPACE - // - while (PtrBuf <= PtrEnd) { - if ((*PtrBuf != 0x0D) && (*PtrBuf != 0x0A ) - && (*PtrBuf != 0x20) && (*PtrBuf != 0x09)) { - break; - } - PtrBuf++; - } - - // - // If no heading CR, LF, TAB or SPACE, directly return - // - if (PtrBuf == Buffer) { - *BufferSize = Length; - return; - } - - *BufferSize = (UINTN)PtrEnd - (UINTN)PtrBuf + 1; - - // - // The first Buffer..PtrBuf characters are CR, LF, TAB or SPACE. - // Now move out all these characters. - // - while (PtrBuf <= PtrEnd) { - *Buffer = *PtrBuf; - Buffer++; - PtrBuf++; - } - - return; -} - -/** - Insert new comment item into comment head. - - @param Buffer Comment buffer to be added. - @param BufferSize Size of comment buffer. - @param CommentHead Comment Item head entry. - - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval EFI_SUCCESS New comment item is inserted. - -**/ -EFI_STATUS -ProfileGetComments ( - IN UINT8 *Buffer, - IN UINTN BufferSize, - IN OUT COMMENT_LINE **CommentHead - ) -{ - COMMENT_LINE *CommentItem; - - CommentItem = NULL; - CommentItem = AllocatePool (sizeof (COMMENT_LINE)); - if (CommentItem == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - CommentItem->ptrNext = *CommentHead; - *CommentHead = CommentItem; - - // - // Add a trailing '\0' - // - CommentItem->ptrComment = AllocatePool (BufferSize + 1); - if (CommentItem->ptrComment == NULL) { - FreePool (CommentItem); - return EFI_OUT_OF_RESOURCES; - } - CopyMem (CommentItem->ptrComment, Buffer, BufferSize); - *(CommentItem->ptrComment + BufferSize) = '\0'; - - return EFI_SUCCESS; -} - -/** - Add new section item into Section head. - - @param Buffer Section item data buffer. - @param BufferSize Size of section item. - @param SectionHead Section item head entry. - - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval EFI_SUCCESS Section item is NULL or Section item is added. - -**/ -EFI_STATUS -ProfileGetSection ( - IN UINT8 *Buffer, - IN UINTN BufferSize, - IN OUT SECTION_ITEM **SectionHead - ) -{ - EFI_STATUS Status; - SECTION_ITEM *SectionItem; - UINTN Length; - UINT8 *PtrBuf; - - Status = EFI_SUCCESS; - // - // The first character of Buffer is '[', now we want for ']' - // - PtrBuf = (UINT8 *)((UINTN)Buffer + BufferSize - 1); - while (PtrBuf > Buffer) { - if (*PtrBuf == ']') { - break; - } - PtrBuf --; - } - if (PtrBuf <= Buffer) { - // - // Not found. Omit this line - // - return Status; - } - - // - // excluding the heading '[' and tailing ']' - // - Length = PtrBuf - Buffer - 1; - ProfileTrim ( - Buffer + 1, - &Length - ); - - // - // omit this line if the section name is null - // - if (Length == 0) { - return Status; - } - - SectionItem = AllocatePool (sizeof (SECTION_ITEM)); - if (SectionItem == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - SectionItem->ptrSection = NULL; - SectionItem->SecNameLen = Length; - SectionItem->ptrEntry = NULL; - SectionItem->ptrValue = NULL; - SectionItem->ptrNext = *SectionHead; - *SectionHead = SectionItem; - - // - // Add a trailing '\0' - // - SectionItem->ptrSection = AllocatePool (Length + 1); - if (SectionItem->ptrSection == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // excluding the heading '[' - // - CopyMem (SectionItem->ptrSection, Buffer + 1, Length); - *(SectionItem->ptrSection + Length) = '\0'; - - return EFI_SUCCESS; -} - -/** - Add new section entry and entry value into Section head. - - @param Buffer Section entry data buffer. - @param BufferSize Size of section entry. - @param SectionHead Section item head entry. - - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval EFI_SUCCESS Section entry is NULL or Section entry is added. - -**/ -EFI_STATUS -ProfileGetEntry ( - IN UINT8 *Buffer, - IN UINTN BufferSize, - IN OUT SECTION_ITEM **SectionHead - ) -{ - EFI_STATUS Status; - SECTION_ITEM *SectionItem; - SECTION_ITEM *PtrSection; - UINTN Length; - UINT8 *PtrBuf; - UINT8 *PtrEnd; - - Status = EFI_SUCCESS; - PtrBuf = Buffer; - PtrEnd = (UINT8 *) ((UINTN)Buffer + BufferSize - 1); - - // - // First search for '=' - // - while (PtrBuf <= PtrEnd) { - if (*PtrBuf == '=') { - break; - } - PtrBuf++; - } - if (PtrBuf > PtrEnd) { - // - // Not found. Omit this line - // - return Status; - } - - // - // excluding the tailing '=' - // - Length = PtrBuf - Buffer; - ProfileTrim ( - Buffer, - &Length - ); - - // - // Omit this line if the entry name is null - // - if (Length == 0) { - return Status; - } - - // - // Omit this line if no section header has been found before - // - if (*SectionHead == NULL) { - return Status; - } - PtrSection = *SectionHead; - - SectionItem = AllocatePool (sizeof (SECTION_ITEM)); - if (SectionItem == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - SectionItem->ptrSection = NULL; - SectionItem->ptrEntry = NULL; - SectionItem->ptrValue = NULL; - SectionItem->SecNameLen = PtrSection->SecNameLen; - SectionItem->ptrNext = *SectionHead; - *SectionHead = SectionItem; - - // - // SectionName, add a trailing '\0' - // - SectionItem->ptrSection = AllocatePool (PtrSection->SecNameLen + 1); - if (SectionItem->ptrSection == NULL) { - return EFI_OUT_OF_RESOURCES; - } - CopyMem (SectionItem->ptrSection, PtrSection->ptrSection, PtrSection->SecNameLen + 1); - - // - // EntryName, add a trailing '\0' - // - SectionItem->ptrEntry = AllocatePool (Length + 1); - if (SectionItem->ptrEntry == NULL) { - return EFI_OUT_OF_RESOURCES; - } - CopyMem (SectionItem->ptrEntry, Buffer, Length); - *(SectionItem->ptrEntry + Length) = '\0'; - - // - // Next search for '#' - // - PtrBuf = PtrBuf + 1; - Buffer = PtrBuf; - while (PtrBuf <= PtrEnd) { - if (*PtrBuf == '#') { - break; - } - PtrBuf++; - } - Length = PtrBuf - Buffer; - ProfileTrim ( - Buffer, - &Length - ); - - if (Length > 0) { - // - // EntryValue, add a trailing '\0' - // - SectionItem->ptrValue = AllocatePool (Length + 1); - if (SectionItem->ptrValue == NULL) { - return EFI_OUT_OF_RESOURCES; - } - CopyMem (SectionItem->ptrValue, Buffer, Length); - *(SectionItem->ptrValue + Length) = '\0'; - } - - return EFI_SUCCESS; -} - -/** - Free all comment entry and section entry. - - @param Section Section entry list. - @param Comment Comment entry list. - -**/ -VOID -FreeAllList ( - IN SECTION_ITEM *Section, - IN COMMENT_LINE *Comment - ) -{ - SECTION_ITEM *PtrSection; - COMMENT_LINE *PtrComment; - - while (Section != NULL) { - PtrSection = Section; - Section = Section->ptrNext; - if (PtrSection->ptrEntry != NULL) { - FreePool (PtrSection->ptrEntry); - } - if (PtrSection->ptrSection != NULL) { - FreePool (PtrSection->ptrSection); - } - if (PtrSection->ptrValue != NULL) { - FreePool (PtrSection->ptrValue); - } - FreePool (PtrSection); - } - - while (Comment != NULL) { - PtrComment = Comment; - Comment = Comment->ptrNext; - if (PtrComment->ptrComment != NULL) { - FreePool (PtrComment->ptrComment); - } - FreePool (PtrComment); - } - - return; -} - -/** - Get section entry value. - - @param Section Section entry list. - @param SectionName Section name. - @param EntryName Section entry name. - @param EntryValue Point to the got entry value. - - @retval EFI_NOT_FOUND Section is not found. - @retval EFI_SUCCESS Section entry value is got. - -**/ -EFI_STATUS -UpdateGetProfileString ( - IN SECTION_ITEM *Section, - IN UINT8 *SectionName, - IN UINT8 *EntryName, - OUT UINT8 **EntryValue - ) -{ - *EntryValue = NULL; - - while (Section != NULL) { - if (AsciiStrCmp ((CONST CHAR8 *) Section->ptrSection, (CONST CHAR8 *) SectionName) == 0) { - if (Section->ptrEntry != NULL) { - if (AsciiStrCmp ((CONST CHAR8 *) Section->ptrEntry, (CONST CHAR8 *) EntryName) == 0) { - break; - } - } - } - Section = Section->ptrNext; - } - - if (Section == NULL) { - return EFI_NOT_FOUND; - } - - *EntryValue = (UINT8 *) Section->ptrValue; - - return EFI_SUCCESS; -} - -/** - Convert the dec or hex ascii string to value. - - @param Str ascii string to be converted. - - @return the converted value. - -**/ -UINTN -UpdateAtoi ( - IN UINT8 *Str - ) -{ - UINTN Number; - - Number = 0; - - // - // Skip preceeding while spaces - // - while (*Str != '\0') { - if (*Str != 0x20) { - break; - } - Str++; - } - - if (*Str == '\0') { - return Number; - } - - // - // Find whether the string is prefixed by 0x. - // That is, it should be xtoi or atoi. - // - if (*Str == '0') { - if ((*(Str+1) == 'x' ) || ( *(Str+1) == 'X')) { - return AsciiStrHexToUintn ((CONST CHAR8 *) Str); - } - } - - while (*Str != '\0') { - if ((*Str >= '0') && (*Str <= '9')) { - Number = Number * 10 + *Str - '0'; - } else { - break; - } - Str++; - } - - return Number; -} - -/** - Converts a decimal value to a Null-terminated ascii string. - - @param Buffer Pointer to the output buffer for the produced Null-terminated - ASCII string. - @param Value The 64-bit sgned value to convert to a string. - - @return The number of ASCII characters in Buffer not including the Null-terminator. - -**/ -UINTN -UpdateValueToString ( - IN OUT UINT8 *Buffer, - IN INT64 Value - ) -{ - UINT8 TempBuffer[30]; - UINT8 *TempStr; - UINT8 *BufferPtr; - UINTN Count; - UINT32 Remainder; - - TempStr = TempBuffer; - BufferPtr = Buffer; - Count = 0; - - if (Value < 0) { - *BufferPtr = '-'; - BufferPtr++; - Value = -Value; - Count++; - } - - do { - Value = (INT64) DivU64x32Remainder ((UINT64)Value, 10, &Remainder); - // - // The first item of TempStr is not occupied. It's kind of flag - // - TempStr++; - Count++; - *TempStr = (UINT8) ((UINT8)Remainder + '0'); - } while (Value != 0); - - // - // Reverse temp string into Buffer. - // - while (TempStr != TempBuffer) { - *BufferPtr = *TempStr; - BufferPtr++; - TempStr --; - } - - *BufferPtr = 0; - - return Count; -} - -/** - Convert the input value to a ascii string, - and concatenates this string to the input string. - - @param Str Pointer to a Null-terminated ASCII string. - @param Number The unsgned value to convert to a string. - -**/ -VOID -UpdateStrCatNumber ( - IN OUT UINT8 *Str, - IN UINTN Number - ) -{ - UINTN Count; - - while (*Str != '\0') { - Str++; - } - - Count = UpdateValueToString (Str, (INT64)Number); - - *(Str + Count) = '\0'; - - return; -} - -/** - Convert the input ascii string into GUID value. - - @param Str Ascii GUID string to be converted. - @param Guid Pointer to the converted GUID value. - - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval EFI_NOT_FOUND The input ascii string is not a valid GUID format string. - @retval EFI_SUCCESS GUID value is got. - -**/ -EFI_STATUS -UpdateStringToGuid ( - IN UINT8 *Str, - IN OUT EFI_GUID *Guid - ) -{ - UINT8 *PtrBuffer; - UINT8 *PtrPosition; - UINT8 *Buffer; - UINTN Data; - UINTN StrLen; - UINTN Index; - UINT8 Digits[3]; - - StrLen = AsciiStrLen ((CONST CHAR8 *) Str); - Buffer = AllocateCopyPool (StrLen + 1, Str); - if (Buffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Data1 - // - PtrBuffer = Buffer; - PtrPosition = PtrBuffer; - while (*PtrBuffer != '\0') { - if (*PtrBuffer == '-') { - break; - } - PtrBuffer++; - } - if (*PtrBuffer == '\0') { - FreePool (Buffer); - return EFI_NOT_FOUND; - } - - *PtrBuffer = '\0'; - Data = AsciiStrHexToUintn ((CONST CHAR8 *) PtrPosition); - Guid->Data1 = (UINT32)Data; - - // - // Data2 - // - PtrBuffer++; - PtrPosition = PtrBuffer; - while (*PtrBuffer != '\0') { - if (*PtrBuffer == '-') { - break; - } - PtrBuffer++; - } - if (*PtrBuffer == '\0') { - FreePool (Buffer); - return EFI_NOT_FOUND; - } - *PtrBuffer = '\0'; - Data = AsciiStrHexToUintn ((CONST CHAR8 *) PtrPosition); - Guid->Data2 = (UINT16)Data; - - // - // Data3 - // - PtrBuffer++; - PtrPosition = PtrBuffer; - while (*PtrBuffer != '\0') { - if (*PtrBuffer == '-') { - break; - } - PtrBuffer++; - } - if (*PtrBuffer == '\0') { - FreePool (Buffer); - return EFI_NOT_FOUND; - } - *PtrBuffer = '\0'; - Data = AsciiStrHexToUintn ((CONST CHAR8 *) PtrPosition); - Guid->Data3 = (UINT16)Data; - - // - // Data4[0..1] - // - for ( Index = 0 ; Index < 2 ; Index++) { - PtrBuffer++; - if ((*PtrBuffer == '\0') || ( *(PtrBuffer + 1) == '\0')) { - FreePool (Buffer); - return EFI_NOT_FOUND; - } - Digits[0] = *PtrBuffer; - PtrBuffer++; - Digits[1] = *PtrBuffer; - Digits[2] = '\0'; - Data = AsciiStrHexToUintn ((CONST CHAR8 *) Digits); - Guid->Data4[Index] = (UINT8)Data; - } - - // - // skip the '-' - // - PtrBuffer++; - if ((*PtrBuffer != '-' ) || ( *PtrBuffer == '\0')) { - return EFI_NOT_FOUND; - } - - // - // Data4[2..7] - // - for ( ; Index < 8; Index++) { - PtrBuffer++; - if ((*PtrBuffer == '\0') || ( *(PtrBuffer + 1) == '\0')) { - FreePool (Buffer); - return EFI_NOT_FOUND; - } - Digits[0] = *PtrBuffer; - PtrBuffer++; - Digits[1] = *PtrBuffer; - Digits[2] = '\0'; - Data = AsciiStrHexToUintn ((CONST CHAR8 *) Digits); - Guid->Data4[Index] = (UINT8)Data; - } - - FreePool (Buffer); - - return EFI_SUCCESS; -} - -/** - Pre process config data buffer into Section entry list and Comment entry list. - - @param DataBuffer Config raw file buffer. - @param BufferSize Size of raw buffer. - @param SectionHead Pointer to the section entry list. - @param CommentHead Pointer to the comment entry list. - - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval EFI_SUCCESS Config data buffer is preprocessed. - -**/ -EFI_STATUS -PreProcessDataFile ( - IN UINT8 *DataBuffer, - IN UINTN BufferSize, - IN OUT SECTION_ITEM **SectionHead, - IN OUT COMMENT_LINE **CommentHead - ) -{ - EFI_STATUS Status; - CHAR8 *Source; - CHAR8 *CurrentPtr; - CHAR8 *BufferEnd; - CHAR8 *PtrLine; - UINTN LineLength; - UINTN SourceLength; - UINTN MaxLineLength; - - *SectionHead = NULL; - *CommentHead = NULL; - BufferEnd = (CHAR8 *) ( (UINTN) DataBuffer + BufferSize); - CurrentPtr = (CHAR8 *) DataBuffer; - MaxLineLength = MAX_LINE_LENGTH; - Status = EFI_SUCCESS; - - PtrLine = AllocatePool (MaxLineLength); - if (PtrLine == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - while (CurrentPtr < BufferEnd) { - Source = CurrentPtr; - SourceLength = (UINTN)BufferEnd - (UINTN)CurrentPtr; - LineLength = MaxLineLength; - // - // With the assumption that line length is less than 512 - // characters. Otherwise BUFFER_TOO_SMALL will be returned. - // - Status = ProfileGetLine ( - (UINT8 *) Source, - SourceLength, - (UINT8 *) PtrLine, - &LineLength - ); - if (EFI_ERROR (Status)) { - if (Status == EFI_BUFFER_TOO_SMALL) { - // - // If buffer too small, re-allocate the buffer according - // to the returned LineLength and try again. - // - FreePool (PtrLine); - PtrLine = NULL; - PtrLine = AllocatePool (LineLength); - if (PtrLine == NULL) { - Status = EFI_OUT_OF_RESOURCES; - break; - } - SourceLength = LineLength; - Status = ProfileGetLine ( - (UINT8 *) Source, - SourceLength, - (UINT8 *) PtrLine, - &LineLength - ); - if (EFI_ERROR (Status)) { - break; - } - MaxLineLength = LineLength; - } else { - break; - } - } - CurrentPtr = (CHAR8 *) ( (UINTN) CurrentPtr + LineLength); - - // - // Line got. Trim the line before processing it. - // - ProfileTrim ( - (UINT8 *) PtrLine, - &LineLength - ); - - // - // Blank line - // - if (LineLength == 0) { - continue; - } - - if (PtrLine[0] == '#') { - Status = ProfileGetComments ( - (UINT8 *) PtrLine, - LineLength, - CommentHead - ); - } else if (PtrLine[0] == '[') { - Status = ProfileGetSection ( - (UINT8 *) PtrLine, - LineLength, - SectionHead - ); - } else { - Status = ProfileGetEntry ( - (UINT8 *) PtrLine, - LineLength, - SectionHead - ); - } - - if (EFI_ERROR (Status)) { - break; - } - } - - // - // Free buffer - // - FreePool (PtrLine); - - return Status; -} - -/** - Parse Config data file to get the updated data array. - - @param DataBuffer Config raw file buffer. - @param BufferSize Size of raw buffer. - @param NumOfUpdates Pointer to the number of update data. - @param UpdateArray Pointer to the config of update data. - - @retval EFI_NOT_FOUND No config data is found. - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval EFI_SUCCESS Parse the config file successfully. - -**/ -EFI_STATUS -ParseUpdateDataFile ( - IN UINT8 *DataBuffer, - IN UINTN BufferSize, - IN OUT UINTN *NumOfUpdates, - IN OUT UPDATE_CONFIG_DATA **UpdateArray - ) -{ - EFI_STATUS Status; - CHAR8 *Value; - CHAR8 *SectionName; - CHAR8 Entry[MAX_LINE_LENGTH]; - SECTION_ITEM *SectionHead; - COMMENT_LINE *CommentHead; - UINTN Num; - UINTN Index; - EFI_GUID FileGuid; - - SectionHead = NULL; - CommentHead = NULL; - - // - // First process the data buffer and get all sections and entries - // - Status = PreProcessDataFile ( - DataBuffer, - BufferSize, - &SectionHead, - &CommentHead - ); - if (EFI_ERROR (Status)) { - FreeAllList (SectionHead, CommentHead); - return Status; - } - - // - // Now get NumOfUpdate - // - Value = NULL; - Status = UpdateGetProfileString ( - SectionHead, - (UINT8 *) "Head", - (UINT8 *) "NumOfUpdate", - (UINT8 **) &Value - ); - if (Value == NULL) { - FreeAllList (SectionHead, CommentHead); - return EFI_NOT_FOUND; - } - Num = UpdateAtoi((UINT8 *) Value); - if (Num <= 0) { - FreeAllList (SectionHead, CommentHead); - return EFI_NOT_FOUND; - } - - *NumOfUpdates = Num; - *UpdateArray = AllocatePool ((sizeof (UPDATE_CONFIG_DATA) * Num)); - if (*UpdateArray == NULL) { - FreeAllList (SectionHead, CommentHead); - return EFI_OUT_OF_RESOURCES; - } - - for ( Index = 0 ; Index < *NumOfUpdates ; Index++) { - // - // Get the section name of each update - // - AsciiStrCpyS (Entry, MAX_LINE_LENGTH, "Update"); - UpdateStrCatNumber ((UINT8 *) Entry, Index); - Value = NULL; - Status = UpdateGetProfileString ( - SectionHead, - (UINT8 *) "Head", - (UINT8 *) Entry, - (UINT8 **) &Value - ); - if (Value == NULL) { - FreeAllList (SectionHead, CommentHead); - return EFI_NOT_FOUND; - } - - // - // The section name of this update has been found. - // Now looks for all the config data of this update - // - SectionName = Value; - - // - // UpdateType - // - Value = NULL; - Status = UpdateGetProfileString ( - SectionHead, - (UINT8 *) SectionName, - (UINT8 *) "UpdateType", - (UINT8 **) &Value - ); - if (Value == NULL) { - FreeAllList (SectionHead, CommentHead); - return EFI_NOT_FOUND; - } - - Num = UpdateAtoi((UINT8 *) Value); - if (( Num >= (UINTN) UpdateOperationMaximum)) { - FreeAllList (SectionHead, CommentHead); - return Status; - } - (*UpdateArray)[Index].Index = Index; - (*UpdateArray)[Index].UpdateType = (UPDATE_OPERATION_TYPE) Num; - - // - // FvBaseAddress - // - Value = NULL; - Status = UpdateGetProfileString ( - SectionHead, - (UINT8 *) SectionName, - (UINT8 *) "FvBaseAddress", - (UINT8 **) &Value - ); - if (Value == NULL) { - FreeAllList (SectionHead, CommentHead); - return EFI_NOT_FOUND; - } - - Num = AsciiStrHexToUintn ((CONST CHAR8 *) Value); - (*UpdateArray)[Index].BaseAddress = (EFI_PHYSICAL_ADDRESS) Num; - - // - // FileBuid - // - Value = NULL; - Status = UpdateGetProfileString ( - SectionHead, - (UINT8 *) SectionName, - (UINT8 *) "FileGuid", - (UINT8 **) &Value - ); - if (Value == NULL) { - FreeAllList (SectionHead, CommentHead); - return EFI_NOT_FOUND; - } - - Status = UpdateStringToGuid ((UINT8 *) Value, &FileGuid); - if (EFI_ERROR (Status)) { - FreeAllList (SectionHead, CommentHead); - return Status; - } - CopyMem (&((*UpdateArray)[Index].FileGuid), &FileGuid, sizeof(EFI_GUID)); - - // - // FaultTolerant - // Default value is FALSE - // - Value = NULL; - (*UpdateArray)[Index].FaultTolerant = FALSE; - Status = UpdateGetProfileString ( - SectionHead, - (UINT8 *) SectionName, - (UINT8 *) "FaultTolerant", - (UINT8 **) &Value - ); - if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - FreeAllList (SectionHead, CommentHead); - return Status; - } else if (Value != NULL) { - if (AsciiStriCmp ((CONST CHAR8 *) Value, (CONST CHAR8 *) "TRUE") == 0) { - (*UpdateArray)[Index].FaultTolerant = TRUE; - } else if (AsciiStriCmp ((CONST CHAR8 *) Value, (CONST CHAR8 *) "FALSE") == 0) { - (*UpdateArray)[Index].FaultTolerant = FALSE; - } - } - - if ((*UpdateArray)[Index].UpdateType == UpdateFvRange) { - // - // Length - // - Value = NULL; - Status = UpdateGetProfileString ( - SectionHead, - (UINT8 *) SectionName, - (UINT8 *) "Length", - (UINT8 **) &Value - ); - if (Value == NULL) { - FreeAllList (SectionHead, CommentHead); - return EFI_NOT_FOUND; - } - - Num = AsciiStrHexToUintn ((CONST CHAR8 *) Value); - (*UpdateArray)[Index].Length = (UINTN) Num; - } - } - - // - // Now all configuration data got. Free those temporary buffers - // - FreeAllList (SectionHead, CommentHead); - - return EFI_SUCCESS; -} - diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDispatcher.c b/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDispatcher.c deleted file mode 100644 index e1f1b023dc..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDispatcher.c +++ /dev/null @@ -1,846 +0,0 @@ -/** @file - Functions in this file will mainly focus on looking through the capsule - for the image to be programmed, and the flash area that is going to be - programed. - - Copyright (c) 2002 - 2014, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#include "UpdateDriver.h" - -EFI_HII_HANDLE gHiiHandle; - -/** - Update the whole FV, or certain files in the FV. - - @param ConfigData Pointer to the config data on updating file. - @param ImageBuffer Image buffer to be updated. - @param ImageSize Image size. - @param FileType FFS file type. - @param FileAttributes FFS file attribute. - - @retval EFI_NOT_FOUND The matched FVB protocol is not found. - @retval EFI_SUCCESS The image buffer is updated into FV. - -**/ -EFI_STATUS -PerformUpdateOnFirmwareVolume ( - IN UPDATE_CONFIG_DATA *ConfigData, - IN UINT8 *ImageBuffer, - IN UINTN ImageSize, - IN EFI_FV_FILETYPE FileType, - IN EFI_FV_FILE_ATTRIBUTES FileAttributes - ) -{ - EFI_STATUS Status; - BOOLEAN Found; - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol; - UINTN Index; - UINTN NumOfHandles; - EFI_HANDLE *HandleBuffer; - EFI_PHYSICAL_ADDRESS BaseAddress; - EFI_FVB_ATTRIBUTES_2 Attributes; - - // - // Locate all Fvb protocol - // - HandleBuffer = NULL; - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiFirmwareVolumeBlockProtocolGuid, - NULL, - &NumOfHandles, - &HandleBuffer - ); - if ((EFI_ERROR (Status)) || (NumOfHandles == 0) || (HandleBuffer == NULL)) { - if (HandleBuffer != NULL) { - FreePool (HandleBuffer); - } - return EFI_NOT_FOUND; - } - - // - // Check the FVB protocol one by one - // - Found = FALSE; - FvbProtocol = NULL; - for (Index = 0; Index < NumOfHandles; Index++) { - Status = gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiFirmwareVolumeBlockProtocolGuid, - (VOID **) &FvbProtocol - ); - if (EFI_ERROR (Status)) { - break; - } - - // - // Ensure this FVB protocol supported Write operation. - // - Status = FvbProtocol->GetAttributes (FvbProtocol, &Attributes); - if (EFI_ERROR (Status) || ((Attributes & EFI_FVB2_WRITE_STATUS) == 0)) { - continue; - } - - Status = FvbProtocol->GetPhysicalAddress ( - FvbProtocol, - &BaseAddress - ); - if (EFI_ERROR (Status)) { - break; - } - if (BaseAddress == ConfigData->BaseAddress) { - Found = TRUE; - break; - } - } - - if (!Found) { - if (HandleBuffer != NULL) { - FreePool (HandleBuffer); - HandleBuffer = NULL; - } - return EFI_NOT_FOUND; - } - - // - // Now we have got the corresponding FVB protocol. Use the FVB protocol - // to update the whole FV, or certain files in the FV. - // - if (ConfigData->UpdateType == UpdateWholeFV) { - if (FileType != EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) { - Status = EFI_INVALID_PARAMETER; - } else { - Status = PerformUpdateOnWholeFv ( - HandleBuffer[Index], - FvbProtocol, - ConfigData, - ImageBuffer, - ImageSize - ); - } - } else if (ConfigData->UpdateType == UpdateFvFile) { - Status = PerformUpdateOnFvFile ( - HandleBuffer[Index], - FvbProtocol, - ConfigData, - ImageBuffer, - ImageSize, - FileType, - FileAttributes - ); - } - - if (HandleBuffer != NULL) { - FreePool (HandleBuffer); - HandleBuffer = NULL; - } - - return Status; -} - -/** - Update the file directly into flash area. - - @param ConfigData Pointer to the config data on updating file. - @param ImageBuffer Image buffer to be updated. - @param ImageSize Image size. - - @retval EFI_SUCCESS The file is updated into flash area. - @retval EFI_NOT_FOUND The FVB protocol for the updated flash area is not found. - -**/ -EFI_STATUS -PerformUpdateOnFlashArea ( - IN UPDATE_CONFIG_DATA *ConfigData, - IN UINT8 *ImageBuffer, - IN UINTN ImageSize - ) -{ - EFI_STATUS Status; - UINTN SizeLeft; - EFI_PHYSICAL_ADDRESS FlashAddress; - UINT8 *PtrImage; - BOOLEAN Found; - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol; - UINTN Index; - UINTN NumOfHandles; - EFI_HANDLE *HandleBuffer; - EFI_PHYSICAL_ADDRESS BaseAddress; - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - EFI_HANDLE FvbHandle; - UINTN SizeUpdated; - CHAR16 *TmpStr; - EFI_FVB_ATTRIBUTES_2 Attributes; - - SizeLeft = ImageSize; - PtrImage = ImageBuffer; - FlashAddress = ConfigData->BaseAddress; - Status = EFI_SUCCESS; - HandleBuffer = NULL; - - // - // Print on screen - // - TmpStr = HiiGetString (gHiiHandle, STRING_TOKEN(UPDATE_FLASH_RANGE), NULL); - if (TmpStr != NULL) { - Print (TmpStr, FlashAddress, ((UINT64)SizeLeft + FlashAddress)); - FreePool (TmpStr); - } - - // - // Locate all Fvb protocol - // - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiFirmwareVolumeBlockProtocolGuid, - NULL, - &NumOfHandles, - &HandleBuffer - ); - if ((EFI_ERROR (Status)) || (NumOfHandles == 0) || (HandleBuffer == NULL)) { - if (HandleBuffer != NULL) { - FreePool (HandleBuffer); - } - return EFI_NOT_FOUND; - } - - while (SizeLeft > 0) { - // - // First get the FVB protocols. If the flash area is a FV, or sub FV, - // we can directly locate all the FVB protocol. Otherwise we should use - // implementation specific method to get the alternate FVB protocol - // - Found = FALSE; - FvbProtocol = NULL; - - // - // Check the FVB protocol one by one - // - for (Index = 0; Index < NumOfHandles; Index++) { - Status = gBS->HandleProtocol ( - HandleBuffer[Index], - &gEfiFirmwareVolumeBlockProtocolGuid, - (VOID **) &FvbProtocol - ); - if (EFI_ERROR (Status)) { - break; - } - - // - // Ensure this FVB protocol supported Write operation. - // - Status = FvbProtocol->GetAttributes (FvbProtocol, &Attributes); - if (EFI_ERROR (Status) || ((Attributes & EFI_FVB2_WRITE_STATUS) == 0)) { - continue; - } - - Status = FvbProtocol->GetPhysicalAddress ( - FvbProtocol, - &BaseAddress - ); - if (EFI_ERROR (Status)) { - break; - } - FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)BaseAddress; - - // - // This sub area entry falls in the range of the FV - // - if ((FlashAddress >= BaseAddress) && (FlashAddress < (BaseAddress + FwVolHeader->FvLength))) { - Found = TRUE; - break; - } - } - - if (!Found) { - if (HandleBuffer != NULL) { - FreePool (HandleBuffer); - HandleBuffer = NULL; - } - return EFI_NOT_FOUND; - } - - FvbHandle = HandleBuffer[Index]; - SizeUpdated = 0; - - // - // If the flash area is boot required, the update must be fault tolerant - // - if (ConfigData->FaultTolerant) { - // - // Finally we are here. We have got the corresponding FVB protocol. Now - // we need to convert the physical address to LBA and offset and call - // FTW write. Also check if the flash range is larger than the FV. - // - Status = FaultTolerantUpdateOnPartFv ( - PtrImage, - SizeLeft, - &SizeUpdated, - ConfigData, - FlashAddress, - FvbProtocol, - FvbHandle - ); - } else { - // - // Finally we are here. We have got the corresponding FVB protocol. Now - // we need to convert the physical address to LBA and offset and call - // FVB write. Also check if the flash range is larger than the FV. - // - Status = NonFaultTolerantUpdateOnPartFv ( - PtrImage, - SizeLeft, - &SizeUpdated, - FlashAddress, - FvbProtocol, - FvbHandle - ); - } - - if (EFI_ERROR (Status)) { - return Status; - } - - // - // As part of the FV has been replaced, the FV driver shall re-parse - // the firmware volume. So re-install FVB protocol here - // - Status = gBS->ReinstallProtocolInterface ( - FvbHandle, - &gEfiFirmwareVolumeBlockProtocolGuid, - FvbProtocol, - FvbProtocol - ); - - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Check if we are done with the update - // - SizeLeft = SizeLeft - SizeUpdated; - FlashAddress = FlashAddress + SizeUpdated; - PtrImage = PtrImage + SizeUpdated; - } - - if (HandleBuffer != NULL) { - FreePool (HandleBuffer); - HandleBuffer = NULL; - } - - return Status; -} - -/** - Find the updated file, and program it into the flash area based on the config data. - - @param FwVolProtocol Pointer to FV protocol that contains the updated file. - @param ConfigData Pointer to the Config Data on updating file. - - @retval EFI_INVALID_PARAMETER The update operation is not valid. - @retval EFI_NOT_FOUND The updated file is not found. - @retval EFI_SUCCESS The file is updated into the flash area. - -**/ -EFI_STATUS -PerformUpdate ( - IN EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVolProtocol, - IN UPDATE_CONFIG_DATA *ConfigData - ) -{ - EFI_STATUS Status; - UINT8 *FileBuffer; - UINTN FileBufferSize; - EFI_FV_FILETYPE FileType; - EFI_FV_FILE_ATTRIBUTES Attrib; - EFI_SECTION_TYPE SectionType; - UINT32 AuthenticationStatus; - CHAR16 *TmpStr; - BOOLEAN StartToUpdate; - - Status = EFI_SUCCESS; - FileBuffer = NULL; - FileBufferSize = 0; - Status = FwVolProtocol->ReadFile ( - FwVolProtocol, - &(ConfigData->FileGuid), - (VOID **) &FileBuffer, - &FileBufferSize, - &FileType, - &Attrib, - &AuthenticationStatus - ); - if (EFI_ERROR (Status)) { - return Status; - } - - StartToUpdate = FALSE; - - // - // Check if the update image is the one we require - // and then perform the update - // - switch (ConfigData->UpdateType) { - - case UpdateWholeFV: - - // - // For UpdateWholeFv, the update file shall be a firmware volume - // image file. - // - if (FileType != EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) { - DEBUG ((EFI_D_UPDATE, "UpdateDriver: Data file should be of TYPE EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\n")); - Status = EFI_INVALID_PARAMETER; - } else { - if (FileBuffer != NULL) { - FreePool (FileBuffer); - } - SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE; - FileBuffer = NULL; - FileBufferSize = 0; - Status = FwVolProtocol->ReadSection ( - FwVolProtocol, - &(ConfigData->FileGuid), - SectionType, - 0, - (VOID **) &FileBuffer, - &FileBufferSize, - &AuthenticationStatus - ); - if (!EFI_ERROR (Status)) { - // - // Execute the update. For UpdateWholeFv, the update - // will always execute on a whole FV - // - StartToUpdate = TRUE; - Status = PerformUpdateOnFirmwareVolume ( - ConfigData, - FileBuffer, - FileBufferSize, - FileType, - Attrib - ); - - } else { - DEBUG ((EFI_D_UPDATE, "UpdateDriver: Data file should be sectioned with TYPE EFI_SECTION_FIRMWARE_VOLUME_IMAGE\n")); - } - } - break; - - case UpdateFvRange: - - // - // For UpdateFvRange, the update file shall be a raw file - // which does not contain any sections. The contents of the file - // will be directly programmed. - // - if (FileType != EFI_FV_FILETYPE_RAW) { - DEBUG ((EFI_D_UPDATE, "UpdateDriver: Data file should of TYPE EFI_FV_FILETYPE_RAW\n")); - Status = EFI_INVALID_PARAMETER; - } else { - // - // For UpdateFvRange, the update may be performed on a sub area - // of a certain FV, or a flash area that is not FV, or part of FV. - // The update may also go across more than one FVs. - // - StartToUpdate = TRUE; - Status = PerformUpdateOnFlashArea ( - ConfigData, - FileBuffer, - FileBufferSize - ); - } - break; - - case UpdateFvFile: - - // - // No check will be done the the file got. The contents of the file - // will be directly programmed. - // Though UpdateFvFile will only update a single file, but the update - // will always execute on a FV - // - StartToUpdate = TRUE; - Status = PerformUpdateOnFirmwareVolume ( - ConfigData, - FileBuffer, - FileBufferSize, - FileType, - Attrib - ); - break; - - default: - Status = EFI_INVALID_PARAMETER; - } - - if (StartToUpdate) { - if (EFI_ERROR (Status)) { - TmpStr = HiiGetString (gHiiHandle, STRING_TOKEN(UPDATE_DRIVER_ABORTED), NULL); - } else { - TmpStr = HiiGetString (gHiiHandle, STRING_TOKEN(UPDATE_DRIVER_DONE), NULL); - } - if (TmpStr != NULL) { - Print (TmpStr); - FreePool (TmpStr); - } - } - - if (FileBuffer != NULL) { - FreePool(FileBuffer); - FileBuffer = NULL; - } - - return Status; -} - -/** - Process the input firmware volume by using DXE service ProcessFirmwareVolume. - - @param DataBuffer Point to the FV image to be processed. - @param BufferSize Size of the FV image buffer. - @param FwVolProtocol Point to the installed FV protocol for the input FV image. - - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval EFI_VOLUME_CORRUPTED FV image is corrupted. - @retval EFI_SUCCESS FV image is processed and FV protocol is installed. - -**/ -EFI_STATUS -ProcessUpdateImage ( - UINT8 *DataBuffer, - UINTN BufferSize, - EFI_FIRMWARE_VOLUME2_PROTOCOL **FwVolProtocol - ) -{ - EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; - EFI_HANDLE FwVolHandle; - EFI_STATUS Status; - UINT8 *ProcessedDataBuffer; - UINT32 FvAlignment; - - ProcessedDataBuffer = NULL; - FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) DataBuffer; - if (FwVolHeader->FvLength != BufferSize) { - return EFI_VOLUME_CORRUPTED; - } - - FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16); - // - // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value. - // - if (FvAlignment < 8) { - FvAlignment = 8; - } - // - // Check FvImage Align is required. - // - if (((UINTN) FwVolHeader % FvAlignment) == 0) { - ProcessedDataBuffer = DataBuffer; - } else { - // - // Allocate new aligned buffer to store DataBuffer. - // - ProcessedDataBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment); - if (ProcessedDataBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - CopyMem (ProcessedDataBuffer, DataBuffer, BufferSize); - } - // - // Process the firmware volume - // - gDS->ProcessFirmwareVolume ( - ProcessedDataBuffer, - BufferSize, - &FwVolHandle - ); - - // - // Get the FwVol protocol - // - Status = gBS->HandleProtocol ( - FwVolHandle, - &gEfiFirmwareVolume2ProtocolGuid, - (VOID **) FwVolProtocol - ); - - return Status; -} - -/** - Find the image in the same FV and program it in a target Firmware Volume device. - After update image, it will reset system and no return. - - @param ImageHandle A handle for the image that is initializing this driver - @param SystemTable A pointer to the EFI system table - - @retval EFI_ABORTED System reset failed. - @retval EFI_NOT_FOUND The updated image is not found in the same FV. - -**/ -EFI_STATUS -EFIAPI -InitializeUpdateDriver ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_STATUS Status; - EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocol; - EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVolProtocol; - EFI_FIRMWARE_VOLUME2_PROTOCOL *DataFwVolProtocol; - MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FwVolFilePathNode; - MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *AlignedDevPathNode; - EFI_DEVICE_PATH_PROTOCOL *FilePathNode; - EFI_SECTION_TYPE SectionType; - UINT8 *FileBuffer; - UINTN FileBufferSize; - EFI_FV_FILETYPE FileType; - EFI_FV_FILE_ATTRIBUTES Attrib; - UINT32 AuthenticationStatus; - UPDATE_CONFIG_DATA *ConfigData; - UPDATE_CONFIG_DATA *UpdateConfigData; - UINTN NumOfUpdates; - UINTN Index; - CHAR16 *TmpStr; - - // - // Clear screen - // - if (gST->ConOut != NULL) { - gST->ConOut->ClearScreen (gST->ConOut); - gST->ConOut->SetAttribute (gST->ConOut, EFI_YELLOW | EFI_BRIGHT); - gST->ConOut->EnableCursor (gST->ConOut, FALSE); - } - - gHiiHandle = HiiAddPackages ( - &gEfiCallerIdGuid, - NULL, - UpdateDriverDxeStrings, - NULL - ); - ASSERT (gHiiHandle != NULL); - - // - // In order to look for the update data file and programmed image file - // from the same volume which this driver is dispatched from, we need - // to get the device path of this driver image. It is done by first - // locate the LoadedImageProtocol and then get its device path - // - Status = gBS->OpenProtocol ( - ImageHandle, - &gEfiLoadedImageProtocolGuid, - (VOID **)&LoadedImageProtocol, - ImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR (Status)) { - return Status; - } - // - // Get the firmware volume protocol where this file resides - // - Status = gBS->HandleProtocol ( - LoadedImageProtocol->DeviceHandle, - &gEfiFirmwareVolume2ProtocolGuid, - (VOID **) &FwVolProtocol - ); - if (EFI_ERROR (Status)) { - return EFI_NOT_FOUND; - } - - // - // Shall do some extra check to see if it is really contained in the FV? - // Should be able to find the section of this driver in the the FV. - // - FilePathNode = LoadedImageProtocol->FilePath; - FwVolFilePathNode = NULL; - while (!IsDevicePathEnd (FilePathNode)) { - if (EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)FilePathNode)!= NULL) { - FwVolFilePathNode = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) FilePathNode; - break; - } - FilePathNode = NextDevicePathNode (FilePathNode); - } - - if (FwVolFilePathNode != NULL) { - AlignedDevPathNode = AllocateCopyPool (DevicePathNodeLength (FwVolFilePathNode), FwVolFilePathNode); - - SectionType = EFI_SECTION_PE32; - FileBuffer = NULL; - FileBufferSize = 0; - Status = FwVolProtocol->ReadSection ( - FwVolProtocol, - &(AlignedDevPathNode->FvFileName), - SectionType, - 0, - (VOID **) &FileBuffer, - &FileBufferSize, - &AuthenticationStatus - ); - if (EFI_ERROR (Status)) { - FreePool (AlignedDevPathNode); - return Status; - } - - if (FileBuffer != NULL) { - FreePool(FileBuffer); - FileBuffer = NULL; - } - - // - // Check the NameGuid of the udpate driver so that it can be - // used as the CallerId in fault tolerant write protocol - // - if (!CompareGuid (&gEfiCallerIdGuid, &(AlignedDevPathNode->FvFileName))) { - FreePool (AlignedDevPathNode); - return EFI_NOT_FOUND; - } - FreePool (AlignedDevPathNode); - } else { - return EFI_NOT_FOUND; - } - - // - // Now try to find the script file. The script file is usually - // a raw data file which does not contain any sections. - // - FileBuffer = NULL; - FileBufferSize = 0; - Status = FwVolProtocol->ReadFile ( - FwVolProtocol, - &gEfiConfigFileNameGuid, - (VOID **) &FileBuffer, - &FileBufferSize, - &FileType, - &Attrib, - &AuthenticationStatus - ); - if (EFI_ERROR (Status)) { - return Status; - } - if (FileType != EFI_FV_FILETYPE_RAW) { - return EFI_NOT_FOUND; - } - - // - // Parse the configuration file. - // - ConfigData = NULL; - NumOfUpdates = 0; - Status = ParseUpdateDataFile ( - FileBuffer, - FileBufferSize, - &NumOfUpdates, - &ConfigData - ); - if (FileBuffer != NULL) { - FreePool (FileBuffer); - FileBuffer = NULL; - } - if (EFI_ERROR (Status)) { - return Status; - } - ASSERT (ConfigData != NULL); - - // - // Now find the update image. The update image should be put in a FV, and then - // encapsulated as a raw FFS file. This is to prevent the update image from - // being dispatched. So the raw data we get here should be an FV. We need to - // process this FV and read the files that is going to be updated. - // - FileBuffer = NULL; - FileBufferSize = 0; - Status = FwVolProtocol->ReadFile ( - FwVolProtocol, - &gEfiUpdateDataFileGuid, - (VOID **) &FileBuffer, - &FileBufferSize, - &FileType, - &Attrib, - &AuthenticationStatus - ); - if (EFI_ERROR (Status)) { - return Status; - } - if (FileType != EFI_FV_FILETYPE_RAW) { - return EFI_NOT_FOUND; - } - - // - // FileBuffer should be an FV. Process the FV - // - DataFwVolProtocol = NULL; - Status = ProcessUpdateImage ( - FileBuffer, - FileBufferSize, - &DataFwVolProtocol - ); - if (EFI_ERROR (Status)) { - FreePool (FileBuffer); - return Status; - } - - // - // Print on screen - // - TmpStr = HiiGetString (gHiiHandle, STRING_TOKEN(UPDATE_PROCESS_DATA), NULL); - if (TmpStr != NULL) { - Print (TmpStr); - FreePool(TmpStr); - } - - // - // Execute the update - // - Index = 0; - UpdateConfigData = ConfigData; - while (Index < NumOfUpdates) { - Status = PerformUpdate ( - DataFwVolProtocol, - UpdateConfigData - ); - // - // Shall updates be serialized so that if an update is not successfully completed, - // the remaining updates won't be performed. - // - if (EFI_ERROR (Status)) { - break; - } - - Index++; - UpdateConfigData++; - } - - if (EFI_ERROR (Status)) { - if (ConfigData != NULL) { - FreePool(ConfigData); - ConfigData = NULL; - } - return Status; - } - - // - // Call system reset - // - gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL); - - // - // Hopefully it won't be reached - // - return EFI_ABORTED; -} diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriver.h b/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriver.h deleted file mode 100644 index e1f22a9d5a..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriver.h +++ /dev/null @@ -1,213 +0,0 @@ -/** @file - Common defines and definitions for a component update driver. - - Copyright (c) 2002 - 2010, Intel Corporation. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions - of the BSD License which accompanies this distribution. The - full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. - -**/ - -#ifndef _EFI_UPDATE_DRIVER_H_ -#define _EFI_UPDATE_DRIVER_H_ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern EFI_HII_HANDLE gHiiHandle; - -typedef enum { - UpdateWholeFV = 0, // 0, update whole FV - UpdateFvFile, // 1, update a set of FV files asynchronously - UpdateFvRange, // 2, update part of FV or flash - UpdateOperationMaximum // 3 -} UPDATE_OPERATION_TYPE; - -typedef struct { - UINTN Index; - UPDATE_OPERATION_TYPE UpdateType; - EFI_DEVICE_PATH_PROTOCOL DevicePath; - EFI_PHYSICAL_ADDRESS BaseAddress; - EFI_GUID FileGuid; - UINTN Length; - BOOLEAN FaultTolerant; -} UPDATE_CONFIG_DATA; - -typedef struct _SECTION_ITEM SECTION_ITEM; -struct _SECTION_ITEM { - CHAR8 *ptrSection; - UINTN SecNameLen; - CHAR8 *ptrEntry; - CHAR8 *ptrValue; - SECTION_ITEM *ptrNext; -}; - -typedef struct _COMMENT_LINE COMMENT_LINE; -struct _COMMENT_LINE { - CHAR8 *ptrComment; - COMMENT_LINE *ptrNext; -}; - -typedef struct { - EFI_GUID FileGuid; -} UPDATE_PRIVATE_DATA; - -#define MAX_LINE_LENGTH 512 -#define EFI_D_UPDATE EFI_D_ERROR - -#define MIN_ALIGNMENT_SIZE 4 -#define ALIGN_SIZE(a) ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0) - -/** - Parse Config data file to get the updated data array. - - @param DataBuffer Config raw file buffer. - @param BufferSize Size of raw buffer. - @param NumOfUpdates Pointer to the number of update data. - @param UpdateArray Pointer to the config of update data. - - @retval EFI_NOT_FOUND No config data is found. - @retval EFI_OUT_OF_RESOURCES No enough memory is allocated. - @retval EFI_SUCCESS Parse the config file successfully. - -**/ -EFI_STATUS -ParseUpdateDataFile ( - IN UINT8 *DataBuffer, - IN UINTN BufferSize, - IN OUT UINTN *NumOfUpdates, - IN OUT UPDATE_CONFIG_DATA **UpdateArray - ); - -/** - Update the whole FV image, and reinsall FVB protocol for the updated FV image. - - @param FvbHandle Handle of FVB protocol for the updated flash range. - @param FvbProtocol FVB protocol. - @param ConfigData Config data on updating driver. - @param ImageBuffer Image buffer to be updated. - @param ImageSize Image size. - - @retval EFI_INVALID_PARAMETER Update type is not UpdateWholeFV. - Or Image size is not same to the size of whole FV. - @retval EFI_OUT_OF_RESOURCES No enoug memory is allocated. - @retval EFI_SUCCESS FV image is updated, and its FVB protocol is reinstalled. - -**/ -EFI_STATUS -PerformUpdateOnWholeFv ( - IN EFI_HANDLE FvbHandle, - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN UPDATE_CONFIG_DATA *ConfigData, - IN UINT8 *ImageBuffer, - IN UINTN ImageSize - ); - -/** - Update certain file in the FV. - - @param FvbHandle Handle of FVB protocol for the updated flash range. - @param FvbProtocol FVB protocol. - @param ConfigData Config data on updating driver. - @param ImageBuffer Image buffer to be updated. - @param ImageSize Image size. - @param FileType FFS file type. - @param FileAttributes FFS file attribute - - @retval EFI_INVALID_PARAMETER Update type is not UpdateFvFile. - Or Image size is not same to the size of whole FV. - @retval EFI_UNSUPPORTED PEIM FFS is unsupported to be updated. - @retval EFI_SUCCESS The FFS file is added into FV. - -**/ -EFI_STATUS -PerformUpdateOnFvFile ( - IN EFI_HANDLE FvbHandle, - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN UPDATE_CONFIG_DATA *ConfigData, - IN UINT8 *ImageBuffer, - IN UINTN ImageSize, - IN EFI_FV_FILETYPE FileType, - IN EFI_FV_FILE_ATTRIBUTES FileAttributes - ); - -/** - Update the buffer into flash area in fault tolerant write method. - - @param ImageBuffer Image buffer to be updated. - @param SizeLeft Size of the image buffer. - @param UpdatedSize Size of the updated buffer. - @param ConfigData Config data on updating driver. - @param FlashAddress Flash address to be updated as start address. - @param FvbProtocol FVB protocol. - @param FvbHandle Handle of FVB protocol for the updated flash range. - - @retval EFI_SUCCESS Buffer data is updated into flash. - @retval EFI_INVALID_PARAMETER Base flash address is not in FVB flash area. - @retval EFI_NOT_FOUND FTW protocol doesn't exist. - @retval EFI_OUT_OF_RESOURCES No enough backup space. - @retval EFI_ABORTED Error happen when update flash area. - -**/ -EFI_STATUS -FaultTolerantUpdateOnPartFv ( - IN UINT8 *ImageBuffer, - IN UINTN SizeLeft, - IN OUT UINTN *UpdatedSize, - IN UPDATE_CONFIG_DATA *ConfigData, - IN EFI_PHYSICAL_ADDRESS FlashAddress, - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN EFI_HANDLE FvbHandle - ); - -/** - Directly update the buffer into flash area without fault tolerant write method. - - @param ImageBuffer Image buffer to be updated. - @param SizeLeft Size of the image buffer. - @param UpdatedSize Size of the updated buffer. - @param FlashAddress Flash address to be updated as start address. - @param FvbProtocol FVB protocol. - @param FvbHandle Handle of FVB protocol for the updated flash range. - - @retval EFI_SUCCESS Buffer data is updated into flash. - @retval EFI_INVALID_PARAMETER Base flash address is not in FVB flash area. - @retval EFI_OUT_OF_RESOURCES No enough backup space. - -**/ -EFI_STATUS -NonFaultTolerantUpdateOnPartFv ( - IN UINT8 *ImageBuffer, - IN UINTN SizeLeft, - IN OUT UINTN *UpdatedSize, - IN EFI_PHYSICAL_ADDRESS FlashAddress, - IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol, - IN EFI_HANDLE FvbHandle - ); - -#endif diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxe.inf b/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxe.inf deleted file mode 100644 index d83a1ecb57..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxe.inf +++ /dev/null @@ -1,76 +0,0 @@ -## @file -# Update Driver for Capulse update. -# -# This driver is intended to be put in a capsule (FV). If all goes well, -# then it should be dispatched from the capsule FV, then find the image -# in the same FV and program it in a target Firmware Volume device. -# -# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
-# -# This program and the accompanying materials are -# licensed and made available under the terms and conditions of the BSD License -# which accompanies this distribution. The full text of the license may be found at -# http://opensource.org/licenses/bsd-license.php -# -# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -## - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = UpdateDriverDxe - MODULE_UNI_FILE = UpdateDriverDxe.uni - FILE_GUID = 0E84FC69-29CC-4C6D-92AC-6D476921850F - MODULE_TYPE = DXE_DRIVER - VERSION_STRING = 1.0 - ENTRY_POINT = InitializeUpdateDriver - -# -# The following information is for reference only and not required by the build tools. -# -# VALID_ARCHITECTURES = IA32 X64 IPF EBC -# - -[Sources] - UpdateDriver.h - UpdateStrings.uni - UpdateDispatcher.c - ParseUpdateProfile.c - FlashUpdate.c - -[Packages] - MdePkg/MdePkg.dec - MdeModulePkg/MdeModulePkg.dec - IntelFrameworkPkg/IntelFrameworkPkg.dec - IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec - -[LibraryClasses] - BaseLib - PrintLib - HiiLib - DxeServicesTableLib - MemoryAllocationLib - UefiLib - UefiBootServicesTableLib - UefiDriverEntryPoint - UefiRuntimeServicesTableLib - BaseMemoryLib - DebugLib - DevicePathLib - -[Guids] - gEfiConfigFileNameGuid ## CONSUMES ## File # FileName to store ConfigFile - gEfiUpdateDataFileGuid ## CONSUMES ## File # FileName to store Capsule Data. - -[Protocols] - gEfiFaultTolerantWriteProtocolGuid ## CONSUMES - gEfiFirmwareVolume2ProtocolGuid ## CONSUMES - gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES - gEfiLoadedImageProtocolGuid ## CONSUMES - -[Depex] - gEfiFirmwareVolumeBlockProtocolGuid AND gEfiFaultTolerantWriteProtocolGuid - -[UserExtensions.TianoCore."ExtraFiles"] - UpdateDriverDxeExtra.uni diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxe.uni b/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxe.uni deleted file mode 100644 index dd240520da..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxe.uni +++ /dev/null @@ -1,24 +0,0 @@ -// /** @file -// Update Driver for Capulse update. -// -// This driver is intended to be put in a capsule (FV). If all goes well, -// then it should be dispatched from the capsule FV, then find the image -// in the same FV and program it in a target Firmware Volume device. -// -// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
-// -// This program and the accompanying materials are -// licensed and made available under the terms and conditions of the BSD License -// which accompanies this distribution. The full text of the license may be found at -// http://opensource.org/licenses/bsd-license.php -// -// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -// -// **/ - - -#string STR_MODULE_ABSTRACT #language en-US "Update Driver for Capsule update" - -#string STR_MODULE_DESCRIPTION #language en-US "This driver is intended to be put in a capsule (FV). If all goes correctly, it should be dispatched from the capsule FV, and then it finds the image in the same FV, and programs it in a target Firmware Volume device." - diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxeExtra.uni b/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxeExtra.uni deleted file mode 100644 index 8336074989..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateDriverDxeExtra.uni +++ /dev/null @@ -1,20 +0,0 @@ -// /** @file -// UpdateDriverDxe Localized Strings and Content -// -// Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.
-// -// This program and the accompanying materials are -// licensed and made available under the terms and conditions of the BSD License -// which accompanies this distribution. The full text of the license may be found at -// http://opensource.org/licenses/bsd-license.php -// -// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -// -// **/ - -#string STR_PROPERTIES_MODULE_NAME -#language en-US -"Firmware Update DXE Driver" - - diff --git a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateStrings.uni b/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateStrings.uni deleted file mode 100644 index 6aacd5961f..0000000000 --- a/IntelFrameworkModulePkg/Universal/FirmwareVolume/UpdateDriverDxe/UpdateStrings.uni +++ /dev/null @@ -1,25 +0,0 @@ -/// @file -// String definitions for UpdateDispatcher formset. -// -// Copyright (c) 2003 - 2014, Intel Corporation. All rights reserved.
-// -// This program and the accompanying materials -// are licensed and made available under the terms and conditions of the BSD License -// which accompanies this distribution. The full text of the license may be found at -// http://opensource.org/licenses/bsd-license.php -// -// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -// -/// - -/=# - -#langdef en-US "English" - -#string UPDATE_PROCESS_DATA #language en-US "Update driver loaded, processing update image\n\r" -#string UPDATE_DRIVER_DONE #language en-US "Done\n\r" -#string UPDATE_FLASH_RANGE #language en-US "Updating flash area from %08LX to %08LX ...\n\r" -#string UPDATE_DRIVER_ABORTED #language en-US "Aborted\n\r" -#string UPDATE_FIRMWARE_VOLUME_FILE #language en-US "Update firmware volume file %g ..\n\r" -#string UPDATE_FIRMWARE_VOLUME #language en-US "Updating whole firmware volume from %08LX to %08LX ..\n\r" -- cgit v1.2.3