]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h
PI 1.1 SMM Feature Check-in
[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
5Copyright (c) 2006 - 2008, Intel Corporation. <BR>\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
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
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
13492369 54 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
55 @param Attributes output buffer which contains attributes.\r
162ed594 56\r
13492369 57 @retval EFI_SUCCESS Successfully got volume attributes.\r
162ed594 58\r
59**/\r
28a00297 60EFI_STATUS\r
61EFIAPI\r
62FvGetVolumeAttributes (\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
13492369 71 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
022c6d45 72 @param Attributes At input, contains attributes to be set. At output\r
13492369 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 78EFI_STATUS\r
79EFIAPI\r
80FvSetVolumeAttributes (\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
13492369 89 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
022c6d45 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
162ed594 129 @retval EFI_INVALID_PARAMETER Invalid parameter\r
28a00297 130\r
162ed594 131**/\r
28a00297 132EFI_STATUS\r
133EFIAPI\r
134FvGetNextFile (\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
13492369 149 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
022c6d45 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
162ed594 182 @retval EFI_OUT_OF_RESOURCES Not enough buffer to be allocated.\r
183\r
184**/\r
28a00297 185EFI_STATUS\r
186EFIAPI\r
187FvReadFile (\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
13492369 202 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
022c6d45 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
162ed594 212 UINTN.\r
022c6d45 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
162ed594 223 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
224\r
225**/\r
28a00297 226EFI_STATUS\r
227EFIAPI\r
228FvReadFileSection (\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
13492369 242 @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r
022c6d45 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
162ed594 248 EFI_FV_WRITE_DATA. Each element of array\r
022c6d45 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
162ed594 257 @retval EFI_UNSUPPORTED This function not supported.\r
258\r
259**/\r
28a00297 260EFI_STATUS\r
261EFIAPI\r
262FvWriteFile (\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
022c6d45 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
162ed594 279\r
280 @retval EFI_SUCCESS Successfully got volume Information.\r
281\r
282**/\r
0c2b5da8 283EFI_STATUS\r
284EFIAPI\r
285FvGetVolumeInfo (\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
022c6d45 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
162ed594 303\r
304 @retval EFI_SUCCESS Successfully set volume Information.\r
28a00297 305\r
162ed594 306**/\r
0c2b5da8 307EFI_STATUS\r
308EFIAPI\r
309FvSetVolumeInfo (\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
022c6d45 315\r
28a00297 316\r
162ed594 317\r
318/**\r
319 Check if a block of buffer is erased.\r
320\r
022c6d45 321 @param ErasePolarity Erase polarity attribute of the firmware volume\r
322 @param InBuffer The buffer to be checked\r
323 @param BufferSize Size of the buffer in bytes\r
162ed594 324\r
022c6d45 325 @retval TRUE The block of buffer is erased\r
162ed594 326 @retval FALSE The block of buffer is not erased\r
327\r
328**/\r
28a00297 329BOOLEAN\r
330IsBufferErased (\r
331 IN UINT8 ErasePolarity,\r
23c98c94 332 IN VOID *InBuffer,\r
28a00297 333 IN UINTN BufferSize\r
23c98c94 334 );\r
28a00297 335\r
28a00297 336\r
162ed594 337/**\r
338 Get the FFS file state by checking the highest bit set in the header's state field.\r
28a00297 339\r
022c6d45 340 @param ErasePolarity Erase polarity attribute of the firmware volume\r
341 @param FfsHeader Points to the FFS file header\r
162ed594 342\r
343 @return FFS File state\r
344\r
345**/\r
23c98c94 346EFI_FFS_FILE_STATE\r
28a00297 347GetFileState (\r
348 IN UINT8 ErasePolarity,\r
349 IN EFI_FFS_FILE_HEADER *FfsHeader\r
23c98c94 350 );\r
28a00297 351\r
28a00297 352\r
162ed594 353/**\r
354 Set the FFS file state.\r
355\r
022c6d45 356 @param State The state to be set.\r
357 @param FfsHeader Points to the FFS file header\r
162ed594 358\r
359 @return None.\r
28a00297 360\r
162ed594 361**/\r
28a00297 362VOID\r
363SetFileState (\r
364 IN UINT8 State,\r
365 IN EFI_FFS_FILE_HEADER *FfsHeader\r
23c98c94 366 );\r
28a00297 367\r
28a00297 368\r
162ed594 369/**\r
370 Verify checksum of the firmware volume header.\r
371\r
022c6d45 372 @param FvHeader Points to the firmware volume header to be checked\r
28a00297 373\r
022c6d45 374 @retval TRUE Checksum verification passed\r
162ed594 375 @retval FALSE Checksum verification failed\r
376\r
377**/\r
28a00297 378BOOLEAN\r
379VerifyFvHeaderChecksum (\r
380 IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader\r
23c98c94 381 );\r
022c6d45 382\r
162ed594 383\r
384/**\r
385 Check if it's a valid FFS file header.\r
386\r
022c6d45 387 @param ErasePolarity Erase polarity attribute of the firmware volume\r
388 @param FfsHeader Points to the FFS file header to be checked\r
389 @param FileState FFS file state to be returned\r
162ed594 390\r
022c6d45 391 @retval TRUE Valid FFS file header\r
162ed594 392 @retval FALSE Invalid FFS file header\r
393\r
394**/\r
28a00297 395BOOLEAN\r
396IsValidFfsHeader (\r
23c98c94 397 IN UINT8 ErasePolarity,\r
398 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
399 OUT EFI_FFS_FILE_STATE *FileState\r
400 );\r
28a00297 401\r
28a00297 402\r
162ed594 403/**\r
404 Check if it's a valid FFS file.\r
405 Here we are sure that it has a valid FFS file header since we must call IsValidFfsHeader() first.\r
406\r
022c6d45 407 @param ErasePolarity Erase polarity attribute of the firmware volume\r
408 @param FfsHeader Points to the FFS file to be checked\r
28a00297 409\r
022c6d45 410 @retval TRUE Valid FFS file\r
162ed594 411 @retval FALSE Invalid FFS file\r
412\r
413**/\r
28a00297 414BOOLEAN\r
415IsValidFfsFile (\r
416 IN UINT8 ErasePolarity,\r
417 IN EFI_FFS_FILE_HEADER *FfsHeader\r
23c98c94 418 );\r
28a00297 419\r
28a00297 420\r
162ed594 421/**\r
422 given the supplied FW_VOL_BLOCK_PROTOCOL, allocate a buffer for output and\r
423 copy the volume header into it.\r
424\r
022c6d45 425 @param Fvb The FW_VOL_BLOCK_PROTOCOL instance from which to\r
426 read the volume header\r
427 @param FwVolHeader Pointer to pointer to allocated buffer in which\r
428 the volume header is returned.\r
28a00297 429\r
022c6d45 430 @retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated.\r
431 @retval EFI_SUCCESS Successfully read volume header to the allocated\r
162ed594 432 buffer.\r
433\r
434**/\r
28a00297 435EFI_STATUS\r
436GetFwVolHeader (\r
23c98c94 437 IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,\r
438 OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader\r
439 );\r
28a00297 440\r
28a00297 441\r
28a00297 442\r
162ed594 443/**\r
022c6d45 444 Check if an FV is consistent and allocate cache for it.\r
28a00297 445\r
022c6d45 446 @param FvDevice A pointer to the FvDevice to be checked.\r
28a00297 447\r
022c6d45 448 @retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated.\r
449 @retval EFI_SUCCESS FV is consistent and cache is allocated.\r
162ed594 450 @retval EFI_VOLUME_CORRUPTED File system is corrupted.\r
28a00297 451\r
162ed594 452**/\r
28a00297 453EFI_STATUS\r
454FvCheck (\r
455 IN OUT FV_DEVICE *FvDevice\r
23c98c94 456 );\r
28a00297 457\r
458#endif\r