- return Status;\r
-}
-
-EFI_STATUS
-NorFlashReadCfiData (
- IN UINTN BaseAddress,
- IN UINTN CfiOffset,
- IN UINT32 NumberOfBytes,
- OUT UINT32 *Data
- )
-{
- UINT32 CurrentByte;
- UINTN ReadAddress;
- UINT32 ReadData;
- UINT32 Byte1;
- UINT32 Byte2;
- UINT32 CombinedData = 0;
- EFI_STATUS Status = EFI_SUCCESS;
-
-
- if (NumberOfBytes > 4) {
- // Using 32 bit variable so can only read 4 bytes
- return EFI_INVALID_PARAMETER;
- }
-
- // First combine the base address with the offset address to create an absolute read address.
- // However, because we are in little endian, read from the last address down to the first
- ReadAddress = CREATE_NOR_ADDRESS (BaseAddress, CfiOffset) + (NumberOfBytes - 1) * sizeof(UINT32);
-
- // Although each read returns 32 bits, because of the NOR Flash structure,
- // each 16 bits (16 MSB and 16 LSB) come from two different chips.
- // When in CFI mode, each chip read returns valid data in only the 8 LSBits;
- // the 8 MSBits are invalid and can be ignored.
- // Therefore, each read address returns one byte from each chip.
- //
- // Also note: As we are in little endian notation and we are reading
- // bytes from incremental addresses, we should assemble them in little endian order.
- for (CurrentByte=0; CurrentByte<NumberOfBytes; CurrentByte++) {
- // Read the bytes from the two chips
- ReadData = MmioRead32(ReadAddress);
-
- // Check the data validity:
- // The 'Dual Data' function means that
- // each chip should return identical data.
- // If that is not the case then we have a problem.
- Byte1 = GET_LOW_BYTE (ReadData);
- Byte2 = GET_HIGH_BYTE(ReadData);
-
- if(Byte1 != Byte2) {
- // The two bytes should have been identical
- return EFI_DEVICE_ERROR;
- } else {
- // Each successive iteration of the 'for' loop reads a lower address.
- // As we read lower addresses and as we use little endian,
- // we read lower significance bytes. So combine them in the correct order.
- CombinedData = (CombinedData << 8) | Byte1;
-
- // Decrement down to the next address
- ReadAddress -= sizeof(UINT32);
- }
- }
-
- *Data = CombinedData;
-