X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FFirmwareVolume%2FFaultTolerantWriteDxe%2FFtwMisc.c;fp=MdeModulePkg%2FUniversal%2FFirmwareVolume%2FFaultTolerantWriteDxe%2FFtwMisc.c;h=eb487b737f2ba53cc1cf2947d58be60d6c9db8c6;hp=fccf889a3d057207535ee1c5e0e5e9d50875436f;hb=6aab82140b20fab408f79dd428555b5d03370f72;hpb=b414ea4b21bf58098fd95f83fe79bb6fbc2e6ea1 diff --git a/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwMisc.c b/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwMisc.c index fccf889a3d..eb487b737f 100644 --- a/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwMisc.c +++ b/MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwMisc.c @@ -15,29 +15,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include -BOOLEAN -IsErasedFlashBuffer ( - IN BOOLEAN Polarity, - IN UINT8 *Buffer, - IN UINTN BufferSize - ) -/*++ - -Routine Description: +/** Check whether a flash buffer is erased. -Arguments: - - Polarity - All 1 or all 0 - Buffer - Buffer to check - BufferSize - Size of the buffer -Returns: + @param Polarity All 1 or all 0 + @param Buffer Buffer to check + @param BufferSize Size of the buffer - Erased or not. + @return A BOOLEAN value indicating erased or not. ---*/ +**/ +BOOLEAN +IsErasedFlashBuffer ( + IN BOOLEAN Polarity, + IN UINT8 *Buffer, + IN UINTN BufferSize + ) { UINT8 ErasedValue; UINT8 *Ptr; @@ -49,7 +44,7 @@ Returns: } Ptr = Buffer; - while (BufferSize--) { + while ((BufferSize--) != 0) { if (*Ptr++ != ErasedValue) { return FALSE; } @@ -58,27 +53,24 @@ Returns: return TRUE; } +/** + To Erase one block. The size is FTW_BLOCK_SIZE + + + @param FtwLiteDevice Calling context + @param FvBlock FVB Protocol interface + @param Lba Lba of the firmware block + + @retval EFI_SUCCESS Block LBA is Erased successfully + @retval Others Error occurs + +**/ EFI_STATUS FtwEraseBlock ( IN EFI_FTW_LITE_DEVICE *FtwLiteDevice, EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock, EFI_LBA Lba ) -/*++ - -Routine Description: - To Erase one block. The size is FTW_BLOCK_SIZE - -Arguments: - FtwLiteDevice - Calling context - FvBlock - FVB Protocol interface - Lba - Lba of the firmware block - -Returns: - EFI_SUCCESS - Block LBA is Erased successfully - Others - Error occurs - ---*/ { return FvBlock->EraseBlocks ( FvBlock, @@ -88,25 +80,32 @@ Returns: ); } -EFI_STATUS -FtwEraseSpareBlock ( - IN EFI_FTW_LITE_DEVICE *FtwLiteDevice - ) -/*++ - -Routine Description: +/** Erase spare block. -Arguments: - FtwLiteDevice - Calling context + @param FtwLiteDevice Calling context -Returns: + @retval EFI_SUCCESS The erase request was successfully + completed. + + @retval EFI_ACCESS_DENIED The firmware volume is in the + WriteDisabled state. + @retval EFI_DEVICE_ERROR The block device is not functioning + correctly and could not be written. + The firmware device may have been + partially erased. + @retval EFI_INVALID_PARAMETER One or more of the LBAs listed + in the variable argument list do + not exist in the firmware volume. - Status code ---*/ +**/ +EFI_STATUS +FtwEraseSpareBlock ( + IN EFI_FTW_LITE_DEVICE *FtwLiteDevice + ) { return FtwLiteDevice->FtwBackupFvb->EraseBlocks ( FtwLiteDevice->FtwBackupFvb, @@ -116,25 +115,23 @@ Returns: ); } +/** + Retrive the proper FVB protocol interface by HANDLE. + + + @param FvBlockHandle The handle of FVB protocol that provides services for + reading, writing, and erasing the target block. + @param FvBlock The interface of FVB protocol + + @retval EFI_SUCCESS The function completed successfully + @retval EFI_ABORTED The function could not complete successfully + +**/ EFI_STATUS FtwGetFvbByHandle ( IN EFI_HANDLE FvBlockHandle, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock ) -/*++ - -Routine Description: - Retrive the proper FVB protocol interface by HANDLE. - -Arguments: - FvBlockHandle - The handle of FVB protocol that provides services for - reading, writing, and erasing the target block. - FvBlock - The interface of FVB protocol - -Returns: - EFI_SUCCESS - The function completed successfully - EFI_ABORTED - The function could not complete successfully ---*/ { // // To get the FVB protocol interface on the handle @@ -146,29 +143,23 @@ Returns: ); } -EFI_STATUS -GetFvbByAddress ( - IN EFI_PHYSICAL_ADDRESS Address, - OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock - ) -/*++ - -Routine Description: +/** Get firmware block by address. -Arguments: - - Address - Address specified the block - FvBlock - The block caller wanted -Returns: + @param Address Address specified the block + @param FvBlock The block caller wanted - Status code + @retval EFI_SUCCESS The protocol instance if found. + @retval EFI_NOT_FOUND Block not found - EFI_NOT_FOUND - Block not found - ---*/ +**/ +EFI_STATUS +GetFvbByAddress ( + IN EFI_PHYSICAL_ADDRESS Address, + OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock + ) { EFI_STATUS Status; EFI_HANDLE *HandleBuffer; @@ -225,29 +216,24 @@ Returns: return Status; } -BOOLEAN -IsInWorkingBlock ( - EFI_FTW_LITE_DEVICE *FtwLiteDevice, - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock, - EFI_LBA Lba - ) -/*++ - -Routine Description: +/** Is it in working block? -Arguments: - FtwLiteDevice - Calling context - FvBlock - Fvb protocol instance - Lba - The block specified + @param FtwLiteDevice Calling context + @param FvBlock Fvb protocol instance + @param Lba The block specified -Returns: + @return A BOOLEAN value indicating in working block or not. - In working block or not - ---*/ +**/ +BOOLEAN +IsInWorkingBlock ( + EFI_FTW_LITE_DEVICE *FtwLiteDevice, + EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock, + EFI_LBA Lba + ) { // // If matching the following condition, the target block is in working block. @@ -262,32 +248,29 @@ Returns: ); } +/** + Copy the content of spare block to a target block. Size is FTW_BLOCK_SIZE. + Spare block is accessed by FTW backup FVB protocol interface. LBA is + FtwLiteDevice->FtwSpareLba. + Target block is accessed by FvBlock protocol interface. LBA is Lba. + + + @param FtwLiteDevice The private data of FTW_LITE driver + @param FvBlock FVB Protocol interface to access target block + @param Lba Lba of the target block + + @retval EFI_SUCCESS Spare block content is copied to target block + @retval EFI_INVALID_PARAMETER Input parameter error + @retval EFI_OUT_OF_RESOURCES Allocate memory error + @retval EFI_ABORTED The function could not complete successfully + +**/ EFI_STATUS FlushSpareBlockToTargetBlock ( EFI_FTW_LITE_DEVICE *FtwLiteDevice, EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock, EFI_LBA Lba ) -/*++ - -Routine Description: - Copy the content of spare block to a target block. Size is FTW_BLOCK_SIZE. - Spare block is accessed by FTW backup FVB protocol interface. LBA is - FtwLiteDevice->FtwSpareLba. - Target block is accessed by FvBlock protocol interface. LBA is Lba. - -Arguments: - FtwLiteDevice - The private data of FTW_LITE driver - FvBlock - FVB Protocol interface to access target block - Lba - Lba of the target block - -Returns: - EFI_SUCCESS - Spare block content is copied to target block - EFI_INVALID_PARAMETER - Input parameter error - EFI_OUT_OF_RESOURCES - Allocate memory error - EFI_ABORTED - The function could not complete successfully - ---*/ { EFI_STATUS Status; UINTN Length; @@ -356,33 +339,29 @@ Returns: return Status; } -EFI_STATUS -FlushSpareBlockToWorkingBlock ( - EFI_FTW_LITE_DEVICE *FtwLiteDevice - ) -/*++ - -Routine Description: - Copy the content of spare block to working block. Size is FTW_BLOCK_SIZE. - Spare block is accessed by FTW backup FVB protocol interface. LBA is - FtwLiteDevice->FtwSpareLba. - Working block is accessed by FTW working FVB protocol interface. LBA is - FtwLiteDevice->FtwWorkBlockLba. +/** + Copy the content of spare block to working block. Size is FTW_BLOCK_SIZE. + Spare block is accessed by FTW backup FVB protocol interface. LBA is + FtwLiteDevice->FtwSpareLba. + Working block is accessed by FTW working FVB protocol interface. LBA is + FtwLiteDevice->FtwWorkBlockLba. -Arguments: - FtwLiteDevice - The private data of FTW_LITE driver -Returns: - EFI_SUCCESS - Spare block content is copied to target block - EFI_OUT_OF_RESOURCES - Allocate memory error - EFI_ABORTED - The function could not complete successfully + @param FtwLiteDevice The private data of FTW_LITE driver -Notes: - Since the working block header is important when FTW initializes, the - state of the operation should be handled carefully. The Crc value is - calculated without STATE element. + @retval EFI_SUCCESS Spare block content is copied to target block + @retval EFI_OUT_OF_RESOURCES Allocate memory error + @retval EFI_ABORTED The function could not complete successfully + Notes: + Since the working block header is important when FTW initializes, the + state of the operation should be handled carefully. The Crc value is + calculated without STATE element. ---*/ +**/ +EFI_STATUS +FlushSpareBlockToWorkingBlock ( + EFI_FTW_LITE_DEVICE *FtwLiteDevice + ) { EFI_STATUS Status; UINTN Length;