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