]>
Commit | Line | Data |
---|---|---|
b88bd019 | 1 | /*++\r |
2 | RealView EB FVB DXE Driver\r | |
3 | \r | |
4 | Copyright (c) 2010, Apple Inc. All rights reserved.<BR> \r | |
5 | This program and the accompanying materials \r | |
6 | are licensed and made available under the terms and conditions of the BSD License \r | |
7 | which accompanies this distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php \r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
12 | \r | |
13 | \r | |
14 | --*/\r | |
15 | \r | |
16 | #include <PiDxe.h>\r | |
17 | \r | |
18 | #include <Library/BaseLib.h>\r | |
19 | #include <Library/DebugLib.h>\r | |
20 | #include <Library/BaseMemoryLib.h>\r | |
21 | #include <Library/UefiBootServicesTableLib.h>\r | |
22 | #include <Library/UefiLib.h>\r | |
23 | #include <Library/PcdLib.h>\r | |
24 | \r | |
25 | #include <Protocol/FirmwareVolumeBlock.h>\r | |
26 | \r | |
27 | \r | |
28 | \r | |
29 | /**\r | |
30 | The GetAttributes() function retrieves the attributes and\r | |
31 | current settings of the block.\r | |
32 | \r | |
33 | @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r | |
34 | \r | |
35 | @param Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the\r | |
36 | attributes and current settings are\r | |
37 | returned. Type EFI_FVB_ATTRIBUTES_2 is defined\r | |
38 | in EFI_FIRMWARE_VOLUME_HEADER.\r | |
39 | \r | |
40 | @retval EFI_SUCCESS The firmware volume attributes were\r | |
41 | returned.\r | |
42 | \r | |
43 | **/\r | |
44 | \r | |
45 | EFI_STATUS\r | |
46 | EFIAPI\r | |
47 | FvbGetAttributes (\r | |
48 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r | |
49 | OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r | |
50 | )\r | |
51 | {\r | |
52 | return EFI_UNSUPPORTED;\r | |
53 | }\r | |
54 | \r | |
55 | \r | |
56 | /**\r | |
57 | The SetAttributes() function sets configurable firmware volume\r | |
58 | attributes and returns the new settings of the firmware volume.\r | |
59 | \r | |
60 | \r | |
61 | @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r | |
62 | \r | |
63 | @param Attributes On input, Attributes is a pointer to\r | |
64 | EFI_FVB_ATTRIBUTES_2 that contains the\r | |
65 | desired firmware volume settings. On\r | |
66 | successful return, it contains the new\r | |
67 | settings of the firmware volume. Type\r | |
68 | EFI_FVB_ATTRIBUTES_2 is defined in\r | |
69 | EFI_FIRMWARE_VOLUME_HEADER.\r | |
70 | \r | |
71 | @retval EFI_SUCCESS The firmware volume attributes were returned.\r | |
72 | \r | |
73 | @retval EFI_INVALID_PARAMETER The attributes requested are in\r | |
74 | conflict with the capabilities\r | |
75 | as declared in the firmware\r | |
76 | volume header.\r | |
77 | \r | |
78 | **/\r | |
79 | EFI_STATUS\r | |
80 | EFIAPI\r | |
81 | FvbSetAttributes (\r | |
82 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r | |
83 | IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes\r | |
84 | )\r | |
85 | {\r | |
86 | return EFI_UNSUPPORTED;\r | |
87 | }\r | |
88 | \r | |
89 | \r | |
90 | /**\r | |
91 | The GetPhysicalAddress() function retrieves the base address of\r | |
92 | a memory-mapped firmware volume. This function should be called\r | |
93 | only for memory-mapped firmware volumes.\r | |
94 | \r | |
95 | @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r | |
96 | \r | |
97 | @param Address Pointer to a caller-allocated\r | |
98 | EFI_PHYSICAL_ADDRESS that, on successful\r | |
99 | return from GetPhysicalAddress(), contains the\r | |
100 | base address of the firmware volume.\r | |
101 | \r | |
102 | @retval EFI_SUCCESS The firmware volume base address was returned.\r | |
103 | \r | |
104 | @retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped.\r | |
105 | \r | |
106 | **/\r | |
107 | EFI_STATUS\r | |
108 | EFIAPI\r | |
109 | FvbGetPhysicalAddress (\r | |
110 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r | |
111 | OUT EFI_PHYSICAL_ADDRESS *Address\r | |
112 | )\r | |
113 | {\r | |
114 | return EFI_UNSUPPORTED;\r | |
115 | }\r | |
116 | \r | |
117 | \r | |
118 | /**\r | |
119 | The GetBlockSize() function retrieves the size of the requested\r | |
120 | block. It also returns the number of additional blocks with\r | |
121 | the identical size. The GetBlockSize() function is used to\r | |
122 | retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER).\r | |
123 | \r | |
124 | \r | |
125 | @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r | |
126 | \r | |
127 | @param Lba Indicates the block for which to return the size.\r | |
128 | \r | |
129 | @param BlockSize Pointer to a caller-allocated UINTN in which\r | |
130 | the size of the block is returned.\r | |
131 | \r | |
132 | @param NumberOfBlocks Pointer to a caller-allocated UINTN in\r | |
133 | which the number of consecutive blocks,\r | |
134 | starting with Lba, is returned. All\r | |
135 | blocks in this range have a size of\r | |
136 | BlockSize.\r | |
137 | \r | |
138 | \r | |
139 | @retval EFI_SUCCESS The firmware volume base address was returned.\r | |
140 | \r | |
141 | @retval EFI_INVALID_PARAMETER The requested LBA is out of range.\r | |
142 | \r | |
143 | **/\r | |
144 | EFI_STATUS\r | |
145 | EFIAPI\r | |
146 | FvbGetBlockSize (\r | |
147 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r | |
148 | IN EFI_LBA Lba,\r | |
149 | OUT UINTN *BlockSize,\r | |
150 | OUT UINTN *NumberOfBlocks\r | |
151 | )\r | |
152 | {\r | |
153 | return EFI_UNSUPPORTED;\r | |
154 | }\r | |
155 | \r | |
156 | \r | |
157 | \r | |
158 | /**\r | |
159 | Reads the specified number of bytes into a buffer from the specified block.\r | |
160 | \r | |
161 | The Read() function reads the requested number of bytes from the\r | |
162 | requested block and stores them in the provided buffer.\r | |
163 | Implementations should be mindful that the firmware volume\r | |
164 | might be in the ReadDisabled state. If it is in this state,\r | |
165 | the Read() function must return the status code\r | |
166 | EFI_ACCESS_DENIED without modifying the contents of the\r | |
167 | buffer. The Read() function must also prevent spanning block\r | |
168 | boundaries. If a read is requested that would span a block\r | |
169 | boundary, the read must read up to the boundary but not\r | |
170 | beyond. The output parameter NumBytes must be set to correctly\r | |
171 | indicate the number of bytes actually read. The caller must be\r | |
172 | aware that a read may be partially completed.\r | |
173 | \r | |
174 | @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r | |
175 | \r | |
176 | @param Lba The starting logical block index\r | |
177 | from which to read.\r | |
178 | \r | |
179 | @param Offset Offset into the block at which to begin reading.\r | |
180 | \r | |
181 | @param NumBytes Pointer to a UINTN. At entry, *NumBytes\r | |
182 | contains the total size of the buffer. At\r | |
183 | exit, *NumBytes contains the total number of\r | |
184 | bytes read.\r | |
185 | \r | |
186 | @param Buffer Pointer to a caller-allocated buffer that will\r | |
187 | be used to hold the data that is read.\r | |
188 | \r | |
189 | @retval EFI_SUCCESS The firmware volume was read successfully,\r | |
190 | and contents are in Buffer.\r | |
191 | \r | |
192 | @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA\r | |
193 | boundary. On output, NumBytes\r | |
194 | contains the total number of bytes\r | |
195 | returned in Buffer.\r | |
196 | \r | |
197 | @retval EFI_ACCESS_DENIED The firmware volume is in the\r | |
198 | ReadDisabled state.\r | |
199 | \r | |
200 | @retval EFI_DEVICE_ERROR The block device is not\r | |
201 | functioning correctly and could\r | |
202 | not be read.\r | |
203 | \r | |
204 | **/\r | |
205 | EFI_STATUS\r | |
206 | EFIAPI\r | |
207 | FvbRead (\r | |
208 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r | |
209 | IN EFI_LBA Lba,\r | |
210 | IN UINTN Offset,\r | |
211 | IN OUT UINTN *NumBytes,\r | |
212 | IN OUT UINT8 *Buffer\r | |
213 | )\r | |
214 | {\r | |
215 | return EFI_UNSUPPORTED;\r | |
216 | }\r | |
217 | \r | |
218 | \r | |
219 | /**\r | |
220 | Writes the specified number of bytes from the input buffer to the block.\r | |
221 | \r | |
222 | The Write() function writes the specified number of bytes from\r | |
223 | the provided buffer to the specified block and offset. If the\r | |
224 | firmware volume is sticky write, the caller must ensure that\r | |
225 | all the bits of the specified range to write are in the\r | |
226 | EFI_FVB_ERASE_POLARITY state before calling the Write()\r | |
227 | function, or else the result will be unpredictable. This\r | |
228 | unpredictability arises because, for a sticky-write firmware\r | |
229 | volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY\r | |
230 | state but cannot flip it back again. Before calling the\r | |
231 | Write() function, it is recommended for the caller to first call \r | |
232 | the EraseBlocks() function to erase the specified block to\r | |
233 | write. A block erase cycle will transition bits from the\r | |
234 | (NOT)EFI_FVB_ERASE_POLARITY state back to the\r | |
235 | EFI_FVB_ERASE_POLARITY state. Implementations should be\r | |
236 | mindful that the firmware volume might be in the WriteDisabled\r | |
237 | state. If it is in this state, the Write() function must\r | |
238 | return the status code EFI_ACCESS_DENIED without modifying the\r | |
239 | contents of the firmware volume. The Write() function must\r | |
240 | also prevent spanning block boundaries. If a write is\r | |
241 | requested that spans a block boundary, the write must store up\r | |
242 | to the boundary but not beyond. The output parameter NumBytes\r | |
243 | must be set to correctly indicate the number of bytes actually\r | |
244 | written. The caller must be aware that a write may be\r | |
245 | partially completed. All writes, partial or otherwise, must be\r | |
246 | fully flushed to the hardware before the Write() service\r | |
247 | returns.\r | |
248 | \r | |
249 | @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL instance.\r | |
250 | \r | |
251 | @param Lba The starting logical block index to write to.\r | |
252 | \r | |
253 | @param Offset Offset into the block at which to begin writing.\r | |
254 | \r | |
255 | @param NumBytes The pointer to a UINTN. At entry, *NumBytes\r | |
256 | contains the total size of the buffer. At\r | |
257 | exit, *NumBytes contains the total number of\r | |
258 | bytes actually written.\r | |
259 | \r | |
260 | @param Buffer The pointer to a caller-allocated buffer that\r | |
261 | contains the source for the write.\r | |
262 | \r | |
263 | @retval EFI_SUCCESS The firmware volume was written successfully.\r | |
264 | \r | |
265 | @retval EFI_BAD_BUFFER_SIZE The write was attempted across an\r | |
266 | LBA boundary. On output, NumBytes\r | |
267 | contains the total number of bytes\r | |
268 | actually written.\r | |
269 | \r | |
270 | @retval EFI_ACCESS_DENIED The firmware volume is in the\r | |
271 | WriteDisabled state.\r | |
272 | \r | |
273 | @retval EFI_DEVICE_ERROR The block device is malfunctioning\r | |
274 | and could not be written.\r | |
275 | \r | |
276 | \r | |
277 | **/\r | |
278 | EFI_STATUS\r | |
279 | EFIAPI\r | |
280 | FvbWrite (\r | |
281 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r | |
282 | IN EFI_LBA Lba,\r | |
283 | IN UINTN Offset,\r | |
284 | IN OUT UINTN *NumBytes,\r | |
285 | IN UINT8 *Buffer\r | |
286 | )\r | |
287 | {\r | |
288 | return EFI_UNSUPPORTED;\r | |
289 | }\r | |
290 | \r | |
291 | \r | |
292 | /**\r | |
293 | Erases and initializes a firmware volume block.\r | |
294 | \r | |
295 | The EraseBlocks() function erases one or more blocks as denoted\r | |
296 | by the variable argument list. The entire parameter list of\r | |
297 | blocks must be verified before erasing any blocks. If a block is\r | |
298 | requested that does not exist within the associated firmware\r | |
299 | volume (it has a larger index than the last block of the\r | |
300 | firmware volume), the EraseBlocks() function must return the\r | |
301 | status code EFI_INVALID_PARAMETER without modifying the contents\r | |
302 | of the firmware volume. Implementations should be mindful that\r | |
303 | the firmware volume might be in the WriteDisabled state. If it\r | |
304 | is in this state, the EraseBlocks() function must return the\r | |
305 | status code EFI_ACCESS_DENIED without modifying the contents of\r | |
306 | the firmware volume. All calls to EraseBlocks() must be fully\r | |
307 | flushed to the hardware before the EraseBlocks() service\r | |
308 | returns.\r | |
309 | \r | |
310 | @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL\r | |
311 | instance.\r | |
312 | \r | |
313 | @param ... The variable argument list is a list of tuples.\r | |
314 | Each tuple describes a range of LBAs to erase\r | |
315 | and consists of the following:\r | |
316 | - An EFI_LBA that indicates the starting LBA\r | |
317 | - A UINTN that indicates the number of blocks to\r | |
318 | erase.\r | |
319 | \r | |
320 | The list is terminated with an\r | |
321 | EFI_LBA_LIST_TERMINATOR. For example, the\r | |
322 | following indicates that two ranges of blocks\r | |
323 | (5-7 and 10-11) are to be erased: EraseBlocks\r | |
324 | (This, 5, 3, 10, 2, EFI_LBA_LIST_TERMINATOR);\r | |
325 | \r | |
326 | @retval EFI_SUCCESS The erase request successfully\r | |
327 | completed.\r | |
328 | \r | |
329 | @retval EFI_ACCESS_DENIED The firmware volume is in the\r | |
330 | WriteDisabled state.\r | |
331 | @retval EFI_DEVICE_ERROR The block device is not functioning\r | |
332 | correctly and could not be written.\r | |
333 | The firmware device may have been\r | |
334 | partially erased.\r | |
335 | @retval EFI_INVALID_PARAMETER One or more of the LBAs listed\r | |
336 | in the variable argument list do\r | |
337 | not exist in the firmware volume. \r | |
338 | \r | |
339 | **/\r | |
340 | EFI_STATUS\r | |
341 | EFIAPI\r | |
342 | FvbEraseBlocks (\r | |
343 | IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,\r | |
344 | ...\r | |
345 | )\r | |
346 | {\r | |
347 | return EFI_UNSUPPORTED;\r | |
348 | }\r | |
349 | \r | |
350 | \r | |
351 | //\r | |
352 | // Making this global saves a few bytes in image size\r | |
353 | //\r | |
354 | EFI_HANDLE gFvbHandle = NULL;\r | |
355 | \r | |
356 | \r | |
357 | ///\r | |
358 | /// The Firmware Volume Block Protocol is the low-level interface\r | |
359 | /// to a firmware volume. File-level access to a firmware volume\r | |
360 | /// should not be done using the Firmware Volume Block Protocol.\r | |
361 | /// Normal access to a firmware volume must use the Firmware\r | |
362 | /// Volume Protocol. Typically, only the file system driver that\r | |
363 | /// produces the Firmware Volume Protocol will bind to the\r | |
364 | /// Firmware Volume Block Protocol.\r | |
365 | ///\r | |
366 | EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL gFvbProtocol = {\r | |
367 | FvbGetAttributes,\r | |
368 | FvbSetAttributes,\r | |
369 | FvbGetPhysicalAddress,\r | |
370 | FvbGetBlockSize,\r | |
371 | FvbRead,\r | |
372 | FvbWrite,\r | |
373 | FvbEraseBlocks,\r | |
374 | ///\r | |
375 | /// The handle of the parent firmware volume.\r | |
376 | /// \r | |
377 | NULL\r | |
378 | };\r | |
379 | \r | |
380 | // NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) FixedPcdGet32 (PcdFlashNvStorageVariableBase);\r | |
381 | \r | |
382 | \r | |
383 | /**\r | |
384 | Initialize the state information for the CPU Architectural Protocol\r | |
385 | \r | |
386 | @param ImageHandle of the loaded driver\r | |
387 | @param SystemTable Pointer to the System Table\r | |
388 | \r | |
389 | @retval EFI_SUCCESS Protocol registered\r | |
390 | @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure\r | |
391 | @retval EFI_DEVICE_ERROR Hardware problems\r | |
392 | \r | |
393 | **/\r | |
394 | EFI_STATUS\r | |
395 | EFIAPI\r | |
396 | FvbDxeInitialize (\r | |
397 | IN EFI_HANDLE ImageHandle,\r | |
398 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
399 | )\r | |
400 | {\r | |
401 | EFI_STATUS Status;\r | |
402 | \r | |
403 | \r | |
404 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
405 | &gFvbHandle,\r | |
406 | &gEfiFirmwareVolumeBlockProtocolGuid, &gFvbProtocol,\r | |
407 | NULL\r | |
408 | );\r | |
409 | ASSERT_EFI_ERROR (Status);\r | |
410 | \r | |
411 | // SetVertAddressEvent ()\r | |
412 | \r | |
413 | // GCD Map NAND as RT\r | |
414 | \r | |
415 | return Status;\r | |
416 | }\r | |
417 | \r |