2 FFS file access utilities.
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 Get the FFS file state by checking the highest bit set in the header's state field.
22 @param ErasePolarity Erase polarity attribute of the firmware volume
23 @param FfsHeader Points to the FFS file header
25 @return FFS File state
30 IN UINT8 ErasePolarity
,
31 IN EFI_FFS_FILE_HEADER
*FfsHeader
34 EFI_FFS_FILE_STATE FileState
;
37 FileState
= FfsHeader
->State
;
39 if (ErasePolarity
!= 0) {
40 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
44 while (HighestBit
!= 0 && ((HighestBit
& FileState
) == 0)) {
48 return (EFI_FFS_FILE_STATE
) HighestBit
;
54 Check if a block of buffer is erased.
56 @param ErasePolarity Erase polarity attribute of the firmware volume
57 @param InBuffer The buffer to be checked
58 @param BufferSize Size of the buffer in bytes
60 @retval TRUE The block of buffer is erased
61 @retval FALSE The block of buffer is not erased
66 IN UINT8 ErasePolarity
,
75 if(ErasePolarity
== 1) {
82 for (Count
= 0; Count
< BufferSize
; Count
++) {
83 if (Buffer
[Count
] != EraseByte
) {
94 Verify checksum of the firmware volume header.
96 @param FvHeader Points to the firmware volume header to be checked
98 @retval TRUE Checksum verification passed
99 @retval FALSE Checksum verification failed
103 VerifyFvHeaderChecksum (
104 IN EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
112 HeaderLength
= FvHeader
->HeaderLength
;
113 Ptr
= (UINT16
*)FvHeader
;
116 for (Index
= 0; Index
< HeaderLength
/ sizeof (UINT16
); Index
++) {
117 Checksum
= (UINT16
)(Checksum
+ Ptr
[Index
]);
129 Verify checksum of the FFS file header.
131 @param FfsHeader Points to the FFS file header to be checked
133 @retval TRUE Checksum verification passed
134 @retval FALSE Checksum verification failed
138 VerifyHeaderChecksum (
139 IN EFI_FFS_FILE_HEADER
*FfsHeader
144 UINT8 HeaderChecksum
;
146 Ptr
= (UINT8
*)FfsHeader
;
148 for (Index
= 0; Index
< sizeof(EFI_FFS_FILE_HEADER
); Index
++) {
149 HeaderChecksum
= (UINT8
)(HeaderChecksum
+ Ptr
[Index
]);
152 HeaderChecksum
= (UINT8
) (HeaderChecksum
- FfsHeader
->State
- FfsHeader
->IntegrityCheck
.Checksum
.File
);
154 if (HeaderChecksum
== 0) {
164 Check if it's a valid FFS file header.
166 @param ErasePolarity Erase polarity attribute of the firmware volume
167 @param FfsHeader Points to the FFS file header to be checked
168 @param FileState FFS file state to be returned
170 @retval TRUE Valid FFS file header
171 @retval FALSE Invalid FFS file header
176 IN UINT8 ErasePolarity
,
177 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
178 OUT EFI_FFS_FILE_STATE
*FileState
181 *FileState
= GetFileState (ErasePolarity
, FfsHeader
);
183 switch (*FileState
) {
184 case EFI_FILE_HEADER_VALID
:
185 case EFI_FILE_DATA_VALID
:
186 case EFI_FILE_MARKED_FOR_UPDATE
:
187 case EFI_FILE_DELETED
:
189 // Here we need to verify header checksum
191 return VerifyHeaderChecksum (FfsHeader
);
193 case EFI_FILE_HEADER_CONSTRUCTION
:
194 case EFI_FILE_HEADER_INVALID
:
202 Check if it's a valid FFS file.
203 Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.
205 @param ErasePolarity Erase polarity attribute of the firmware volume
206 @param FfsHeader Points to the FFS file to be checked
208 @retval TRUE Valid FFS file
209 @retval FALSE Invalid FFS file
214 IN UINT8 ErasePolarity
,
215 IN EFI_FFS_FILE_HEADER
*FfsHeader
218 EFI_FFS_FILE_STATE FileState
;
220 FileState
= GetFileState (ErasePolarity
, FfsHeader
);
223 case EFI_FILE_DELETED
:
224 case EFI_FILE_DATA_VALID
:
225 case EFI_FILE_MARKED_FOR_UPDATE
:
227 // Some other vliadation like file content checksum might be done here.
228 // For performance issue, Tiano only do FileState check.