]>
Commit | Line | Data |
---|---|---|
677472aa | 1 | /**@file\r |
2 | \r | |
3 | Firmware Volume Block Protocol Runtime Interface Abstraction\r | |
4 | And FVB Extension protocol Runtime Interface Abstraction\r | |
5 | \r | |
6 | mFvbEntry is an array of Handle Fvb pairs. The Fvb Lib Instance matches the\r | |
7 | index in the mFvbEntry array. This should be the same sequence as the FVB's\r | |
8 | were described in the HOB. We have to remember the handle so we can tell if\r | |
9 | the protocol has been reinstalled and it needs updateing.\r | |
10 | \r | |
677472aa | 11 | \r |
12 | Copyright (c) 2006 - 2008, Intel Corporation\r | |
13 | All rights reserved. This program and the accompanying materials\r | |
14 | are licensed and made available under the terms and conditions of the BSD License\r | |
15 | which accompanies this distribution. The full text of the license may be found at\r | |
16 | http://opensource.org/licenses/bsd-license.php\r | |
17 | \r | |
18 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
19 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
20 | \r | |
21 | **/\r | |
22 | \r | |
23 | \r | |
24 | #include "Fvb.h"\r | |
25 | \r | |
bac86c0d | 26 | \r |
677472aa | 27 | //\r |
28 | // Event for Set Virtual Map Changed Event\r | |
29 | //\r | |
30ae98da | 30 | EFI_EVENT mSetVirtualMapChangedEvent = NULL;\r |
677472aa | 31 | \r |
32 | //\r | |
33 | // Lib will ASSERT if more FVB devices than this are added to the system.\r | |
34 | //\r | |
bac86c0d | 35 | FVB_ENTRY *mFvbEntry = NULL;\r |
36 | EFI_EVENT mFvbRegistration = NULL;\r | |
37 | UINTN mFvbCount = 0;\r | |
677472aa | 38 | \r |
39 | /**\r | |
40 | Check whether an address is runtime memory or not.\r | |
41 | \r | |
42 | @param Address The Address being checked.\r | |
43 | \r | |
44 | @retval TRUE The address is runtime memory.\r | |
45 | @retval FALSE The address is not runtime memory.\r | |
46 | **/\r | |
47 | BOOLEAN\r | |
48 | IsRuntimeMemory (\r | |
49 | IN VOID *Address\r | |
50 | )\r | |
51 | {\r | |
52 | EFI_STATUS Status;\r | |
53 | UINT8 TmpMemoryMap[1];\r | |
54 | UINTN MapKey;\r | |
55 | UINTN DescriptorSize;\r | |
56 | UINT32 DescriptorVersion;\r | |
57 | UINTN MemoryMapSize;\r | |
58 | EFI_MEMORY_DESCRIPTOR *MemoryMap;\r | |
59 | EFI_MEMORY_DESCRIPTOR *MemoryMapPtr;\r | |
60 | BOOLEAN IsRuntime;\r | |
61 | UINTN Index;\r | |
62 | \r | |
63 | IsRuntime = FALSE;\r | |
64 | \r | |
65 | //\r | |
66 | // Get System MemoryMapSize\r | |
67 | //\r | |
68 | MemoryMapSize = 1;\r | |
69 | Status = gBS->GetMemoryMap (\r | |
70 | &MemoryMapSize,\r | |
71 | (EFI_MEMORY_DESCRIPTOR *)TmpMemoryMap,\r | |
72 | &MapKey,\r | |
73 | &DescriptorSize,\r | |
74 | &DescriptorVersion\r | |
75 | );\r | |
76 | ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r | |
77 | //\r | |
78 | // Enlarge space here, because we will allocate pool now.\r | |
79 | //\r | |
80 | MemoryMapSize += EFI_PAGE_SIZE;\r | |
bac86c0d | 81 | MemoryMap = AllocatePool (MemoryMapSize);\r |
82 | ASSERT (MemoryMap != NULL);\r | |
677472aa | 83 | \r |
84 | //\r | |
85 | // Get System MemoryMap\r | |
86 | //\r | |
87 | Status = gBS->GetMemoryMap (\r | |
88 | &MemoryMapSize,\r | |
89 | MemoryMap,\r | |
90 | &MapKey,\r | |
91 | &DescriptorSize,\r | |
92 | &DescriptorVersion\r | |
93 | );\r | |
94 | ASSERT_EFI_ERROR (Status);\r | |
95 | \r | |
96 | MemoryMapPtr = MemoryMap;\r | |
97 | //\r | |
98 | // Search the request Address\r | |
99 | //\r | |
100 | for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {\r | |
101 | if (((EFI_PHYSICAL_ADDRESS)(UINTN)Address >= MemoryMap->PhysicalStart) &&\r | |
102 | ((EFI_PHYSICAL_ADDRESS)(UINTN)Address < MemoryMap->PhysicalStart\r | |
103 | + LShiftU64 (MemoryMap->NumberOfPages, EFI_PAGE_SHIFT))) {\r | |
104 | //\r | |
105 | // Found it\r | |
106 | //\r | |
bac86c0d | 107 | if ((MemoryMap->Attribute & EFI_MEMORY_RUNTIME) != 0) {\r |
677472aa | 108 | IsRuntime = TRUE;\r |
109 | }\r | |
110 | break;\r | |
111 | }\r | |
112 | //\r | |
113 | // Get next item\r | |
114 | //\r | |
bac86c0d | 115 | MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN) MemoryMap + DescriptorSize);\r |
677472aa | 116 | }\r |
117 | \r | |
118 | //\r | |
119 | // Done\r | |
120 | //\r | |
bac86c0d | 121 | FreePool (MemoryMapPtr);\r |
677472aa | 122 | \r |
123 | return IsRuntime;\r | |
124 | }\r | |
125 | \r | |
bac86c0d | 126 | \r |
677472aa | 127 | /**\r |
128 | Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is\r | |
129 | reinstalled.\r | |
130 | \r | |
131 | @param Event The Event that is being processed\r | |
132 | @param Context Event Context\r | |
133 | \r | |
134 | **/\r | |
677472aa | 135 | VOID\r |
136 | EFIAPI\r | |
137 | FvbNotificationEvent (\r | |
138 | IN EFI_EVENT Event,\r | |
139 | IN VOID *Context\r | |
140 | )\r | |
141 | {\r | |
142 | EFI_STATUS Status;\r | |
143 | UINTN BufferSize;\r | |
144 | EFI_HANDLE Handle;\r | |
145 | UINTN Index;\r | |
146 | UINTN UpdateIndex;\r | |
147 | \r | |
148 | while (TRUE) {\r | |
149 | BufferSize = sizeof (Handle);\r | |
150 | Status = gBS->LocateHandle (\r | |
151 | ByRegisterNotify,\r | |
152 | &gEfiFirmwareVolumeBlockProtocolGuid,\r | |
153 | mFvbRegistration,\r | |
154 | &BufferSize,\r | |
155 | &Handle\r | |
156 | );\r | |
157 | if (EFI_ERROR (Status)) {\r | |
158 | //\r | |
159 | // Exit Path of While Loop....\r | |
160 | //\r | |
161 | break;\r | |
162 | }\r | |
163 | \r | |
164 | UpdateIndex = MAX_FVB_COUNT;\r | |
165 | for (Index = 0; Index < mFvbCount; Index++) {\r | |
166 | if (mFvbEntry[Index].Handle == Handle) {\r | |
167 | //\r | |
168 | // If the handle is already in the table just update the protocol\r | |
169 | //\r | |
170 | UpdateIndex = Index;\r | |
171 | break;\r | |
172 | }\r | |
173 | }\r | |
174 | \r | |
175 | if (UpdateIndex == MAX_FVB_COUNT) {\r | |
176 | //\r | |
177 | // Use the next free slot for a new entry\r | |
178 | //\r | |
179 | UpdateIndex = mFvbCount++;\r | |
180 | //\r | |
181 | // Check the UpdateIndex whether exceed the maximum value.\r | |
182 | //\r | |
183 | ASSERT (UpdateIndex < MAX_FVB_COUNT);\r | |
184 | mFvbEntry[UpdateIndex].Handle = Handle;\r | |
185 | }\r | |
186 | //\r | |
187 | // The array does not have enough entries\r | |
188 | //\r | |
189 | ASSERT (UpdateIndex < MAX_FVB_COUNT);\r | |
190 | \r | |
191 | //\r | |
192 | // Get the interface pointer and if it's ours, skip it\r | |
193 | //\r | |
194 | Status = gBS->HandleProtocol (\r | |
195 | Handle,\r | |
196 | &gEfiFirmwareVolumeBlockProtocolGuid,\r | |
197 | (VOID **) &mFvbEntry[UpdateIndex].Fvb\r | |
198 | );\r | |
199 | ASSERT_EFI_ERROR (Status);\r | |
200 | \r | |
201 | Status = gBS->HandleProtocol (\r | |
202 | Handle,\r | |
203 | &gEfiFvbExtensionProtocolGuid,\r | |
204 | (VOID **) &mFvbEntry[UpdateIndex].FvbExtension\r | |
205 | );\r | |
206 | if (Status != EFI_SUCCESS) {\r | |
207 | mFvbEntry[UpdateIndex].FvbExtension = NULL;\r | |
208 | }\r | |
209 | \r | |
210 | //\r | |
bac86c0d | 211 | // Check the FVB can be accessed in RUNTIME, The FVBs in FVB handle list come from two ways:\r |
212 | // 1) Dxe Core. (FVB information is transferred from FV HOB). 2) FVB driver. The FVB produced\r | |
213 | // Dxe core is used to discovery DXE driver and dispatch. These FVBs can only be accessed in\r | |
214 | // boot time. FVB driver will discovery all FV in FLASH and these FVBs can be accessed in\r | |
215 | // runtime. The FVB itself produced by FVB driver is allocated in runtime memory. So we can\r | |
677472aa | 216 | // determine the what FVB can be accessed in RUNTIME by judging whether FVB itself is allocated\r |
217 | // in RUNTIME memory.\r | |
218 | //\r | |
219 | mFvbEntry[UpdateIndex].IsRuntimeAccess = IsRuntimeMemory (mFvbEntry[UpdateIndex].Fvb);\r | |
220 | }\r | |
221 | }\r | |
222 | \r | |
223 | /**\r | |
224 | Convert all pointers in mFvbEntry after ExitBootServices.\r | |
225 | \r | |
226 | @param Event The Event that is being processed\r | |
227 | @param Context Event Context\r | |
228 | \r | |
229 | **/\r | |
230 | VOID\r | |
231 | EFIAPI\r | |
232 | FvbVirtualAddressChangeNotifyEvent (\r | |
233 | IN EFI_EVENT Event,\r | |
234 | IN VOID *Context\r | |
235 | )\r | |
236 | {\r | |
237 | UINTN Index;\r | |
bac86c0d | 238 | \r |
677472aa | 239 | if (mFvbEntry != NULL) {\r |
240 | for (Index = 0; Index < MAX_FVB_COUNT; Index++) {\r | |
241 | if (!mFvbEntry[Index].IsRuntimeAccess) {\r | |
242 | continue;\r | |
243 | }\r | |
244 | \r | |
bac86c0d | 245 | if (mFvbEntry[Index].Fvb != NULL) {\r |
677472aa | 246 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);\r |
247 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);\r | |
248 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->GetAttributes);\r | |
249 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->SetAttributes);\r | |
250 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->Read);\r | |
251 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->Write);\r | |
252 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb->EraseBlocks);\r | |
253 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].Fvb);\r | |
254 | }\r | |
255 | \r | |
bac86c0d | 256 | if (mFvbEntry[Index].FvbExtension != NULL) {\r |
677472aa | 257 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);\r |
258 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry[Index].FvbExtension);\r | |
259 | }\r | |
260 | }\r | |
261 | \r | |
262 | EfiConvertPointer (0x0, (VOID **) &mFvbEntry);\r | |
263 | }\r | |
264 | }\r | |
265 | \r | |
bac86c0d | 266 | \r |
677472aa | 267 | /**\r |
268 | Library constructor function entry.\r | |
269 | \r | |
270 | @param ImageHandle The handle of image who call this libary.\r | |
271 | @param SystemTable The point of System Table.\r | |
272 | \r | |
273 | @retval EFI_SUCESS Sucess construct this library.\r | |
274 | @retval Others Fail to contruct this libary.\r | |
275 | **/\r | |
276 | EFI_STATUS\r | |
277 | EFIAPI\r | |
278 | FvbLibInitialize (\r | |
279 | IN EFI_HANDLE ImageHandle,\r | |
280 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
281 | )\r | |
282 | {\r | |
bac86c0d | 283 | EFI_STATUS Status;\r |
284 | \r | |
285 | mFvbEntry = AllocateRuntimeZeroPool (sizeof (FVB_ENTRY) * MAX_FVB_COUNT);\r | |
286 | ASSERT (mFvbEntry != NULL);\r | |
677472aa | 287 | \r |
bac86c0d | 288 | //\r |
289 | // Register FvbNotificationEvent () notify function.\r | |
290 | // \r | |
677472aa | 291 | EfiCreateProtocolNotifyEvent (\r |
292 | &gEfiFirmwareVolumeBlockProtocolGuid,\r | |
293 | TPL_CALLBACK,\r | |
294 | FvbNotificationEvent,\r | |
295 | NULL,\r | |
296 | &mFvbRegistration\r | |
297 | );\r | |
298 | \r | |
299 | //\r | |
300 | // Register SetVirtualAddressMap () notify function\r | |
301 | //\r | |
302 | Status = gBS->CreateEvent (\r | |
303 | EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r | |
304 | TPL_NOTIFY,\r | |
305 | FvbVirtualAddressChangeNotifyEvent,\r | |
306 | NULL,\r | |
307 | &mSetVirtualMapChangedEvent\r | |
308 | );\r | |
309 | ASSERT_EFI_ERROR (Status);\r | |
310 | \r | |
bac86c0d | 311 | return Status;\r |
677472aa | 312 | }\r |
313 | \r | |
314 | //\r | |
315 | // =============================================================================\r | |
316 | // The following functions wrap Fvb protocol in the Runtime Lib functions.\r | |
317 | // The Instance translates into Fvb instance. The Fvb order defined by HOBs and\r | |
318 | // thus the sequence of FVB protocol addition define Instance.\r | |
319 | //\r | |
677472aa | 320 | \r |
321 | /**\r | |
322 | Reads specified number of bytes into a buffer from the specified block.\r | |
323 | \r | |
324 | The EfiFvbReadBlock() function reads the requested number of bytes from\r | |
325 | the requested block in the specified firmware volume and stores them in\r | |
326 | the provided buffer. Implementations should be mindful that the firmware\r | |
327 | volume might be in the ReadDisabled state. If it is in this state, the \r | |
328 | EfiFvbReadBlock() function must return the status code EFI_ACCESS_DENIED\r | |
329 | without modifying the contents of the buffer.\r | |
330 | \r | |
331 | The EfiFvbReadBlock() function must also prevent spanning block boundaries.\r | |
332 | If a read is requested that would span a block boundary, the read must read\r | |
333 | up to the boundary but not beyond. The output parameter NumBytes must be\r | |
334 | set to correctly indicate the number of bytes actually read. \r | |
335 | The caller must be aware that a read may be partially completed.\r | |
336 | \r | |
337 | If NumBytes is NULL, then ASSERT().\r | |
338 | \r | |
339 | If Buffer is NULL, then ASSERT().\r | |
340 | \r | |
341 | @param[in] Instance The FV instance to be read from.\r | |
342 | @param[in] Lba The logical block address to be read from\r | |
343 | @param[in] Offset The offset relative to the block, at which to begin reading.\r | |
344 | @param[in, out] NumBytes Pointer to a UINTN. On input, *NumBytes contains the total\r | |
345 | size of the buffer. On output, it contains the actual number\r | |
346 | of bytes read.\r | |
347 | @param[out] Buffer Pointer to a caller allocated buffer that will be\r | |
348 | used to hold the data read.\r | |
349 | \r | |
bac86c0d | 350 | @retval EFI_SUCCESS The firmware volume was read successfully and contents are in Buffer.\r |
351 | @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. On output, NumBytes contains\r | |
352 | the total number of bytes returned in Buffer.\r | |
677472aa | 353 | @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled state.\r |
354 | @retval EFI_DEVICE_ERROR The block device is not functioning correctly and could not be read.\r | |
bac86c0d | 355 | @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. Lba index\r |
356 | is larger than the last block of the firmware volume. Offset is larger\r | |
357 | than the block size.\r | |
677472aa | 358 | \r |
359 | **/\r | |
360 | EFI_STATUS\r | |
bac86c0d | 361 | EFIAPI\r |
677472aa | 362 | EfiFvbReadBlock (\r |
363 | IN UINTN Instance,\r | |
364 | IN EFI_LBA Lba,\r | |
365 | IN UINTN Offset,\r | |
366 | IN OUT UINTN *NumBytes,\r | |
367 | OUT UINT8 *Buffer\r | |
368 | )\r | |
369 | {\r | |
370 | ASSERT (NumBytes != NULL);\r | |
371 | ASSERT (Buffer != NULL);\r | |
372 | \r | |
373 | if (Instance >= mFvbCount) {\r | |
374 | return EFI_INVALID_PARAMETER;\r | |
375 | }\r | |
376 | \r | |
377 | if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r | |
378 | return EFI_INVALID_PARAMETER;\r | |
379 | }\r | |
380 | \r | |
381 | return mFvbEntry[Instance].Fvb->Read (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);\r | |
382 | }\r | |
383 | \r | |
384 | /**\r | |
385 | Writes specified number of bytes from the input buffer to the block\r | |
386 | \r | |
387 | The EfiFvbWriteBlock() function writes the specified number of bytes\r | |
388 | from the provided buffer to the specified block and offset in the \r | |
389 | requested firmware volume. \r | |
390 | \r | |
391 | If the firmware volume is sticky write, the caller must ensure that\r | |
392 | all the bits of the specified range to write are in the EFI_FVB_ERASE_POLARITY\r | |
393 | state before calling the EfiFvbWriteBlock() function, or else the \r | |
394 | result will be unpredictable. This unpredictability arises because,\r | |
395 | for a sticky-write firmware volume, a write may negate a bit in the \r | |
396 | EFI_FVB_ERASE_POLARITY state but it cannot flip it back again. In \r | |
397 | general, before calling the EfiFvbWriteBlock() function, the caller\r | |
398 | should call the EfiFvbEraseBlock() function first to erase the specified\r | |
399 | block to write. A block erase cycle will transition bits from the\r | |
400 | (NOT)EFI_FVB_ERASE_POLARITY state back to the EFI_FVB_ERASE_POLARITY state.\r | |
401 | Implementations should be mindful that the firmware volume might be \r | |
402 | in the WriteDisabled state. If it is in this state, the EfiFvbWriteBlock()\r | |
403 | function must return the status code EFI_ACCESS_DENIED without modifying\r | |
404 | the contents of the firmware volume.\r | |
405 | \r | |
406 | The EfiFvbWriteBlock() function must also prevent spanning block boundaries.\r | |
407 | If a write is requested that spans a block boundary, the write must store\r | |
408 | up to the boundary but not beyond. The output parameter NumBytes must be \r | |
409 | set to correctly indicate the number of bytes actually written. The caller\r | |
410 | must be aware that a write may be partially completed.\r | |
411 | All writes, partial or otherwise, must be fully flushed to the hardware \r | |
412 | before the EfiFvbWriteBlock() function returns. \r | |
413 | \r | |
414 | If NumBytes is NULL, then ASSERT().\r | |
415 | \r | |
416 | @param Instance The FV instance to be written to\r | |
417 | @param Lba The starting logical block index to write to\r | |
418 | @param Offset The offset relative to the block, at which to begin writting.\r | |
419 | @param NumBytes Pointer to a UINTN. On input, *NumBytes contains\r | |
420 | the total size of the buffer. On output, it contains\r | |
421 | the actual number of bytes written.\r | |
422 | @param Buffer Pointer to a caller allocated buffer that contains\r | |
423 | the source for the write\r | |
424 | \r | |
425 | @retval EFI_SUCCESS The firmware volume was written successfully.\r | |
426 | @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundary. \r | |
427 | On output, NumBytes contains the total number of bytes actually written.\r | |
bac86c0d | 428 | @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.\r |
677472aa | 429 | @retval EFI_DEVICE_ERROR The block device is malfunctioning and could not be written.\r |
430 | @retval EFI_INVALID_PARAMETER Invalid parameter, Instance is larger than the max FVB number. \r | |
431 | Lba index is larger than the last block of the firmware volume.\r | |
432 | Offset is larger than the block size.\r | |
433 | **/\r | |
434 | EFI_STATUS\r | |
bac86c0d | 435 | EFIAPI\r |
677472aa | 436 | EfiFvbWriteBlock (\r |
437 | IN UINTN Instance,\r | |
438 | IN EFI_LBA Lba,\r | |
439 | IN UINTN Offset,\r | |
440 | IN OUT UINTN *NumBytes,\r | |
441 | IN UINT8 *Buffer\r | |
442 | )\r | |
443 | {\r | |
444 | ASSERT (NumBytes != NULL);\r | |
445 | \r | |
446 | if (Instance >= mFvbCount) {\r | |
447 | return EFI_INVALID_PARAMETER;\r | |
448 | }\r | |
449 | \r | |
450 | if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r | |
451 | return EFI_INVALID_PARAMETER;\r | |
452 | }\r | |
453 | \r | |
454 | return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);\r | |
455 | }\r | |
456 | \r | |
bac86c0d | 457 | \r |
677472aa | 458 | /**\r |
459 | Erases and initializes a firmware volume block.\r | |
460 | \r | |
461 | The EfiFvbEraseBlock() function erases one block specified by Lba.\r | |
462 | Implementations should be mindful that the firmware volume might \r | |
463 | be in the WriteDisabled state. If it is in this state, the EfiFvbEraseBlock()\r | |
464 | function must return the status code EFI_ACCESS_DENIED without \r | |
465 | modifying the contents of the firmware volume. If Instance is \r | |
466 | larger than the max FVB number, or Lba index is larger than the\r | |
467 | last block of the firmware volume, this function return the status\r | |
468 | code EFI_INVALID_PARAMETER.\r | |
469 | \r | |
470 | All calls to EfiFvbEraseBlock() must be fully flushed to the \r | |
471 | hardware before this function returns. \r | |
472 | \r | |
473 | @param[in] Instance The FV instance to be erased.\r | |
474 | @param[in] Lba The logical block index to be erased from.\r | |
475 | \r | |
476 | @retval EFI_SUCCESS The erase request was successfully completed.\r | |
477 | @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.\r | |
478 | @retval EFI_DEVICE_ERROR The block device is not functioning correctly and\r | |
479 | could not be written. The firmware device may \r | |
480 | have been partially erased.\r | |
481 | @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max\r | |
482 | FVB number. Lba index is larger than the last block\r | |
483 | of the firmware volume. \r | |
484 | \r | |
485 | **/\r | |
486 | EFI_STATUS\r | |
bac86c0d | 487 | EFIAPI\r |
677472aa | 488 | EfiFvbEraseBlock (\r |
489 | IN UINTN Instance,\r | |
490 | IN EFI_LBA Lba\r | |
491 | )\r | |
492 | {\r | |
493 | if (Instance >= mFvbCount) {\r | |
494 | return EFI_INVALID_PARAMETER;\r | |
495 | }\r | |
496 | \r | |
497 | if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r | |
498 | return EFI_INVALID_PARAMETER;\r | |
499 | }\r | |
500 | \r | |
501 | return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, 1, EFI_LBA_LIST_TERMINATOR);\r | |
502 | }\r | |
503 | \r | |
bac86c0d | 504 | \r |
677472aa | 505 | /**\r |
506 | Retrieves the attributes and current settings of the specified block, \r | |
507 | returns resulting attributes in output parameter.\r | |
508 | \r | |
509 | The EfiFvbGetAttributes() function retrieves the attributes and current\r | |
510 | settings of the block specified by Instance. If Instance is larger than\r | |
511 | the max FVB number, this function returns the status code EFI_INVALID_PARAMETER.\r | |
512 | \r | |
513 | If Attributes is NULL, then ASSERT().\r | |
514 | \r | |
515 | @param[in] Instance The FV instance to be operated.\r | |
516 | @param[out] Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the\r | |
517 | attributes and current settings are returned.\r | |
518 | \r | |
519 | @retval EFI_EFI_SUCCESS The firmware volume attributes were returned.\r | |
520 | @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. \r | |
521 | **/\r | |
522 | EFI_STATUS\r | |
bac86c0d | 523 | EFIAPI\r |
677472aa | 524 | EfiFvbGetVolumeAttributes (\r |
525 | IN UINTN Instance,\r | |
526 | OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r | |
527 | )\r | |
528 | {\r | |
529 | ASSERT (Attributes != NULL);\r | |
530 | \r | |
531 | if (Instance >= mFvbCount) {\r | |
532 | return EFI_INVALID_PARAMETER;\r | |
533 | }\r | |
534 | \r | |
535 | if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r | |
536 | return EFI_INVALID_PARAMETER;\r | |
537 | }\r | |
538 | \r | |
539 | return mFvbEntry[Instance].Fvb->GetAttributes (mFvbEntry[Instance].Fvb, Attributes);\r | |
540 | }\r | |
541 | \r | |
bac86c0d | 542 | \r |
677472aa | 543 | /**\r |
544 | Modify the attributes and current settings of the specified block\r | |
545 | according to the input parameter.\r | |
546 | \r | |
547 | The EfiFvbSetAttributes() function sets configurable firmware volume\r | |
548 | attributes and returns the new settings of the firmware volume specified\r | |
549 | by Instance. If Instance is larger than the max FVB number, this function\r | |
550 | returns the status code EFI_INVALID_PARAMETER.\r | |
551 | \r | |
552 | If Attributes is NULL, then ASSERT().\r | |
553 | \r | |
554 | @param[in] Instance The FV instance to be operated.\r | |
555 | @param[in, out]Attributes On input, Attributes is a pointer to EFI_FVB_ATTRIBUTES_2\r | |
556 | that contains the desired firmware volume settings. \r | |
557 | On successful return, it contains the new settings of the firmware volume.\r | |
558 | \r | |
559 | @retval EFI_EFI_SUCCESS The firmware volume attributes were modified successfully.\r | |
560 | @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.\r | |
561 | \r | |
562 | **/\r | |
563 | EFI_STATUS\r | |
bac86c0d | 564 | EFIAPI\r |
677472aa | 565 | EfiFvbSetVolumeAttributes (\r |
566 | IN UINTN Instance,\r | |
567 | IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r | |
568 | )\r | |
569 | {\r | |
570 | ASSERT (Attributes != NULL);\r | |
571 | \r | |
572 | if (Instance >= mFvbCount) {\r | |
573 | return EFI_INVALID_PARAMETER;\r | |
574 | }\r | |
575 | \r | |
576 | if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r | |
577 | return EFI_INVALID_PARAMETER;\r | |
578 | }\r | |
579 | \r | |
580 | return mFvbEntry[Instance].Fvb->SetAttributes (mFvbEntry[Instance].Fvb, Attributes);\r | |
581 | }\r | |
582 | \r | |
bac86c0d | 583 | \r |
677472aa | 584 | /**\r |
585 | Retrieves the physical address of the specified memory mapped FV.\r | |
586 | \r | |
587 | Retrieve the base address of a memory-mapped firmware volume specified by Instance.\r | |
588 | If Instance is larger than the max FVB number, this function returns the status \r | |
589 | code EFI_INVALID_PARAMETER.\r | |
590 | \r | |
591 | If BaseAddress is NULL, then ASSERT().\r | |
592 | \r | |
593 | @param[in] Instance The FV instance to be operated.\r | |
594 | @param[out] BaseAddress Pointer to a caller allocated EFI_PHYSICAL_ADDRESS \r | |
595 | that on successful return, contains the base address\r | |
596 | of the firmware volume. \r | |
597 | \r | |
598 | @retval EFI_EFI_SUCCESS The firmware volume base address is returned.\r | |
599 | @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. \r | |
600 | \r | |
601 | **/\r | |
602 | EFI_STATUS\r | |
bac86c0d | 603 | EFIAPI\r |
677472aa | 604 | EfiFvbGetPhysicalAddress (\r |
605 | IN UINTN Instance,\r | |
606 | OUT EFI_PHYSICAL_ADDRESS *BaseAddress\r | |
607 | )\r | |
608 | {\r | |
609 | ASSERT (BaseAddress != NULL);\r | |
610 | \r | |
611 | if (Instance >= mFvbCount) {\r | |
612 | return EFI_INVALID_PARAMETER;\r | |
613 | }\r | |
614 | \r | |
615 | if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r | |
616 | return EFI_INVALID_PARAMETER;\r | |
617 | }\r | |
618 | \r | |
619 | return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress);\r | |
620 | }\r | |
621 | \r | |
bac86c0d | 622 | \r |
677472aa | 623 | /**\r |
624 | Retrieve the block size of the specified fv.\r | |
625 | \r | |
626 | The EfiFvbGetBlockSize() function retrieves the size of the requested block. \r | |
627 | It also returns the number of additional blocks with the identical size. \r | |
628 | If Instance is larger than the max FVB number, or Lba index is larger than\r | |
629 | the last block of the firmware volume, this function return the status code\r | |
630 | EFI_INVALID_PARAMETER.\r | |
631 | \r | |
bac86c0d | 632 | If BlockSize is NULL, then ASSERT().\r |
677472aa | 633 | \r |
634 | If NumOfBlocks is NULL, then ASSERT().\r | |
635 | \r | |
636 | @param[in] Instance The FV instance to be operated.\r | |
637 | @param[in] Lba Indicates which block to return the size for.\r | |
638 | @param[out] BlockSize Pointer to a caller-allocated UINTN in which the\r | |
639 | size of the block is returned.\r | |
640 | @param[out] NumOfBlocks Pointer to a caller-allocated UINTN in which the \r | |
641 | number of consecutive blocks, starting with Lba, \r | |
642 | is returned. All blocks in this range have a size of BlockSize.\r | |
643 | \r | |
644 | @retval EFI_EFI_SUCCESS The firmware volume base address is returned.\r | |
645 | @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number.\r | |
646 | Lba index is larger than the last block of the firmware volume.\r | |
647 | \r | |
648 | **/\r | |
649 | EFI_STATUS\r | |
bac86c0d | 650 | EFIAPI\r |
677472aa | 651 | EfiFvbGetBlockSize (\r |
652 | IN UINTN Instance,\r | |
653 | IN EFI_LBA Lba,\r | |
654 | OUT UINTN *BlockSize,\r | |
655 | OUT UINTN *NumOfBlocks\r | |
656 | )\r | |
657 | {\r | |
658 | ASSERT (BlockSize != NULL);\r | |
659 | ASSERT (NumOfBlocks != NULL);\r | |
660 | \r | |
661 | if (Instance >= mFvbCount) {\r | |
662 | return EFI_INVALID_PARAMETER;\r | |
663 | }\r | |
664 | \r | |
665 | if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r | |
666 | return EFI_INVALID_PARAMETER;\r | |
667 | }\r | |
668 | \r | |
669 | return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks);\r | |
670 | }\r | |
671 | \r | |
bac86c0d | 672 | \r |
677472aa | 673 | /**\r |
674 | Erases and initializes a specified range of a firmware volume.\r | |
675 | \r | |
676 | The EfiFvbEraseCustomBlockRange() function erases the specified range in the firmware\r | |
677 | volume index by Instance. If Instance is larger than the max FVB number, StartLba or \r | |
678 | LastLba index is larger than the last block of the firmware volume, StartLba > LastLba\r | |
679 | or StartLba equal to LastLba but OffsetStartLba > OffsetLastLba, this function return \r | |
680 | the status code EFI_INVALID_PARAMETER.\r | |
681 | \r | |
682 | @param[in] Instance The FV instance to be operated.\r | |
683 | @param[in] StartLba The starting logical block index to be erased.\r | |
684 | @param[in] OffsetStartLba Offset into the starting block at which to \r | |
685 | begin erasing. \r | |
686 | @param[in] LastLba The last logical block index to be erased.\r | |
687 | @param[in] OffsetLastLba Offset into the last block at which to end erasing. \r | |
688 | \r | |
689 | @retval EFI_EFI_SUCCESS Successfully erase custom block range\r | |
690 | @retval EFI_INVALID_PARAMETER Invalid parameter. Instance is larger than the max FVB number. \r | |
691 | @retval EFI_UNSUPPORTED Firmware volume block device has no this capability.\r | |
692 | \r | |
693 | **/\r | |
694 | EFI_STATUS\r | |
bac86c0d | 695 | EFIAPI\r |
677472aa | 696 | EfiFvbEraseCustomBlockRange (\r |
697 | IN UINTN Instance,\r | |
698 | IN EFI_LBA StartLba,\r | |
699 | IN UINTN OffsetStartLba,\r | |
700 | IN EFI_LBA LastLba,\r | |
701 | IN UINTN OffsetLastLba\r | |
702 | )\r | |
703 | {\r | |
704 | if (Instance >= mFvbCount) {\r | |
705 | return EFI_INVALID_PARAMETER;\r | |
706 | }\r | |
707 | \r | |
708 | if (EfiAtRuntime() && !mFvbEntry[Instance].IsRuntimeAccess) {\r | |
709 | return EFI_INVALID_PARAMETER;\r | |
710 | }\r | |
711 | \r | |
712 | if (!(mFvbEntry[Instance].FvbExtension)) {\r | |
713 | return EFI_UNSUPPORTED;\r | |
714 | }\r | |
715 | \r | |
716 | if (!(mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock)) {\r | |
717 | return EFI_UNSUPPORTED;\r | |
718 | }\r | |
719 | \r | |
720 | return mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock (\r | |
721 | mFvbEntry[Instance].FvbExtension,\r | |
722 | StartLba,\r | |
723 | OffsetStartLba,\r | |
724 | LastLba,\r | |
725 | OffsetLastLba\r | |
726 | );\r | |
727 | }\r |