TianoCore EDK2 master
Loading...
Searching...
No Matches
SpiNorFlash.c File Reference
#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)
 

Detailed Description

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.

Function Documentation

◆ Erase()

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.

Parameters
[in]ThisPointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure.
[in]FlashAddressAddress to start erasing
[in]BlockCountNumber of blocks to erase. The block size is indicated in EraseBlockBytes in EFI_SPI_NOR_FLASH_PROTOCOL.
Return values
EFI_SUCCESSThe erase was completed successfully.
EFI_DEVICE_ERRORThe flash devices has problems.
EFI_INVALID_PARAMETERThe given FlashAddress and/or BlockCount is invalid.

Definition at line 971 of file SpiNorFlash.c.

◆ FillWriteBuffer()

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.

Parameters
[in]InstanceThe instance of SPI_NOR_FLASH
[in]OpcodeOpcode for transaction
[in]DummyBytesThe dummy bytes send to SPI flash device
[in]AddressBytesSupportedBytes of address supported by SPI flash device
[in]UseAddressSend the address for SPI flash command
[in]AddressSPI Offset Start Address
[in]WriteBytesNumber of bytes to write to SPI device
[in]WriteBufferBuffer containing bytes to write to SPI device
Return values
Sizeof Data in Buffer

Definition at line 35 of file SpiNorFlash.c.

◆ GetFlashId()

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.

Parameters
[in]ThisPointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure.
[out]BufferPointer to a 3 byte buffer to receive the manufacture and device ID.
Return values
EFI_SUCCESSThe manufacture and device ID was read successfully.
EFI_INVALID_PARAMETERBuffer is NULL
EFI_DEVICE_ERRORInvalid data received from SPI flash part.

Definition at line 415 of file SpiNorFlash.c.

◆ InternalReadStatus()

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.

Parameters
[in]InstanceSPI_NOR_FLASH_INSTANCE structure.
[in]LengthInBytesNumber of status bytes to read.
[out]FlashStatusPointer to a buffer to receive the flash status.
Return values
EFI_SUCCESSThe status register was read successfully.

Definition at line 153 of file SpiNorFlash.c.

◆ LfReadData()

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.

Parameters
[in]ThisPointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure.
[in]FlashAddressAddress in the flash to start reading
[in]LengthInBytesRead length in bytes
[out]BufferAddress of a buffer to receive the data
Return values
EFI_SUCCESSThe data was read successfully.
EFI_INVALID_PARAMETERBuffer is NULL, or FlashAddress >= This->FlashSize, or LengthInBytes > This->FlashSize - FlashAddress

Definition at line 484 of file SpiNorFlash.c.

◆ ReadData()

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.

Parameters
[in]ThisPointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure.
[in]FlashAddressAddress in the flash to start reading
[in]LengthInBytesRead length in bytes
[out]BufferAddress of a buffer to receive the data
Return values
EFI_SUCCESSThe data was read successfully.
EFI_INVALID_PARAMETERBuffer is NULL, or FlashAddress >= This->FlashSize, or LengthInBytes > This->FlashSize - FlashAddress

Definition at line 579 of file SpiNorFlash.c.

◆ ReadStatus()

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.

Parameters
[in]ThisPointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure.
[in]LengthInBytesNumber of status bytes to read.
[out]FlashStatusPointer to a buffer to receive the flash status.
Return values
EFI_SUCCESSThe status register was read successfully.

Definition at line 707 of file SpiNorFlash.c.

◆ SetWel()

EFI_STATUS SetWel ( IN SPI_NOR_FLASH_INSTANCE Instance)

Set Write Enable Latch.

Parameters
[in]InstanceSPI NOR instance with all protocols, etc.
Return values
EFI_SUCCESSSPI Write Enable succeeded
EFI_DEVICE_ERRORSPI Flash part did not respond properly

Definition at line 198 of file SpiNorFlash.c.

◆ WaitNotWelNotWip()

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.

Parameters
[in]SpiNorFlashInstanceSPI NOR instance with all protocols, etc.
[in]TimeoutTimeout in microsecond
[in]RetryCountThe retry count
Return values
EFI_SUCCESSDevice does not have a write in progress and write enable latch is not set
EFI_DEVICE_ERRORSPI Flash part did not respond properly

Definition at line 356 of file SpiNorFlash.c.

◆ WaitNotWip()

EFI_STATUS WaitNotWip ( IN SPI_NOR_FLASH_INSTANCE SpiNorFlashInstance,
IN UINT32  Timeout,
IN UINT32  RetryCount 
)

Check for not device write in progress.

Parameters
[in]SpiNorFlashInstanceSPI NOR instance with all protocols, etc.
[in]TimeoutTimeout in microsecond
[in]RetryCountThe retry count
Return values
EFI_SUCCESSDevice does not have a write in progress
EFI_DEVICE_ERRORSPI Flash part did not respond properly

Definition at line 246 of file SpiNorFlash.c.

◆ WaitWelNotWip()

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.

Parameters
[in]SpiNorFlashInstanceSPI NOR instance with all protocols, etc.
[in]TimeoutTimeout in microsecond
[in]RetryCountThe retry count
Return values
EFI_SUCCESSDevice does not have a write in progress and write enable latch is set
EFI_DEVICE_ERRORSPI Flash part did not respond properly

Definition at line 301 of file SpiNorFlash.c.

◆ WriteData()

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.

Parameters
[in]ThisPointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure.
[in]FlashAddressAddress in the flash to start writing
[in]LengthInBytesWrite length in bytes
[in]BufferAddress of a buffer containing the data
Return values
EFI_SUCCESSThe data was written successfully.
EFI_INVALID_PARAMETERBuffer is NULL, or FlashAddress >= This->FlashSize, or LengthInBytes > This->FlashSize - FlashAddress
EFI_OUT_OF_RESOURCESInsufficient memory to copy buffer.

Definition at line 826 of file SpiNorFlash.c.

◆ WriteStatus()

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.

Parameters
[in]ThisPointer to an EFI_SPI_NOR_FLASH_PROTOCOL data structure.
[in]LengthInBytesNumber of status bytes to write.
[in]FlashStatusPointer to a buffer containing the new status.
Return values
EFI_SUCCESSThe status write was successful.
EFI_OUT_OF_RESOURCESFailed to allocate the write buffer.

Definition at line 744 of file SpiNorFlash.c.