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