TianoCore EDK2 master
|
#include <Base.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/TimerLib.h>
#include <Protocol/SpiConfiguration.h>
#include <Protocol/SpiIo.h>
#include <IndustryStandard/SpiNorFlashJedecSfdp.h>
#include "SpiNorFlash.h"
Go to the source code of this file.
Functions | |
UINT32 | FillWriteBuffer (IN SPI_NOR_FLASH_INSTANCE *Instance, IN UINT8 Opcode, IN UINT32 DummyBytes, IN UINT8 AddressBytesSupported, IN BOOLEAN UseAddress, IN UINT32 Address, IN UINT32 WriteBytes, IN UINT8 *WriteBuffer) |
EFI_STATUS EFIAPI | InternalReadStatus (IN SPI_NOR_FLASH_INSTANCE *Instance, IN UINT32 LengthInBytes, OUT UINT8 *FlashStatus) |
EFI_STATUS | SetWel (IN SPI_NOR_FLASH_INSTANCE *Instance) |
EFI_STATUS | WaitNotWip (IN SPI_NOR_FLASH_INSTANCE *SpiNorFlashInstance, IN UINT32 Timeout, IN UINT32 RetryCount) |
EFI_STATUS | WaitWelNotWip (IN SPI_NOR_FLASH_INSTANCE *SpiNorFlashInstance, IN UINT32 Timeout, IN UINT32 RetryCount) |
EFI_STATUS | WaitNotWelNotWip (IN SPI_NOR_FLASH_INSTANCE *SpiNorFlashInstance, IN UINT32 Timeout, IN UINT32 RetryCount) |
EFI_STATUS EFIAPI | GetFlashId (IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, OUT UINT8 *Buffer) |
EFI_STATUS EFIAPI | LfReadData (IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 FlashAddress, IN UINT32 LengthInBytes, OUT UINT8 *Buffer) |
EFI_STATUS EFIAPI | ReadData (IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 FlashAddress, IN UINT32 LengthInBytes, OUT UINT8 *Buffer) |
EFI_STATUS EFIAPI | ReadStatus (IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 LengthInBytes, OUT UINT8 *FlashStatus) |
EFI_STATUS EFIAPI | WriteStatus (IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 LengthInBytes, IN UINT8 *FlashStatus) |
EFI_STATUS EFIAPI | WriteData (IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 FlashAddress, IN UINT32 LengthInBytes, IN UINT8 *Buffer) |
EFI_STATUS EFIAPI | Erase (IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 FlashAddress, IN UINT32 BlockCount) |
SPI NOR Flash operation functions.
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file SpiNorFlash.c.
EFI_STATUS EFIAPI Erase | ( | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL * | This, |
IN UINT32 | FlashAddress, | ||
IN UINT32 | BlockCount | ||
) |
Efficiently erases blocks in the SPI flash.
This routine must be called at or below TPL_NOTIFY. This routine may use the combination of variable earse sizes to erase the specified area accroding to the flash region.
[in] | This | Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure. |
[in] | FlashAddress | Address to start erasing |
[in] | BlockCount | Number of blocks to erase. The block size is indicated in EraseBlockBytes in EFI_SPI_NOR_FLASH_PROTOCOL. |
EFI_SUCCESS | The erase was completed successfully. |
EFI_DEVICE_ERROR | The flash devices has problems. |
EFI_INVALID_PARAMETER | The given FlashAddress and/or BlockCount is invalid. |
Definition at line 971 of file SpiNorFlash.c.
UINT32 FillWriteBuffer | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN UINT8 | Opcode, | ||
IN UINT32 | DummyBytes, | ||
IN UINT8 | AddressBytesSupported, | ||
IN BOOLEAN | UseAddress, | ||
IN UINT32 | Address, | ||
IN UINT32 | WriteBytes, | ||
IN UINT8 * | WriteBuffer | ||
) |
Fill Write Buffer with Opcode, Address, Dummy Bytes, and Data.
[in] | Instance | The instance of SPI_NOR_FLASH |
[in] | Opcode | Opcode for transaction |
[in] | DummyBytes | The dummy bytes send to SPI flash device |
[in] | AddressBytesSupported | Bytes of address supported by SPI flash device |
[in] | UseAddress | Send the address for SPI flash command |
[in] | Address | SPI Offset Start Address |
[in] | WriteBytes | Number of bytes to write to SPI device |
[in] | WriteBuffer | Buffer containing bytes to write to SPI device |
Size | of Data in Buffer |
Definition at line 35 of file SpiNorFlash.c.
EFI_STATUS EFIAPI GetFlashId | ( | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL * | This, |
OUT UINT8 * | Buffer | ||
) |
Read the 3 byte manufacture and device ID from the SPI flash.
This routine must be called at or below TPL_NOTIFY. This routine reads the 3 byte manufacture and device ID from the flash part filling the buffer provided.
[in] | This | Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure. |
[out] | Buffer | Pointer to a 3 byte buffer to receive the manufacture and device ID. |
EFI_SUCCESS | The manufacture and device ID was read successfully. |
EFI_INVALID_PARAMETER | Buffer is NULL |
EFI_DEVICE_ERROR | Invalid data received from SPI flash part. |
Definition at line 415 of file SpiNorFlash.c.
EFI_STATUS EFIAPI InternalReadStatus | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance, |
IN UINT32 | LengthInBytes, | ||
OUT UINT8 * | FlashStatus | ||
) |
Internal Read the flash status register.
This routine reads the flash part status register.
[in] | Instance | SPI_NOR_FLASH_INSTANCE structure. |
[in] | LengthInBytes | Number of status bytes to read. |
[out] | FlashStatus | Pointer to a buffer to receive the flash status. |
EFI_SUCCESS | The status register was read successfully. |
Definition at line 153 of file SpiNorFlash.c.
EFI_STATUS EFIAPI LfReadData | ( | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL * | This, |
IN UINT32 | FlashAddress, | ||
IN UINT32 | LengthInBytes, | ||
OUT UINT8 * | Buffer | ||
) |
Read data from the SPI flash at not fast speed.
This routine must be called at or below TPL_NOTIFY. This routine reads data from the SPI part in the buffer provided.
[in] | This | Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure. |
[in] | FlashAddress | Address in the flash to start reading |
[in] | LengthInBytes | Read length in bytes |
[out] | Buffer | Address of a buffer to receive the data |
EFI_SUCCESS | The data was read successfully. |
EFI_INVALID_PARAMETER | Buffer is NULL, or FlashAddress >= This->FlashSize, or LengthInBytes > This->FlashSize - FlashAddress |
Definition at line 484 of file SpiNorFlash.c.
EFI_STATUS EFIAPI ReadData | ( | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL * | This, |
IN UINT32 | FlashAddress, | ||
IN UINT32 | LengthInBytes, | ||
OUT UINT8 * | Buffer | ||
) |
Read data from the SPI flash.
This routine must be called at or below TPL_NOTIFY. This routine reads data from the SPI part in the buffer provided.
[in] | This | Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure. |
[in] | FlashAddress | Address in the flash to start reading |
[in] | LengthInBytes | Read length in bytes |
[out] | Buffer | Address of a buffer to receive the data |
EFI_SUCCESS | The data was read successfully. |
EFI_INVALID_PARAMETER | Buffer is NULL, or FlashAddress >= This->FlashSize, or LengthInBytes > This->FlashSize - FlashAddress |
Definition at line 579 of file SpiNorFlash.c.
EFI_STATUS EFIAPI ReadStatus | ( | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL * | This, |
IN UINT32 | LengthInBytes, | ||
OUT UINT8 * | FlashStatus | ||
) |
Read the flash status register.
This routine must be called at or below TPL_NOTIFY. This routine reads the flash part status register.
[in] | This | Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure. |
[in] | LengthInBytes | Number of status bytes to read. |
[out] | FlashStatus | Pointer to a buffer to receive the flash status. |
EFI_SUCCESS | The status register was read successfully. |
Definition at line 707 of file SpiNorFlash.c.
EFI_STATUS SetWel | ( | IN SPI_NOR_FLASH_INSTANCE * | Instance | ) |
Set Write Enable Latch.
[in] | Instance | SPI NOR instance with all protocols, etc. |
EFI_SUCCESS | SPI Write Enable succeeded |
EFI_DEVICE_ERROR | SPI Flash part did not respond properly |
Definition at line 198 of file SpiNorFlash.c.
EFI_STATUS WaitNotWelNotWip | ( | IN SPI_NOR_FLASH_INSTANCE * | SpiNorFlashInstance, |
IN UINT32 | Timeout, | ||
IN UINT32 | RetryCount | ||
) |
Check for not write enable latch set and not device write in progress.
[in] | SpiNorFlashInstance | SPI NOR instance with all protocols, etc. |
[in] | Timeout | Timeout in microsecond |
[in] | RetryCount | The retry count |
EFI_SUCCESS | Device does not have a write in progress and write enable latch is not set |
EFI_DEVICE_ERROR | SPI Flash part did not respond properly |
Definition at line 356 of file SpiNorFlash.c.
EFI_STATUS WaitNotWip | ( | IN SPI_NOR_FLASH_INSTANCE * | SpiNorFlashInstance, |
IN UINT32 | Timeout, | ||
IN UINT32 | RetryCount | ||
) |
Check for not device write in progress.
[in] | SpiNorFlashInstance | SPI NOR instance with all protocols, etc. |
[in] | Timeout | Timeout in microsecond |
[in] | RetryCount | The retry count |
EFI_SUCCESS | Device does not have a write in progress |
EFI_DEVICE_ERROR | SPI Flash part did not respond properly |
Definition at line 246 of file SpiNorFlash.c.
EFI_STATUS WaitWelNotWip | ( | IN SPI_NOR_FLASH_INSTANCE * | SpiNorFlashInstance, |
IN UINT32 | Timeout, | ||
IN UINT32 | RetryCount | ||
) |
Check for write enable latch set and not device write in progress.
[in] | SpiNorFlashInstance | SPI NOR instance with all protocols, etc. |
[in] | Timeout | Timeout in microsecond |
[in] | RetryCount | The retry count |
EFI_SUCCESS | Device does not have a write in progress and write enable latch is set |
EFI_DEVICE_ERROR | SPI Flash part did not respond properly |
Definition at line 301 of file SpiNorFlash.c.
EFI_STATUS EFIAPI WriteData | ( | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL * | This, |
IN UINT32 | FlashAddress, | ||
IN UINT32 | LengthInBytes, | ||
IN UINT8 * | Buffer | ||
) |
Write data to the SPI flash.
This routine must be called at or below TPL_NOTIFY. This routine breaks up the write operation as necessary to write the data to the SPI part.
[in] | This | Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure. |
[in] | FlashAddress | Address in the flash to start writing |
[in] | LengthInBytes | Write length in bytes |
[in] | Buffer | Address of a buffer containing the data |
EFI_SUCCESS | The data was written successfully. |
EFI_INVALID_PARAMETER | Buffer is NULL, or FlashAddress >= This->FlashSize, or LengthInBytes > This->FlashSize - FlashAddress |
EFI_OUT_OF_RESOURCES | Insufficient memory to copy buffer. |
Definition at line 826 of file SpiNorFlash.c.
EFI_STATUS EFIAPI WriteStatus | ( | IN CONST EFI_SPI_NOR_FLASH_PROTOCOL * | This, |
IN UINT32 | LengthInBytes, | ||
IN UINT8 * | FlashStatus | ||
) |
Write the flash status register.
This routine must be called at or below TPL_N OTIFY. This routine writes the flash part status register.
[in] | This | Pointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure. |
[in] | LengthInBytes | Number of status bytes to write. |
[in] | FlashStatus | Pointer to a buffer containing the new status. |
EFI_SUCCESS | The status write was successful. |
EFI_OUT_OF_RESOURCES | Failed to allocate the write buffer. |
Definition at line 744 of file SpiNorFlash.c.