From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::232; helo=mail-wr0-x232.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x232.google.com (mail-wr0-x232.google.com [IPv6:2a00:1450:400c:c0c::232]) (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 19DF22095B06C for ; Thu, 5 Oct 2017 06:24:52 -0700 (PDT) Received: by mail-wr0-x232.google.com with SMTP id k62so10833759wrc.9 for ; Thu, 05 Oct 2017 06:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wdrEg+KSg9Tz1AD76r+MUIod729tpUJ0EyTAQGQ6weQ=; b=Vvqkiga2l5pPxtoS/2/aHyRmg/SwYKaF391BsynhaLfzPOpLT4ePMt2vEfBD1u7cOz L78QSy2kq+Sz7wUZRKnWbuOMHu584hP9gHcZ4JChHknb4VCNYxqwP0xCKyZVutXzb0Kd MXfwVE/uGV2cMsMwxuM8frgzETtoKmZMctoC8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wdrEg+KSg9Tz1AD76r+MUIod729tpUJ0EyTAQGQ6weQ=; b=ARerOuXjefJhzSgz7YSW/sq6h3XhFeZblM7qW5+I+D+WGZlFk/jqXN4/Nv1T7Bd6lz Sz5wvu5W04UvCeOjfoHIrUBuIMtMmI7A/TwYYrpcWW0jfYvnb5KkqvF2m2FS/e2mABDz OumgdEurF3qoYerTjNH5yXmoVm5/mOL8cljs3D1EHaFVUGPH0LZ5GeF3PRO65iK57BYc iD+aJ8OjNDn28EAg97d7ImLggf8ZRPmeqQqQKN71KC+tJNOREDSlLtEwFIxnM1ZaKry3 WvPewRfp+1LPeyhFt2zvIveBq/AF6bcwKWZb+8Hb2d33YniNLp7VAccnP+mKpq8MSlGk XB5w== X-Gm-Message-State: AMCzsaVcBxTCfgXkMnHDPcutmYjTYVSQJQZaYePJ8b+FDkO11xPsaBNS Ch3Lf7cd1jFID5Us0HstSYgls04w0pY= X-Google-Smtp-Source: AOwi7QDOKpS+/vtFkH1p5vs2XtYWxYvXac1yT8YVdW+/ZXD32lDCEigPVnWkT7P8wsy/+E1KiEe/SA== X-Received: by 10.223.182.156 with SMTP id j28mr14281354wre.46.1507210094185; Thu, 05 Oct 2017 06:28:14 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id r134sm934952wmf.3.2017.10.05.06.28.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Oct 2017 06:28:12 -0700 (PDT) Date: Thu, 5 Oct 2017 14:28:10 +0100 From: Leif Lindholm To: Marcin Wojtas Cc: edk2-devel@lists.01.org, ard.biesheuvel@linaro.org, nadavh@marvell.com, neta@marvell.com, kostap@marvell.com, jinghua@marvell.com, agraf@suse.de, jsd@semihalf.com Message-ID: <20171005132810.gxnp7q57ocvrghed@bivouac.eciton.net> References: <1506304319-8620-1-git-send-email-mw@semihalf.com> <1506304319-8620-10-git-send-email-mw@semihalf.com> MIME-Version: 1.0 In-Reply-To: <1506304319-8620-10-git-send-email-mw@semihalf.com> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [platforms: PATCH 09/10] Marvell/Drivers: MvSpiFlash: Fix usage of erase size parameter 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: , X-List-Received-Date: Thu, 05 Oct 2017 13:24:53 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Sep 25, 2017 at 03:51:58AM +0200, Marcin Wojtas wrote: > Although, hitherto support allowed for using configurable EraseSize, > the erase command was fixed to CMD_ERASE_64K. Also it was > assumed that EraseSize equals SectorSize, which is not true > for some flash devices. Fix both issues by adding new PCD > (gMarvellTokenSpaceGuid.PcdSpiFlashPageSize) and using > this parameter properly in MvSpiFlashUpdate routine instead > of the EraseSize. Also erase command is adjusted to the settings. > Update PortingGuide accordingly. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Marcin Wojtas > --- > Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c | 26 +++++++++++++++----- > Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h | 6 +++++ > Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf | 1 + > Platform/Marvell/Marvell.dec | 1 + > Silicon/Marvell/Documentation/PortingGuide.txt | 3 +++ > 5 files changed, 31 insertions(+), 6 deletions(-) > > diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c > index 9a04493..c411296 100755 > --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c > +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.c > @@ -191,7 +191,21 @@ MvSpiFlashErase ( > return EFI_DEVICE_ERROR; > } > > - Cmd[0] = CMD_ERASE_64K; > + switch (EraseSize) { > + case SIZE_4K: > + Cmd[0] = CMD_ERASE_4K; > + break; > + case SIZE_32K: > + Cmd[0] = CMD_ERASE_32K; > + break; > + case SIZE_64K: > + Cmd[0] = CMD_ERASE_64K; > + break; > + default: > + DEBUG ((DEBUG_ERROR, "MvSpiFlash: Invalid EraseSize parameter\n")); > + return EFI_INVALID_PARAMETER; > + } > + > while (Length) { > EraseAddr = Offset; > > @@ -353,14 +367,14 @@ MvSpiFlashUpdate ( > ) > { > EFI_STATUS Status; > - UINT64 EraseSize, ToUpdate, Scale = 1; > + UINT64 SectorSize, ToUpdate, Scale = 1; > UINT8 *TmpBuf, *End; > > - EraseSize = PcdGet64 (PcdSpiFlashEraseSize); > + SectorSize = PcdGet64 (PcdSpiFlashSectorSize); > > End = Buf + ByteCount; > > - TmpBuf = (UINT8 *)AllocateZeroPool (EraseSize); > + TmpBuf = (UINT8 *)AllocateZeroPool (SectorSize); > if (TmpBuf == NULL) { > DEBUG((DEBUG_ERROR, "SpiFlash: Cannot allocate memory\n")); > return EFI_OUT_OF_RESOURCES; > @@ -370,9 +384,9 @@ MvSpiFlashUpdate ( > Scale = (End - Buf) / 100; > > for (; Buf < End; Buf += ToUpdate, Offset += ToUpdate) { > - ToUpdate = MIN((UINT64)(End - Buf), EraseSize); > + ToUpdate = MIN((UINT64)(End - Buf), SectorSize); > Print (L" \rUpdating, %d%%", 100 - (End - Buf) / Scale); > - Status = MvSpiFlashUpdateBlock (Slave, Offset, ToUpdate, Buf, TmpBuf, EraseSize); > + Status = MvSpiFlashUpdateBlock (Slave, Offset, ToUpdate, Buf, TmpBuf, SectorSize); > > if (EFI_ERROR (Status)) { > DEBUG((DEBUG_ERROR, "SpiFlash: Error while updating\n")); > diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h > index 3889643..49cce43 100755 > --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h > +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.h > @@ -57,6 +57,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > #define CMD_READ_ARRAY_FAST 0x0b > #define CMD_PAGE_PROGRAM 0x02 > #define CMD_BANK_WRITE 0xc5 > +#define CMD_ERASE_4K 0x20 > +#define CMD_ERASE_32K 0x52 > #define CMD_ERASE_64K 0xd8 > #define CMD_4B_ADDR_ENABLE 0xb7 > > @@ -66,6 +68,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > #define SPI_TRANSFER_BEGIN 0x01 // Assert CS before transfer > #define SPI_TRANSFER_END 0x02 // Deassert CS after transfers > > +#define SIZE_4K 4096 > +#define SIZE_32K 32768 > +#define SIZE_64K 65536 > + Sorry, this was me being unclear: my meaning was "please just use the existing defines from BaseLib". If deleting this hunk is sufficient to resolve this, I can fold that in when pushing. / Leif > #define SPI_FLASH_16MB_BOUN 0x1000000 > > typedef enum { > diff --git a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf > index d035d47..4519b02 100644 > --- a/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf > +++ b/Platform/Marvell/Drivers/Spi/Devices/MvSpiFlash.inf > @@ -58,6 +58,7 @@ > gMarvellTokenSpaceGuid.PcdSpiFlashEraseSize > gMarvellTokenSpaceGuid.PcdSpiFlashPageSize > gMarvellTokenSpaceGuid.PcdSpiFlashPollCmd > + gMarvellTokenSpaceGuid.PcdSpiFlashSectorSize > > [Protocols] > gMarvellSpiMasterProtocolGuid > diff --git a/Platform/Marvell/Marvell.dec b/Platform/Marvell/Marvell.dec > index 869e376..fc00f1a 100644 > --- a/Platform/Marvell/Marvell.dec > +++ b/Platform/Marvell/Marvell.dec > @@ -127,6 +127,7 @@ > gMarvellTokenSpaceGuid.PcdSpiFlashAddressCycles|0|UINT32|0x3000053 > gMarvellTokenSpaceGuid.PcdSpiFlashEraseSize|0|UINT64|0x3000054 > gMarvellTokenSpaceGuid.PcdSpiFlashPageSize|0|UINT32|0x3000055 > + gMarvellTokenSpaceGuid.PcdSpiFlashSectorSize|65536|UINT64|0x3000059 > gMarvellTokenSpaceGuid.PcdSpiFlashId|0|UINT32|0x3000056 > gMarvellTokenSpaceGuid.PcdSpiFlashCs|0|UINT32|0x3000057 > gMarvellTokenSpaceGuid.PcdSpiFlashMode|0|UINT32|0x3000058 > diff --git a/Silicon/Marvell/Documentation/PortingGuide.txt b/Silicon/Marvell/Documentation/PortingGuide.txt > index 2be658e..83ebe9d 100644 > --- a/Silicon/Marvell/Documentation/PortingGuide.txt > +++ b/Silicon/Marvell/Documentation/PortingGuide.txt > @@ -298,6 +298,9 @@ Folowing PCDs for spi flash driver configuration must be set properly: > - gMarvellTokenSpaceGuid.PcdSpiFlashPageSize > (Size of SPI flash page) > > + - gMarvellTokenSpaceGuid.PcdSpiFlashSectorSize > + (Size of SPI flash sector, 65536 bytes by default) > + > - gMarvellTokenSpaceGuid.PcdSpiFlashId > (Id of SPI flash) > > -- > 1.8.3.1 >