]>
Commit | Line | Data |
---|---|---|
162ed594 | 1 | /** @file\r |
022c6d45 | 2 | Implementations for Firmware Volume Block protocol.\r |
3 | \r | |
4 | It consumes FV HOBs and creates read-lonly Firmare Volume Block protocol\r | |
e94a9ff7 | 5 | instances for each of them.\r |
23c98c94 | 6 | \r |
7 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r | |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
28a00297 | 15 | \r |
797a9d67 | 16 | **/\r |
28a00297 | 17 | \r |
9c4ac31c | 18 | #include "DxeMain.h"\r |
ec90508b | 19 | #include "FwVolBlock.h"\r |
28a00297 | 20 | \r |
84266565 | 21 | FV_MEMMAP_DEVICE_PATH mFvMemmapDevicePathTemplate = {\r |
28a00297 | 22 | {\r |
23 | {\r | |
84266565 | 24 | HARDWARE_DEVICE_PATH,\r |
25 | HW_MEMMAP_DP,\r | |
28a00297 | 26 | {\r |
84266565 | 27 | (UINT8)(sizeof (MEMMAP_DEVICE_PATH)),\r |
28 | (UINT8)(sizeof (MEMMAP_DEVICE_PATH) >> 8)\r | |
29 | }\r | |
28a00297 | 30 | },\r |
84266565 | 31 | EfiMemoryMappedIO,\r |
32 | (EFI_PHYSICAL_ADDRESS) 0,\r | |
33 | (EFI_PHYSICAL_ADDRESS) 0,\r | |
34 | },\r | |
35 | {\r | |
36 | END_DEVICE_PATH_TYPE,\r | |
37 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
28a00297 | 38 | {\r |
84266565 | 39 | END_DEVICE_PATH_LENGTH,\r |
40 | 0\r | |
41 | }\r | |
42 | }\r | |
43 | };\r | |
44 | \r | |
45 | FV_PIWG_DEVICE_PATH mFvPIWGDevicePathTemplate = {\r | |
46 | {\r | |
47 | {\r | |
48 | MEDIA_DEVICE_PATH,\r | |
49 | MEDIA_PIWG_FW_VOL_DP,\r | |
022c6d45 | 50 | {\r |
84266565 | 51 | (UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH)),\r |
52 | (UINT8)(sizeof (MEDIA_FW_VOL_DEVICE_PATH) >> 8)\r | |
022c6d45 | 53 | }\r |
28a00297 | 54 | },\r |
84266565 | 55 | { 0 }\r |
28a00297 | 56 | },\r |
84266565 | 57 | {\r |
58 | END_DEVICE_PATH_TYPE,\r | |
59 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
60 | {\r | |
61 | END_DEVICE_PATH_LENGTH,\r | |
62 | 0\r | |
63 | }\r | |
64 | }\r | |
65 | };\r | |
66 | \r | |
67 | EFI_FW_VOL_BLOCK_DEVICE mFwVolBlock = {\r | |
68 | FVB_DEVICE_SIGNATURE,\r | |
69 | NULL,\r | |
70 | NULL,\r | |
28a00297 | 71 | {\r |
72 | FwVolBlockGetAttributes,\r | |
73 | (EFI_FVB_SET_ATTRIBUTES)FwVolBlockSetAttributes,\r | |
74 | FwVolBlockGetPhysicalAddress,\r | |
75 | FwVolBlockGetBlockSize,\r | |
76 | FwVolBlockReadBlock,\r | |
77 | (EFI_FVB_WRITE)FwVolBlockWriteBlock,\r | |
78 | (EFI_FVB_ERASE_BLOCKS)FwVolBlockEraseBlock,\r | |
022c6d45 | 79 | NULL\r |
28a00297 | 80 | },\r |
81 | 0,\r | |
82 | NULL,\r | |
83 | 0,\r | |
84 | 0\r | |
85 | };\r | |
86 | \r | |
87 | \r | |
88 | \r | |
162ed594 | 89 | /**\r |
90 | Retrieves Volume attributes. No polarity translations are done.\r | |
91 | \r | |
022c6d45 | 92 | @param This Calling context\r |
93 | @param Attributes output buffer which contains attributes\r | |
162ed594 | 94 | \r |
95 | @retval EFI_SUCCESS The firmware volume attributes were returned.\r | |
96 | \r | |
97 | **/\r | |
28a00297 | 98 | EFI_STATUS\r |
99 | EFIAPI\r | |
100 | FwVolBlockGetAttributes (\r | |
101 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r | |
8ee3a199 | 102 | OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r |
28a00297 | 103 | )\r |
28a00297 | 104 | {\r |
105 | EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r | |
022c6d45 | 106 | \r |
28a00297 | 107 | FvbDevice = FVB_DEVICE_FROM_THIS (This);\r |
108 | \r | |
109 | //\r | |
110 | // Since we are read only, it's safe to get attributes data from our in-memory copy.\r | |
111 | //\r | |
8a9e0b72 | 112 | *Attributes = FvbDevice->FvbAttributes & ~EFI_FVB2_WRITE_STATUS;\r |
28a00297 | 113 | \r |
114 | return EFI_SUCCESS;\r | |
115 | }\r | |
116 | \r | |
117 | \r | |
162ed594 | 118 | \r |
119 | /**\r | |
120 | Modifies the current settings of the firmware volume according to the input parameter.\r | |
121 | \r | |
022c6d45 | 122 | @param This Calling context\r |
123 | @param Attributes input buffer which contains attributes\r | |
162ed594 | 124 | \r |
022c6d45 | 125 | @retval EFI_SUCCESS The firmware volume attributes were returned.\r |
126 | @retval EFI_INVALID_PARAMETER The attributes requested are in conflict with\r | |
127 | the capabilities as declared in the firmware\r | |
128 | volume header.\r | |
162ed594 | 129 | @retval EFI_UNSUPPORTED Not supported.\r |
130 | \r | |
131 | **/\r | |
28a00297 | 132 | EFI_STATUS\r |
133 | EFIAPI\r | |
134 | FwVolBlockSetAttributes (\r | |
135 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r | |
8ee3a199 | 136 | IN CONST EFI_FVB_ATTRIBUTES_2 *Attributes\r |
28a00297 | 137 | )\r |
28a00297 | 138 | {\r |
139 | return EFI_UNSUPPORTED;\r | |
140 | }\r | |
141 | \r | |
142 | \r | |
162ed594 | 143 | \r |
144 | /**\r | |
145 | The EraseBlock() function erases one or more blocks as denoted by the\r | |
146 | variable argument list. The entire parameter list of blocks must be verified\r | |
147 | prior to erasing any blocks. If a block is requested that does not exist\r | |
148 | within the associated firmware volume (it has a larger index than the last\r | |
149 | block of the firmware volume), the EraseBlock() function must return\r | |
150 | EFI_INVALID_PARAMETER without modifying the contents of the firmware volume.\r | |
151 | \r | |
022c6d45 | 152 | @param This Calling context\r |
153 | @param ... Starting LBA followed by Number of Lba to erase.\r | |
154 | a -1 to terminate the list.\r | |
155 | \r | |
156 | @retval EFI_SUCCESS The erase request was successfully completed.\r | |
157 | @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled\r | |
158 | state.\r | |
159 | @retval EFI_DEVICE_ERROR The block device is not functioning correctly\r | |
160 | and could not be written. The firmware device\r | |
161 | may have been partially erased.\r | |
162 | @retval EFI_INVALID_PARAMETER One or more of the LBAs listed in the variable\r | |
163 | argument list do\r | |
162ed594 | 164 | @retval EFI_UNSUPPORTED Not supported.\r |
165 | \r | |
166 | **/\r | |
28a00297 | 167 | EFI_STATUS\r |
168 | EFIAPI\r | |
169 | FwVolBlockEraseBlock (\r | |
170 | IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r | |
171 | ...\r | |
172 | )\r | |
28a00297 | 173 | {\r |
174 | return EFI_UNSUPPORTED;\r | |
175 | }\r | |
176 | \r | |
177 | \r | |
162ed594 | 178 | \r |
179 | /**\r | |
180 | Read the specified number of bytes from the block to the input buffer.\r | |
181 | \r | |
022c6d45 | 182 | @param This Indicates the calling context.\r |
183 | @param Lba The starting logical block index to read.\r | |
184 | @param Offset Offset into the block at which to begin reading.\r | |
185 | @param NumBytes Pointer to a UINT32. At entry, *NumBytes\r | |
186 | contains the total size of the buffer. At exit,\r | |
187 | *NumBytes contains the total number of bytes\r | |
188 | actually read.\r | |
189 | @param Buffer Pinter to a caller-allocated buffer that\r | |
190 | contains the destine for the read.\r | |
191 | \r | |
192 | @retval EFI_SUCCESS The firmware volume was read successfully.\r | |
193 | @retval EFI_BAD_BUFFER_SIZE The read was attempted across an LBA boundary.\r | |
194 | @retval EFI_ACCESS_DENIED Access denied.\r | |
195 | @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not\r | |
162ed594 | 196 | be read.\r |
197 | \r | |
198 | **/\r | |
28a00297 | 199 | EFI_STATUS\r |
200 | EFIAPI\r | |
201 | FwVolBlockReadBlock (\r | |
202 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r | |
203 | IN CONST EFI_LBA Lba,\r | |
204 | IN CONST UINTN Offset,\r | |
205 | IN OUT UINTN *NumBytes,\r | |
206 | IN OUT UINT8 *Buffer\r | |
207 | )\r | |
28a00297 | 208 | {\r |
209 | EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r | |
210 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r | |
211 | UINT8 *LbaOffset;\r | |
212 | UINTN LbaStart;\r | |
213 | UINTN NumOfBytesRead;\r | |
214 | UINTN LbaIndex;\r | |
022c6d45 | 215 | \r |
28a00297 | 216 | FvbDevice = FVB_DEVICE_FROM_THIS (This);\r |
217 | \r | |
218 | //\r | |
219 | // Check if This FW can be read\r | |
220 | //\r | |
797a9d67 | 221 | if ((FvbDevice->FvbAttributes & EFI_FVB2_READ_STATUS) == 0) {\r |
28a00297 | 222 | return EFI_ACCESS_DENIED;\r |
223 | }\r | |
022c6d45 | 224 | \r |
e94a9ff7 | 225 | LbaIndex = (UINTN) Lba;\r |
28a00297 | 226 | if (LbaIndex >= FvbDevice->NumBlocks) {\r |
227 | //\r | |
228 | // Invalid Lba, read nothing.\r | |
229 | //\r | |
230 | *NumBytes = 0;\r | |
231 | return EFI_BAD_BUFFER_SIZE;\r | |
232 | }\r | |
022c6d45 | 233 | \r |
28a00297 | 234 | if (Offset > FvbDevice->LbaCache[LbaIndex].Length) {\r |
235 | //\r | |
236 | // all exceed boundry, read nothing.\r | |
237 | //\r | |
238 | *NumBytes = 0;\r | |
239 | return EFI_BAD_BUFFER_SIZE;\r | |
240 | }\r | |
022c6d45 | 241 | \r |
28a00297 | 242 | NumOfBytesRead = *NumBytes;\r |
243 | if (Offset + NumOfBytesRead > FvbDevice->LbaCache[LbaIndex].Length) {\r | |
244 | //\r | |
245 | // partial exceed boundry, read data from current postion to end.\r | |
246 | //\r | |
247 | NumOfBytesRead = FvbDevice->LbaCache[LbaIndex].Length - Offset;\r | |
248 | }\r | |
022c6d45 | 249 | \r |
28a00297 | 250 | LbaStart = FvbDevice->LbaCache[LbaIndex].Base;\r |
e94a9ff7 | 251 | FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN) FvbDevice->BaseAddress);\r |
252 | LbaOffset = (UINT8 *) FwVolHeader + LbaStart + Offset;\r | |
28a00297 | 253 | \r |
254 | //\r | |
255 | // Perform read operation\r | |
256 | //\r | |
257 | CopyMem (Buffer, LbaOffset, NumOfBytesRead);\r | |
022c6d45 | 258 | \r |
28a00297 | 259 | if (NumOfBytesRead == *NumBytes) {\r |
260 | return EFI_SUCCESS;\r | |
261 | }\r | |
022c6d45 | 262 | \r |
28a00297 | 263 | *NumBytes = NumOfBytesRead;\r |
264 | return EFI_BAD_BUFFER_SIZE;\r | |
265 | }\r | |
022c6d45 | 266 | \r |
28a00297 | 267 | \r |
162ed594 | 268 | \r |
269 | /**\r | |
270 | Writes the specified number of bytes from the input buffer to the block.\r | |
271 | \r | |
022c6d45 | 272 | @param This Indicates the calling context.\r |
273 | @param Lba The starting logical block index to write to.\r | |
274 | @param Offset Offset into the block at which to begin writing.\r | |
275 | @param NumBytes Pointer to a UINT32. At entry, *NumBytes\r | |
276 | contains the total size of the buffer. At exit,\r | |
277 | *NumBytes contains the total number of bytes\r | |
278 | actually written.\r | |
279 | @param Buffer Pinter to a caller-allocated buffer that\r | |
280 | contains the source for the write.\r | |
281 | \r | |
282 | @retval EFI_SUCCESS The firmware volume was written successfully.\r | |
283 | @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary.\r | |
284 | On output, NumBytes contains the total number of\r | |
285 | bytes actually written.\r | |
286 | @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled\r | |
287 | state.\r | |
288 | @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not\r | |
289 | be written.\r | |
162ed594 | 290 | @retval EFI_UNSUPPORTED Not supported.\r |
291 | \r | |
292 | **/\r | |
28a00297 | 293 | EFI_STATUS\r |
294 | EFIAPI\r | |
295 | FwVolBlockWriteBlock (\r | |
296 | IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r | |
297 | IN EFI_LBA Lba,\r | |
298 | IN UINTN Offset,\r | |
299 | IN OUT UINTN *NumBytes,\r | |
300 | IN UINT8 *Buffer\r | |
301 | )\r | |
28a00297 | 302 | {\r |
303 | return EFI_UNSUPPORTED;\r | |
304 | }\r | |
022c6d45 | 305 | \r |
28a00297 | 306 | \r |
162ed594 | 307 | \r |
308 | /**\r | |
309 | Get Fvb's base address.\r | |
310 | \r | |
022c6d45 | 311 | @param This Indicates the calling context.\r |
312 | @param Address Fvb device base address.\r | |
162ed594 | 313 | \r |
022c6d45 | 314 | @retval EFI_SUCCESS Successfully got Fvb's base address.\r |
162ed594 | 315 | @retval EFI_UNSUPPORTED Not supported.\r |
316 | \r | |
317 | **/\r | |
28a00297 | 318 | EFI_STATUS\r |
319 | EFIAPI\r | |
320 | FwVolBlockGetPhysicalAddress (\r | |
321 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r | |
322 | OUT EFI_PHYSICAL_ADDRESS *Address\r | |
323 | )\r | |
28a00297 | 324 | {\r |
325 | EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r | |
022c6d45 | 326 | \r |
28a00297 | 327 | FvbDevice = FVB_DEVICE_FROM_THIS (This);\r |
022c6d45 | 328 | \r |
6e536468 | 329 | if ((FvbDevice->FvbAttributes & EFI_FVB2_MEMORY_MAPPED) != 0) {\r |
28a00297 | 330 | *Address = FvbDevice->BaseAddress;\r |
331 | return EFI_SUCCESS;\r | |
332 | }\r | |
022c6d45 | 333 | \r |
28a00297 | 334 | return EFI_UNSUPPORTED;\r |
335 | }\r | |
336 | \r | |
337 | \r | |
162ed594 | 338 | \r |
339 | /**\r | |
340 | Retrieves the size in bytes of a specific block within a firmware volume.\r | |
341 | \r | |
022c6d45 | 342 | @param This Indicates the calling context.\r |
343 | @param Lba Indicates the block for which to return the\r | |
344 | size.\r | |
345 | @param BlockSize Pointer to a caller-allocated UINTN in which the\r | |
346 | size of the block is returned.\r | |
347 | @param NumberOfBlocks Pointer to a caller-allocated UINTN in which the\r | |
348 | number of consecutive blocks starting with Lba\r | |
349 | is returned. All blocks in this range have a\r | |
350 | size of BlockSize.\r | |
351 | \r | |
352 | @retval EFI_SUCCESS The firmware volume base address is returned.\r | |
162ed594 | 353 | @retval EFI_INVALID_PARAMETER The requested LBA is out of range.\r |
354 | \r | |
355 | **/\r | |
28a00297 | 356 | EFI_STATUS\r |
357 | EFIAPI\r | |
358 | FwVolBlockGetBlockSize (\r | |
359 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,\r | |
360 | IN CONST EFI_LBA Lba,\r | |
361 | IN OUT UINTN *BlockSize,\r | |
362 | IN OUT UINTN *NumberOfBlocks\r | |
363 | )\r | |
28a00297 | 364 | {\r |
365 | UINTN TotalBlocks;\r | |
366 | EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r | |
367 | EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;\r | |
368 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r | |
022c6d45 | 369 | \r |
28a00297 | 370 | FvbDevice = FVB_DEVICE_FROM_THIS (This);\r |
022c6d45 | 371 | \r |
28a00297 | 372 | //\r |
373 | // Do parameter checking\r | |
374 | //\r | |
375 | if (Lba >= FvbDevice->NumBlocks) {\r | |
376 | return EFI_INVALID_PARAMETER;\r | |
377 | }\r | |
022c6d45 | 378 | \r |
28a00297 | 379 | FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvbDevice->BaseAddress);\r |
022c6d45 | 380 | \r |
28a00297 | 381 | PtrBlockMapEntry = FwVolHeader->BlockMap;\r |
022c6d45 | 382 | \r |
28a00297 | 383 | //\r |
384 | // Search the block map for the given block\r | |
385 | //\r | |
386 | TotalBlocks = 0;\r | |
387 | while ((PtrBlockMapEntry->NumBlocks != 0) || (PtrBlockMapEntry->Length !=0 )) {\r | |
388 | TotalBlocks += PtrBlockMapEntry->NumBlocks;\r | |
389 | if (Lba < TotalBlocks) {\r | |
390 | //\r | |
391 | // We find the range\r | |
392 | //\r | |
393 | break;\r | |
394 | }\r | |
022c6d45 | 395 | \r |
28a00297 | 396 | PtrBlockMapEntry++;\r |
397 | }\r | |
022c6d45 | 398 | \r |
28a00297 | 399 | *BlockSize = PtrBlockMapEntry->Length;\r |
400 | *NumberOfBlocks = TotalBlocks - (UINTN)Lba;\r | |
022c6d45 | 401 | \r |
28a00297 | 402 | return EFI_SUCCESS;\r |
403 | }\r | |
404 | \r | |
405 | \r | |
162ed594 | 406 | \r |
407 | /**\r | |
408 | This routine produces a firmware volume block protocol on a given\r | |
409 | buffer.\r | |
410 | \r | |
022c6d45 | 411 | @param BaseAddress base address of the firmware volume image\r |
412 | @param Length length of the firmware volume image\r | |
413 | @param ParentHandle handle of parent firmware volume, if this image\r | |
414 | came from an FV image file in another firmware\r | |
415 | volume (ala capsules)\r | |
416 | @param FvProtocol Firmware volume block protocol produced.\r | |
162ed594 | 417 | \r |
022c6d45 | 418 | @retval EFI_VOLUME_CORRUPTED Volume corrupted.\r |
419 | @retval EFI_OUT_OF_RESOURCES No enough buffer to be allocated.\r | |
420 | @retval EFI_SUCCESS Successfully produced a FVB protocol on given\r | |
162ed594 | 421 | buffer.\r |
422 | \r | |
423 | **/\r | |
28a00297 | 424 | EFI_STATUS\r |
425 | ProduceFVBProtocolOnBuffer (\r | |
426 | IN EFI_PHYSICAL_ADDRESS BaseAddress,\r | |
427 | IN UINT64 Length,\r | |
428 | IN EFI_HANDLE ParentHandle,\r | |
429 | OUT EFI_HANDLE *FvProtocol OPTIONAL\r | |
430 | )\r | |
28a00297 | 431 | {\r |
432 | EFI_STATUS Status;\r | |
433 | EFI_FW_VOL_BLOCK_DEVICE *FvbDev;\r | |
434 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r | |
435 | UINTN BlockIndex;\r | |
436 | UINTN BlockIndex2;\r | |
437 | UINTN LinearOffset;\r | |
38837959 | 438 | UINT32 FvAlignment;\r |
28a00297 | 439 | EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;\r |
022c6d45 | 440 | \r |
38837959 | 441 | FvAlignment = 0;\r |
e94a9ff7 | 442 | FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN) BaseAddress;\r |
28a00297 | 443 | //\r |
444 | // Validate FV Header, if not as expected, return\r | |
445 | //\r | |
446 | if (FwVolHeader->Signature != EFI_FVH_SIGNATURE) {\r | |
447 | return EFI_VOLUME_CORRUPTED;\r | |
448 | }\r | |
449 | //\r | |
38837959 LG |
450 | // Get FvHeader alignment\r |
451 | //\r | |
452 | FvAlignment = 1 << ((FwVolHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r | |
453 | if (FvAlignment < 8) {\r | |
454 | FvAlignment = 8;\r | |
455 | }\r | |
456 | if ((UINTN)BaseAddress % FvAlignment != 0) {\r | |
457 | //\r | |
458 | // FvImage buffer is not at its required alignment.\r | |
459 | //\r | |
460 | return EFI_VOLUME_CORRUPTED;\r | |
461 | }\r | |
462 | //\r | |
022c6d45 | 463 | // Allocate EFI_FW_VOL_BLOCK_DEVICE\r |
28a00297 | 464 | //\r |
9c4ac31c | 465 | FvbDev = AllocateCopyPool (sizeof (EFI_FW_VOL_BLOCK_DEVICE), &mFwVolBlock);\r |
28a00297 | 466 | if (FvbDev == NULL) {\r |
467 | return EFI_OUT_OF_RESOURCES;\r | |
468 | }\r | |
469 | \r | |
470 | FvbDev->BaseAddress = BaseAddress;\r | |
471 | FvbDev->FvbAttributes = FwVolHeader->Attributes;\r | |
472 | FvbDev->FwVolBlockInstance.ParentHandle = ParentHandle;\r | |
473 | \r | |
474 | //\r | |
475 | // Init the block caching fields of the device\r | |
476 | // First, count the number of blocks\r | |
477 | //\r | |
478 | FvbDev->NumBlocks = 0;\r | |
479 | for (PtrBlockMapEntry = FwVolHeader->BlockMap;\r | |
e94a9ff7 | 480 | PtrBlockMapEntry->NumBlocks != 0;\r |
481 | PtrBlockMapEntry++) {\r | |
28a00297 | 482 | FvbDev->NumBlocks += PtrBlockMapEntry->NumBlocks;\r |
483 | }\r | |
484 | //\r | |
485 | // Second, allocate the cache\r | |
486 | //\r | |
9c4ac31c | 487 | FvbDev->LbaCache = AllocatePool (FvbDev->NumBlocks * sizeof (LBA_CACHE));\r |
28a00297 | 488 | if (FvbDev->LbaCache == NULL) {\r |
489 | CoreFreePool (FvbDev);\r | |
490 | return EFI_OUT_OF_RESOURCES;\r | |
491 | }\r | |
84266565 | 492 | \r |
28a00297 | 493 | //\r |
494 | // Last, fill in the cache with the linear address of the blocks\r | |
495 | //\r | |
496 | BlockIndex = 0;\r | |
497 | LinearOffset = 0;\r | |
498 | for (PtrBlockMapEntry = FwVolHeader->BlockMap;\r | |
e94a9ff7 | 499 | PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {\r |
28a00297 | 500 | for (BlockIndex2 = 0; BlockIndex2 < PtrBlockMapEntry->NumBlocks; BlockIndex2++) {\r |
501 | FvbDev->LbaCache[BlockIndex].Base = LinearOffset;\r | |
502 | FvbDev->LbaCache[BlockIndex].Length = PtrBlockMapEntry->Length;\r | |
503 | LinearOffset += PtrBlockMapEntry->Length;\r | |
504 | BlockIndex++;\r | |
505 | }\r | |
506 | }\r | |
507 | \r | |
508 | //\r | |
84266565 | 509 | // Judget whether FV name guid is produced in Fv extension header\r |
28a00297 | 510 | //\r |
84266565 | 511 | if (FwVolHeader->ExtHeaderOffset == 0) {\r |
512 | //\r | |
513 | // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH\r | |
514 | //\r | |
515 | FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);\r | |
18fcd6a7 LG |
516 | if (FvbDev->DevicePath == NULL) {\r |
517 | FreePool (FvbDev);\r | |
518 | return EFI_OUT_OF_RESOURCES;\r | |
519 | }\r | |
84266565 | 520 | ((FV_MEMMAP_DEVICE_PATH *) FvbDev->DevicePath)->MemMapDevPath.StartingAddress = BaseAddress;\r |
521 | ((FV_MEMMAP_DEVICE_PATH *) FvbDev->DevicePath)->MemMapDevPath.EndingAddress = BaseAddress + FwVolHeader->FvLength - 1;\r | |
522 | } else {\r | |
523 | //\r | |
524 | // FV contains extension header, then produce MEDIA_FW_VOL_DEVICE_PATH\r | |
525 | //\r | |
526 | FvbDev->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);\r | |
18fcd6a7 LG |
527 | if (FvbDev->DevicePath == NULL) {\r |
528 | FreePool (FvbDev);\r | |
529 | return EFI_OUT_OF_RESOURCES;\r | |
530 | }\r | |
84266565 | 531 | CopyGuid (\r |
532 | &((FV_PIWG_DEVICE_PATH *)FvbDev->DevicePath)->FvDevPath.FvName, \r | |
533 | (GUID *)(UINTN)(BaseAddress + FwVolHeader->ExtHeaderOffset)\r | |
534 | );\r | |
535 | }\r | |
536 | \r | |
28a00297 | 537 | //\r |
538 | //\r | |
539 | // Attach FvVolBlock Protocol to new handle\r | |
540 | //\r | |
541 | Status = CoreInstallMultipleProtocolInterfaces (\r | |
e94a9ff7 | 542 | &FvbDev->Handle,\r |
543 | &gEfiFirmwareVolumeBlockProtocolGuid, &FvbDev->FwVolBlockInstance,\r | |
84266565 | 544 | &gEfiDevicePathProtocolGuid, FvbDev->DevicePath,\r |
e94a9ff7 | 545 | NULL\r |
546 | );\r | |
28a00297 | 547 | \r |
548 | //\r | |
549 | // If they want the handle back, set it.\r | |
550 | //\r | |
551 | if (FvProtocol != NULL) {\r | |
552 | *FvProtocol = FvbDev->Handle;\r | |
553 | }\r | |
554 | \r | |
555 | return Status;\r | |
556 | }\r | |
557 | \r | |
558 | \r | |
162ed594 | 559 | \r |
560 | /**\r | |
ec90508b | 561 | This routine consumes FV hobs and produces instances of FW_VOL_BLOCK_PROTOCOL as appropriate.\r |
162ed594 | 562 | \r |
022c6d45 | 563 | @param ImageHandle The image handle.\r |
564 | @param SystemTable The system table.\r | |
162ed594 | 565 | \r |
022c6d45 | 566 | @retval EFI_SUCCESS Successfully initialized firmware volume block\r |
162ed594 | 567 | driver.\r |
568 | \r | |
569 | **/\r | |
28a00297 | 570 | EFI_STATUS\r |
571 | EFIAPI\r | |
572 | FwVolBlockDriverInit (\r | |
573 | IN EFI_HANDLE ImageHandle,\r | |
574 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
575 | )\r | |
28a00297 | 576 | {\r |
577 | EFI_PEI_HOB_POINTERS FvHob;\r | |
e94a9ff7 | 578 | \r |
28a00297 | 579 | //\r |
580 | // Core Needs Firmware Volumes to function\r | |
581 | //\r | |
582 | FvHob.Raw = GetHobList ();\r | |
583 | while ((FvHob.Raw = GetNextHob (EFI_HOB_TYPE_FV, FvHob.Raw)) != NULL) {\r | |
584 | //\r | |
585 | // Produce an FVB protocol for it\r | |
586 | //\r | |
022c6d45 | 587 | ProduceFVBProtocolOnBuffer (FvHob.FirmwareVolume->BaseAddress, FvHob.FirmwareVolume->Length, NULL, NULL);\r |
28a00297 | 588 | FvHob.Raw = GET_NEXT_HOB (FvHob);\r |
589 | }\r | |
e94a9ff7 | 590 | \r |
28a00297 | 591 | return EFI_SUCCESS;\r |
592 | }\r | |
593 | \r | |
594 | \r | |
162ed594 | 595 | \r |
596 | /**\r | |
597 | This DXE service routine is used to process a firmware volume. In\r | |
598 | particular, it can be called by BDS to process a single firmware\r | |
599 | volume found in a capsule.\r | |
600 | \r | |
022c6d45 | 601 | @param FvHeader pointer to a firmware volume header\r |
602 | @param Size the size of the buffer pointed to by FvHeader\r | |
603 | @param FVProtocolHandle the handle on which a firmware volume protocol\r | |
604 | was produced for the firmware volume passed in.\r | |
162ed594 | 605 | \r |
022c6d45 | 606 | @retval EFI_OUT_OF_RESOURCES if an FVB could not be produced due to lack of\r |
607 | system resources\r | |
608 | @retval EFI_VOLUME_CORRUPTED if the volume was corrupted\r | |
609 | @retval EFI_SUCCESS a firmware volume protocol was produced for the\r | |
162ed594 | 610 | firmware volume\r |
611 | \r | |
612 | **/\r | |
28a00297 | 613 | EFI_STATUS\r |
3b6ffb6a | 614 | EFIAPI\r |
28a00297 | 615 | CoreProcessFirmwareVolume (\r |
616 | IN VOID *FvHeader,\r | |
022c6d45 | 617 | IN UINTN Size,\r |
28a00297 | 618 | OUT EFI_HANDLE *FVProtocolHandle\r |
619 | )\r | |
28a00297 | 620 | {\r |
621 | VOID *Ptr;\r | |
622 | EFI_STATUS Status;\r | |
623 | \r | |
624 | *FVProtocolHandle = NULL;\r | |
022c6d45 | 625 | Status = ProduceFVBProtocolOnBuffer (\r |
626 | (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r | |
627 | (UINT64)Size,\r | |
628 | NULL,\r | |
28a00297 | 629 | FVProtocolHandle\r |
630 | );\r | |
631 | //\r | |
632 | // Since in our implementation we use register-protocol-notify to put a\r | |
633 | // FV protocol on the FVB protocol handle, we can't directly verify that\r | |
634 | // the FV protocol was produced. Therefore here we will check the handle\r | |
022c6d45 | 635 | // and make sure an FV protocol is on it. This indicates that all went\r |
636 | // well. Otherwise we have to assume that the volume was corrupted\r | |
28a00297 | 637 | // somehow.\r |
638 | //\r | |
639 | if (!EFI_ERROR(Status)) {\r | |
640 | Ptr = NULL;\r | |
e94a9ff7 | 641 | Status = CoreHandleProtocol (*FVProtocolHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **) &Ptr);\r |
28a00297 | 642 | if (EFI_ERROR(Status) || (Ptr == NULL)) {\r |
643 | return EFI_VOLUME_CORRUPTED;\r | |
644 | }\r | |
645 | return EFI_SUCCESS;\r | |
646 | }\r | |
647 | return Status;\r | |
648 | }\r | |
649 | \r | |
650 | \r | |
162ed594 | 651 | \r |