1 | /** @file
|
---|
2 |
|
---|
3 | The internal header file includes the common header files, defines
|
---|
4 | internal structure and functions used by FtwLite module.
|
---|
5 |
|
---|
6 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
---|
7 | This program and the accompanying materials
|
---|
8 | are licensed and made available under the terms and conditions of the BSD License
|
---|
9 | which accompanies this distribution. The full text of the license may be found at
|
---|
10 | http://opensource.org/licenses/bsd-license.php
|
---|
11 |
|
---|
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
14 |
|
---|
15 | **/
|
---|
16 |
|
---|
17 | #ifndef _EFI_FAULT_TOLERANT_WRITE_H_
|
---|
18 | #define _EFI_FAULT_TOLERANT_WRITE_H_
|
---|
19 |
|
---|
20 | #include <PiDxe.h>
|
---|
21 |
|
---|
22 | #include <Guid/SystemNvDataGuid.h>
|
---|
23 | #include <Protocol/FaultTolerantWrite.h>
|
---|
24 | #include <Protocol/FirmwareVolumeBlock.h>
|
---|
25 | #include <Protocol/SwapAddressRange.h>
|
---|
26 |
|
---|
27 | #include <Library/PcdLib.h>
|
---|
28 | #include <Library/DebugLib.h>
|
---|
29 | #include <Library/UefiLib.h>
|
---|
30 | #include <Library/UefiDriverEntryPoint.h>
|
---|
31 | #include <Library/BaseMemoryLib.h>
|
---|
32 | #include <Library/MemoryAllocationLib.h>
|
---|
33 | #include <Library/UefiBootServicesTableLib.h>
|
---|
34 |
|
---|
35 | //
|
---|
36 | // Flash erase polarity is 1
|
---|
37 | //
|
---|
38 | #define FTW_ERASE_POLARITY 1
|
---|
39 |
|
---|
40 | #define FTW_VALID_STATE 0
|
---|
41 | #define FTW_INVALID_STATE 1
|
---|
42 |
|
---|
43 | #define FTW_ERASED_BYTE ((UINT8) (255))
|
---|
44 | #define FTW_POLARITY_REVERT ((UINT8) (255))
|
---|
45 |
|
---|
46 | //
|
---|
47 | // EFI Fault tolerant block update write queue entry
|
---|
48 | //
|
---|
49 | typedef struct {
|
---|
50 | UINT8 HeaderAllocated : 1;
|
---|
51 | UINT8 WritesAllocated : 1;
|
---|
52 | UINT8 Complete : 1;
|
---|
53 | #define HEADER_ALLOCATED 0x1
|
---|
54 | #define WRITES_ALLOCATED 0x2
|
---|
55 | #define WRITES_COMPLETED 0x4
|
---|
56 | UINT8 Reserved : 5;
|
---|
57 | EFI_GUID CallerId;
|
---|
58 | UINTN NumberOfWrites;
|
---|
59 | UINTN PrivateDataSize;
|
---|
60 | } EFI_FAULT_TOLERANT_WRITE_HEADER;
|
---|
61 |
|
---|
62 | //
|
---|
63 | // EFI Fault tolerant block update write queue record
|
---|
64 | //
|
---|
65 | typedef struct {
|
---|
66 | UINT8 BootBlockUpdate : 1;
|
---|
67 | UINT8 SpareComplete : 1;
|
---|
68 | UINT8 DestinationComplete : 1;
|
---|
69 | #define BOOT_BLOCK_UPDATE 0x1
|
---|
70 | #define SPARE_COMPLETED 0x2
|
---|
71 | #define DEST_COMPLETED 0x4
|
---|
72 | UINT8 Reserved : 5;
|
---|
73 | EFI_LBA Lba;
|
---|
74 | UINTN Offset;
|
---|
75 | UINTN Length;
|
---|
76 | EFI_PHYSICAL_ADDRESS FvBaseAddress;
|
---|
77 | //
|
---|
78 | // UINT8 PrivateData[PrivateDataSize]
|
---|
79 | //
|
---|
80 | } EFI_FAULT_TOLERANT_WRITE_RECORD;
|
---|
81 |
|
---|
82 |
|
---|
83 | #define RECORD_SIZE(PrivateDataSize) (sizeof (EFI_FAULT_TOLERANT_WRITE_RECORD) + PrivateDataSize)
|
---|
84 |
|
---|
85 | #define RECORD_TOTAL_SIZE(NumberOfWrites, PrivateDataSize) \
|
---|
86 | ((NumberOfWrites) * (sizeof (EFI_FAULT_TOLERANT_WRITE_RECORD) + PrivateDataSize))
|
---|
87 |
|
---|
88 | #define WRITE_TOTAL_SIZE(NumberOfWrites, PrivateDataSize) \
|
---|
89 | ( \
|
---|
90 | sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER) + (NumberOfWrites) * \
|
---|
91 | (sizeof (EFI_FAULT_TOLERANT_WRITE_RECORD) + PrivateDataSize) \
|
---|
92 | )
|
---|
93 |
|
---|
94 | #define FTW_DEVICE_SIGNATURE SIGNATURE_32 ('F', 'T', 'W', 'D')
|
---|
95 |
|
---|
96 | //
|
---|
97 | // EFI Fault tolerant protocol private data structure
|
---|
98 | //
|
---|
99 | typedef struct {
|
---|
100 | UINTN Signature;
|
---|
101 | EFI_HANDLE Handle;
|
---|
102 | EFI_FAULT_TOLERANT_WRITE_PROTOCOL FtwInstance;
|
---|
103 | EFI_PHYSICAL_ADDRESS WorkSpaceAddress; // Base address of working space range in flash.
|
---|
104 | EFI_PHYSICAL_ADDRESS SpareAreaAddress; // Base address of spare range in flash.
|
---|
105 | UINTN WorkSpaceLength; // Size of working space range in flash.
|
---|
106 | UINTN SpareAreaLength; // Size of spare range in flash.
|
---|
107 | UINTN NumberOfSpareBlock; // Number of the blocks in spare block.
|
---|
108 | UINTN BlockSize; // Block size in bytes of the blocks in flash
|
---|
109 | EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *FtwWorkSpaceHeader;// Pointer to Working Space Header in memory buffer
|
---|
110 | EFI_FAULT_TOLERANT_WRITE_HEADER *FtwLastWriteHeader;// Pointer to last record header in memory buffer
|
---|
111 | EFI_FAULT_TOLERANT_WRITE_RECORD *FtwLastWriteRecord;// Pointer to last record in memory buffer
|
---|
112 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FtwFvBlock; // FVB of working block
|
---|
113 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FtwBackupFvb; // FVB of spare block
|
---|
114 | EFI_LBA FtwSpareLba; // Start LBA of spare block
|
---|
115 | EFI_LBA FtwWorkBlockLba; // Start LBA of working block that contains working space in its last block.
|
---|
116 | EFI_LBA FtwWorkSpaceLba; // Start LBA of working space
|
---|
117 | UINTN FtwWorkSpaceBase; // Offset into the FtwWorkSpaceLba block.
|
---|
118 | UINTN FtwWorkSpaceSize; // Size of working space range that stores write record.
|
---|
119 | UINT8 *FtwWorkSpace; // Point to Work Space in memory buffer
|
---|
120 | //
|
---|
121 | // Following a buffer of FtwWorkSpace[FTW_WORK_SPACE_SIZE],
|
---|
122 | // Allocated with EFI_FTW_DEVICE.
|
---|
123 | //
|
---|
124 | } EFI_FTW_DEVICE;
|
---|
125 |
|
---|
126 | #define FTW_CONTEXT_FROM_THIS(a) CR (a, EFI_FTW_DEVICE, FtwInstance, FTW_DEVICE_SIGNATURE)
|
---|
127 |
|
---|
128 | //
|
---|
129 | // Driver entry point
|
---|
130 | //
|
---|
131 | /**
|
---|
132 | This function is the entry point of the Fault Tolerant Write driver.
|
---|
133 |
|
---|
134 | @param ImageHandle A handle for the image that is initializing this driver
|
---|
135 | @param SystemTable A pointer to the EFI system table
|
---|
136 |
|
---|
137 | @return EFI_SUCCESS FTW has finished the initialization
|
---|
138 | @retval EFI_NOT_FOUND Locate FVB protocol error
|
---|
139 | @retval EFI_OUT_OF_RESOURCES Allocate memory error
|
---|
140 | @retval EFI_VOLUME_CORRUPTED Firmware volume is error
|
---|
141 | @retval EFI_ABORTED FTW initialization error
|
---|
142 |
|
---|
143 | **/
|
---|
144 | EFI_STATUS
|
---|
145 | EFIAPI
|
---|
146 | InitializeFaultTolerantWrite (
|
---|
147 | IN EFI_HANDLE ImageHandle,
|
---|
148 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
149 | );
|
---|
150 |
|
---|
151 | //
|
---|
152 | // Fault Tolerant Write Protocol API
|
---|
153 | //
|
---|
154 |
|
---|
155 | /**
|
---|
156 | Query the largest block that may be updated in a fault tolerant manner.
|
---|
157 |
|
---|
158 |
|
---|
159 | @param This Indicates a pointer to the calling context.
|
---|
160 | @param BlockSize A pointer to a caller allocated UINTN that is updated to
|
---|
161 | indicate the size of the largest block that can be updated.
|
---|
162 |
|
---|
163 | @return EFI_SUCCESS The function completed successfully
|
---|
164 |
|
---|
165 | **/
|
---|
166 | EFI_STATUS
|
---|
167 | EFIAPI
|
---|
168 | FtwGetMaxBlockSize (
|
---|
169 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
|
---|
170 | OUT UINTN *BlockSize
|
---|
171 | );
|
---|
172 |
|
---|
173 | /**
|
---|
174 | Allocates space for the protocol to maintain information about writes.
|
---|
175 | Since writes must be completed in a fault tolerant manner and multiple
|
---|
176 | updates will require more resources to be successful, this function
|
---|
177 | enables the protocol to ensure that enough space exists to track
|
---|
178 | information about the upcoming writes.
|
---|
179 |
|
---|
180 | All writes must be completed or aborted before another fault tolerant write can occur.
|
---|
181 |
|
---|
182 | @param This Indicates a pointer to the calling context.
|
---|
183 | @param CallerId The GUID identifying the write.
|
---|
184 | @param PrivateDataSize The size of the caller's private data
|
---|
185 | that must be recorded for each write.
|
---|
186 | @param NumberOfWrites The number of fault tolerant block writes
|
---|
187 | that will need to occur.
|
---|
188 |
|
---|
189 | @return EFI_SUCCESS The function completed successfully
|
---|
190 | @retval EFI_ABORTED The function could not complete successfully.
|
---|
191 | @retval EFI_ACCESS_DENIED All allocated writes have not been completed.
|
---|
192 |
|
---|
193 | **/
|
---|
194 | EFI_STATUS
|
---|
195 | EFIAPI
|
---|
196 | FtwAllocate (
|
---|
197 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
|
---|
198 | IN EFI_GUID *CallerId,
|
---|
199 | IN UINTN PrivateDataSize,
|
---|
200 | IN UINTN NumberOfWrites
|
---|
201 | );
|
---|
202 |
|
---|
203 | /**
|
---|
204 | Starts a target block update. This function will record data about write
|
---|
205 | in fault tolerant storage and will complete the write in a recoverable
|
---|
206 | manner, ensuring at all times that either the original contents or
|
---|
207 | the modified contents are available.
|
---|
208 |
|
---|
209 |
|
---|
210 | @param This Calling context
|
---|
211 | @param Lba The logical block address of the target block.
|
---|
212 | @param Offset The offset within the target block to place the data.
|
---|
213 | @param Length The number of bytes to write to the target block.
|
---|
214 | @param PrivateData A pointer to private data that the caller requires to
|
---|
215 | complete any pending writes in the event of a fault.
|
---|
216 | @param FvBlockHandle The handle of FVB protocol that provides services for
|
---|
217 | reading, writing, and erasing the target block.
|
---|
218 | @param Buffer The data to write.
|
---|
219 |
|
---|
220 | @retval EFI_SUCCESS The function completed successfully
|
---|
221 | @retval EFI_ABORTED The function could not complete successfully.
|
---|
222 | @retval EFI_BAD_BUFFER_SIZE The input data can't fit within the spare block.
|
---|
223 | Offset + *NumBytes > SpareAreaLength.
|
---|
224 | @retval EFI_ACCESS_DENIED No writes have been allocated.
|
---|
225 | @retval EFI_OUT_OF_RESOURCES Cannot allocate enough memory resource.
|
---|
226 | @retval EFI_NOT_FOUND Cannot find FVB protocol by handle.
|
---|
227 |
|
---|
228 | **/
|
---|
229 | EFI_STATUS
|
---|
230 | EFIAPI
|
---|
231 | FtwWrite (
|
---|
232 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
|
---|
233 | IN EFI_LBA Lba,
|
---|
234 | IN UINTN Offset,
|
---|
235 | IN UINTN Length,
|
---|
236 | IN VOID *PrivateData,
|
---|
237 | IN EFI_HANDLE FvBlockHandle,
|
---|
238 | IN VOID *Buffer
|
---|
239 | );
|
---|
240 |
|
---|
241 | /**
|
---|
242 | Restarts a previously interrupted write. The caller must provide the
|
---|
243 | block protocol needed to complete the interrupted write.
|
---|
244 |
|
---|
245 | @param This Calling context.
|
---|
246 | @param FvBlockHandle The handle of FVB protocol that provides services for
|
---|
247 | reading, writing, and erasing the target block.
|
---|
248 |
|
---|
249 | @retval EFI_SUCCESS The function completed successfully
|
---|
250 | @retval EFI_ACCESS_DENIED No pending writes exist
|
---|
251 | @retval EFI_NOT_FOUND FVB protocol not found by the handle
|
---|
252 | @retval EFI_ABORTED The function could not complete successfully
|
---|
253 |
|
---|
254 | **/
|
---|
255 | EFI_STATUS
|
---|
256 | EFIAPI
|
---|
257 | FtwRestart (
|
---|
258 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
|
---|
259 | IN EFI_HANDLE FvBlockHandle
|
---|
260 | );
|
---|
261 |
|
---|
262 | /**
|
---|
263 | Aborts all previous allocated writes.
|
---|
264 |
|
---|
265 | @param This Calling context
|
---|
266 |
|
---|
267 | @retval EFI_SUCCESS The function completed successfully
|
---|
268 | @retval EFI_ABORTED The function could not complete successfully.
|
---|
269 | @retval EFI_NOT_FOUND No allocated writes exist.
|
---|
270 |
|
---|
271 | **/
|
---|
272 | EFI_STATUS
|
---|
273 | EFIAPI
|
---|
274 | FtwAbort (
|
---|
275 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This
|
---|
276 | );
|
---|
277 |
|
---|
278 | /**
|
---|
279 | Starts a target block update. This records information about the write
|
---|
280 | in fault tolerant storage and will complete the write in a recoverable
|
---|
281 | manner, ensuring at all times that either the original contents or
|
---|
282 | the modified contents are available.
|
---|
283 |
|
---|
284 | @param This Indicates a pointer to the calling context.
|
---|
285 | @param CallerId The GUID identifying the last write.
|
---|
286 | @param Lba The logical block address of the last write.
|
---|
287 | @param Offset The offset within the block of the last write.
|
---|
288 | @param Length The length of the last write.
|
---|
289 | @param PrivateDataSize bytes from the private data
|
---|
290 | stored for this write.
|
---|
291 | @param PrivateData A pointer to a buffer. The function will copy
|
---|
292 | @param Complete A Boolean value with TRUE indicating
|
---|
293 | that the write was completed.
|
---|
294 |
|
---|
295 | @retval EFI_SUCCESS The function completed successfully
|
---|
296 | @retval EFI_ABORTED The function could not complete successfully
|
---|
297 | @retval EFI_NOT_FOUND No allocated writes exist
|
---|
298 | @retval EFI_BUFFER_TOO_SMALL Input buffer is not larget enough
|
---|
299 |
|
---|
300 | **/
|
---|
301 | EFI_STATUS
|
---|
302 | EFIAPI
|
---|
303 | FtwGetLastWrite (
|
---|
304 | IN EFI_FAULT_TOLERANT_WRITE_PROTOCOL *This,
|
---|
305 | OUT EFI_GUID *CallerId,
|
---|
306 | OUT EFI_LBA *Lba,
|
---|
307 | OUT UINTN *Offset,
|
---|
308 | OUT UINTN *Length,
|
---|
309 | IN OUT UINTN *PrivateDataSize,
|
---|
310 | OUT VOID *PrivateData,
|
---|
311 | OUT BOOLEAN *Complete
|
---|
312 | );
|
---|
313 |
|
---|
314 | /**
|
---|
315 | Erase spare block.
|
---|
316 |
|
---|
317 | @param FtwDevice The private data of FTW driver
|
---|
318 |
|
---|
319 | @retval EFI_SUCCESS The erase request was successfully completed.
|
---|
320 | @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled state.
|
---|
321 | @retval EFI_DEVICE_ERROR The block device is not functioning
|
---|
322 | correctly and could not be written.
|
---|
323 | The firmware device may have been
|
---|
324 | partially erased.
|
---|
325 | @retval EFI_INVALID_PARAMETER One or more of the LBAs listed
|
---|
326 | in the variable argument list do
|
---|
327 | not exist in the firmware volume.
|
---|
328 |
|
---|
329 |
|
---|
330 | **/
|
---|
331 | EFI_STATUS
|
---|
332 | FtwEraseSpareBlock (
|
---|
333 | IN EFI_FTW_DEVICE *FtwDevice
|
---|
334 | );
|
---|
335 |
|
---|
336 | /**
|
---|
337 | Retrive the proper FVB protocol interface by HANDLE.
|
---|
338 |
|
---|
339 |
|
---|
340 | @param FvBlockHandle The handle of FVB protocol that provides services for
|
---|
341 | reading, writing, and erasing the target block.
|
---|
342 | @param FvBlock The interface of FVB protocol
|
---|
343 |
|
---|
344 | @retval EFI_SUCCESS The function completed successfully
|
---|
345 | @retval EFI_ABORTED The function could not complete successfully
|
---|
346 |
|
---|
347 | **/
|
---|
348 | EFI_STATUS
|
---|
349 | FtwGetFvbByHandle (
|
---|
350 | IN EFI_HANDLE FvBlockHandle,
|
---|
351 | OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
|
---|
352 | );
|
---|
353 |
|
---|
354 | /**
|
---|
355 |
|
---|
356 | Is it in working block?
|
---|
357 |
|
---|
358 | @param FtwDevice The private data of FTW driver
|
---|
359 | @param FvBlock Fvb protocol instance
|
---|
360 | @param Lba The block specified
|
---|
361 |
|
---|
362 | @return A BOOLEAN value indicating in working block or not.
|
---|
363 |
|
---|
364 | **/
|
---|
365 | BOOLEAN
|
---|
366 | IsWorkingBlock (
|
---|
367 | EFI_FTW_DEVICE *FtwDevice,
|
---|
368 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
|
---|
369 | EFI_LBA Lba
|
---|
370 | );
|
---|
371 |
|
---|
372 | /**
|
---|
373 |
|
---|
374 | Is it in boot block?
|
---|
375 |
|
---|
376 | @param FtwDevice The private data of FTW driver
|
---|
377 | @param FvBlock Fvb protocol instance
|
---|
378 | @param Lba The block specified
|
---|
379 |
|
---|
380 | @return A BOOLEAN value indicating in boot block or not.
|
---|
381 |
|
---|
382 | **/
|
---|
383 | BOOLEAN
|
---|
384 | IsBootBlock (
|
---|
385 | EFI_FTW_DEVICE *FtwDevice,
|
---|
386 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
|
---|
387 | EFI_LBA Lba
|
---|
388 | );
|
---|
389 |
|
---|
390 | /**
|
---|
391 | Copy the content of spare block to a target block. Size is FTW_BLOCK_SIZE.
|
---|
392 | Spare block is accessed by FTW backup FVB protocol interface. LBA is 1.
|
---|
393 | Target block is accessed by FvbBlock protocol interface. LBA is Lba.
|
---|
394 |
|
---|
395 |
|
---|
396 | @param FtwDevice The private data of FTW driver
|
---|
397 | @param FvBlock FVB Protocol interface to access target block
|
---|
398 | @param Lba Lba of the target block
|
---|
399 |
|
---|
400 | @retval EFI_SUCCESS Spare block content is copied to target block
|
---|
401 | @retval EFI_INVALID_PARAMETER Input parameter error
|
---|
402 | @retval EFI_OUT_OF_RESOURCES Allocate memory error
|
---|
403 | @retval EFI_ABORTED The function could not complete successfully
|
---|
404 |
|
---|
405 | **/
|
---|
406 | EFI_STATUS
|
---|
407 | FlushSpareBlockToTargetBlock (
|
---|
408 | EFI_FTW_DEVICE *FtwDevice,
|
---|
409 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
|
---|
410 | EFI_LBA Lba
|
---|
411 | );
|
---|
412 |
|
---|
413 | /**
|
---|
414 | Copy the content of spare block to working block. Size is FTW_BLOCK_SIZE.
|
---|
415 | Spare block is accessed by FTW backup FVB protocol interface. LBA is
|
---|
416 | FtwDevice->FtwSpareLba.
|
---|
417 | Working block is accessed by FTW working FVB protocol interface. LBA is
|
---|
418 | FtwDevice->FtwWorkBlockLba.
|
---|
419 |
|
---|
420 | Since the working block header is important when FTW initializes, the
|
---|
421 | state of the operation should be handled carefully. The Crc value is
|
---|
422 | calculated without STATE element.
|
---|
423 |
|
---|
424 | @param FtwDevice The private data of FTW driver
|
---|
425 |
|
---|
426 | @retval EFI_SUCCESS Spare block content is copied to target block
|
---|
427 | @retval EFI_OUT_OF_RESOURCES Allocate memory error
|
---|
428 | @retval EFI_ABORTED The function could not complete successfully
|
---|
429 |
|
---|
430 | **/
|
---|
431 | EFI_STATUS
|
---|
432 | FlushSpareBlockToWorkingBlock (
|
---|
433 | EFI_FTW_DEVICE *FtwDevice
|
---|
434 | );
|
---|
435 |
|
---|
436 | /**
|
---|
437 | Copy the content of spare block to a boot block. Size is FTW_BLOCK_SIZE.
|
---|
438 | Spare block is accessed by FTW working FVB protocol interface. LBA is 1.
|
---|
439 | Target block is accessed by FvbBlock protocol interface. LBA is Lba.
|
---|
440 |
|
---|
441 | FTW will do extra work on boot block update.
|
---|
442 | FTW should depend on a protocol of EFI_ADDRESS_RANGE_SWAP_PROTOCOL,
|
---|
443 | which is produced by a chipset driver.
|
---|
444 | FTW updating boot block steps may be:
|
---|
445 | 1. GetRangeLocation(), if the Range is inside the boot block, FTW know
|
---|
446 | that boot block will be update. It shall add a FLAG in the working block.
|
---|
447 | 2. When spare block is ready,
|
---|
448 | 3. SetSwapState(EFI_SWAPPED)
|
---|
449 | 4. erasing boot block,
|
---|
450 | 5. programming boot block until the boot block is ok.
|
---|
451 | 6. SetSwapState(UNSWAPPED)
|
---|
452 | FTW shall not allow to update boot block when battery state is error.
|
---|
453 |
|
---|
454 | @param FtwDevice The private data of FTW driver
|
---|
455 |
|
---|
456 | @retval EFI_SUCCESS Spare block content is copied to boot block
|
---|
457 | @retval EFI_INVALID_PARAMETER Input parameter error
|
---|
458 | @retval EFI_OUT_OF_RESOURCES Allocate memory error
|
---|
459 | @retval EFI_ABORTED The function could not complete successfully
|
---|
460 |
|
---|
461 | **/
|
---|
462 | EFI_STATUS
|
---|
463 | FlushSpareBlockToBootBlock (
|
---|
464 | EFI_FTW_DEVICE *FtwDevice
|
---|
465 | );
|
---|
466 |
|
---|
467 | /**
|
---|
468 | Update a bit of state on a block device. The location of the bit is
|
---|
469 | calculated by the (Lba, Offset, bit). Here bit is determined by the
|
---|
470 | the name of a certain bit.
|
---|
471 |
|
---|
472 |
|
---|
473 | @param FvBlock FVB Protocol interface to access SrcBlock and DestBlock
|
---|
474 | @param Lba Lba of a block
|
---|
475 | @param Offset Offset on the Lba
|
---|
476 | @param NewBit New value that will override the old value if it can be change
|
---|
477 |
|
---|
478 | @retval EFI_SUCCESS A state bit has been updated successfully
|
---|
479 | @retval Others Access block device error.
|
---|
480 | Notes:
|
---|
481 | Assume all bits of State are inside the same BYTE.
|
---|
482 | @retval EFI_ABORTED Read block fail
|
---|
483 |
|
---|
484 | **/
|
---|
485 | EFI_STATUS
|
---|
486 | FtwUpdateFvState (
|
---|
487 | IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvBlock,
|
---|
488 | IN EFI_LBA Lba,
|
---|
489 | IN UINTN Offset,
|
---|
490 | IN UINT8 NewBit
|
---|
491 | );
|
---|
492 |
|
---|
493 | /**
|
---|
494 | Get the last Write Header pointer.
|
---|
495 | The last write header is the header whose 'complete' state hasn't been set.
|
---|
496 | After all, this header may be a EMPTY header entry for next Allocate.
|
---|
497 |
|
---|
498 |
|
---|
499 | @param FtwWorkSpaceHeader Pointer of the working block header
|
---|
500 | @param FtwWorkSpaceSize Size of the work space
|
---|
501 | @param FtwWriteHeader Pointer to retrieve the last write header
|
---|
502 |
|
---|
503 | @retval EFI_SUCCESS Get the last write record successfully
|
---|
504 | @retval EFI_ABORTED The FTW work space is damaged
|
---|
505 |
|
---|
506 | **/
|
---|
507 | EFI_STATUS
|
---|
508 | FtwGetLastWriteHeader (
|
---|
509 | IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *FtwWorkSpaceHeader,
|
---|
510 | IN UINTN FtwWorkSpaceSize,
|
---|
511 | OUT EFI_FAULT_TOLERANT_WRITE_HEADER **FtwWriteHeader
|
---|
512 | );
|
---|
513 |
|
---|
514 | /**
|
---|
515 | Get the last Write Record pointer. The last write Record is the Record
|
---|
516 | whose DestinationCompleted state hasn't been set. After all, this Record
|
---|
517 | may be a EMPTY record entry for next write.
|
---|
518 |
|
---|
519 |
|
---|
520 | @param FtwWriteHeader Pointer to the write record header
|
---|
521 | @param FtwWriteRecord Pointer to retrieve the last write record
|
---|
522 |
|
---|
523 | @retval EFI_SUCCESS Get the last write record successfully
|
---|
524 | @retval EFI_ABORTED The FTW work space is damaged
|
---|
525 |
|
---|
526 | **/
|
---|
527 | EFI_STATUS
|
---|
528 | FtwGetLastWriteRecord (
|
---|
529 | IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwWriteHeader,
|
---|
530 | OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwWriteRecord
|
---|
531 | );
|
---|
532 |
|
---|
533 | /**
|
---|
534 | To check if FtwRecord is the first record of FtwHeader.
|
---|
535 |
|
---|
536 | @param FtwHeader Pointer to the write record header
|
---|
537 | @param FtwRecord Pointer to the write record
|
---|
538 |
|
---|
539 | @retval TRUE FtwRecord is the first Record of the FtwHeader
|
---|
540 | @retval FALSE FtwRecord is not the first Record of the FtwHeader
|
---|
541 |
|
---|
542 | **/
|
---|
543 | BOOLEAN
|
---|
544 | IsFirstRecordOfWrites (
|
---|
545 | IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
|
---|
546 | IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord
|
---|
547 | );
|
---|
548 |
|
---|
549 | /**
|
---|
550 | To check if FtwRecord is the last record of FtwHeader. Because the
|
---|
551 | FtwHeader has NumberOfWrites & PrivateDataSize, the FtwRecord can be
|
---|
552 | determined if it is the last record of FtwHeader.
|
---|
553 |
|
---|
554 | @param FtwHeader Pointer to the write record header
|
---|
555 | @param FtwRecord Pointer to the write record
|
---|
556 |
|
---|
557 | @retval TRUE FtwRecord is the last Record of the FtwHeader
|
---|
558 | @retval FALSE FtwRecord is not the last Record of the FtwHeader
|
---|
559 |
|
---|
560 | **/
|
---|
561 | BOOLEAN
|
---|
562 | IsLastRecordOfWrites (
|
---|
563 | IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
|
---|
564 | IN EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord
|
---|
565 | );
|
---|
566 |
|
---|
567 | /**
|
---|
568 | To check if FtwRecord is the first record of FtwHeader.
|
---|
569 |
|
---|
570 | @param FtwHeader Pointer to the write record header
|
---|
571 | @param FtwRecord Pointer to retrieve the previous write record
|
---|
572 |
|
---|
573 | @retval EFI_ACCESS_DENIED Input record is the first record, no previous record is return.
|
---|
574 | @retval EFI_SUCCESS The previous write record is found.
|
---|
575 |
|
---|
576 | **/
|
---|
577 | EFI_STATUS
|
---|
578 | GetPreviousRecordOfWrites (
|
---|
579 | IN EFI_FAULT_TOLERANT_WRITE_HEADER *FtwHeader,
|
---|
580 | IN OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwRecord
|
---|
581 | );
|
---|
582 |
|
---|
583 | /**
|
---|
584 |
|
---|
585 | Check whether a flash buffer is erased.
|
---|
586 |
|
---|
587 | @param Buffer Buffer to check
|
---|
588 | @param BufferSize Size of the buffer
|
---|
589 |
|
---|
590 | @return A BOOLEAN value indicating erased or not.
|
---|
591 |
|
---|
592 | **/
|
---|
593 | BOOLEAN
|
---|
594 | IsErasedFlashBuffer (
|
---|
595 | IN UINT8 *Buffer,
|
---|
596 | IN UINTN BufferSize
|
---|
597 | );
|
---|
598 | /**
|
---|
599 | Initialize a work space when there is no work space.
|
---|
600 |
|
---|
601 | @param WorkingHeader Pointer of working block header
|
---|
602 |
|
---|
603 | @retval EFI_SUCCESS The function completed successfully
|
---|
604 | @retval EFI_ABORTED The function could not complete successfully.
|
---|
605 |
|
---|
606 | **/
|
---|
607 | EFI_STATUS
|
---|
608 | InitWorkSpaceHeader (
|
---|
609 | IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
|
---|
610 | );
|
---|
611 | /**
|
---|
612 | Read from working block to refresh the work space in memory.
|
---|
613 |
|
---|
614 | @param FtwDevice Point to private data of FTW driver
|
---|
615 |
|
---|
616 | @retval EFI_SUCCESS The function completed successfully
|
---|
617 | @retval EFI_ABORTED The function could not complete successfully.
|
---|
618 |
|
---|
619 | **/
|
---|
620 | EFI_STATUS
|
---|
621 | WorkSpaceRefresh (
|
---|
622 | IN EFI_FTW_DEVICE *FtwDevice
|
---|
623 | );
|
---|
624 | /**
|
---|
625 | Check to see if it is a valid work space.
|
---|
626 |
|
---|
627 |
|
---|
628 | @param WorkingHeader Pointer of working block header
|
---|
629 |
|
---|
630 | @retval EFI_SUCCESS The function completed successfully
|
---|
631 | @retval EFI_ABORTED The function could not complete successfully.
|
---|
632 |
|
---|
633 | **/
|
---|
634 | BOOLEAN
|
---|
635 | IsValidWorkSpace (
|
---|
636 | IN EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *WorkingHeader
|
---|
637 | );
|
---|
638 | /**
|
---|
639 | Reclaim the work space on the working block.
|
---|
640 |
|
---|
641 | @param FtwDevice Point to private data of FTW driver
|
---|
642 | @param PreserveRecord Whether to preserve the working record is needed
|
---|
643 |
|
---|
644 | @retval EFI_SUCCESS The function completed successfully
|
---|
645 | @retval EFI_OUT_OF_RESOURCES Allocate memory error
|
---|
646 | @retval EFI_ABORTED The function could not complete successfully
|
---|
647 |
|
---|
648 | **/
|
---|
649 | EFI_STATUS
|
---|
650 | FtwReclaimWorkSpace (
|
---|
651 | IN EFI_FTW_DEVICE *FtwDevice,
|
---|
652 | IN BOOLEAN PreserveRecord
|
---|
653 | );
|
---|
654 |
|
---|
655 | /**
|
---|
656 |
|
---|
657 | Get firmware block by address.
|
---|
658 |
|
---|
659 |
|
---|
660 | @param Address Address specified the block
|
---|
661 | @param FvBlock The block caller wanted
|
---|
662 |
|
---|
663 | @retval EFI_SUCCESS The protocol instance if found.
|
---|
664 | @retval EFI_NOT_FOUND Block not found
|
---|
665 |
|
---|
666 | **/
|
---|
667 | EFI_HANDLE
|
---|
668 | GetFvbByAddress (
|
---|
669 | IN EFI_PHYSICAL_ADDRESS Address,
|
---|
670 | OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock
|
---|
671 | );
|
---|
672 |
|
---|
673 | /**
|
---|
674 | Retrive the proper Swap Address Range protocol interface.
|
---|
675 |
|
---|
676 | @param[out] SarProtocol The interface of SAR protocol
|
---|
677 |
|
---|
678 | @retval EFI_SUCCESS The SAR protocol instance was found and returned in SarProtocol.
|
---|
679 | @retval EFI_NOT_FOUND The SAR protocol instance was not found.
|
---|
680 | @retval EFI_INVALID_PARAMETER SarProtocol is NULL.
|
---|
681 |
|
---|
682 | **/
|
---|
683 | EFI_STATUS
|
---|
684 | FtwGetSarProtocol (
|
---|
685 | OUT VOID **SarProtocol
|
---|
686 | );
|
---|
687 |
|
---|
688 | /**
|
---|
689 | Function returns an array of handles that support the FVB protocol
|
---|
690 | in a buffer allocated from pool.
|
---|
691 |
|
---|
692 | @param[out] NumberHandles The number of handles returned in Buffer.
|
---|
693 | @param[out] Buffer A pointer to the buffer to return the requested
|
---|
694 | array of handles that support FVB protocol.
|
---|
695 |
|
---|
696 | @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of
|
---|
697 | handles in Buffer was returned in NumberHandles.
|
---|
698 | @retval EFI_NOT_FOUND No FVB handle was found.
|
---|
699 | @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.
|
---|
700 | @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.
|
---|
701 |
|
---|
702 | **/
|
---|
703 | EFI_STATUS
|
---|
704 | GetFvbCountAndBuffer (
|
---|
705 | OUT UINTN *NumberHandles,
|
---|
706 | OUT EFI_HANDLE **Buffer
|
---|
707 | );
|
---|
708 |
|
---|
709 |
|
---|
710 | /**
|
---|
711 | Allocate private data for FTW driver and initialize it.
|
---|
712 |
|
---|
713 | @param[out] FtwData Pointer to the FTW device structure
|
---|
714 |
|
---|
715 | @retval EFI_SUCCESS Initialize the FTW device successfully.
|
---|
716 | @retval EFI_OUT_OF_RESOURCES Allocate memory error
|
---|
717 | @retval EFI_INVALID_PARAMETER Workspace or Spare block does not exist
|
---|
718 |
|
---|
719 | **/
|
---|
720 | EFI_STATUS
|
---|
721 | InitFtwDevice (
|
---|
722 | OUT EFI_FTW_DEVICE **FtwData
|
---|
723 | );
|
---|
724 |
|
---|
725 |
|
---|
726 | /**
|
---|
727 | Initialization for Fault Tolerant Write is done in this handler.
|
---|
728 |
|
---|
729 | @param[in, out] FtwDevice Pointer to the FTW device structure
|
---|
730 |
|
---|
731 | @retval EFI_SUCCESS Initialize the FTW protocol successfully.
|
---|
732 | @retval EFI_NOT_FOUND No proper FVB protocol was found.
|
---|
733 |
|
---|
734 | **/
|
---|
735 | EFI_STATUS
|
---|
736 | InitFtwProtocol (
|
---|
737 | IN OUT EFI_FTW_DEVICE *FtwDevice
|
---|
738 | );
|
---|
739 |
|
---|
740 | #endif
|
---|