2 RealView EB FVB DXE Driver
4 Copyright (c) 2010, Apple Inc. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/UefiLib.h>
23 #include <Library/PcdLib.h>
25 #include <Protocol/FirmwareVolumeBlock.h>
30 The GetAttributes() function retrieves the attributes and
31 current settings of the block.
33 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
35 @param Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the
36 attributes and current settings are
37 returned. Type EFI_FVB_ATTRIBUTES_2 is defined
38 in EFI_FIRMWARE_VOLUME_HEADER.
40 @retval EFI_SUCCESS The firmware volume attributes were
48 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
*This
,
49 OUT EFI_FVB_ATTRIBUTES_2
*Attributes
52 return EFI_UNSUPPORTED
;
57 The SetAttributes() function sets configurable firmware volume
58 attributes and returns the new settings of the firmware volume.
61 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
63 @param Attributes On input, Attributes is a pointer to
64 EFI_FVB_ATTRIBUTES_2 that contains the
65 desired firmware volume settings. On
66 successful return, it contains the new
67 settings of the firmware volume. Type
68 EFI_FVB_ATTRIBUTES_2 is defined in
69 EFI_FIRMWARE_VOLUME_HEADER.
71 @retval EFI_SUCCESS The firmware volume attributes were returned.
73 @retval EFI_INVALID_PARAMETER The attributes requested are in
74 conflict with the capabilities
75 as declared in the firmware
82 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
*This
,
83 IN OUT EFI_FVB_ATTRIBUTES_2
*Attributes
86 return EFI_UNSUPPORTED
;
91 The GetPhysicalAddress() function retrieves the base address of
92 a memory-mapped firmware volume. This function should be called
93 only for memory-mapped firmware volumes.
95 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
97 @param Address Pointer to a caller-allocated
98 EFI_PHYSICAL_ADDRESS that, on successful
99 return from GetPhysicalAddress(), contains the
100 base address of the firmware volume.
102 @retval EFI_SUCCESS The firmware volume base address was returned.
104 @retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped.
109 FvbGetPhysicalAddress (
110 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
*This
,
111 OUT EFI_PHYSICAL_ADDRESS
*Address
114 return EFI_UNSUPPORTED
;
119 The GetBlockSize() function retrieves the size of the requested
120 block. It also returns the number of additional blocks with
121 the identical size. The GetBlockSize() function is used to
122 retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).
125 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
127 @param Lba Indicates the block for which to return the size.
129 @param BlockSize Pointer to a caller-allocated UINTN in which
130 the size of the block is returned.
132 @param NumberOfBlocks Pointer to a caller-allocated UINTN in
133 which the number of consecutive blocks,
134 starting with Lba, is returned. All
135 blocks in this range have a size of
139 @retval EFI_SUCCESS The firmware volume base address was returned.
141 @retval EFI_INVALID_PARAMETER The requested LBA is out of range.
147 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
*This
,
149 OUT UINTN
*BlockSize
,
150 OUT UINTN
*NumberOfBlocks
153 return EFI_UNSUPPORTED
;
159 Reads the specified number of bytes into a buffer from the specified block.
161 The Read() function reads the requested number of bytes from the
162 requested block and stores them in the provided buffer.
163 Implementations should be mindful that the firmware volume
164 might be in the ReadDisabled state. If it is in this state,
165 the Read() function must return the status code
166 EFI_ACCESS_DENIED without modifying the contents of the
167 buffer. The Read() function must also prevent spanning block
168 boundaries. If a read is requested that would span a block
169 boundary, the read must read up to the boundary but not
170 beyond. The output parameter NumBytes must be set to correctly
171 indicate the number of bytes actually read. The caller must be
172 aware that a read may be partially completed.
174 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
176 @param Lba The starting logical block index
179 @param Offset Offset into the block at which to begin reading.
181 @param NumBytes Pointer to a UINTN. At entry, *NumBytes
182 contains the total size of the buffer. At
183 exit, *NumBytes contains the total number of
186 @param Buffer Pointer to a caller-allocated buffer that will
187 be used to hold the data that is read.
189 @retval EFI_SUCCESS The firmware volume was read successfully,
190 and contents are in Buffer.
192 @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA
193 boundary. On output, NumBytes
194 contains the total number of bytes
197 @retval EFI_ACCESS_DENIED The firmware volume is in the
200 @retval EFI_DEVICE_ERROR The block device is not
201 functioning correctly and could
208 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
*This
,
211 IN OUT UINTN
*NumBytes
,
215 return EFI_UNSUPPORTED
;
220 Writes the specified number of bytes from the input buffer to the block.
222 The Write() function writes the specified number of bytes from
223 the provided buffer to the specified block and offset. If the
224 firmware volume is sticky write, the caller must ensure that
225 all the bits of the specified range to write are in the
226 EFI_FVB_ERASE_POLARITY state before calling the Write()
227 function, or else the result will be unpredictable. This
228 unpredictability arises because, for a sticky-write firmware
229 volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY
230 state but cannot flip it back again. Before calling the
231 Write() function, it is recommended for the caller to first call
232 the EraseBlocks() function to erase the specified block to
233 write. A block erase cycle will transition bits from the
234 (NOT)EFI_FVB_ERASE_POLARITY state back to the
235 EFI_FVB_ERASE_POLARITY state. Implementations should be
236 mindful that the firmware volume might be in the WriteDisabled
237 state. If it is in this state, the Write() function must
238 return the status code EFI_ACCESS_DENIED without modifying the
239 contents of the firmware volume. The Write() function must
240 also prevent spanning block boundaries. If a write is
241 requested that spans a block boundary, the write must store up
242 to the boundary but not beyond. The output parameter NumBytes
243 must be set to correctly indicate the number of bytes actually
244 written. The caller must be aware that a write may be
245 partially completed. All writes, partial or otherwise, must be
246 fully flushed to the hardware before the Write() service
249 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.
251 @param Lba The starting logical block index to write to.
253 @param Offset Offset into the block at which to begin writing.
255 @param NumBytes The pointer to a UINTN. At entry, *NumBytes
256 contains the total size of the buffer. At
257 exit, *NumBytes contains the total number of
258 bytes actually written.
260 @param Buffer The pointer to a caller-allocated buffer that
261 contains the source for the write.
263 @retval EFI_SUCCESS The firmware volume was written successfully.
265 @retval EFI_BAD_BUFFER_SIZE The write was attempted across an
266 LBA boundary. On output, NumBytes
267 contains the total number of bytes
270 @retval EFI_ACCESS_DENIED The firmware volume is in the
273 @retval EFI_DEVICE_ERROR The block device is malfunctioning
274 and could not be written.
281 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
*This
,
284 IN OUT UINTN
*NumBytes
,
288 return EFI_UNSUPPORTED
;
293 Erases and initializes a firmware volume block.
295 The EraseBlocks() function erases one or more blocks as denoted
296 by the variable argument list. The entire parameter list of
297 blocks must be verified before erasing any blocks. If a block is
298 requested that does not exist within the associated firmware
299 volume (it has a larger index than the last block of the
300 firmware volume), the EraseBlocks() function must return the
301 status code EFI_INVALID_PARAMETER without modifying the contents
302 of the firmware volume. Implementations should be mindful that
303 the firmware volume might be in the WriteDisabled state. If it
304 is in this state, the EraseBlocks() function must return the
305 status code EFI_ACCESS_DENIED without modifying the contents of
306 the firmware volume. All calls to EraseBlocks() must be fully
307 flushed to the hardware before the EraseBlocks() service
310 @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
313 @param ... The variable argument list is a list of tuples.
314 Each tuple describes a range of LBAs to erase
315 and consists of the following:
316 - An EFI_LBA that indicates the starting LBA
317 - A UINTN that indicates the number of blocks to
320 The list is terminated with an
321 EFI_LBA_LIST_TERMINATOR. For example, the
322 following indicates that two ranges of blocks
323 (5-7 and 10-11) are to be erased: EraseBlocks
324 (This, 5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR);
326 @retval EFI_SUCCESS The erase request successfully
329 @retval EFI_ACCESS_DENIED The firmware volume is in the
331 @retval EFI_DEVICE_ERROR The block device is not functioning
332 correctly and could not be written.
333 The firmware device may have been
335 @retval EFI_INVALID_PARAMETER One or more of the LBAs listed
336 in the variable argument list do
337 not exist in the firmware volume.
343 IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL
*This
,
347 return EFI_UNSUPPORTED
;
352 // Making this global saves a few bytes in image size
354 EFI_HANDLE gFvbHandle
= NULL
;
358 /// The Firmware Volume Block Protocol is the low-level interface
359 /// to a firmware volume. File-level access to a firmware volume
360 /// should not be done using the Firmware Volume Block Protocol.
361 /// Normal access to a firmware volume must use the Firmware
362 /// Volume Protocol. Typically, only the file system driver that
363 /// produces the Firmware Volume Protocol will bind to the
364 /// Firmware Volume Block Protocol.
366 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL gFvbProtocol
= {
369 FvbGetPhysicalAddress
,
375 /// The handle of the parent firmware volume.
380 // NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) FixedPcdGet32 (PcdFlashNvStorageVariableBase);
384 Initialize the state information for the CPU Architectural Protocol
386 @param ImageHandle of the loaded driver
387 @param SystemTable Pointer to the System Table
389 @retval EFI_SUCCESS Protocol registered
390 @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure
391 @retval EFI_DEVICE_ERROR Hardware problems
397 IN EFI_HANDLE ImageHandle
,
398 IN EFI_SYSTEM_TABLE
*SystemTable
404 Status
= gBS
->InstallMultipleProtocolInterfaces (
406 &gEfiFirmwareVolumeBlockProtocolGuid
, &gFvbProtocol
,
409 ASSERT_EFI_ERROR (Status
);
411 // SetVertAddressEvent ()
413 // GCD Map NAND as RT