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