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.
18 #define PHYSICAL_ADDRESS_TO_POINTER(Address) ((VOID *)((UINTN)(Address)))
22 Get the FFS file state by checking the highest bit set in the header's state field.
24 @param ErasePolarity Erase polarity attribute of the firmware volume
25 @param FfsHeader Points to the FFS file header
27 @return FFS File state
32 IN UINT8 ErasePolarity
,
33 IN EFI_FFS_FILE_HEADER
*FfsHeader
36 EFI_FFS_FILE_STATE FileState
;
39 FileState
= FfsHeader
->State
;
41 if (ErasePolarity
!= 0) {
42 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
46 while (HighestBit
!= 0 && ((HighestBit
& FileState
) == 0)) {
50 return (EFI_FFS_FILE_STATE
)HighestBit
;
56 Check if a block of buffer is erased.
58 @param ErasePolarity Erase polarity attribute of the firmware volume
59 @param InBuffer The buffer to be checked
60 @param BufferSize Size of the buffer in bytes
62 @retval TRUE The block of buffer is erased
63 @retval FALSE The block of buffer is not erased
68 IN UINT8 ErasePolarity
,
77 if(ErasePolarity
== 1) {
84 for (Count
= 0; Count
< BufferSize
; Count
++) {
85 if (Buffer
[Count
] != EraseByte
) {
96 Verify checksum of the firmware volume header.
98 @param FvHeader Points to the firmware volume header to be checked
100 @retval TRUE Checksum verification passed
101 @retval FALSE Checksum verification failed
105 VerifyFvHeaderChecksum (
106 IN EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
114 HeaderLength
= FvHeader
->HeaderLength
;
115 Ptr
= (UINT16
*)FvHeader
;
118 for (Index
= 0; Index
< HeaderLength
/ sizeof (UINT16
); Index
++) {
119 Checksum
= (UINT16
)(Checksum
+ Ptr
[Index
]);
131 Verify checksum of the FFS file header.
133 @param FfsHeader Points to the FFS file header to be checked
135 @retval TRUE Checksum verification passed
136 @retval FALSE Checksum verification failed
140 VerifyHeaderChecksum (
141 IN EFI_FFS_FILE_HEADER
*FfsHeader
146 UINT8 HeaderChecksum
;
148 Ptr
= (UINT8
*)FfsHeader
;
150 for (Index
= 0; Index
< sizeof(EFI_FFS_FILE_HEADER
); Index
++) {
151 HeaderChecksum
= (UINT8
)(HeaderChecksum
+ Ptr
[Index
]);
154 HeaderChecksum
= (UINT8
) (HeaderChecksum
- FfsHeader
->State
- FfsHeader
->IntegrityCheck
.Checksum
.File
);
156 if (HeaderChecksum
== 0) {
166 Check if it's a valid FFS file header.
168 @param ErasePolarity Erase polarity attribute of the firmware volume
169 @param FfsHeader Points to the FFS file header to be checked
170 @param FileState FFS file state to be returned
172 @retval TRUE Valid FFS file header
173 @retval FALSE Invalid FFS file header
178 IN UINT8 ErasePolarity
,
179 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
180 OUT EFI_FFS_FILE_STATE
*FileState
183 *FileState
= GetFileState (ErasePolarity
, FfsHeader
);
185 switch (*FileState
) {
186 case EFI_FILE_HEADER_VALID
:
187 case EFI_FILE_DATA_VALID
:
188 case EFI_FILE_MARKED_FOR_UPDATE
:
189 case EFI_FILE_DELETED
:
191 // Here we need to verify header checksum
193 return VerifyHeaderChecksum (FfsHeader
);
195 case EFI_FILE_HEADER_CONSTRUCTION
:
196 case EFI_FILE_HEADER_INVALID
:
205 Check if it's a valid FFS file.
206 Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.
208 @param ErasePolarity Erase polarity attribute of the firmware volume
209 @param FfsHeader Points to the FFS file to be checked
211 @retval TRUE Valid FFS file
212 @retval FALSE Invalid FFS file
217 IN UINT8 ErasePolarity
,
218 IN EFI_FFS_FILE_HEADER
*FfsHeader
221 EFI_FFS_FILE_STATE FileState
;
223 FileState
= GetFileState (ErasePolarity
, FfsHeader
);
226 case EFI_FILE_DELETED
:
227 case EFI_FILE_DATA_VALID
:
228 case EFI_FILE_MARKED_FOR_UPDATE
:
230 // Some other vliadation like file content checksum might be done here.
231 // For performance issue, Tiano only do FileState check.