3 Internal generic functions to operate flash block.
5 Copyright (c) 2006 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "FaultTolerantWrite.h"
20 Check whether a flash buffer is erased.
22 @param Buffer Buffer to check
23 @param BufferSize Size of the buffer
25 @return A BOOLEAN value indicating erased or not.
40 for (Index
= 0; Index
< BufferSize
; Index
+= 1) {
41 if (*Ptr
++ != FTW_ERASED_BYTE
) {
51 To erase the block with the spare block size.
54 @param FtwDevice The private data of FTW driver
55 @param FvBlock FVB Protocol interface
56 @param Lba Lba of the firmware block
58 @retval EFI_SUCCESS Block LBA is Erased successfully
59 @retval Others Error occurs
64 IN EFI_FTW_DEVICE
*FtwDevice
,
65 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*FvBlock
,
69 return FvBlock
->EraseBlocks (
72 FtwDevice
->NumberOfSpareBlock
,
73 EFI_LBA_LIST_TERMINATOR
80 @param FtwDevice The private data of FTW driver
82 @retval EFI_SUCCESS The erase request was successfully completed.
83 @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
84 @retval EFI_DEVICE_ERROR The block device is not functioning
85 correctly and could not be written.
86 The firmware device may have been
88 @retval EFI_INVALID_PARAMETER One or more of the LBAs listed
89 in the variable argument list do
90 not exist in the firmware volume.
96 IN EFI_FTW_DEVICE
*FtwDevice
99 return FtwDevice
->FtwBackupFvb
->EraseBlocks (
100 FtwDevice
->FtwBackupFvb
,
101 FtwDevice
->FtwSpareLba
,
102 FtwDevice
->NumberOfSpareBlock
,
103 EFI_LBA_LIST_TERMINATOR
108 Retrive the proper FVB protocol interface by HANDLE.
111 @param FvBlockHandle The handle of FVB protocol that provides services for
112 reading, writing, and erasing the target block.
113 @param FvBlock The interface of FVB protocol
115 @retval EFI_SUCCESS The function completed successfully
116 @retval EFI_ABORTED The function could not complete successfully
121 IN EFI_HANDLE FvBlockHandle
,
122 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
**FvBlock
126 // To get the FVB protocol interface on the handle
128 return gBS
->HandleProtocol (
130 &gEfiFirmwareVolumeBlockProtocolGuid
,
137 Is it in working block?
139 @param FtwDevice The private data of FTW driver
140 @param FvBlock Fvb protocol instance
141 @param Lba The block specified
143 @return A BOOLEAN value indicating in working block or not.
148 EFI_FTW_DEVICE
*FtwDevice
,
149 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*FvBlock
,
154 // If matching the following condition, the target block is in working block.
155 // 1. Target block is on the FV of working block (Using the same FVB protocol instance).
156 // 2. Lba falls into the range of working block.
160 (FvBlock
== FtwDevice
->FtwFvBlock
) &&
161 (Lba
>= FtwDevice
->FtwWorkBlockLba
) &&
162 (Lba
<= FtwDevice
->FtwWorkSpaceLba
)
168 Get firmware block by address.
171 @param Address Address specified the block
172 @param FvBlock The block caller wanted
174 @retval EFI_SUCCESS The protocol instance if found.
175 @retval EFI_NOT_FOUND Block not found
180 IN EFI_PHYSICAL_ADDRESS Address
,
181 OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
**FvBlock
185 EFI_HANDLE
*HandleBuffer
;
188 EFI_PHYSICAL_ADDRESS FvbBaseAddress
;
189 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*Fvb
;
190 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
191 EFI_HANDLE FvbHandle
;
196 // Locate all handles of Fvb protocol
198 Status
= gBS
->LocateHandleBuffer (
200 &gEfiFirmwareVolumeBlockProtocolGuid
,
205 if (EFI_ERROR (Status
)) {
209 // Get the FVB to access variable store
211 for (Index
= 0; Index
< HandleCount
; Index
+= 1) {
212 Status
= gBS
->HandleProtocol (
214 &gEfiFirmwareVolumeBlockProtocolGuid
,
217 if (EFI_ERROR (Status
)) {
221 // Compare the address and select the right one
223 Status
= Fvb
->GetPhysicalAddress (Fvb
, &FvbBaseAddress
);
224 if (EFI_ERROR (Status
)) {
228 FwVolHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) ((UINTN
) FvbBaseAddress
);
229 if ((Address
>= FvbBaseAddress
) && (Address
<= (FvbBaseAddress
+ (FwVolHeader
->FvLength
- 1)))) {
231 FvbHandle
= HandleBuffer
[Index
];
236 FreePool (HandleBuffer
);
244 @param FtwDevice The private data of FTW driver
245 @param FvBlock Fvb protocol instance
246 @param Lba The block specified
248 @return A BOOLEAN value indicating in boot block or not.
253 EFI_FTW_DEVICE
*FtwDevice
,
254 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*FvBlock
,
259 EFI_SWAP_ADDRESS_RANGE_PROTOCOL
*SarProtocol
;
260 EFI_PHYSICAL_ADDRESS BootBlockBase
;
262 EFI_PHYSICAL_ADDRESS BackupBlockBase
;
263 UINTN BackupBlockSize
;
264 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*BootFvb
;
266 EFI_HANDLE FvbHandle
;
268 if (!FeaturePcdGet(PcdFullFtwServiceEnable
)) {
272 Status
= gBS
->LocateProtocol (&gEfiSwapAddressRangeProtocolGuid
, NULL
, (VOID
**) &SarProtocol
);
273 if (EFI_ERROR (Status
)) {
277 // Get the boot block range
279 Status
= SarProtocol
->GetRangeLocation (
286 if (EFI_ERROR (Status
)) {
290 Status
= SarProtocol
->GetSwapState (SarProtocol
, &IsSwapped
);
291 if (EFI_ERROR (Status
)) {
295 // Get FVB by address
298 FvbHandle
= GetFvbByAddress (BootBlockBase
, &BootFvb
);
300 FvbHandle
= GetFvbByAddress (BackupBlockBase
, &BootFvb
);
303 if (FvbHandle
== NULL
) {
309 return (BOOLEAN
) (FvBlock
== BootFvb
);
313 Copy the content of spare block to a boot block. Size is FTW_BLOCK_SIZE.
314 Spare block is accessed by FTW working FVB protocol interface. LBA is 1.
315 Target block is accessed by FvbBlock protocol interface. LBA is Lba.
317 FTW will do extra work on boot block update.
318 FTW should depend on a protocol of EFI_ADDRESS_RANGE_SWAP_PROTOCOL,
319 which is produced by a chipset driver.
320 FTW updating boot block steps may be:
321 1. GetRangeLocation(), if the Range is inside the boot block, FTW know
322 that boot block will be update. It shall add a FLAG in the working block.
323 2. When spare block is ready,
324 3. SetSwapState(EFI_SWAPPED)
325 4. erasing boot block,
326 5. programming boot block until the boot block is ok.
327 6. SetSwapState(UNSWAPPED)
328 FTW shall not allow to update boot block when battery state is error.
330 @param FtwDevice The private data of FTW driver
332 @retval EFI_SUCCESS Spare block content is copied to boot block
333 @retval EFI_INVALID_PARAMETER Input parameter error
334 @retval EFI_OUT_OF_RESOURCES Allocate memory error
335 @retval EFI_ABORTED The function could not complete successfully
339 FlushSpareBlockToBootBlock (
340 EFI_FTW_DEVICE
*FtwDevice
350 EFI_SWAP_ADDRESS_RANGE_PROTOCOL
*SarProtocol
;
351 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*BootFvb
;
354 if (!FeaturePcdGet(PcdFullFtwServiceEnable
)) {
355 return EFI_UNSUPPORTED
;
359 // Locate swap address range protocol
361 Status
= gBS
->LocateProtocol (&gEfiSwapAddressRangeProtocolGuid
, NULL
, (VOID
**) &SarProtocol
);
362 if (EFI_ERROR (Status
)) {
366 // Allocate a memory buffer
368 Length
= FtwDevice
->SpareAreaLength
;
369 Buffer
= AllocatePool (Length
);
370 if (Buffer
== NULL
) {
371 return EFI_OUT_OF_RESOURCES
;
374 // Get TopSwap bit state
376 Status
= SarProtocol
->GetSwapState (SarProtocol
, &TopSwap
);
377 if (EFI_ERROR (Status
)) {
378 DEBUG ((EFI_D_ERROR
, "Ftw: Get Top Swapped status - %r\n", Status
));
385 // Get FVB of current boot block
387 if (GetFvbByAddress (FtwDevice
->SpareAreaAddress
+ FtwDevice
->SpareAreaLength
, &BootFvb
) == NULL
) {
392 // Read data from current boot block
396 for (Index
= 0; Index
< FtwDevice
->NumberOfSpareBlock
; Index
+= 1) {
397 Count
= FtwDevice
->BlockSize
;
398 Status
= BootFvb
->Read (
405 if (EFI_ERROR (Status
)) {
414 // Read data from spare block
417 for (Index
= 0; Index
< FtwDevice
->NumberOfSpareBlock
; Index
+= 1) {
418 Count
= FtwDevice
->BlockSize
;
419 Status
= FtwDevice
->FtwBackupFvb
->Read (
420 FtwDevice
->FtwBackupFvb
,
421 FtwDevice
->FtwSpareLba
+ Index
,
426 if (EFI_ERROR (Status
)) {
436 Status
= SarProtocol
->SetSwapState (SarProtocol
, TRUE
);
437 if (EFI_ERROR (Status
)) {
443 // Erase current spare block
444 // Because TopSwap is set, this actually erase the top block (boot block)!
446 Status
= FtwEraseSpareBlock (FtwDevice
);
447 if (EFI_ERROR (Status
)) {
452 // Write memory buffer currenet spare block. Still top block.
455 for (Index
= 0; Index
< FtwDevice
->NumberOfSpareBlock
; Index
+= 1) {
456 Count
= FtwDevice
->BlockSize
;
457 Status
= FtwDevice
->FtwBackupFvb
->Write (
458 FtwDevice
->FtwBackupFvb
,
459 FtwDevice
->FtwSpareLba
+ Index
,
464 if (EFI_ERROR (Status
)) {
465 DEBUG ((EFI_D_ERROR
, "Ftw: FVB Write boot block - %r\n", Status
));
478 Status
= SarProtocol
->SetSwapState (SarProtocol
, FALSE
);
484 Copy the content of spare block to a target block. Size is FTW_BLOCK_SIZE.
485 Spare block is accessed by FTW backup FVB protocol interface. LBA is 1.
486 Target block is accessed by FvbBlock protocol interface. LBA is Lba.
489 @param FtwDevice The private data of FTW driver
490 @param FvBlock FVB Protocol interface to access target block
491 @param Lba Lba of the target block
493 @retval EFI_SUCCESS Spare block content is copied to target block
494 @retval EFI_INVALID_PARAMETER Input parameter error
495 @retval EFI_OUT_OF_RESOURCES Allocate memory error
496 @retval EFI_ABORTED The function could not complete successfully
500 FlushSpareBlockToTargetBlock (
501 EFI_FTW_DEVICE
*FtwDevice
,
502 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*FvBlock
,
513 if ((FtwDevice
== NULL
) || (FvBlock
== NULL
)) {
514 return EFI_INVALID_PARAMETER
;
517 // Allocate a memory buffer
519 Length
= FtwDevice
->SpareAreaLength
;
520 Buffer
= AllocatePool (Length
);
521 if (Buffer
== NULL
) {
522 return EFI_OUT_OF_RESOURCES
;
525 // Read all content of spare block to memory buffer
528 for (Index
= 0; Index
< FtwDevice
->NumberOfSpareBlock
; Index
+= 1) {
529 Count
= FtwDevice
->BlockSize
;
530 Status
= FtwDevice
->FtwBackupFvb
->Read (
531 FtwDevice
->FtwBackupFvb
,
532 FtwDevice
->FtwSpareLba
+ Index
,
537 if (EFI_ERROR (Status
)) {
545 // Erase the target block
547 Status
= FtwEraseBlock (FtwDevice
, FvBlock
, Lba
);
548 if (EFI_ERROR (Status
)) {
553 // Write memory buffer to block, using the FvbBlock protocol interface
556 for (Index
= 0; Index
< FtwDevice
->NumberOfSpareBlock
; Index
+= 1) {
557 Count
= FtwDevice
->BlockSize
;
558 Status
= FvBlock
->Write (FvBlock
, Lba
+ Index
, 0, &Count
, Ptr
);
559 if (EFI_ERROR (Status
)) {
560 DEBUG ((EFI_D_ERROR
, "Ftw: FVB Write block - %r\n", Status
));
574 Copy the content of spare block to working block. Size is FTW_BLOCK_SIZE.
575 Spare block is accessed by FTW backup FVB protocol interface. LBA is
576 FtwDevice->FtwSpareLba.
577 Working block is accessed by FTW working FVB protocol interface. LBA is
578 FtwDevice->FtwWorkBlockLba.
580 Since the working block header is important when FTW initializes, the
581 state of the operation should be handled carefully. The Crc value is
582 calculated without STATE element.
584 @param FtwDevice The private data of FTW driver
586 @retval EFI_SUCCESS Spare block content is copied to target block
587 @retval EFI_OUT_OF_RESOURCES Allocate memory error
588 @retval EFI_ABORTED The function could not complete successfully
592 FlushSpareBlockToWorkingBlock (
593 EFI_FTW_DEVICE
*FtwDevice
599 EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER
*WorkingBlockHeader
;
603 EFI_LBA WorkSpaceLbaOffset
;
606 // Allocate a memory buffer
608 Length
= FtwDevice
->SpareAreaLength
;
609 Buffer
= AllocatePool (Length
);
610 if (Buffer
== NULL
) {
611 return EFI_OUT_OF_RESOURCES
;
614 // To guarantee that the WorkingBlockValid is set on spare block
616 // Offset = OFFSET_OF(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER,
617 // WorkingBlockValid);
618 // To skip Signature and Crc: sizeof(EFI_GUID)+sizeof(UINT32).
621 FtwDevice
->FtwBackupFvb
,
622 FtwDevice
->FtwWorkSpaceLba
,
623 FtwDevice
->FtwWorkSpaceBase
+ sizeof (EFI_GUID
) + sizeof (UINT32
),
627 // Read from spare block to memory buffer
630 for (Index
= 0; Index
< FtwDevice
->NumberOfSpareBlock
; Index
+= 1) {
631 Count
= FtwDevice
->BlockSize
;
632 Status
= FtwDevice
->FtwBackupFvb
->Read (
633 FtwDevice
->FtwBackupFvb
,
634 FtwDevice
->FtwSpareLba
+ Index
,
639 if (EFI_ERROR (Status
)) {
647 // Clear the CRC and STATE, copy data from spare to working block.
649 WorkSpaceLbaOffset
= FtwDevice
->FtwWorkSpaceLba
- FtwDevice
->FtwWorkBlockLba
;
650 WorkingBlockHeader
= (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER
*) (Buffer
+ (UINTN
) WorkSpaceLbaOffset
* FtwDevice
->BlockSize
+ FtwDevice
->FtwWorkSpaceBase
);
651 InitWorkSpaceHeader (WorkingBlockHeader
);
652 WorkingBlockHeader
->WorkingBlockValid
= FTW_ERASE_POLARITY
;
653 WorkingBlockHeader
->WorkingBlockInvalid
= FTW_ERASE_POLARITY
;
656 // target block is working block, then
657 // Set WorkingBlockInvalid in EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER
658 // before erase the working block.
660 // Offset = OFFSET_OF(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER,
661 // WorkingBlockInvalid);
662 // So hardcode offset as sizeof(EFI_GUID)+sizeof(UINT32) to
663 // skip Signature and Crc.
665 Status
= FtwUpdateFvState (
666 FtwDevice
->FtwFvBlock
,
667 FtwDevice
->FtwWorkSpaceLba
,
668 FtwDevice
->FtwWorkSpaceBase
+ sizeof (EFI_GUID
) + sizeof (UINT32
),
669 WORKING_BLOCK_INVALID
671 if (EFI_ERROR (Status
)) {
676 FtwDevice
->FtwWorkSpaceHeader
->WorkingBlockInvalid
= FTW_VALID_STATE
;
679 // Erase the working block
681 Status
= FtwEraseBlock (FtwDevice
, FtwDevice
->FtwFvBlock
, FtwDevice
->FtwWorkBlockLba
);
682 if (EFI_ERROR (Status
)) {
687 // Write memory buffer to working block, using the FvbBlock protocol interface
690 for (Index
= 0; Index
< FtwDevice
->NumberOfSpareBlock
; Index
+= 1) {
691 Count
= FtwDevice
->BlockSize
;
692 Status
= FtwDevice
->FtwFvBlock
->Write (
693 FtwDevice
->FtwFvBlock
,
694 FtwDevice
->FtwWorkBlockLba
+ Index
,
699 if (EFI_ERROR (Status
)) {
700 DEBUG ((EFI_D_ERROR
, "Ftw: FVB Write block - %r\n", Status
));
708 // Since the memory buffer will not be used, free memory Buffer.
713 // Update the VALID of the working block
715 // Offset = OFFSET_OF(EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER, WorkingBlockValid);
716 // So hardcode offset as sizeof(EFI_GUID)+sizeof(UINT32) to skip Signature and Crc.
718 Status
= FtwUpdateFvState (
719 FtwDevice
->FtwFvBlock
,
720 FtwDevice
->FtwWorkSpaceLba
,
721 FtwDevice
->FtwWorkSpaceBase
+ sizeof (EFI_GUID
) + sizeof (UINT32
),
724 if (EFI_ERROR (Status
)) {
728 FtwDevice
->FtwWorkSpaceHeader
->WorkingBlockValid
= FTW_VALID_STATE
;
734 Update a bit of state on a block device. The location of the bit is
735 calculated by the (Lba, Offset, bit). Here bit is determined by the
736 the name of a certain bit.
739 @param FvBlock FVB Protocol interface to access SrcBlock and DestBlock
740 @param Lba Lba of a block
741 @param Offset Offset on the Lba
742 @param NewBit New value that will override the old value if it can be change
744 @retval EFI_SUCCESS A state bit has been updated successfully
745 @retval Others Access block device error.
747 Assume all bits of State are inside the same BYTE.
748 @retval EFI_ABORTED Read block fail
753 IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*FvBlock
,
764 // Read state from device, assume State is only one byte.
766 Length
= sizeof (UINT8
);
767 Status
= FvBlock
->Read (FvBlock
, Lba
, Offset
, &Length
, &State
);
768 if (EFI_ERROR (Status
)) {
772 State
^= FTW_POLARITY_REVERT
;
773 State
= (UINT8
) (State
| NewBit
);
774 State
^= FTW_POLARITY_REVERT
;
777 // Write state back to device
779 Length
= sizeof (UINT8
);
780 Status
= FvBlock
->Write (FvBlock
, Lba
, Offset
, &Length
, &State
);
786 Get the last Write Header pointer.
787 The last write header is the header whose 'complete' state hasn't been set.
788 After all, this header may be a EMPTY header entry for next Allocate.
791 @param FtwWorkSpaceHeader Pointer of the working block header
792 @param FtwWorkSpaceSize Size of the work space
793 @param FtwWriteHeader Pointer to retrieve the last write header
795 @retval EFI_SUCCESS Get the last write record successfully
796 @retval EFI_ABORTED The FTW work space is damaged
800 FtwGetLastWriteHeader (
801 IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER
*FtwWorkSpaceHeader
,
802 IN UINTN FtwWorkSpaceSize
,
803 OUT EFI_FAULT_TOLERANT_WRITE_HEADER
**FtwWriteHeader
807 EFI_FAULT_TOLERANT_WRITE_HEADER
*FtwHeader
;
809 *FtwWriteHeader
= NULL
;
810 FtwHeader
= (EFI_FAULT_TOLERANT_WRITE_HEADER
*) (FtwWorkSpaceHeader
+ 1);
811 Offset
= sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER
);
813 while (FtwHeader
->Complete
== FTW_VALID_STATE
) {
814 Offset
+= WRITE_TOTAL_SIZE (FtwHeader
->NumberOfWrites
, FtwHeader
->PrivateDataSize
);
816 // If Offset exceed the FTW work space boudary, return error.
818 if (Offset
> FtwWorkSpaceSize
) {
819 *FtwWriteHeader
= FtwHeader
;
823 FtwHeader
= (EFI_FAULT_TOLERANT_WRITE_HEADER
*) ((UINT8
*) FtwWorkSpaceHeader
+ Offset
);
826 // Last write header is found
828 *FtwWriteHeader
= FtwHeader
;
834 Get the last Write Record pointer. The last write Record is the Record
835 whose DestinationCompleted state hasn't been set. After all, this Record
836 may be a EMPTY record entry for next write.
839 @param FtwWriteHeader Pointer to the write record header
840 @param FtwWriteRecord Pointer to retrieve the last write record
842 @retval EFI_SUCCESS Get the last write record successfully
843 @retval EFI_ABORTED The FTW work space is damaged
847 FtwGetLastWriteRecord (
848 IN EFI_FAULT_TOLERANT_WRITE_HEADER
*FtwWriteHeader
,
849 OUT EFI_FAULT_TOLERANT_WRITE_RECORD
**FtwWriteRecord
853 EFI_FAULT_TOLERANT_WRITE_RECORD
*FtwRecord
;
855 *FtwWriteRecord
= NULL
;
856 FtwRecord
= (EFI_FAULT_TOLERANT_WRITE_RECORD
*) (FtwWriteHeader
+ 1);
859 // Try to find the last write record "that has not completed"
861 for (Index
= 0; Index
< FtwWriteHeader
->NumberOfWrites
; Index
+= 1) {
862 if (FtwRecord
->DestinationComplete
!= FTW_VALID_STATE
) {
864 // The last write record is found
866 *FtwWriteRecord
= FtwRecord
;
872 if (FtwWriteHeader
->PrivateDataSize
!= 0) {
873 FtwRecord
= (EFI_FAULT_TOLERANT_WRITE_RECORD
*) ((UINTN
) FtwRecord
+ FtwWriteHeader
->PrivateDataSize
);
877 // if Index == NumberOfWrites, then
878 // the last record has been written successfully,
879 // but the Header->Complete Flag has not been set.
880 // also return the last record.
882 if (Index
== FtwWriteHeader
->NumberOfWrites
) {
883 *FtwWriteRecord
= (EFI_FAULT_TOLERANT_WRITE_RECORD
*) ((UINTN
) FtwRecord
- RECORD_SIZE (FtwWriteHeader
->PrivateDataSize
));
891 To check if FtwRecord is the first record of FtwHeader.
893 @param FtwHeader Pointer to the write record header
894 @param FtwRecord Pointer to the write record
896 @retval TRUE FtwRecord is the first Record of the FtwHeader
897 @retval FALSE FtwRecord is not the first Record of the FtwHeader
901 IsFirstRecordOfWrites (
902 IN EFI_FAULT_TOLERANT_WRITE_HEADER
*FtwHeader
,
903 IN EFI_FAULT_TOLERANT_WRITE_RECORD
*FtwRecord
909 Head
= (UINT8
*) FtwHeader
;
910 Ptr
= (UINT8
*) FtwRecord
;
912 Head
+= sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER
);
913 return (BOOLEAN
) (Head
== Ptr
);
917 To check if FtwRecord is the last record of FtwHeader. Because the
918 FtwHeader has NumberOfWrites & PrivateDataSize, the FtwRecord can be
919 determined if it is the last record of FtwHeader.
921 @param FtwHeader Pointer to the write record header
922 @param FtwRecord Pointer to the write record
924 @retval TRUE FtwRecord is the last Record of the FtwHeader
925 @retval FALSE FtwRecord is not the last Record of the FtwHeader
929 IsLastRecordOfWrites (
930 IN EFI_FAULT_TOLERANT_WRITE_HEADER
*FtwHeader
,
931 IN EFI_FAULT_TOLERANT_WRITE_RECORD
*FtwRecord
937 Head
= (UINT8
*) FtwHeader
;
938 Ptr
= (UINT8
*) FtwRecord
;
940 Head
+= WRITE_TOTAL_SIZE (FtwHeader
->NumberOfWrites
- 1, FtwHeader
->PrivateDataSize
);
941 return (BOOLEAN
) (Head
== Ptr
);
945 To check if FtwRecord is the first record of FtwHeader.
947 @param FtwHeader Pointer to the write record header
948 @param FtwRecord Pointer to retrieve the previous write record
950 @retval EFI_ACCESS_DENIED Input record is the first record, no previous record is return.
951 @retval EFI_SUCCESS The previous write record is found.
955 GetPreviousRecordOfWrites (
956 IN EFI_FAULT_TOLERANT_WRITE_HEADER
*FtwHeader
,
957 IN OUT EFI_FAULT_TOLERANT_WRITE_RECORD
**FtwRecord
962 if (IsFirstRecordOfWrites (FtwHeader
, *FtwRecord
)) {
964 return EFI_ACCESS_DENIED
;
967 Ptr
= (UINT8
*) (*FtwRecord
);
968 Ptr
-= RECORD_SIZE (FtwHeader
->PrivateDataSize
);
969 *FtwRecord
= (EFI_FAULT_TOLERANT_WRITE_RECORD
*) Ptr
;