]>
Commit | Line | Data |
---|---|---|
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 | |
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 | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #ifndef __FW_VOL_DRIVER_H_\r | |
17 | #define __FW_VOL_DRIVER_H_\r | |
18 | \r | |
19 | \r | |
20 | #define FV2_DEVICE_SIGNATURE SIGNATURE_32 ('_', 'F', 'V', '2')\r | |
21 | \r | |
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 | |
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 | |
35 | EFI_FIRMWARE_VOLUME2_PROTOCOL Fv;\r | |
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 | |
48 | #define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE)\r | |
49 | \r | |
50 | /**\r | |
51 | Retrieves attributes, insures positive polarity of attribute bits, returns\r | |
52 | resulting attributes in output parameter.\r | |
53 | \r | |
54 | @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\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 | |
60 | EFI_STATUS\r | |
61 | EFIAPI\r | |
62 | FvGetVolumeAttributes (\r | |
63 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r | |
64 | OUT EFI_FV_ATTRIBUTES *Attributes\r | |
65 | );\r | |
66 | \r | |
67 | \r | |
68 | /**\r | |
69 | Sets current attributes for volume\r | |
70 | \r | |
71 | @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\r | |
72 | @param Attributes At input, contains attributes to be set. At output\r | |
73 | contains new value of FV.\r | |
74 | \r | |
75 | @retval EFI_UNSUPPORTED Could not be set.\r | |
76 | \r | |
77 | **/\r | |
78 | EFI_STATUS\r | |
79 | EFIAPI\r | |
80 | FvSetVolumeAttributes (\r | |
81 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r | |
82 | IN OUT EFI_FV_ATTRIBUTES *Attributes\r | |
83 | );\r | |
84 | \r | |
85 | \r | |
86 | /**\r | |
87 | Given the input key, search for the next matching file in the volume.\r | |
88 | \r | |
89 | @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\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 | |
130 | \r | |
131 | **/\r | |
132 | EFI_STATUS\r | |
133 | EFIAPI\r | |
134 | FvGetNextFile (\r | |
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 | |
142 | \r | |
143 | \r | |
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 Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\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 | |
185 | EFI_STATUS\r | |
186 | EFIAPI\r | |
187 | FvReadFile (\r | |
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 | |
196 | \r | |
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 Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\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 | |
226 | EFI_STATUS\r | |
227 | EFIAPI\r | |
228 | FvReadFileSection (\r | |
229 | IN CONST EFI_FIRMWARE_VOLUME2_PROTOCOL *This,\r | |
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 | |
236 | );\r | |
237 | \r | |
238 | \r | |
239 | /**\r | |
240 | Writes one or more files to the firmware volume.\r | |
241 | \r | |
242 | @param This Pointer to EFI_FIRMWARE_VOLUME2_PROTOCOL.\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 | |
260 | EFI_STATUS\r | |
261 | EFIAPI\r | |
262 | FvWriteFile (\r | |
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 | |
268 | \r | |
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 | |
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 | |
288 | IN OUT UINTN *BufferSize,\r | |
289 | OUT VOID *Buffer\r | |
290 | );\r | |
291 | \r | |
292 | \r | |
293 | \r | |
294 | /**\r | |
295 | Set information of type InformationType for the requested firmware\r | |
296 | volume.\r | |
297 | \r | |
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 | |
305 | \r | |
306 | **/\r | |
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 | |
312 | IN UINTN BufferSize,\r | |
313 | IN CONST VOID *Buffer\r | |
314 | );\r | |
315 | \r | |
316 | \r | |
317 | \r | |
318 | /**\r | |
319 | Check if a block of buffer is erased.\r | |
320 | \r | |
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 | |
324 | \r | |
325 | @retval TRUE The block of buffer is erased\r | |
326 | @retval FALSE The block of buffer is not erased\r | |
327 | \r | |
328 | **/\r | |
329 | BOOLEAN\r | |
330 | IsBufferErased (\r | |
331 | IN UINT8 ErasePolarity,\r | |
332 | IN VOID *InBuffer,\r | |
333 | IN UINTN BufferSize\r | |
334 | );\r | |
335 | \r | |
336 | \r | |
337 | /**\r | |
338 | Get the FFS file state by checking the highest bit set in the header's state field.\r | |
339 | \r | |
340 | @param ErasePolarity Erase polarity attribute of the firmware volume\r | |
341 | @param FfsHeader Points to the FFS file header\r | |
342 | \r | |
343 | @return FFS File state\r | |
344 | \r | |
345 | **/\r | |
346 | EFI_FFS_FILE_STATE\r | |
347 | GetFileState (\r | |
348 | IN UINT8 ErasePolarity,\r | |
349 | IN EFI_FFS_FILE_HEADER *FfsHeader\r | |
350 | );\r | |
351 | \r | |
352 | \r | |
353 | /**\r | |
354 | Set the FFS file state.\r | |
355 | \r | |
356 | @param State The state to be set.\r | |
357 | @param FfsHeader Points to the FFS file header\r | |
358 | \r | |
359 | @return None.\r | |
360 | \r | |
361 | **/\r | |
362 | VOID\r | |
363 | SetFileState (\r | |
364 | IN UINT8 State,\r | |
365 | IN EFI_FFS_FILE_HEADER *FfsHeader\r | |
366 | );\r | |
367 | \r | |
368 | \r | |
369 | /**\r | |
370 | Verify checksum of the firmware volume header.\r | |
371 | \r | |
372 | @param FvHeader Points to the firmware volume header to be checked\r | |
373 | \r | |
374 | @retval TRUE Checksum verification passed\r | |
375 | @retval FALSE Checksum verification failed\r | |
376 | \r | |
377 | **/\r | |
378 | BOOLEAN\r | |
379 | VerifyFvHeaderChecksum (\r | |
380 | IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader\r | |
381 | );\r | |
382 | \r | |
383 | \r | |
384 | /**\r | |
385 | Check if it's a valid FFS file header.\r | |
386 | \r | |
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 | |
390 | \r | |
391 | @retval TRUE Valid FFS file header\r | |
392 | @retval FALSE Invalid FFS file header\r | |
393 | \r | |
394 | **/\r | |
395 | BOOLEAN\r | |
396 | IsValidFfsHeader (\r | |
397 | IN UINT8 ErasePolarity,\r | |
398 | IN EFI_FFS_FILE_HEADER *FfsHeader,\r | |
399 | OUT EFI_FFS_FILE_STATE *FileState\r | |
400 | );\r | |
401 | \r | |
402 | \r | |
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 | |
407 | @param ErasePolarity Erase polarity attribute of the firmware volume\r | |
408 | @param FfsHeader Points to the FFS file to be checked\r | |
409 | \r | |
410 | @retval TRUE Valid FFS file\r | |
411 | @retval FALSE Invalid FFS file\r | |
412 | \r | |
413 | **/\r | |
414 | BOOLEAN\r | |
415 | IsValidFfsFile (\r | |
416 | IN UINT8 ErasePolarity,\r | |
417 | IN EFI_FFS_FILE_HEADER *FfsHeader\r | |
418 | );\r | |
419 | \r | |
420 | \r | |
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 | |
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 | |
429 | \r | |
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 | |
432 | buffer.\r | |
433 | \r | |
434 | **/\r | |
435 | EFI_STATUS\r | |
436 | GetFwVolHeader (\r | |
437 | IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,\r | |
438 | OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader\r | |
439 | );\r | |
440 | \r | |
441 | \r | |
442 | \r | |
443 | /**\r | |
444 | Check if an FV is consistent and allocate cache for it.\r | |
445 | \r | |
446 | @param FvDevice A pointer to the FvDevice to be checked.\r | |
447 | \r | |
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 | |
450 | @retval EFI_VOLUME_CORRUPTED File system is corrupted.\r | |
451 | \r | |
452 | **/\r | |
453 | EFI_STATUS\r | |
454 | FvCheck (\r | |
455 | IN OUT FV_DEVICE *FvDevice\r | |
456 | );\r | |
457 | \r | |
458 | #endif\r |