From 822f314f2c29a589ebde99ea4a10a4e0f84cbd50 Mon Sep 17 00:00:00 2001 From: Marcin Wojtas Date: Mon, 25 Sep 2017 03:25:14 +0200 Subject: Marvell/Drivers: MvSpiFlash: Improve ReadId Fix the ReadId routine by using master's ReadWrite callback instead of the raw Transfer - no longer swapping and byte shifting is needed. Simplify code by using local array instead of dynamic allocation. Moreover store the FlashId in an UINT8 array PCD instead of the concatenated UINT32 format - this way less overhead in the driver is needed for comparing the buffers. The new handling allowed for cleaning Fupdate and Sf shell commands FlashProbe routines. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas Reviewed-by: Leif Lindholm --- Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c | 41 +++++++++++++---------- Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h | 2 ++ 2 files changed, 26 insertions(+), 17 deletions(-) (limited to 'Platform/Marvell/Drivers/Spi/Devices') diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c index 6f7d9c7f07..ab3ed6a55a 100755 --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c @@ -409,28 +409,35 @@ MvSpiFlashReadId ( ) { EFI_STATUS Status; - UINT8 *DataOut; + UINT8 Id[NOR_FLASH_MAX_ID_LEN]; + UINT8 Cmd; + + Cmd = CMD_READ_ID; + Status = SpiMasterProtocol->ReadWrite (SpiMasterProtocol, + SpiDev, + &Cmd, + SPI_CMD_LEN, + NULL, + Id, + NOR_FLASH_MAX_ID_LEN); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "ReadId: Spi transfer error\n")); + return Status; + } - DataOut = (UINT8 *) AllocateZeroPool (DataByteCount); - if (DataOut == NULL) { - DEBUG((DEBUG_ERROR, "SpiFlash: Cannot allocate memory\n")); - return EFI_OUT_OF_RESOURCES; + if (CompareMem (Id, Buffer, DataByteCount) != 0) { + Status = EFI_NOT_FOUND; } - Status = SpiMasterProtocol->Transfer (SpiMasterProtocol, SpiDev, - DataByteCount, Buffer, DataOut, SPI_TRANSFER_BEGIN | SPI_TRANSFER_END); - if (EFI_ERROR(Status)) { - FreePool (DataOut); - DEBUG((DEBUG_ERROR, "SpiFlash: Spi transfer error\n")); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "%a: Unrecognized JEDEC Id bytes: 0x%02x%02x%02x\n", + __FUNCTION__, + Id[0], + Id[1], + Id[2])); return Status; } - // Bytes 1,2 and 3 contain SPI flash ID - Buffer[0] = DataOut[1]; - Buffer[1] = DataOut[2]; - Buffer[2] = DataOut[3]; - - FreePool (DataOut); - return EFI_SUCCESS; } diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h index f90abb771e..2583484afe 100755 --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h @@ -62,6 +62,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define CMD_ERASE_64K 0xd8 #define CMD_4B_ADDR_ENABLE 0xb7 +#define SPI_CMD_LEN 1 + #define STATUS_REG_POLL_WIP (1 << 0) #define STATUS_REG_POLL_PEC (1 << 7) -- cgit v1.2.3