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