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)))
24 IN UINT8 ErasePolarity
,
25 IN EFI_FFS_FILE_HEADER
*FfsHeader
30 Get the FFS file state by checking the highest bit set in the header's state field
33 ErasePolarity - Erase polarity attribute of the firmware volume
34 FfsHeader - Points to the FFS file header
41 EFI_FFS_FILE_STATE FileState
;
44 FileState
= FfsHeader
->State
;
46 if (ErasePolarity
!= 0) {
47 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
51 while (HighestBit
!= 0 && ((HighestBit
& FileState
) == 0)) {
55 return (EFI_FFS_FILE_STATE
)HighestBit
;
61 IN UINT8 ErasePolarity
,
68 Check if a block of buffer is erased
71 ErasePolarity - Erase polarity attribute of the firmware volume
72 InBuffer - The buffer to be checked
73 BufferSize - Size of the buffer in bytes
76 TRUE - The block of buffer is erased
77 FALSE - The block of buffer is not erased
85 if(ErasePolarity
== 1) {
92 for (Count
= 0; Count
< BufferSize
; Count
++) {
93 if (Buffer
[Count
] != EraseByte
) {
103 VerifyFvHeaderChecksum (
104 IN EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
109 Verify checksum of the firmware volume header
112 FvHeader - Points to the firmware volume header to be checked
115 TRUE - Checksum verification passed
116 FALSE - Checksum verification failed
125 HeaderLength
= FvHeader
->HeaderLength
;
126 ptr
= (UINT16
*)FvHeader
;
129 for (Index
= 0; Index
< HeaderLength
/ sizeof (UINT16
); Index
++) {
130 Checksum
= (UINT16
)(Checksum
+ ptr
[Index
]);
142 VerifyHeaderChecksum (
143 IN EFI_FFS_FILE_HEADER
*FfsHeader
148 Verify checksum of the FFS file header
151 FfsHeader - Points to the FFS file header to be checked
154 TRUE - Checksum verification passed
155 FALSE - Checksum verification failed
161 UINT8 HeaderChecksum
;
163 ptr
= (UINT8
*)FfsHeader
;
165 for (Index
= 0; Index
< sizeof(EFI_FFS_FILE_HEADER
); Index
++) {
166 HeaderChecksum
= (UINT8
)(HeaderChecksum
+ ptr
[Index
]);
169 HeaderChecksum
= (UINT8
) (HeaderChecksum
- FfsHeader
->State
- FfsHeader
->IntegrityCheck
.Checksum
.File
);
171 if (HeaderChecksum
== 0) {
181 IN UINT8 ErasePolarity
,
182 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
183 OUT EFI_FFS_FILE_STATE
*FileState
188 Check if it's a valid FFS file header
191 ErasePolarity - Erase polarity attribute of the firmware volume
192 FfsHeader - Points to the FFS file header to be checked
193 FileState - FFS file state to be returned
196 TRUE - Valid FFS file header
197 FALSE - Invalid FFS file header
201 *FileState
= GetFileState (ErasePolarity
, FfsHeader
);
203 switch (*FileState
) {
204 case EFI_FILE_HEADER_VALID
:
205 case EFI_FILE_DATA_VALID
:
206 case EFI_FILE_MARKED_FOR_UPDATE
:
207 case EFI_FILE_DELETED
:
209 // Here we need to verify header checksum
211 return VerifyHeaderChecksum (FfsHeader
);
213 case EFI_FILE_HEADER_CONSTRUCTION
:
214 case EFI_FILE_HEADER_INVALID
:
223 IN UINT8 ErasePolarity
,
224 IN EFI_FFS_FILE_HEADER
*FfsHeader
229 Check if it's a valid FFS file.
230 Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.
233 ErasePolarity - Erase polarity attribute of the firmware volume
234 FfsHeader - Points to the FFS file to be checked
237 TRUE - Valid FFS file
238 FALSE - Invalid FFS file
242 EFI_FFS_FILE_STATE FileState
;
244 FileState
= GetFileState (ErasePolarity
, FfsHeader
);
247 case EFI_FILE_DELETED
:
248 case EFI_FILE_DATA_VALID
:
249 case EFI_FILE_MARKED_FOR_UPDATE
:
251 // Some other vliadation like file content checksum might be done here.
252 // For performance issue, Tiano only do FileState check.