-/*++\r
+/** @file\r
\r
-Copyright (c) 2006 - 2007, Intel Corporation \r
+ Internal generic functions to support fault tolerant write.\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation \r
All rights reserved. This program and the accompanying materials \r
are licensed and made available under the terms and conditions of the BSD License \r
which accompanies this distribution. The full text of the license may be found at \r
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
\r
-Module Name:\r
+**/\r
\r
- FtwMisc.c\r
- \r
-Abstract:\r
- \r
- Internal functions to support fault tolerant write.\r
+#include "FtwLite.h"\r
+\r
+/**\r
+\r
+ Check whether a flash buffer is erased.\r
\r
-Revision History\r
\r
---*/\r
+ @param Polarity All 1 or all 0\r
+ @param Buffer Buffer to check\r
+ @param BufferSize Size of the buffer\r
\r
-#include <FtwLite.h>\r
+ @return A BOOLEAN value indicating erased or not.\r
\r
+**/\r
BOOLEAN\r
IsErasedFlashBuffer (\r
IN BOOLEAN Polarity,\r
IN UINT8 *Buffer,\r
IN UINTN BufferSize\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Check whether a flash buffer is erased.\r
-\r
-Arguments:\r
-\r
- Polarity - All 1 or all 0\r
- Buffer - Buffer to check\r
- BufferSize - Size of the buffer\r
-\r
-Returns:\r
-\r
- Erased or not.\r
-\r
---*/\r
{\r
UINT8 ErasedValue;\r
UINT8 *Ptr;\r
}\r
\r
Ptr = Buffer;\r
- while (BufferSize--) {\r
+ while ((BufferSize--) != 0) {\r
if (*Ptr++ != ErasedValue) {\r
return FALSE;\r
}\r
return TRUE;\r
}\r
\r
+/**\r
+ To Erase one block. The size is FTW_BLOCK_SIZE\r
+\r
+\r
+ @param FtwLiteDevice Calling context\r
+ @param FvBlock FVB Protocol interface\r
+ @param Lba Lba of the firmware block\r
+\r
+ @retval EFI_SUCCESS Block LBA is Erased successfully\r
+ @retval Others Error occurs\r
+\r
+**/\r
EFI_STATUS\r
FtwEraseBlock (\r
IN EFI_FTW_LITE_DEVICE *FtwLiteDevice,\r
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,\r
EFI_LBA Lba\r
)\r
-/*++\r
-\r
-Routine Description:\r
- To Erase one block. The size is FTW_BLOCK_SIZE\r
-\r
-Arguments:\r
- FtwLiteDevice - Calling context\r
- FvBlock - FVB Protocol interface\r
- Lba - Lba of the firmware block\r
-\r
-Returns:\r
- EFI_SUCCESS - Block LBA is Erased successfully\r
- Others - Error occurs\r
-\r
---*/\r
{\r
return FvBlock->EraseBlocks (\r
FvBlock,\r
);\r
}\r
\r
-EFI_STATUS\r
-FtwEraseSpareBlock (\r
- IN EFI_FTW_LITE_DEVICE *FtwLiteDevice\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
Erase spare block.\r
\r
-Arguments:\r
-\r
- FtwLiteDevice - Calling context\r
-\r
-Returns:\r
\r
- Status code\r
+ @param FtwLiteDevice Calling context\r
\r
---*/\r
+ @retval EFI_SUCCESS The erase request was successfully\r
+ completed.\r
+ \r
+ @retval EFI_ACCESS_DENIED The firmware volume is in the\r
+ WriteDisabled state.\r
+ @retval EFI_DEVICE_ERROR The block device is not functioning\r
+ correctly and could not be written.\r
+ The firmware device may have been\r
+ partially erased.\r
+ @retval EFI_INVALID_PARAMETER One or more of the LBAs listed\r
+ in the variable argument list do\r
+ not exist in the firmware volume. \r
+\r
+\r
+**/\r
+EFI_STATUS\r
+FtwEraseSpareBlock (\r
+ IN EFI_FTW_LITE_DEVICE *FtwLiteDevice\r
+ )\r
{\r
return FtwLiteDevice->FtwBackupFvb->EraseBlocks (\r
FtwLiteDevice->FtwBackupFvb,\r
);\r
}\r
\r
+/**\r
+ Retrive the proper FVB protocol interface by HANDLE.\r
+\r
+\r
+ @param FvBlockHandle The handle of FVB protocol that provides services for\r
+ reading, writing, and erasing the target block.\r
+ @param FvBlock The interface of FVB protocol\r
+\r
+ @retval EFI_SUCCESS The function completed successfully\r
+ @retval EFI_ABORTED The function could not complete successfully\r
+\r
+**/\r
EFI_STATUS\r
FtwGetFvbByHandle (\r
IN EFI_HANDLE FvBlockHandle,\r
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r
)\r
-/*++\r
-\r
-Routine Description:\r
- Retrive the proper FVB protocol interface by HANDLE.\r
-\r
-Arguments:\r
- FvBlockHandle - The handle of FVB protocol that provides services for \r
- reading, writing, and erasing the target block.\r
- FvBlock - The interface of FVB protocol\r
-\r
-Returns:\r
- EFI_SUCCESS - The function completed successfully\r
- EFI_ABORTED - The function could not complete successfully\r
---*/\r
{\r
//\r
// To get the FVB protocol interface on the handle\r
);\r
}\r
\r
-EFI_STATUS\r
-GetFvbByAddress (\r
- IN EFI_PHYSICAL_ADDRESS Address,\r
- OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
Get firmware block by address.\r
\r
-Arguments:\r
-\r
- Address - Address specified the block\r
- FvBlock - The block caller wanted\r
-\r
-Returns:\r
\r
- Status code\r
+ @param Address Address specified the block\r
+ @param FvBlock The block caller wanted\r
\r
- EFI_NOT_FOUND - Block not found\r
+ @retval EFI_SUCCESS The protocol instance if found.\r
+ @retval EFI_NOT_FOUND Block not found\r
\r
---*/\r
+**/\r
+EFI_STATUS\r
+GetFvbByAddress (\r
+ IN EFI_PHYSICAL_ADDRESS Address,\r
+ OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r
+ )\r
{\r
EFI_STATUS Status;\r
EFI_HANDLE *HandleBuffer;\r
return Status;\r
}\r
\r
-BOOLEAN\r
-IsInWorkingBlock (\r
- EFI_FTW_LITE_DEVICE *FtwLiteDevice,\r
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,\r
- EFI_LBA Lba\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
Is it in working block?\r
\r
-Arguments:\r
\r
- FtwLiteDevice - Calling context\r
- FvBlock - Fvb protocol instance\r
- Lba - The block specified\r
+ @param FtwLiteDevice Calling context\r
+ @param FvBlock Fvb protocol instance\r
+ @param Lba The block specified\r
\r
-Returns:\r
+ @return A BOOLEAN value indicating in working block or not.\r
\r
- In working block or not\r
-\r
---*/\r
+**/\r
+BOOLEAN\r
+IsInWorkingBlock (\r
+ EFI_FTW_LITE_DEVICE *FtwLiteDevice,\r
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,\r
+ EFI_LBA Lba\r
+ )\r
{\r
//\r
// If matching the following condition, the target block is in working block.\r
);\r
}\r
\r
+/**\r
+ Copy the content of spare block to a target block. Size is FTW_BLOCK_SIZE.\r
+ Spare block is accessed by FTW backup FVB protocol interface. LBA is\r
+ FtwLiteDevice->FtwSpareLba.\r
+ Target block is accessed by FvBlock protocol interface. LBA is Lba.\r
+\r
+\r
+ @param FtwLiteDevice The private data of FTW_LITE driver\r
+ @param FvBlock FVB Protocol interface to access target block\r
+ @param Lba Lba of the target block\r
+\r
+ @retval EFI_SUCCESS Spare block content is copied to target block\r
+ @retval EFI_INVALID_PARAMETER Input parameter error\r
+ @retval EFI_OUT_OF_RESOURCES Allocate memory error\r
+ @retval EFI_ABORTED The function could not complete successfully\r
+\r
+**/\r
EFI_STATUS\r
FlushSpareBlockToTargetBlock (\r
EFI_FTW_LITE_DEVICE *FtwLiteDevice,\r
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,\r
EFI_LBA Lba\r
)\r
-/*++\r
-\r
-Routine Description:\r
- Copy the content of spare block to a target block. Size is FTW_BLOCK_SIZE.\r
- Spare block is accessed by FTW backup FVB protocol interface. LBA is \r
- FtwLiteDevice->FtwSpareLba.\r
- Target block is accessed by FvBlock protocol interface. LBA is Lba.\r
-\r
-Arguments:\r
- FtwLiteDevice - The private data of FTW_LITE driver\r
- FvBlock - FVB Protocol interface to access target block\r
- Lba - Lba of the target block\r
-\r
-Returns:\r
- EFI_SUCCESS - Spare block content is copied to target block\r
- EFI_INVALID_PARAMETER - Input parameter error\r
- EFI_OUT_OF_RESOURCES - Allocate memory error\r
- EFI_ABORTED - The function could not complete successfully\r
-\r
---*/\r
{\r
EFI_STATUS Status;\r
UINTN Length;\r
return Status;\r
}\r
\r
-EFI_STATUS\r
-FlushSpareBlockToWorkingBlock (\r
- EFI_FTW_LITE_DEVICE *FtwLiteDevice\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Copy the content of spare block to working block. Size is FTW_BLOCK_SIZE.\r
- Spare block is accessed by FTW backup FVB protocol interface. LBA is \r
- FtwLiteDevice->FtwSpareLba.\r
- Working block is accessed by FTW working FVB protocol interface. LBA is \r
- FtwLiteDevice->FtwWorkBlockLba.\r
+/**\r
+ Copy the content of spare block to working block. Size is FTW_BLOCK_SIZE.\r
+ Spare block is accessed by FTW backup FVB protocol interface. LBA is\r
+ FtwLiteDevice->FtwSpareLba.\r
+ Working block is accessed by FTW working FVB protocol interface. LBA is\r
+ FtwLiteDevice->FtwWorkBlockLba.\r
\r
-Arguments:\r
- FtwLiteDevice - The private data of FTW_LITE driver\r
\r
-Returns:\r
- EFI_SUCCESS - Spare block content is copied to target block\r
- EFI_OUT_OF_RESOURCES - Allocate memory error\r
- EFI_ABORTED - The function could not complete successfully\r
+ @param FtwLiteDevice The private data of FTW_LITE driver\r
\r
-Notes:\r
- Since the working block header is important when FTW initializes, the \r
- state of the operation should be handled carefully. The Crc value is \r
- calculated without STATE element. \r
+ @retval EFI_SUCCESS Spare block content is copied to target block\r
+ @retval EFI_OUT_OF_RESOURCES Allocate memory error\r
+ @retval EFI_ABORTED The function could not complete successfully\r
+ Notes:\r
+ Since the working block header is important when FTW initializes, the\r
+ state of the operation should be handled carefully. The Crc value is\r
+ calculated without STATE element.\r
\r
---*/\r
+**/\r
+EFI_STATUS\r
+FlushSpareBlockToWorkingBlock (\r
+ EFI_FTW_LITE_DEVICE *FtwLiteDevice\r
+ )\r
{\r
EFI_STATUS Status;\r
UINTN Length;\r