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