From nobody Wed Dec 25 14:41:26 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1509731851912750.9477560931687; Fri, 3 Nov 2017 10:57:31 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 31708202E5E62; Fri, 3 Nov 2017 10:53:35 -0700 (PDT) Received: from mail-lf0-x244.google.com (mail-lf0-x244.google.com [IPv6:2a00:1450:4010:c07::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 867D8203555FC for ; Fri, 3 Nov 2017 10:53:33 -0700 (PDT) Received: by mail-lf0-x244.google.com with SMTP id a132so4061542lfa.7 for ; Fri, 03 Nov 2017 10:57:28 -0700 (PDT) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id g29sm1120441lfh.3.2017.11.03.10.57.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Nov 2017 10:57:26 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2a00:1450:4010:c07::244; helo=mail-lf0-x244.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=B56zvCwqQmW3c7thsNGineHa5ImOvhdhQOyO+Rh20Y0=; b=qgMTz1uFJZ6S6msuqtrBLKEZMkYIKhvNY2SgUrBmvmOW3QsmwtJKV2YVmiXkdlVUxK SAeLUD6/FFjLFc6/M5Nkj2plXt2P481siEqNcUnp5nAmBkTj+jpN+tHhJi9uh5Cu0CDG N1D/AyZTxyLa0WJYErM98N6GxDEyZgh75WvbEICOWO5xwmQXbvM/s0eyQtU1l29wKZxF Rk4ejReUfdLlNkkvjyg1YeJJFCNlLC/pA1pG8fO6AJ8bIzEnYhnSGcgTPxHO8RmApbZC rbDACZI8oxhNRy0d6OFsb6W3MscNQBBWl/C0dPBUSmovN0yuSnT6yjRMX60kSTxJeqhS ltUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=B56zvCwqQmW3c7thsNGineHa5ImOvhdhQOyO+Rh20Y0=; b=jQTC+zR/medqI3hjEZhDWtL4Cet0TRP89v2iL6pVUAiYenUeXX78QofwJT1O+zWx08 h9bpUNklJYNRjZySQROZdBT7UoI+DK6/symCkKLicwhy8qJETm/Z96oza0z0L+BHS/WL nWokHCWcsUUON+VfWgZy3pa2J12a0+InuAGiOBpSBbBiGDXfTeeQA7BAwdiYMGGwy4Yn FtR6jKzbDUfZlegQsjAor26uizmGKnknGBelM/+NtAst+R9EAzVtQ381G1M9xLiHVFvC tJ4o/ZnOM8XcPDs+s4XPY2TWRCwv30uOR9brjZtZ8uCfpoxIgSVLHXDPy4jTlwFb+zWt W2gQ== X-Gm-Message-State: AMCzsaXmZ7yhTaVHz13uZb/N9Hexqc5gP9TGMFovYcOQWYXAUPltsHMn Qhd+OHAQblCEZbrVeg1AWaeFZpdTFG8= X-Google-Smtp-Source: ABhQp+SCsb3DReHMtzwVdxUnSgUU+o7kAs2Cj5N1QKsqMkSdVdiQAiPnAz2gIBbNP8sK+yWzRc5XAg== X-Received: by 10.46.56.14 with SMTP id f14mr3659107lja.46.1509731846863; Fri, 03 Nov 2017 10:57:26 -0700 (PDT) From: Marcin Wojtas To: edk2-devel@lists.01.org Date: Fri, 3 Nov 2017 18:57:10 +0100 Message-Id: <1509731835-5664-2-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509731835-5664-1-git-send-email-mw@semihalf.com> References: <1509731835-5664-1-git-send-email-mw@semihalf.com> Subject: [edk2] [platforms: PATCH v2 1/6] Marvell/Drivers: MvSpiFlash: Improve ReadId X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jinghua@marvell.com, ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, nadavh@marvell.com, neta@marvell.com, kostap@marvell.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 --- Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c | 24 ++++-------- Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c | 39 +++++++-------= ----- Platform/Marvell/Armada/Armada70x0.dsc | 2 +- Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c | 41 ++++++++++++--= ------ Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h | 2 + Platform/Marvell/Include/Protocol/SpiFlash.h | 2 + Platform/Marvell/Marvell.dec | 2 +- 7 files changed, 51 insertions(+), 61 deletions(-) diff --git a/Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c b/Platf= orm/Marvell/Applications/FirmwareUpdate/FUpdate.c index 664411a..8a2ad3f 100644 --- a/Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c +++ b/Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c @@ -94,28 +94,18 @@ SpiFlashProbe ( ) { EFI_STATUS Status; - UINT32 IdBuffer, Id, RefId; + UINT32 FlashIdLen; + UINT8 *FlashId; =20 - Id =3D PcdGet32 (PcdSpiFlashId); - - IdBuffer =3D CMD_READ_ID & 0xff; + FlashId =3D (UINT8 *)PcdGetPtr (PcdSpiFlashId); + FlashIdLen =3D PcdGetSize (PcdSpiFlashId); =20 // Read SPI flash ID - SpiFlashProtocol->ReadId (Slave, sizeof (UINT32), (UINT8 *)&IdBuffer); - - // Swap and extract 3 bytes of the ID - RefId =3D SwapBytes32 (IdBuffer) >> 8; - - if (RefId =3D=3D 0) { - Print (L"%s: No SPI flash detected"); - return EFI_DEVICE_ERROR; - } else if (RefId !=3D Id) { - Print (L"%s: Unsupported SPI flash detected with ID=3D%2x\n", CMD_NAME= _STRING, RefId); - return EFI_DEVICE_ERROR; + Status =3D SpiFlashProtocol->ReadId (Slave, FlashIdLen, FlashId); + if (EFI_ERROR (Status)) { + return SHELL_ABORTED; } =20 - Print (L"%s: Detected supported SPI flash with ID=3D%3x\n", CMD_NAME_STR= ING, RefId); - Status =3D SpiFlashProtocol->Init (SpiFlashProtocol, Slave); if (EFI_ERROR(Status)) { Print (L"%s: Cannot initialize flash device\n", CMD_NAME_STRING); diff --git a/Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c b/Platform= /Marvell/Applications/SpiTool/SpiFlashCmd.c index 9321f6b..7c81bfc 100644 --- a/Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c +++ b/Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c @@ -166,37 +166,26 @@ FlashProbe ( ) { EFI_STATUS Status; - UINT8 IdBuffer[4]; - UINT32 Id, RefId; + UINT32 FlashIdLen; + UINT8 *FlashId; =20 - Id =3D PcdGet32 (PcdSpiFlashId); + FlashId =3D (UINT8 *)PcdGetPtr (PcdSpiFlashId); + FlashIdLen =3D PcdGetSize (PcdSpiFlashId); =20 - IdBuffer[0] =3D CMD_READ_ID; - - SpiFlashProtocol->ReadId ( - Slave, - 4, - IdBuffer - ); - - RefId =3D (IdBuffer[0] << 16) + (IdBuffer[1] << 8) + IdBuffer[2]; + Status =3D SpiFlashProtocol->ReadId (Slave, FlashIdLen, FlashId); + if (EFI_ERROR (Status)) { + return SHELL_ABORTED; + } =20 - if (RefId =3D=3D Id) { - Print (L"sf: Detected supported SPI flash with ID=3D%3x\n", RefId); - Status =3D SpiFlashProtocol->Init (SpiFlashProtocol, Slave); - if (EFI_ERROR(Status)) { - Print (L"sf: Cannot initialize flash device\n"); - return SHELL_ABORTED; - } - InitFlag =3D 0; - return EFI_SUCCESS; - } else if (RefId !=3D 0) { - Print (L"sf: Unsupported SPI flash detected with ID=3D%2x\n", RefId); + Status =3D SpiFlashProtocol->Init (SpiFlashProtocol, Slave); + if (EFI_ERROR (Status)) { + Print (L"sf: Cannot initialize flash device\n"); return SHELL_ABORTED; } =20 - Print (L"sf: No SPI flash detected"); - return SHELL_ABORTED; + InitFlag =3D 0; + + return SHELL_SUCCESS; } =20 SHELL_STATUS diff --git a/Platform/Marvell/Armada/Armada70x0.dsc b/Platform/Marvell/Arma= da/Armada70x0.dsc index 0396e8e..4d5f55f 100644 --- a/Platform/Marvell/Armada/Armada70x0.dsc +++ b/Platform/Marvell/Armada/Armada70x0.dsc @@ -94,7 +94,7 @@ gMarvellTokenSpaceGuid.PcdSpiFlashAddressCycles|3 gMarvellTokenSpaceGuid.PcdSpiFlashEraseSize|65536 gMarvellTokenSpaceGuid.PcdSpiFlashPageSize|256 - gMarvellTokenSpaceGuid.PcdSpiFlashId|0x20BA18 + gMarvellTokenSpaceGuid.PcdSpiFlashId|{ 0x20, 0xBA, 0x18 } gMarvellTokenSpaceGuid.PcdSpiFlashMode|3 gMarvellTokenSpaceGuid.PcdSpiFlashCs|0 =20 diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c b/Platform/M= arvell/Drivers/Spi/Devices/MvSpiFlash.c index 6f7d9c7..ab3ed6a 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 =3D CMD_READ_ID; + Status =3D 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; + } =20 - DataOut =3D (UINT8 *) AllocateZeroPool (DataByteCount); - if (DataOut =3D=3D NULL) { - DEBUG((DEBUG_ERROR, "SpiFlash: Cannot allocate memory\n")); - return EFI_OUT_OF_RESOURCES; + if (CompareMem (Id, Buffer, DataByteCount) !=3D 0) { + Status =3D EFI_NOT_FOUND; } - Status =3D 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; } =20 - // Bytes 1,2 and 3 contain SPI flash ID - Buffer[0] =3D DataOut[1]; - Buffer[1] =3D DataOut[2]; - Buffer[2] =3D DataOut[3]; - - FreePool (DataOut); - return EFI_SUCCESS; } =20 diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h b/Platform/M= arvell/Drivers/Spi/Devices/MvSpiFlash.h index f90abb7..2583484 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 DAMA= GE. #define CMD_ERASE_64K 0xd8 #define CMD_4B_ADDR_ENABLE 0xb7 =20 +#define SPI_CMD_LEN 1 + #define STATUS_REG_POLL_WIP (1 << 0) #define STATUS_REG_POLL_PEC (1 << 7) =20 diff --git a/Platform/Marvell/Include/Protocol/SpiFlash.h b/Platform/Marvel= l/Include/Protocol/SpiFlash.h index 743bb87..f65a12d 100644 --- a/Platform/Marvell/Include/Protocol/SpiFlash.h +++ b/Platform/Marvell/Include/Protocol/SpiFlash.h @@ -47,6 +47,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMA= GE. #define CMD_ERASE_64K 0xd8 #define CMD_4B_ADDR_ENABLE 0xb7 =20 +#define NOR_FLASH_MAX_ID_LEN 6 + extern EFI_GUID gMarvellSpiFlashProtocolGuid; =20 typedef struct _MARVELL_SPI_FLASH_PROTOCOL MARVELL_SPI_FLASH_PROTOCOL; diff --git a/Platform/Marvell/Marvell.dec b/Platform/Marvell/Marvell.dec index cd800c8..679a9d0 100644 --- a/Platform/Marvell/Marvell.dec +++ b/Platform/Marvell/Marvell.dec @@ -133,7 +133,7 @@ gMarvellTokenSpaceGuid.PcdSpiFlashEraseSize|0|UINT64|0x3000054 gMarvellTokenSpaceGuid.PcdSpiFlashPageSize|0|UINT32|0x3000055 gMarvellTokenSpaceGuid.PcdSpiFlashSectorSize|65536|UINT64|0x3000059 - gMarvellTokenSpaceGuid.PcdSpiFlashId|0|UINT32|0x3000056 + gMarvellTokenSpaceGuid.PcdSpiFlashId|{ 0x0 }|VOID*|0x3000056 gMarvellTokenSpaceGuid.PcdSpiFlashCs|0|UINT32|0x3000057 gMarvellTokenSpaceGuid.PcdSpiFlashMode|0|UINT32|0x3000058 =20 --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel