]>
Commit | Line | Data |
---|---|---|
162ed594 | 1 | /** @file\r |
797a9d67 | 2 | Firmware File System protocol. Layers on top of Firmware\r |
3 | Block protocol to produce a file abstraction of FV based files.\r | |
23c98c94 | 4 | \r |
5 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
28a00297 | 13 | \r |
797a9d67 | 14 | **/\r |
28a00297 | 15 | \r |
162ed594 | 16 | #ifndef __FW_VOL_DRIVER_H_\r |
17 | #define __FW_VOL_DRIVER_H_\r | |
28a00297 | 18 | \r |
19 | \r | |
0c2b5da8 | 20 | #define FV2_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('_', 'F', 'V', '2')\r |
21 | \r | |
28a00297 | 22 | //\r |
23 | // Used to track all non-deleted files\r | |
24 | //\r | |
25 | typedef struct {\r | |
26 | LIST_ENTRY Link;\r | |
27 | EFI_FFS_FILE_HEADER *FfsHeader;\r | |
28 | UINTN StreamHandle;\r | |
28a00297 | 29 | } FFS_FILE_LIST_ENTRY;\r |
30 | \r | |
31 | typedef struct {\r | |
32 | UINTN Signature;\r | |
33 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;\r | |
34 | EFI_HANDLE Handle;\r | |
0c2b5da8 | 35 | EFI_FIRMWARE_VOLUME2_PROTOCOL Fv;\r |
28a00297 | 36 | \r |
37 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r | |
38 | UINT8 *CachedFv;\r | |
39 | UINT8 *EndOfCachedFv;\r | |
40 | \r | |
41 | FFS_FILE_LIST_ENTRY *LastKey;\r | |
42 | \r | |
43 | LIST_ENTRY FfsFileListHeader;\r | |
44 | \r | |
45 | UINT8 ErasePolarity;\r | |
46 | } FV_DEVICE;\r | |
47 | \r | |
0c2b5da8 | 48 | #define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE)\r |
28a00297 | 49 | \r |
162ed594 | 50 | /**\r |
51 | Retrieves attributes, insures positive polarity of attribute bits, returns\r | |
52 | resulting attributes in output parameter.\r | |
28a00297 | 53 | \r |
162ed594 | 54 | @param This Calling context \r |
55 | @param Attributes output buffer which contains attributes \r | |
56 | \r | |
57 | @retval EFI_SUCCESS Successfully got volume attributes\r | |
58 | \r | |
59 | **/\r | |
28a00297 | 60 | EFI_STATUS\r |
61 | EFIAPI\r | |
62 | FvGetVolumeAttributes (\r | |
23c98c94 | 63 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r |
64 | OUT EFI_FV_ATTRIBUTES *Attributes\r | |
65 | );\r | |
28a00297 | 66 | \r |
28a00297 | 67 | \r |
162ed594 | 68 | /**\r |
69 | Sets current attributes for volume\r | |
28a00297 | 70 | \r |
162ed594 | 71 | @param This Calling context \r |
72 | @param Attributes At input, contains attributes to be set. At output \r | |
73 | contains new value of FV \r | |
28a00297 | 74 | \r |
162ed594 | 75 | @retval EFI_UNSUPPORTED Could not be set.\r |
28a00297 | 76 | \r |
162ed594 | 77 | **/\r |
28a00297 | 78 | EFI_STATUS\r |
79 | EFIAPI\r | |
80 | FvSetVolumeAttributes (\r | |
23c98c94 | 81 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r |
82 | IN OUT EFI_FV_ATTRIBUTES *Attributes\r | |
83 | );\r | |
28a00297 | 84 | \r |
28a00297 | 85 | \r |
162ed594 | 86 | /**\r |
87 | Given the input key, search for the next matching file in the volume.\r | |
88 | \r | |
89 | @param This Indicates the calling context. \r | |
90 | @param Key Key is a pointer to a caller allocated \r | |
91 | buffer that contains implementation specific \r | |
92 | data that is used to track where to begin \r | |
93 | the search for the next file. The size of \r | |
94 | the buffer must be at least This->KeySize \r | |
95 | bytes long. To reinitialize the search and \r | |
96 | begin from the beginning of the firmware \r | |
97 | volume, the entire buffer must be cleared to \r | |
98 | zero. Other than clearing the buffer to \r | |
99 | initiate a new search, the caller must not \r | |
100 | modify the data in the buffer between calls \r | |
101 | to GetNextFile(). \r | |
102 | @param FileType FileType is a pointer to a caller allocated \r | |
103 | EFI_FV_FILETYPE. The GetNextFile() API can \r | |
104 | filter it's search for files based on the \r | |
105 | value of *FileType input. A *FileType input \r | |
106 | of 0 causes GetNextFile() to search for \r | |
107 | files of all types. If a file is found, the \r | |
108 | file's type is returned in *FileType. \r | |
109 | *FileType is not modified if no file is \r | |
110 | found. \r | |
111 | @param NameGuid NameGuid is a pointer to a caller allocated \r | |
112 | EFI_GUID. If a file is found, the file's \r | |
113 | name is returned in *NameGuid. *NameGuid is \r | |
114 | not modified if no file is found. \r | |
115 | @param Attributes Attributes is a pointer to a caller \r | |
116 | allocated EFI_FV_FILE_ATTRIBUTES. If a file \r | |
117 | is found, the file's attributes are returned \r | |
118 | in *Attributes. *Attributes is not modified \r | |
119 | if no file is found. \r | |
120 | @param Size Size is a pointer to a caller allocated \r | |
121 | UINTN. If a file is found, the file's size \r | |
122 | is returned in *Size. *Size is not modified \r | |
123 | if no file is found. \r | |
124 | \r | |
125 | @retval EFI_SUCCESS Successfully find the file. \r | |
126 | @retval EFI_DEVICE_ERROR Device error. \r | |
127 | @retval EFI_ACCESS_DENIED Fv could not read. \r | |
128 | @retval EFI_NOT_FOUND No matching file found. \r | |
129 | @retval EFI_INVALID_PARAMETER Invalid parameter\r | |
28a00297 | 130 | \r |
162ed594 | 131 | **/\r |
28a00297 | 132 | EFI_STATUS\r |
133 | EFIAPI\r | |
134 | FvGetNextFile (\r | |
23c98c94 | 135 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r |
136 | IN OUT VOID *Key,\r | |
137 | IN OUT EFI_FV_FILETYPE *FileType,\r | |
138 | OUT EFI_GUID *NameGuid,\r | |
139 | OUT EFI_FV_FILE_ATTRIBUTES *Attributes,\r | |
140 | OUT UINTN *Size\r | |
141 | );\r | |
28a00297 | 142 | \r |
143 | \r | |
162ed594 | 144 | \r |
145 | /**\r | |
146 | Locates a file in the firmware volume and\r | |
147 | copies it to the supplied buffer.\r | |
148 | \r | |
149 | @param This Indicates the calling context. \r | |
150 | @param NameGuid Pointer to an EFI_GUID, which is the \r | |
151 | filename. \r | |
152 | @param Buffer Buffer is a pointer to pointer to a buffer \r | |
153 | in which the file or section contents or are \r | |
154 | returned. \r | |
155 | @param BufferSize BufferSize is a pointer to caller allocated \r | |
156 | UINTN. On input *BufferSize indicates the \r | |
157 | size in bytes of the memory region pointed \r | |
158 | to by Buffer. On output, *BufferSize \r | |
159 | contains the number of bytes required to \r | |
160 | read the file. \r | |
161 | @param FoundType FoundType is a pointer to a caller allocated \r | |
162 | EFI_FV_FILETYPE that on successful return \r | |
163 | from Read() contains the type of file read. \r | |
164 | This output reflects the file type \r | |
165 | irrespective of the value of the SectionType \r | |
166 | input. \r | |
167 | @param FileAttributes FileAttributes is a pointer to a caller \r | |
168 | allocated EFI_FV_FILE_ATTRIBUTES. On \r | |
169 | successful return from Read(), \r | |
170 | *FileAttributes contains the attributes of \r | |
171 | the file read. \r | |
172 | @param AuthenticationStatus AuthenticationStatus is a pointer to a \r | |
173 | caller allocated UINTN in which the \r | |
174 | authentication status is returned. \r | |
175 | \r | |
176 | @retval EFI_SUCCESS Successfully read to memory buffer. \r | |
177 | @retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small. \r | |
178 | @retval EFI_NOT_FOUND Not found. \r | |
179 | @retval EFI_DEVICE_ERROR Device error. \r | |
180 | @retval EFI_ACCESS_DENIED Could not read. \r | |
181 | @retval EFI_INVALID_PARAMETER Invalid parameter. \r | |
182 | @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated.\r | |
183 | \r | |
184 | **/\r | |
28a00297 | 185 | EFI_STATUS\r |
186 | EFIAPI\r | |
187 | FvReadFile (\r | |
23c98c94 | 188 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r |
189 | IN CONST EFI_GUID *NameGuid,\r | |
190 | IN OUT VOID **Buffer,\r | |
191 | IN OUT UINTN *BufferSize,\r | |
192 | OUT EFI_FV_FILETYPE *FoundType,\r | |
193 | OUT EFI_FV_FILE_ATTRIBUTES *FileAttributes,\r | |
194 | OUT UINT32 *AuthenticationStatus\r | |
195 | );\r | |
28a00297 | 196 | \r |
162ed594 | 197 | \r |
198 | /**\r | |
199 | Locates a section in a given FFS File and\r | |
200 | copies it to the supplied buffer (not including section header).\r | |
201 | \r | |
202 | @param This Indicates the calling context. \r | |
203 | @param NameGuid Pointer to an EFI_GUID, which is the \r | |
204 | filename. \r | |
205 | @param SectionType Indicates the section type to return. \r | |
206 | @param SectionInstance Indicates which instance of sections with a \r | |
207 | type of SectionType to return. \r | |
208 | @param Buffer Buffer is a pointer to pointer to a buffer \r | |
209 | in which the file or section contents or are \r | |
210 | returned. \r | |
211 | @param BufferSize BufferSize is a pointer to caller allocated \r | |
212 | UINTN.\r | |
213 | @param AuthenticationStatus AuthenticationStatus is a pointer to a \r | |
214 | caller allocated UINT32 in which the \r | |
215 | authentication status is returned. \r | |
216 | \r | |
217 | @retval EFI_SUCCESS Successfully read the file section into \r | |
218 | buffer. \r | |
219 | @retval EFI_WARN_BUFFER_TOO_SMALL Buffer too small. \r | |
220 | @retval EFI_NOT_FOUND Section not found. \r | |
221 | @retval EFI_DEVICE_ERROR Device error. \r | |
222 | @retval EFI_ACCESS_DENIED Could not read. \r | |
223 | @retval EFI_INVALID_PARAMETER Invalid parameter.\r | |
224 | \r | |
225 | **/\r | |
28a00297 | 226 | EFI_STATUS\r |
227 | EFIAPI\r | |
228 | FvReadFileSection (\r | |
23c98c94 | 229 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r |
0c2b5da8 | 230 | IN CONST EFI_GUID *NameGuid,\r |
231 | IN EFI_SECTION_TYPE SectionType,\r | |
232 | IN UINTN SectionInstance,\r | |
233 | IN OUT VOID **Buffer,\r | |
234 | IN OUT UINTN *BufferSize,\r | |
235 | OUT UINT32 *AuthenticationStatus\r | |
23c98c94 | 236 | );\r |
28a00297 | 237 | \r |
162ed594 | 238 | \r |
239 | /**\r | |
240 | Writes one or more files to the firmware volume.\r | |
241 | \r | |
242 | @param This Indicates the calling context. \r | |
243 | @param NumberOfFiles Number of files. \r | |
244 | @param WritePolicy WritePolicy indicates the level of reliability \r | |
245 | for the write in the event of a power failure or \r | |
246 | other system failure during the write operation. \r | |
247 | @param FileData FileData is an pointer to an array of \r | |
248 | EFI_FV_WRITE_DATA. Each element of array\r | |
249 | FileData represents a file to be written. \r | |
250 | \r | |
251 | @retval EFI_SUCCESS Files successfully written to firmware volume \r | |
252 | @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated. \r | |
253 | @retval EFI_DEVICE_ERROR Device error. \r | |
254 | @retval EFI_WRITE_PROTECTED Write protected. \r | |
255 | @retval EFI_NOT_FOUND Not found. \r | |
256 | @retval EFI_INVALID_PARAMETER Invalid parameter. \r | |
257 | @retval EFI_UNSUPPORTED This function not supported.\r | |
258 | \r | |
259 | **/\r | |
28a00297 | 260 | EFI_STATUS\r |
261 | EFIAPI\r | |
262 | FvWriteFile (\r | |
23c98c94 | 263 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r |
264 | IN UINT32 NumberOfFiles,\r | |
265 | IN EFI_FV_WRITE_POLICY WritePolicy,\r | |
266 | IN EFI_FV_WRITE_FILE_DATA *FileData\r | |
267 | );\r | |
28a00297 | 268 | \r |
162ed594 | 269 | \r |
270 | /**\r | |
271 | Return information of type InformationType for the requested firmware\r | |
272 | volume.\r | |
273 | \r | |
274 | @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL. \r | |
275 | @param InformationType InformationType for requested. \r | |
276 | @param BufferSize On input, size of Buffer.On output, the amount of data \r | |
277 | returned in Buffer. \r | |
278 | @param Buffer A poniter to the data buffer to return. \r | |
279 | \r | |
280 | @retval EFI_SUCCESS Successfully got volume Information.\r | |
281 | \r | |
282 | **/\r | |
0c2b5da8 | 283 | EFI_STATUS\r |
284 | EFIAPI\r | |
285 | FvGetVolumeInfo (\r | |
286 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r | |
287 | IN CONST EFI_GUID *InformationType,\r | |
23c98c94 | 288 | IN OUT UINTN *BufferSize,\r |
289 | OUT VOID *Buffer\r | |
290 | );\r | |
0c2b5da8 | 291 | \r |
162ed594 | 292 | \r |
293 | \r | |
294 | /**\r | |
295 | Set information of type InformationType for the requested firmware\r | |
0c2b5da8 | 296 | volume.\r |
0c2b5da8 | 297 | \r |
162ed594 | 298 | @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL. \r |
299 | @param InformationType InformationType for requested. \r | |
300 | @param BufferSize On input, size of Buffer.On output, the amount of data \r | |
301 | returned in Buffer. \r | |
302 | @param Buffer A poniter to the data buffer to return. \r | |
303 | \r | |
304 | @retval EFI_SUCCESS Successfully set volume Information.\r | |
28a00297 | 305 | \r |
162ed594 | 306 | **/\r |
0c2b5da8 | 307 | EFI_STATUS\r |
308 | EFIAPI\r | |
309 | FvSetVolumeInfo (\r | |
310 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r | |
311 | IN CONST EFI_GUID *InformationType,\r | |
23c98c94 | 312 | IN UINTN BufferSize,\r |
313 | IN CONST VOID *Buffer\r | |
314 | );\r | |
28a00297 | 315 | \r |
316 | //\r | |
317 | //Internal functions\r | |
318 | //\r | |
319 | typedef enum {\r | |
320 | EfiCheckSumUint8 = 0,\r | |
321 | EfiCheckSumUint16 = 1,\r | |
322 | EfiCheckSumUint32 = 2,\r | |
323 | EfiCheckSumUint64 = 3,\r | |
324 | EfiCheckSumMaximum = 4\r | |
325 | } EFI_CHECKSUM_TYPE;\r | |
326 | \r | |
327 | \r | |
162ed594 | 328 | \r |
329 | /**\r | |
330 | Check if a block of buffer is erased.\r | |
331 | \r | |
332 | @param ErasePolarity Erase polarity attribute of the firmware volume \r | |
333 | @param InBuffer The buffer to be checked \r | |
334 | @param BufferSize Size of the buffer in bytes \r | |
335 | \r | |
336 | @retval TRUE The block of buffer is erased \r | |
337 | @retval FALSE The block of buffer is not erased\r | |
338 | \r | |
339 | **/\r | |
28a00297 | 340 | BOOLEAN\r |
341 | IsBufferErased (\r | |
342 | IN UINT8 ErasePolarity,\r | |
23c98c94 | 343 | IN VOID *InBuffer,\r |
28a00297 | 344 | IN UINTN BufferSize\r |
23c98c94 | 345 | );\r |
28a00297 | 346 | \r |
28a00297 | 347 | \r |
162ed594 | 348 | /**\r |
349 | Get the FFS file state by checking the highest bit set in the header's state field.\r | |
28a00297 | 350 | \r |
162ed594 | 351 | @param ErasePolarity Erase polarity attribute of the firmware volume \r |
352 | @param FfsHeader Points to the FFS file header \r | |
353 | \r | |
354 | @return FFS File state\r | |
355 | \r | |
356 | **/\r | |
23c98c94 | 357 | EFI_FFS_FILE_STATE\r |
28a00297 | 358 | GetFileState (\r |
359 | IN UINT8 ErasePolarity,\r | |
360 | IN EFI_FFS_FILE_HEADER *FfsHeader\r | |
23c98c94 | 361 | );\r |
28a00297 | 362 | \r |
28a00297 | 363 | \r |
162ed594 | 364 | /**\r |
365 | Set the FFS file state.\r | |
366 | \r | |
367 | @param State The state to be set. \r | |
368 | @param FfsHeader Points to the FFS file header \r | |
369 | \r | |
370 | @return None.\r | |
28a00297 | 371 | \r |
162ed594 | 372 | **/\r |
28a00297 | 373 | VOID\r |
374 | SetFileState (\r | |
375 | IN UINT8 State,\r | |
376 | IN EFI_FFS_FILE_HEADER *FfsHeader\r | |
23c98c94 | 377 | );\r |
28a00297 | 378 | \r |
28a00297 | 379 | \r |
162ed594 | 380 | /**\r |
381 | Verify checksum of the firmware volume header.\r | |
382 | \r | |
383 | @param FvHeader Points to the firmware volume header to be checked \r | |
28a00297 | 384 | \r |
162ed594 | 385 | @retval TRUE Checksum verification passed \r |
386 | @retval FALSE Checksum verification failed\r | |
387 | \r | |
388 | **/\r | |
28a00297 | 389 | BOOLEAN\r |
390 | VerifyFvHeaderChecksum (\r | |
391 | IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader\r | |
23c98c94 | 392 | );\r |
28a00297 | 393 | \r |
162ed594 | 394 | \r |
395 | /**\r | |
396 | Check if it's a valid FFS file header.\r | |
397 | \r | |
398 | @param ErasePolarity Erase polarity attribute of the firmware volume \r | |
399 | @param FfsHeader Points to the FFS file header to be checked \r | |
400 | @param FileState FFS file state to be returned \r | |
401 | \r | |
402 | @retval TRUE Valid FFS file header \r | |
403 | @retval FALSE Invalid FFS file header\r | |
404 | \r | |
405 | **/\r | |
28a00297 | 406 | BOOLEAN\r |
407 | IsValidFfsHeader (\r | |
23c98c94 | 408 | IN UINT8 ErasePolarity,\r |
409 | IN EFI_FFS_FILE_HEADER *FfsHeader,\r | |
410 | OUT EFI_FFS_FILE_STATE *FileState\r | |
411 | );\r | |
28a00297 | 412 | \r |
28a00297 | 413 | \r |
162ed594 | 414 | /**\r |
415 | Check if it's a valid FFS file.\r | |
416 | Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.\r | |
417 | \r | |
418 | @param ErasePolarity Erase polarity attribute of the firmware volume \r | |
419 | @param FfsHeader Points to the FFS file to be checked \r | |
28a00297 | 420 | \r |
162ed594 | 421 | @retval TRUE Valid FFS file \r |
422 | @retval FALSE Invalid FFS file\r | |
423 | \r | |
424 | **/\r | |
28a00297 | 425 | BOOLEAN\r |
426 | IsValidFfsFile (\r | |
427 | IN UINT8 ErasePolarity,\r | |
428 | IN EFI_FFS_FILE_HEADER *FfsHeader\r | |
23c98c94 | 429 | );\r |
28a00297 | 430 | \r |
28a00297 | 431 | \r |
162ed594 | 432 | /**\r |
433 | given the supplied FW_VOL_BLOCK_PROTOCOL, allocate a buffer for output and\r | |
434 | copy the volume header into it.\r | |
435 | \r | |
436 | @param Fvb The FW_VOL_BLOCK_PROTOCOL instance from which to \r | |
437 | read the volume header \r | |
438 | @param FwVolHeader Pointer to pointer to allocated buffer in which \r | |
439 | the volume header is returned. \r | |
28a00297 | 440 | \r |
162ed594 | 441 | @retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated. \r |
442 | @retval EFI_SUCCESS Successfully read volume header to the allocated \r | |
443 | buffer.\r | |
444 | \r | |
445 | **/\r | |
28a00297 | 446 | EFI_STATUS\r |
447 | GetFwVolHeader (\r | |
23c98c94 | 448 | IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,\r |
449 | OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader\r | |
450 | );\r | |
28a00297 | 451 | \r |
28a00297 | 452 | \r |
28a00297 | 453 | \r |
162ed594 | 454 | /**\r |
455 | Check if a FV is consistent and allocate cache\r | |
28a00297 | 456 | \r |
162ed594 | 457 | @param FvDevice pointer to the FvDevice to be checked. \r |
28a00297 | 458 | \r |
162ed594 | 459 | @retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated. \r |
460 | @retval EFI_SUCCESS FV is consistent and cache is allocated. \r | |
461 | @retval EFI_VOLUME_CORRUPTED File system is corrupted.\r | |
28a00297 | 462 | \r |
162ed594 | 463 | **/\r |
28a00297 | 464 | EFI_STATUS\r |
465 | FvCheck (\r | |
466 | IN OUT FV_DEVICE *FvDevice\r | |
23c98c94 | 467 | );\r |
28a00297 | 468 | \r |
469 | #endif\r |