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