3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 FFS file access utilities.
25 #define PHYSICAL_ADDRESS_TO_POINTER(Address) ((VOID *)((UINTN)(Address)))
30 IN UINT8 ErasePolarity
,
31 IN EFI_FFS_FILE_HEADER
*FfsHeader
36 Get the FFS file state by checking the highest bit set in the header's state field
39 ErasePolarity - Erase polarity attribute of the firmware volume
40 FfsHeader - Points to the FFS file header
47 EFI_FFS_FILE_STATE FileState
;
50 FileState
= FfsHeader
->State
;
52 if (ErasePolarity
!= 0) {
53 FileState
= (EFI_FFS_FILE_STATE
)~FileState
;
57 while (HighestBit
!= 0 && ((HighestBit
& FileState
) == 0)) {
61 return (EFI_FFS_FILE_STATE
)HighestBit
;
67 IN UINT8 ErasePolarity
,
74 Check if a block of buffer is erased
77 ErasePolarity - Erase polarity attribute of the firmware volume
78 InBuffer - The buffer to be checked
79 BufferSize - Size of the buffer in bytes
82 TRUE - The block of buffer is erased
83 FALSE - The block of buffer is not erased
91 if(ErasePolarity
== 1) {
98 for (Count
= 0; Count
< BufferSize
; Count
++) {
99 if (Buffer
[Count
] != EraseByte
) {
109 VerifyFvHeaderChecksum (
110 IN EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
115 Verify checksum of the firmware volume header
118 FvHeader - Points to the firmware volume header to be checked
121 TRUE - Checksum verification passed
122 FALSE - Checksum verification failed
131 HeaderLength
= FvHeader
->HeaderLength
;
132 ptr
= (UINT16
*)FvHeader
;
135 for (Index
= 0; Index
< HeaderLength
/ sizeof (UINT16
); Index
++) {
136 Checksum
= (UINT16
)(Checksum
+ ptr
[Index
]);
148 VerifyHeaderChecksum (
149 IN EFI_FFS_FILE_HEADER
*FfsHeader
154 Verify checksum of the FFS file header
157 FfsHeader - Points to the FFS file header to be checked
160 TRUE - Checksum verification passed
161 FALSE - Checksum verification failed
167 UINT8 HeaderChecksum
;
169 ptr
= (UINT8
*)FfsHeader
;
171 for (Index
= 0; Index
< sizeof(EFI_FFS_FILE_HEADER
); Index
++) {
172 HeaderChecksum
= (UINT8
)(HeaderChecksum
+ ptr
[Index
]);
175 HeaderChecksum
= (UINT8
) (HeaderChecksum
- FfsHeader
->State
- FfsHeader
->IntegrityCheck
.Checksum
.File
);
177 if (HeaderChecksum
== 0) {
187 IN UINT8 ErasePolarity
,
188 IN EFI_FFS_FILE_HEADER
*FfsHeader
,
189 OUT EFI_FFS_FILE_STATE
*FileState
194 Check if it's a valid FFS file header
197 ErasePolarity - Erase polarity attribute of the firmware volume
198 FfsHeader - Points to the FFS file header to be checked
199 FileState - FFS file state to be returned
202 TRUE - Valid FFS file header
203 FALSE - Invalid FFS file header
207 *FileState
= GetFileState (ErasePolarity
, FfsHeader
);
209 switch (*FileState
) {
210 case EFI_FILE_HEADER_VALID
:
211 case EFI_FILE_DATA_VALID
:
212 case EFI_FILE_MARKED_FOR_UPDATE
:
213 case EFI_FILE_DELETED
:
215 // Here we need to verify header checksum
217 return VerifyHeaderChecksum (FfsHeader
);
219 case EFI_FILE_HEADER_CONSTRUCTION
:
220 case EFI_FILE_HEADER_INVALID
:
229 IN UINT8 ErasePolarity
,
230 IN EFI_FFS_FILE_HEADER
*FfsHeader
235 Check if it's a valid FFS file.
236 Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.
239 ErasePolarity - Erase polarity attribute of the firmware volume
240 FfsHeader - Points to the FFS file to be checked
243 TRUE - Valid FFS file
244 FALSE - Invalid FFS file
248 EFI_FFS_FILE_STATE FileState
;
250 FileState
= GetFileState (ErasePolarity
, FfsHeader
);
253 case EFI_FILE_DELETED
:
254 case EFI_FILE_DATA_VALID
:
255 case EFI_FILE_MARKED_FOR_UPDATE
:
257 // Some other vliadation like file content checksum might be done here.
258 // For performance issue, Tiano only do FileState check.