3 FFS file access utilities.
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.
19 #define PHYSICAL_ADDRESS_TO_POINTER(Address) ((VOID *)((UINTN)(Address)))
23 Get the FFS file state by checking the highest bit set in the header's state field.
25 @param ErasePolarity Erase polarity attribute of the firmware volume
26 @param FfsHeader Points to the FFS file header
28 @return FFS File state
33 IN UINT8 ErasePolarity
,
34 IN EFI_FFS_FILE_HEADER
*FfsHeader
37 EFI_FFS_FILE_STATE FileState
;
40 FileState
= FfsHeader
->State
;
42 if (ErasePolarity
!= 0) {
43 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
47 while (HighestBit
!= 0 && ((HighestBit
& FileState
) == 0)) {
51 return (EFI_FFS_FILE_STATE
)HighestBit
;
57 Check if a block of buffer is erased.
59 @param ErasePolarity Erase polarity attribute of the firmware volume
60 @param InBuffer The buffer to be checked
61 @param BufferSize Size of the buffer in bytes
63 @retval TRUE The block of buffer is erased
64 @retval FALSE The block of buffer is not erased
69 IN UINT8 ErasePolarity
,
78 if(ErasePolarity
== 1) {
85 for (Count
= 0; Count
< BufferSize
; Count
++) {
86 if (Buffer
[Count
] != EraseByte
) {
97 Verify checksum of the firmware volume header.
99 @param FvHeader Points to the firmware volume header to be checked
101 @retval TRUE Checksum verification passed
102 @retval FALSE Checksum verification failed
106 VerifyFvHeaderChecksum (
107 IN EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
115 HeaderLength
= FvHeader
->HeaderLength
;
116 Ptr
= (UINT16
*)FvHeader
;
119 for (Index
= 0; Index
< HeaderLength
/ sizeof (UINT16
); Index
++) {
120 Checksum
= (UINT16
)(Checksum
+ Ptr
[Index
]);
132 Verify checksum of the FFS file header.
134 @param FfsHeader Points to the FFS file header to be checked
136 @retval TRUE Checksum verification passed
137 @retval FALSE Checksum verification failed
142 VerifyHeaderChecksum (
143 IN EFI_FFS_FILE_HEADER
*FfsHeader
148 UINT8 HeaderChecksum
;
150 Ptr
= (UINT8
*)FfsHeader
;
152 for (Index
= 0; Index
< sizeof(EFI_FFS_FILE_HEADER
); Index
++) {
153 HeaderChecksum
= (UINT8
)(HeaderChecksum
+ Ptr
[Index
]);
156 HeaderChecksum
= (UINT8
) (HeaderChecksum
- FfsHeader
->State
- FfsHeader
->IntegrityCheck
.Checksum
.File
);
158 if (HeaderChecksum
== 0) {
168 Check if it's a valid FFS file header.
170 @param ErasePolarity Erase polarity attribute of the firmware volume
171 @param FfsHeader Points to the FFS file header to be checked
172 @param FileState FFS file state to be returned
174 @retval TRUE Valid FFS file header
175 @retval FALSE Invalid FFS file header
180 IN UINT8 ErasePolarity
,
181 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
182 OUT EFI_FFS_FILE_STATE
*FileState
185 *FileState
= GetFileState (ErasePolarity
, FfsHeader
);
187 switch (*FileState
) {
188 case EFI_FILE_HEADER_VALID
:
189 case EFI_FILE_DATA_VALID
:
190 case EFI_FILE_MARKED_FOR_UPDATE
:
191 case EFI_FILE_DELETED
:
193 // Here we need to verify header checksum
195 return VerifyHeaderChecksum (FfsHeader
);
197 case EFI_FILE_HEADER_CONSTRUCTION
:
198 case EFI_FILE_HEADER_INVALID
:
207 Check if it's a valid FFS file.
208 Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.
210 @param ErasePolarity Erase polarity attribute of the firmware volume
211 @param FfsHeader Points to the FFS file to be checked
213 @retval TRUE Valid FFS file
214 @retval FALSE Invalid FFS file
219 IN UINT8 ErasePolarity
,
220 IN EFI_FFS_FILE_HEADER
*FfsHeader
223 EFI_FFS_FILE_STATE FileState
;
225 FileState
= GetFileState (ErasePolarity
, FfsHeader
);
228 case EFI_FILE_DELETED
:
229 case EFI_FILE_DATA_VALID
:
230 case EFI_FILE_MARKED_FOR_UPDATE
:
232 // Some other vliadation like file content checksum might be done here.
233 // For performance issue, Tiano only do FileState check.