1 /** @file NorFlashDxe.c
3 Copyright (c) 2011 - 2014, ARM Ltd. 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.
15 #include <Library/UefiLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/MemoryAllocationLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/PcdLib.h>
21 #include "NorFlashDxe.h"
23 STATIC EFI_EVENT mNorFlashVirtualAddrChangeEvent
;
26 // Global variable declarations
28 NOR_FLASH_INSTANCE
**mNorFlashInstances
;
29 UINT32 mNorFlashDeviceCount
;
31 NOR_FLASH_INSTANCE mNorFlashInstanceTemplate
= {
32 NOR_FLASH_SIGNATURE
, // Signature
33 NULL
, // Handle ... NEED TO BE FILLED
35 0, // DeviceBaseAddress ... NEED TO BE FILLED
36 0, // RegionBaseAddress ... NEED TO BE FILLED
37 0, // Size ... NEED TO BE FILLED
41 EFI_BLOCK_IO_PROTOCOL_REVISION2
, // Revision
42 NULL
, // Media ... NEED TO BE FILLED
43 NorFlashBlockIoReset
, // Reset;
44 NorFlashBlockIoReadBlocks
, // ReadBlocks
45 NorFlashBlockIoWriteBlocks
, // WriteBlocks
46 NorFlashBlockIoFlushBlocks
// FlushBlocks
50 0, // MediaId ... NEED TO BE FILLED
51 FALSE
, // RemovableMedia
53 FALSE
, // LogicalPartition
55 FALSE
, // WriteCaching;
56 0, // BlockSize ... NEED TO BE FILLED
58 0, // LastBlock ... NEED TO BE FILLED
59 0, // LowestAlignedLba
60 1, // LogicalBlocksPerPhysicalBlock
64 EFI_DISK_IO_PROTOCOL_REVISION
, // Revision
65 NorFlashDiskIoReadDisk
, // ReadDisk
66 NorFlashDiskIoWriteDisk
// WriteDisk
70 FvbGetAttributes
, // GetAttributes
71 FvbSetAttributes
, // SetAttributes
72 FvbGetPhysicalAddress
, // GetPhysicalAddress
73 FvbGetBlockSize
, // GetBlockSize
76 FvbEraseBlocks
, // EraseBlocks
86 (UINT8
)(OFFSET_OF (NOR_FLASH_DEVICE_PATH
, End
)),
87 (UINT8
)(OFFSET_OF (NOR_FLASH_DEVICE_PATH
, End
) >> 8)
90 { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }, // GUID ... NEED TO BE FILLED
95 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
96 { sizeof (EFI_DEVICE_PATH_PROTOCOL
), 0 }
102 NorFlashCreateInstance (
103 IN UINTN NorFlashDeviceBase
,
104 IN UINTN NorFlashRegionBase
,
105 IN UINTN NorFlashSize
,
108 IN BOOLEAN SupportFvb
,
109 OUT NOR_FLASH_INSTANCE
** NorFlashInstance
113 NOR_FLASH_INSTANCE
* Instance
;
115 ASSERT(NorFlashInstance
!= NULL
);
117 Instance
= AllocateRuntimeCopyPool (sizeof(NOR_FLASH_INSTANCE
),&mNorFlashInstanceTemplate
);
118 if (Instance
== NULL
) {
119 return EFI_OUT_OF_RESOURCES
;
122 Instance
->DeviceBaseAddress
= NorFlashDeviceBase
;
123 Instance
->RegionBaseAddress
= NorFlashRegionBase
;
124 Instance
->Size
= NorFlashSize
;
126 Instance
->BlockIoProtocol
.Media
= &Instance
->Media
;
127 Instance
->Media
.MediaId
= Index
;
128 Instance
->Media
.BlockSize
= BlockSize
;
129 Instance
->Media
.LastBlock
= (NorFlashSize
/ BlockSize
)-1;
131 CopyGuid (&Instance
->DevicePath
.Vendor
.Guid
, &gEfiCallerIdGuid
);
132 Instance
->DevicePath
.Index
= (UINT8
)Index
;
134 Instance
->ShadowBuffer
= AllocateRuntimePool (BlockSize
);;
135 if (Instance
->ShadowBuffer
== NULL
) {
136 return EFI_OUT_OF_RESOURCES
;
140 NorFlashFvbInitialize (Instance
);
142 Status
= gBS
->InstallMultipleProtocolInterfaces (
144 &gEfiDevicePathProtocolGuid
, &Instance
->DevicePath
,
145 &gEfiBlockIoProtocolGuid
, &Instance
->BlockIoProtocol
,
146 &gEfiFirmwareVolumeBlockProtocolGuid
, &Instance
->FvbProtocol
,
149 if (EFI_ERROR(Status
)) {
154 Status
= gBS
->InstallMultipleProtocolInterfaces (
156 &gEfiDevicePathProtocolGuid
, &Instance
->DevicePath
,
157 &gEfiBlockIoProtocolGuid
, &Instance
->BlockIoProtocol
,
158 &gEfiDiskIoProtocolGuid
, &Instance
->DiskIoProtocol
,
161 if (EFI_ERROR(Status
)) {
167 *NorFlashInstance
= Instance
;
172 NorFlashReadStatusRegister (
173 IN NOR_FLASH_INSTANCE
*Instance
,
177 // Prepare to read the status register
178 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_READ_STATUS_REGISTER
);
179 return MmioRead32 (Instance
->DeviceBaseAddress
);
184 NorFlashBlockIsLocked (
185 IN NOR_FLASH_INSTANCE
*Instance
,
186 IN UINTN BlockAddress
191 // Send command for reading device id
192 SEND_NOR_COMMAND (BlockAddress
, 2, P30_CMD_READ_DEVICE_ID
);
194 // Read block lock status
195 LockStatus
= MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress
, 2));
197 // Decode block lock status
198 LockStatus
= FOLD_32BIT_INTO_16BIT(LockStatus
);
200 if ((LockStatus
& 0x2) != 0) {
201 DEBUG((EFI_D_ERROR
, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOWN\n"));
204 return ((LockStatus
& 0x1) != 0);
209 NorFlashUnlockSingleBlock (
210 IN NOR_FLASH_INSTANCE
*Instance
,
211 IN UINTN BlockAddress
216 // Raise the Task Priority Level to TPL_NOTIFY to serialise all its operations
217 // and to protect shared data structures.
219 if (FeaturePcdGet (PcdNorFlashCheckBlockLocked
) == TRUE
) {
221 // Request a lock setup
222 SEND_NOR_COMMAND (BlockAddress
, 0, P30_CMD_LOCK_BLOCK_SETUP
);
225 SEND_NOR_COMMAND (BlockAddress
, 0, P30_CMD_UNLOCK_BLOCK
);
227 // Send command for reading device id
228 SEND_NOR_COMMAND (BlockAddress
, 2, P30_CMD_READ_DEVICE_ID
);
230 // Read block lock status
231 LockStatus
= MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress
, 2));
233 // Decode block lock status
234 LockStatus
= FOLD_32BIT_INTO_16BIT(LockStatus
);
235 } while ((LockStatus
& 0x1) == 1);
237 // Request a lock setup
238 SEND_NOR_COMMAND (BlockAddress
, 0, P30_CMD_LOCK_BLOCK_SETUP
);
241 SEND_NOR_COMMAND (BlockAddress
, 0, P30_CMD_UNLOCK_BLOCK
);
243 // Wait until the status register gives us the all clear
245 LockStatus
= NorFlashReadStatusRegister (Instance
, BlockAddress
);
246 } while ((LockStatus
& P30_SR_BIT_WRITE
) != P30_SR_BIT_WRITE
);
249 // Put device back into Read Array mode
250 SEND_NOR_COMMAND (BlockAddress
, 0, P30_CMD_READ_ARRAY
);
252 DEBUG((DEBUG_BLKIO
, "UnlockSingleBlock: BlockAddress=0x%08x\n", BlockAddress
));
259 NorFlashUnlockSingleBlockIfNecessary (
260 IN NOR_FLASH_INSTANCE
*Instance
,
261 IN UINTN BlockAddress
266 Status
= EFI_SUCCESS
;
268 if (NorFlashBlockIsLocked (Instance
, BlockAddress
) == TRUE
) {
269 Status
= NorFlashUnlockSingleBlock (Instance
, BlockAddress
);
277 * The following function presumes that the block has already been unlocked.
281 NorFlashEraseSingleBlock (
282 IN NOR_FLASH_INSTANCE
*Instance
,
283 IN UINTN BlockAddress
287 UINT32 StatusRegister
;
289 Status
= EFI_SUCCESS
;
291 // Request a block erase and then confirm it
292 SEND_NOR_COMMAND(BlockAddress
, 0, P30_CMD_BLOCK_ERASE_SETUP
);
293 SEND_NOR_COMMAND(BlockAddress
, 0, P30_CMD_BLOCK_ERASE_CONFIRM
);
295 // Wait until the status register gives us the all clear
297 StatusRegister
= NorFlashReadStatusRegister (Instance
, BlockAddress
);
298 } while ((StatusRegister
& P30_SR_BIT_WRITE
) != P30_SR_BIT_WRITE
);
300 if (StatusRegister
& P30_SR_BIT_VPP
) {
301 DEBUG((EFI_D_ERROR
,"EraseSingleBlock(BlockAddress=0x%08x: VPP Range Error\n", BlockAddress
));
302 Status
= EFI_DEVICE_ERROR
;
305 if ((StatusRegister
& (P30_SR_BIT_ERASE
| P30_SR_BIT_PROGRAM
)) == (P30_SR_BIT_ERASE
| P30_SR_BIT_PROGRAM
)) {
306 DEBUG((EFI_D_ERROR
,"EraseSingleBlock(BlockAddress=0x%08x: Command Sequence Error\n", BlockAddress
));
307 Status
= EFI_DEVICE_ERROR
;
310 if (StatusRegister
& P30_SR_BIT_ERASE
) {
311 DEBUG((EFI_D_ERROR
,"EraseSingleBlock(BlockAddress=0x%08x: Block Erase Error StatusRegister:0x%X\n", BlockAddress
, StatusRegister
));
312 Status
= EFI_DEVICE_ERROR
;
315 if (StatusRegister
& P30_SR_BIT_BLOCK_LOCKED
) {
316 // The debug level message has been reduced because a device lock might happen. In this case we just retry it ...
317 DEBUG((EFI_D_INFO
,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error\n", BlockAddress
));
318 Status
= EFI_WRITE_PROTECTED
;
321 if (EFI_ERROR(Status
)) {
322 // Clear the Status Register
323 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_CLEAR_STATUS_REGISTER
);
326 // Put device back into Read Array mode
327 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_READ_ARRAY
);
333 * This function unlock and erase an entire NOR Flash block.
336 NorFlashUnlockAndEraseSingleBlock (
337 IN NOR_FLASH_INSTANCE
*Instance
,
338 IN UINTN BlockAddress
345 if (!EfiAtRuntime ()) {
346 // Raise TPL to TPL_HIGH to stop anyone from interrupting us.
347 OriginalTPL
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
349 // This initialization is only to prevent the compiler to complain about the
350 // use of uninitialized variables
351 OriginalTPL
= TPL_HIGH_LEVEL
;
355 // The block erase might fail a first time (SW bug ?). Retry it ...
357 // Unlock the block if we have to
358 Status
= NorFlashUnlockSingleBlockIfNecessary (Instance
, BlockAddress
);
359 if (EFI_ERROR (Status
)) {
362 Status
= NorFlashEraseSingleBlock (Instance
, BlockAddress
);
364 } while ((Index
< NOR_FLASH_ERASE_RETRY
) && (Status
== EFI_WRITE_PROTECTED
));
366 if (Index
== NOR_FLASH_ERASE_RETRY
) {
367 DEBUG((EFI_D_ERROR
,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress
,Index
));
370 if (!EfiAtRuntime ()) {
371 // Interruptions can resume.
372 gBS
->RestoreTPL (OriginalTPL
);
381 NorFlashWriteSingleWord (
382 IN NOR_FLASH_INSTANCE
*Instance
,
383 IN UINTN WordAddress
,
388 UINT32 StatusRegister
;
390 Status
= EFI_SUCCESS
;
392 // Request a write single word command
393 SEND_NOR_COMMAND(WordAddress
, 0, P30_CMD_WORD_PROGRAM_SETUP
);
395 // Store the word into NOR Flash;
396 MmioWrite32 (WordAddress
, WriteData
);
398 // Wait for the write to complete and then check for any errors; i.e. check the Status Register
400 // Prepare to read the status register
401 StatusRegister
= NorFlashReadStatusRegister (Instance
, WordAddress
);
402 // The chip is busy while the WRITE bit is not asserted
403 } while ((StatusRegister
& P30_SR_BIT_WRITE
) != P30_SR_BIT_WRITE
);
406 // Perform a full status check:
407 // Mask the relevant bits of Status Register.
408 // Everything should be zero, if not, we have a problem
410 if (StatusRegister
& P30_SR_BIT_VPP
) {
411 DEBUG((EFI_D_ERROR
,"NorFlashWriteSingleWord(WordAddress:0x%X): VPP Range Error\n",WordAddress
));
412 Status
= EFI_DEVICE_ERROR
;
415 if (StatusRegister
& P30_SR_BIT_PROGRAM
) {
416 DEBUG((EFI_D_ERROR
,"NorFlashWriteSingleWord(WordAddress:0x%X): Program Error\n",WordAddress
));
417 Status
= EFI_DEVICE_ERROR
;
420 if (StatusRegister
& P30_SR_BIT_BLOCK_LOCKED
) {
421 DEBUG((EFI_D_ERROR
,"NorFlashWriteSingleWord(WordAddress:0x%X): Device Protect Error\n",WordAddress
));
422 Status
= EFI_DEVICE_ERROR
;
425 if (!EFI_ERROR(Status
)) {
426 // Clear the Status Register
427 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_CLEAR_STATUS_REGISTER
);
430 // Put device back into Read Array mode
431 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_READ_ARRAY
);
437 * Writes data to the NOR Flash using the Buffered Programming method.
439 * The maximum size of the on-chip buffer is 32-words, because of hardware restrictions.
440 * Therefore this function will only handle buffers up to 32 words or 128 bytes.
441 * To deal with larger buffers, call this function again.
443 * This function presumes that both the TargetAddress and the TargetAddress+BufferSize
444 * exist entirely within the NOR Flash. Therefore these conditions will not be checked here.
446 * In buffered programming, if the target address not at the beginning of a 32-bit word boundary,
447 * then programming time is doubled and power consumption is increased.
448 * Therefore, it is a requirement to align buffer writes to 32-bit word boundaries.
449 * i.e. the last 4 bits of the target start address must be zero: 0x......00
452 NorFlashWriteBuffer (
453 IN NOR_FLASH_INSTANCE
*Instance
,
454 IN UINTN TargetAddress
,
455 IN UINTN BufferSizeInBytes
,
460 UINTN BufferSizeInWords
;
462 volatile UINT32
*Data
;
464 BOOLEAN BufferAvailable
;
465 UINT32 StatusRegister
;
467 WaitForBuffer
= MAX_BUFFERED_PROG_ITERATIONS
;
468 BufferAvailable
= FALSE
;
470 // Check that the target address does not cross a 32-word boundary.
471 if ((TargetAddress
& BOUNDARY_OF_32_WORDS
) != 0) {
472 return EFI_INVALID_PARAMETER
;
475 // Check there are some data to program
476 if (BufferSizeInBytes
== 0) {
477 return EFI_BUFFER_TOO_SMALL
;
480 // Check that the buffer size does not exceed the maximum hardware buffer size on chip.
481 if (BufferSizeInBytes
> P30_MAX_BUFFER_SIZE_IN_BYTES
) {
482 return EFI_BAD_BUFFER_SIZE
;
485 // Check that the buffer size is a multiple of 32-bit words
486 if ((BufferSizeInBytes
% 4) != 0) {
487 return EFI_BAD_BUFFER_SIZE
;
490 // Pre-programming conditions checked, now start the algorithm.
492 // Prepare the data destination address
493 Data
= (UINT32
*)TargetAddress
;
495 // Check the availability of the buffer
497 // Issue the Buffered Program Setup command
498 SEND_NOR_COMMAND(TargetAddress
, 0, P30_CMD_BUFFERED_PROGRAM_SETUP
);
500 // Read back the status register bit#7 from the same address
501 if (((*Data
) & P30_SR_BIT_WRITE
) == P30_SR_BIT_WRITE
) {
502 BufferAvailable
= TRUE
;
505 // Update the loop counter
508 } while ((WaitForBuffer
> 0) && (BufferAvailable
== FALSE
));
510 // The buffer was not available for writing
511 if (WaitForBuffer
== 0) {
512 Status
= EFI_DEVICE_ERROR
;
516 // From now on we work in 32-bit words
517 BufferSizeInWords
= BufferSizeInBytes
/ (UINTN
)4;
519 // Write the word count, which is (buffer_size_in_words - 1),
520 // because word count 0 means one word.
521 SEND_NOR_COMMAND(TargetAddress
, 0, (BufferSizeInWords
- 1));
523 // Write the data to the NOR Flash, advancing each address by 4 bytes
524 for(Count
=0; Count
< BufferSizeInWords
; Count
++, Data
++, Buffer
++) {
525 MmioWrite32 ((UINTN
)Data
, *Buffer
);
528 // Issue the Buffered Program Confirm command, to start the programming operation
529 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_BUFFERED_PROGRAM_CONFIRM
);
531 // Wait for the write to complete and then check for any errors; i.e. check the Status Register
533 StatusRegister
= NorFlashReadStatusRegister (Instance
, TargetAddress
);
534 // The chip is busy while the WRITE bit is not asserted
535 } while ((StatusRegister
& P30_SR_BIT_WRITE
) != P30_SR_BIT_WRITE
);
538 // Perform a full status check:
539 // Mask the relevant bits of Status Register.
540 // Everything should be zero, if not, we have a problem
542 Status
= EFI_SUCCESS
;
544 if (StatusRegister
& P30_SR_BIT_VPP
) {
545 DEBUG((EFI_D_ERROR
,"NorFlashWriteBuffer(TargetAddress:0x%X): VPP Range Error\n", TargetAddress
));
546 Status
= EFI_DEVICE_ERROR
;
549 if (StatusRegister
& P30_SR_BIT_PROGRAM
) {
550 DEBUG((EFI_D_ERROR
,"NorFlashWriteBuffer(TargetAddress:0x%X): Program Error\n", TargetAddress
));
551 Status
= EFI_DEVICE_ERROR
;
554 if (StatusRegister
& P30_SR_BIT_BLOCK_LOCKED
) {
555 DEBUG((EFI_D_ERROR
,"NorFlashWriteBuffer(TargetAddress:0x%X): Device Protect Error\n",TargetAddress
));
556 Status
= EFI_DEVICE_ERROR
;
559 if (!EFI_ERROR(Status
)) {
560 // Clear the Status Register
561 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_CLEAR_STATUS_REGISTER
);
565 // Put device back into Read Array mode
566 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_READ_ARRAY
);
573 NorFlashWriteFullBlock (
574 IN NOR_FLASH_INSTANCE
*Instance
,
576 IN UINT32
*DataBuffer
,
577 IN UINT32 BlockSizeInWords
585 UINTN BuffersInBlock
;
586 UINTN RemainingWords
;
590 Status
= EFI_SUCCESS
;
592 // Get the physical address of the block
593 BlockAddress
= GET_NOR_BLOCK_ADDRESS (Instance
->RegionBaseAddress
, Lba
, BlockSizeInWords
* 4);
595 // Start writing from the first address at the start of the block
596 WordAddress
= BlockAddress
;
598 if (!EfiAtRuntime ()) {
599 // Raise TPL to TPL_HIGH to stop anyone from interrupting us.
600 OriginalTPL
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
602 // This initialization is only to prevent the compiler to complain about the
603 // use of uninitialized variables
604 OriginalTPL
= TPL_HIGH_LEVEL
;
607 Status
= NorFlashUnlockAndEraseSingleBlock (Instance
, BlockAddress
);
608 if (EFI_ERROR(Status
)) {
609 DEBUG((EFI_D_ERROR
, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress
));
613 // To speed up the programming operation, NOR Flash is programmed using the Buffered Programming method.
615 // Check that the address starts at a 32-word boundary, i.e. last 7 bits must be zero
616 if ((WordAddress
& BOUNDARY_OF_32_WORDS
) == 0x00) {
618 // First, break the entire block into buffer-sized chunks.
619 BuffersInBlock
= (UINTN
)(BlockSizeInWords
* 4) / P30_MAX_BUFFER_SIZE_IN_BYTES
;
621 // Then feed each buffer chunk to the NOR Flash
622 // If a buffer does not contain any data, don't write it.
624 BufferIndex
< BuffersInBlock
;
625 BufferIndex
++, WordAddress
+= P30_MAX_BUFFER_SIZE_IN_BYTES
, DataBuffer
+= P30_MAX_BUFFER_SIZE_IN_WORDS
627 // Check the buffer to see if it contains any data (not set all 1s).
628 for (Cnt
= 0; Cnt
< P30_MAX_BUFFER_SIZE_IN_WORDS
; Cnt
++) {
629 if (~DataBuffer
[Cnt
] != 0 ) {
630 // Some data found, write the buffer.
631 Status
= NorFlashWriteBuffer (Instance
, WordAddress
, P30_MAX_BUFFER_SIZE_IN_BYTES
,
633 if (EFI_ERROR(Status
)) {
641 // Finally, finish off any remaining words that are less than the maximum size of the buffer
642 RemainingWords
= BlockSizeInWords
% P30_MAX_BUFFER_SIZE_IN_WORDS
;
644 if(RemainingWords
!= 0) {
645 Status
= NorFlashWriteBuffer (Instance
, WordAddress
, (RemainingWords
* 4), DataBuffer
);
646 if (EFI_ERROR(Status
)) {
652 // For now, use the single word programming algorithm
653 // It is unlikely that the NOR Flash will exist in an address which falls within a 32 word boundary range,
654 // i.e. which ends in the range 0x......01 - 0x......7F.
655 for(WordIndex
=0; WordIndex
<BlockSizeInWords
; WordIndex
++, DataBuffer
++, WordAddress
= WordAddress
+ 4) {
656 Status
= NorFlashWriteSingleWord (Instance
, WordAddress
, *DataBuffer
);
657 if (EFI_ERROR(Status
)) {
664 if (!EfiAtRuntime ()) {
665 // Interruptions can resume.
666 gBS
->RestoreTPL (OriginalTPL
);
669 if (EFI_ERROR(Status
)) {
670 DEBUG((EFI_D_ERROR
, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress
, Status
));
677 NorFlashWriteBlocks (
678 IN NOR_FLASH_INSTANCE
*Instance
,
680 IN UINTN BufferSizeInBytes
,
684 UINT32
*pWriteBuffer
;
685 EFI_STATUS Status
= EFI_SUCCESS
;
686 EFI_LBA CurrentBlock
;
687 UINT32 BlockSizeInWords
;
691 // The buffer must be valid
692 if (Buffer
== NULL
) {
693 return EFI_INVALID_PARAMETER
;
696 if(Instance
->Media
.ReadOnly
== TRUE
) {
697 return EFI_WRITE_PROTECTED
;
700 // We must have some bytes to read
701 DEBUG((DEBUG_BLKIO
, "NorFlashWriteBlocks: BufferSizeInBytes=0x%x\n", BufferSizeInBytes
));
702 if(BufferSizeInBytes
== 0) {
703 return EFI_BAD_BUFFER_SIZE
;
706 // The size of the buffer must be a multiple of the block size
707 DEBUG((DEBUG_BLKIO
, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", Instance
->Media
.BlockSize
));
708 if ((BufferSizeInBytes
% Instance
->Media
.BlockSize
) != 0) {
709 return EFI_BAD_BUFFER_SIZE
;
712 // All blocks must be within the device
713 NumBlocks
= ((UINT32
)BufferSizeInBytes
) / Instance
->Media
.BlockSize
;
715 DEBUG((DEBUG_BLKIO
, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks
, Instance
->Media
.LastBlock
, Lba
));
717 if ((Lba
+ NumBlocks
) > (Instance
->Media
.LastBlock
+ 1)) {
718 DEBUG((EFI_D_ERROR
, "NorFlashWriteBlocks: ERROR - Write will exceed last block.\n"));
719 return EFI_INVALID_PARAMETER
;
722 BlockSizeInWords
= Instance
->Media
.BlockSize
/ 4;
724 // Because the target *Buffer is a pointer to VOID, we must put all the data into a pointer
725 // to a proper data type, so use *ReadBuffer
726 pWriteBuffer
= (UINT32
*)Buffer
;
729 for (BlockCount
=0; BlockCount
< NumBlocks
; BlockCount
++, CurrentBlock
++, pWriteBuffer
= pWriteBuffer
+ BlockSizeInWords
) {
731 DEBUG((DEBUG_BLKIO
, "NorFlashWriteBlocks: Writing block #%d\n", (UINTN
)CurrentBlock
));
733 Status
= NorFlashWriteFullBlock (Instance
, CurrentBlock
, pWriteBuffer
, BlockSizeInWords
);
735 if (EFI_ERROR(Status
)) {
740 DEBUG((DEBUG_BLKIO
, "NorFlashWriteBlocks: Exit Status = \"%r\".\n", Status
));
744 #define BOTH_ALIGNED(a, b, align) ((((UINTN)(a) | (UINTN)(b)) & ((align) - 1)) == 0)
747 Copy Length bytes from Source to Destination, using aligned accesses only.
748 Note that this implementation uses memcpy() semantics rather then memmove()
749 semantics, i.e., SourceBuffer and DestinationBuffer should not overlap.
751 @param DestinationBuffer The target of the copy request.
752 @param SourceBuffer The place to copy from.
753 @param Length The number of bytes to copy.
761 OUT VOID
*DestinationBuffer
,
762 IN CONST VOID
*SourceBuffer
,
767 CONST UINT8
*Source8
;
768 UINT32
*Destination32
;
769 CONST UINT32
*Source32
;
770 UINT64
*Destination64
;
771 CONST UINT64
*Source64
;
773 if (BOTH_ALIGNED(DestinationBuffer
, SourceBuffer
, 8) && Length
>= 8) {
774 Destination64
= DestinationBuffer
;
775 Source64
= SourceBuffer
;
776 while (Length
>= 8) {
777 *Destination64
++ = *Source64
++;
781 Destination8
= (UINT8
*)Destination64
;
782 Source8
= (CONST UINT8
*)Source64
;
783 } else if (BOTH_ALIGNED(DestinationBuffer
, SourceBuffer
, 4) && Length
>= 4) {
784 Destination32
= DestinationBuffer
;
785 Source32
= SourceBuffer
;
786 while (Length
>= 4) {
787 *Destination32
++ = *Source32
++;
791 Destination8
= (UINT8
*)Destination32
;
792 Source8
= (CONST UINT8
*)Source32
;
794 Destination8
= DestinationBuffer
;
795 Source8
= SourceBuffer
;
797 while (Length
-- != 0) {
798 *Destination8
++ = *Source8
++;
800 return DestinationBuffer
;
805 IN NOR_FLASH_INSTANCE
*Instance
,
807 IN UINTN BufferSizeInBytes
,
814 DEBUG((DEBUG_BLKIO
, "NorFlashReadBlocks: BufferSize=0x%xB BlockSize=0x%xB LastBlock=%ld, Lba=%ld.\n",
815 BufferSizeInBytes
, Instance
->Media
.BlockSize
, Instance
->Media
.LastBlock
, Lba
));
817 // The buffer must be valid
818 if (Buffer
== NULL
) {
819 return EFI_INVALID_PARAMETER
;
822 // Return if we have not any byte to read
823 if (BufferSizeInBytes
== 0) {
827 // The size of the buffer must be a multiple of the block size
828 if ((BufferSizeInBytes
% Instance
->Media
.BlockSize
) != 0) {
829 return EFI_BAD_BUFFER_SIZE
;
832 // All blocks must be within the device
833 NumBlocks
= ((UINT32
)BufferSizeInBytes
) / Instance
->Media
.BlockSize
;
835 if ((Lba
+ NumBlocks
) > (Instance
->Media
.LastBlock
+ 1)) {
836 DEBUG((EFI_D_ERROR
, "NorFlashReadBlocks: ERROR - Read will exceed last block\n"));
837 return EFI_INVALID_PARAMETER
;
840 // Get the address to start reading from
841 StartAddress
= GET_NOR_BLOCK_ADDRESS (Instance
->RegionBaseAddress
,
843 Instance
->Media
.BlockSize
846 // Put the device into Read Array mode
847 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_READ_ARRAY
);
850 AlignedCopyMem (Buffer
, (VOID
*)StartAddress
, BufferSizeInBytes
);
857 IN NOR_FLASH_INSTANCE
*Instance
,
860 IN UINTN BufferSizeInBytes
,
866 // The buffer must be valid
867 if (Buffer
== NULL
) {
868 return EFI_INVALID_PARAMETER
;
871 // Return if we have not any byte to read
872 if (BufferSizeInBytes
== 0) {
876 if (((Lba
* Instance
->Media
.BlockSize
) + Offset
+ BufferSizeInBytes
) > Instance
->Size
) {
877 DEBUG ((EFI_D_ERROR
, "NorFlashRead: ERROR - Read will exceed device size.\n"));
878 return EFI_INVALID_PARAMETER
;
881 // Get the address to start reading from
882 StartAddress
= GET_NOR_BLOCK_ADDRESS (Instance
->RegionBaseAddress
,
884 Instance
->Media
.BlockSize
887 // Put the device into Read Array mode
888 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_READ_ARRAY
);
891 AlignedCopyMem (Buffer
, (VOID
*)(StartAddress
+ Offset
), BufferSizeInBytes
);
897 Write a full or portion of a block. It must not span block boundaries; that is,
898 Offset + *NumBytes <= Instance->Media.BlockSize.
901 NorFlashWriteSingleBlock (
902 IN NOR_FLASH_INSTANCE
*Instance
,
905 IN OUT UINTN
*NumBytes
,
909 EFI_STATUS TempStatus
;
920 UINTN PrevBlockAddress
;
922 PrevBlockAddress
= 0;
924 DEBUG ((DEBUG_BLKIO
, "NorFlashWriteSingleBlock(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Lba
, Offset
, *NumBytes
, Buffer
));
926 // Detect WriteDisabled state
927 if (Instance
->Media
.ReadOnly
== TRUE
) {
928 DEBUG ((EFI_D_ERROR
, "NorFlashWriteSingleBlock: ERROR - Can not write: Device is in WriteDisabled state.\n"));
929 // It is in WriteDisabled state, return an error right away
930 return EFI_ACCESS_DENIED
;
933 // Cache the block size to avoid de-referencing pointers all the time
934 BlockSize
= Instance
->Media
.BlockSize
;
936 // The write must not span block boundaries.
937 // We need to check each variable individually because adding two large values together overflows.
938 if ( ( Offset
>= BlockSize
) ||
939 ( *NumBytes
> BlockSize
) ||
940 ( (Offset
+ *NumBytes
) > BlockSize
) ) {
941 DEBUG ((EFI_D_ERROR
, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset
, *NumBytes
, BlockSize
));
942 return EFI_BAD_BUFFER_SIZE
;
945 // We must have some bytes to write
946 if (*NumBytes
== 0) {
947 DEBUG ((EFI_D_ERROR
, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset
, *NumBytes
, BlockSize
));
948 return EFI_BAD_BUFFER_SIZE
;
951 // Pick 128bytes as a good start for word operations as opposed to erasing the
952 // block and writing the data regardless if an erase is really needed.
953 // It looks like most individual NV variable writes are smaller than 128bytes.
954 if (*NumBytes
<= 128) {
955 // Check to see if we need to erase before programming the data into NOR.
956 // If the destination bits are only changing from 1s to 0s we can just write.
957 // After a block is erased all bits in the block is set to 1.
958 // If any byte requires us to erase we just give up and rewrite all of it.
960 BytesToWrite
= *NumBytes
;
963 while (BytesToWrite
> 0) {
964 // Read full word from NOR, splice as required. A word is the smallest
965 // unit we can write.
966 TempStatus
= NorFlashRead (Instance
, Lba
, CurOffset
& ~(0x3), sizeof(Tmp
), &Tmp
);
967 if (EFI_ERROR (TempStatus
)) {
968 return EFI_DEVICE_ERROR
;
971 // Physical address of word in NOR to write.
972 WordAddr
= (CurOffset
& ~(0x3)) + GET_NOR_BLOCK_ADDRESS (Instance
->RegionBaseAddress
,
974 // The word of data that is to be written.
975 TmpBuf
= *((UINT32
*)(Buffer
+ (*NumBytes
- BytesToWrite
)));
977 // First do word aligned chunks.
978 if ((CurOffset
& 0x3) == 0) {
979 if (BytesToWrite
>= 4) {
980 // Is the destination still in 'erased' state?
982 // Check to see if we are only changing bits to zero.
983 if ((Tmp
^ TmpBuf
) & TmpBuf
) {
988 // Write this word to NOR
989 WordToWrite
= TmpBuf
;
990 CurOffset
+= sizeof(TmpBuf
);
991 BytesToWrite
-= sizeof(TmpBuf
);
993 // BytesToWrite < 4. Do small writes and left-overs
994 Mask
= ~((~0) << (BytesToWrite
* 8));
995 // Mask out the bytes we want.
997 // Is the destination still in 'erased' state?
998 if ((Tmp
& Mask
) != Mask
) {
999 // Check to see if we are only changing bits to zero.
1000 if ((Tmp
^ TmpBuf
) & TmpBuf
) {
1005 // Merge old and new data. Write merged word to NOR
1006 WordToWrite
= (Tmp
& ~Mask
) | TmpBuf
;
1007 CurOffset
+= BytesToWrite
;
1011 // Do multiple words, but starting unaligned.
1012 if (BytesToWrite
> (4 - (CurOffset
& 0x3))) {
1013 Mask
= ((~0) << ((CurOffset
& 0x3) * 8));
1014 // Mask out the bytes we want.
1016 // Is the destination still in 'erased' state?
1017 if ((Tmp
& Mask
) != Mask
) {
1018 // Check to see if we are only changing bits to zero.
1019 if ((Tmp
^ TmpBuf
) & TmpBuf
) {
1024 // Merge old and new data. Write merged word to NOR
1025 WordToWrite
= (Tmp
& ~Mask
) | TmpBuf
;
1026 BytesToWrite
-= (4 - (CurOffset
& 0x3));
1027 CurOffset
+= (4 - (CurOffset
& 0x3));
1029 // Unaligned and fits in one word.
1030 Mask
= (~((~0) << (BytesToWrite
* 8))) << ((CurOffset
& 0x3) * 8);
1031 // Mask out the bytes we want.
1032 TmpBuf
= (TmpBuf
<< ((CurOffset
& 0x3) * 8)) & Mask
;
1033 // Is the destination still in 'erased' state?
1034 if ((Tmp
& Mask
) != Mask
) {
1035 // Check to see if we are only changing bits to zero.
1036 if ((Tmp
^ TmpBuf
) & TmpBuf
) {
1041 // Merge old and new data. Write merged word to NOR
1042 WordToWrite
= (Tmp
& ~Mask
) | TmpBuf
;
1043 CurOffset
+= BytesToWrite
;
1049 // Write the word to NOR.
1052 BlockAddress
= GET_NOR_BLOCK_ADDRESS (Instance
->RegionBaseAddress
, Lba
, BlockSize
);
1053 if (BlockAddress
!= PrevBlockAddress
) {
1054 TempStatus
= NorFlashUnlockSingleBlockIfNecessary (Instance
, BlockAddress
);
1055 if (EFI_ERROR (TempStatus
)) {
1056 return EFI_DEVICE_ERROR
;
1058 PrevBlockAddress
= BlockAddress
;
1060 TempStatus
= NorFlashWriteSingleWord (Instance
, WordAddr
, WordToWrite
);
1061 if (EFI_ERROR (TempStatus
)) {
1062 return EFI_DEVICE_ERROR
;
1065 // Exit if we got here and could write all the data. Otherwise do the
1066 // Erase-Write cycle.
1072 // Check we did get some memory. Buffer is BlockSize.
1073 if (Instance
->ShadowBuffer
== NULL
) {
1074 DEBUG ((EFI_D_ERROR
, "FvbWrite: ERROR - Buffer not ready\n"));
1075 return EFI_DEVICE_ERROR
;
1078 // Read NOR Flash data into shadow buffer
1079 TempStatus
= NorFlashReadBlocks (Instance
, Lba
, BlockSize
, Instance
->ShadowBuffer
);
1080 if (EFI_ERROR (TempStatus
)) {
1081 // Return one of the pre-approved error statuses
1082 return EFI_DEVICE_ERROR
;
1085 // Put the data at the appropriate location inside the buffer area
1086 CopyMem ((VOID
*)((UINTN
)Instance
->ShadowBuffer
+ Offset
), Buffer
, *NumBytes
);
1088 // Write the modified buffer back to the NorFlash
1089 TempStatus
= NorFlashWriteBlocks (Instance
, Lba
, BlockSize
, Instance
->ShadowBuffer
);
1090 if (EFI_ERROR (TempStatus
)) {
1091 // Return one of the pre-approved error statuses
1092 return EFI_DEVICE_ERROR
;
1099 Although DiskIoDxe will automatically install the DiskIO protocol whenever
1100 we install the BlockIO protocol, its implementation is sub-optimal as it reads
1101 and writes entire blocks using the BlockIO protocol. In fact we can access
1102 NOR flash with a finer granularity than that, so we can improve performance
1103 by directly producing the DiskIO protocol.
1107 Read BufferSize bytes from Offset into Buffer.
1109 @param This Protocol instance pointer.
1110 @param MediaId Id of the media, changes every time the media is replaced.
1111 @param Offset The starting byte offset to read from
1112 @param BufferSize Size of Buffer
1113 @param Buffer Buffer containing read data
1115 @retval EFI_SUCCESS The data was read correctly from the device.
1116 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
1117 @retval EFI_NO_MEDIA There is no media in the device.
1118 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1119 @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not
1120 valid for the device.
1125 NorFlashDiskIoReadDisk (
1126 IN EFI_DISK_IO_PROTOCOL
*This
,
1128 IN UINT64 DiskOffset
,
1129 IN UINTN BufferSize
,
1133 NOR_FLASH_INSTANCE
*Instance
;
1138 Instance
= INSTANCE_FROM_DISKIO_THIS(This
);
1140 if (MediaId
!= Instance
->Media
.MediaId
) {
1141 return EFI_MEDIA_CHANGED
;
1144 BlockSize
= Instance
->Media
.BlockSize
;
1145 Lba
= (EFI_LBA
) DivU64x32Remainder (DiskOffset
, BlockSize
, &BlockOffset
);
1147 return NorFlashRead (Instance
, Lba
, BlockOffset
, BufferSize
, Buffer
);
1151 Writes a specified number of bytes to a device.
1153 @param This Indicates a pointer to the calling context.
1154 @param MediaId ID of the medium to be written.
1155 @param Offset The starting byte offset on the logical block I/O device to write.
1156 @param BufferSize The size in bytes of Buffer. The number of bytes to write to the device.
1157 @param Buffer A pointer to the buffer containing the data to be written.
1159 @retval EFI_SUCCESS The data was written correctly to the device.
1160 @retval EFI_WRITE_PROTECTED The device can not be written to.
1161 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1162 @retval EFI_NO_MEDIA There is no media in the device.
1163 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1164 @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not
1165 valid for the device.
1170 NorFlashDiskIoWriteDisk (
1171 IN EFI_DISK_IO_PROTOCOL
*This
,
1173 IN UINT64 DiskOffset
,
1174 IN UINTN BufferSize
,
1178 NOR_FLASH_INSTANCE
*Instance
;
1182 UINTN RemainingBytes
;
1186 Instance
= INSTANCE_FROM_DISKIO_THIS(This
);
1188 if (MediaId
!= Instance
->Media
.MediaId
) {
1189 return EFI_MEDIA_CHANGED
;
1192 BlockSize
= Instance
->Media
.BlockSize
;
1193 Lba
= (EFI_LBA
) DivU64x32Remainder (DiskOffset
, BlockSize
, &BlockOffset
);
1195 RemainingBytes
= BufferSize
;
1197 // Write either all the remaining bytes, or the number of bytes that bring
1198 // us up to a block boundary, whichever is less.
1199 // (DiskOffset | (BlockSize - 1)) + 1) rounds DiskOffset up to the next
1200 // block boundary (even if it is already on one).
1201 WriteSize
= MIN (RemainingBytes
, ((DiskOffset
| (BlockSize
- 1)) + 1) - DiskOffset
);
1204 if (WriteSize
== BlockSize
) {
1205 // Write a full block
1206 Status
= NorFlashWriteFullBlock (Instance
, Lba
, Buffer
, BlockSize
/ sizeof (UINT32
));
1208 // Write a partial block
1209 Status
= NorFlashWriteSingleBlock (Instance
, Lba
, BlockOffset
, &WriteSize
, Buffer
);
1211 if (EFI_ERROR (Status
)) {
1214 // Now continue writing either all the remaining bytes or single blocks.
1215 RemainingBytes
-= WriteSize
;
1216 Buffer
= (UINT8
*) Buffer
+ WriteSize
;
1219 WriteSize
= MIN (RemainingBytes
, BlockSize
);
1220 } while (RemainingBytes
);
1227 IN NOR_FLASH_INSTANCE
*Instance
1230 // As there is no specific RESET to perform, ensure that the devices is in the default Read Array mode
1231 SEND_NOR_COMMAND (Instance
->DeviceBaseAddress
, 0, P30_CMD_READ_ARRAY
);
1236 Fixup internal data so that EFI can be call in virtual mode.
1237 Call the passed in Child Notify event and convert any pointers in
1238 lib to virtual mode.
1240 @param[in] Event The Event that is being processed
1241 @param[in] Context Event Context
1245 NorFlashVirtualNotifyEvent (
1252 for (Index
= 0; Index
< mNorFlashDeviceCount
; Index
++) {
1253 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->DeviceBaseAddress
);
1254 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->RegionBaseAddress
);
1256 // Convert BlockIo protocol
1257 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->BlockIoProtocol
.FlushBlocks
);
1258 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->BlockIoProtocol
.ReadBlocks
);
1259 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->BlockIoProtocol
.Reset
);
1260 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->BlockIoProtocol
.WriteBlocks
);
1263 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->FvbProtocol
.EraseBlocks
);
1264 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->FvbProtocol
.GetAttributes
);
1265 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->FvbProtocol
.GetBlockSize
);
1266 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->FvbProtocol
.GetPhysicalAddress
);
1267 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->FvbProtocol
.Read
);
1268 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->FvbProtocol
.SetAttributes
);
1269 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->FvbProtocol
.Write
);
1271 if (mNorFlashInstances
[Index
]->ShadowBuffer
!= NULL
) {
1272 EfiConvertPointer (0x0, (VOID
**)&mNorFlashInstances
[Index
]->ShadowBuffer
);
1281 NorFlashInitialise (
1282 IN EFI_HANDLE ImageHandle
,
1283 IN EFI_SYSTEM_TABLE
*SystemTable
1288 NOR_FLASH_DESCRIPTION
* NorFlashDevices
;
1289 BOOLEAN ContainVariableStorage
;
1291 Status
= NorFlashPlatformInitialization ();
1292 if (EFI_ERROR(Status
)) {
1293 DEBUG((EFI_D_ERROR
,"NorFlashInitialise: Fail to initialize Nor Flash devices\n"));
1297 Status
= NorFlashPlatformGetDevices (&NorFlashDevices
, &mNorFlashDeviceCount
);
1298 if (EFI_ERROR(Status
)) {
1299 DEBUG((EFI_D_ERROR
,"NorFlashInitialise: Fail to get Nor Flash devices\n"));
1303 mNorFlashInstances
= AllocateRuntimePool (sizeof(NOR_FLASH_INSTANCE
*) * mNorFlashDeviceCount
);
1305 for (Index
= 0; Index
< mNorFlashDeviceCount
; Index
++) {
1306 // Check if this NOR Flash device contain the variable storage region
1307 ContainVariableStorage
=
1308 (NorFlashDevices
[Index
].RegionBaseAddress
<= PcdGet32 (PcdFlashNvStorageVariableBase
)) &&
1309 (PcdGet32 (PcdFlashNvStorageVariableBase
) + PcdGet32 (PcdFlashNvStorageVariableSize
) <= NorFlashDevices
[Index
].RegionBaseAddress
+ NorFlashDevices
[Index
].Size
);
1311 Status
= NorFlashCreateInstance (
1312 NorFlashDevices
[Index
].DeviceBaseAddress
,
1313 NorFlashDevices
[Index
].RegionBaseAddress
,
1314 NorFlashDevices
[Index
].Size
,
1316 NorFlashDevices
[Index
].BlockSize
,
1317 ContainVariableStorage
,
1318 &mNorFlashInstances
[Index
]
1320 if (EFI_ERROR(Status
)) {
1321 DEBUG((EFI_D_ERROR
,"NorFlashInitialise: Fail to create instance for NorFlash[%d]\n",Index
));
1326 // Register for the virtual address change event
1328 Status
= gBS
->CreateEventEx (
1331 NorFlashVirtualNotifyEvent
,
1333 &gEfiEventVirtualAddressChangeGuid
,
1334 &mNorFlashVirtualAddrChangeEvent
1336 ASSERT_EFI_ERROR (Status
);