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