From nobody Wed Dec 25 14:39:32 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 1509731860993546.0636557594026; Fri, 3 Nov 2017 10:57:40 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id F1A26202E5E6B; Fri, 3 Nov 2017 10:53:38 -0700 (PDT) Received: from mail-lf0-x22c.google.com (mail-lf0-x22c.google.com [IPv6:2a00:1450:4010:c07::22c]) (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 CC634202E5E6B for ; Fri, 3 Nov 2017 10:53:37 -0700 (PDT) Received: by mail-lf0-x22c.google.com with SMTP id r129so4062431lff.8 for ; Fri, 03 Nov 2017 10:57:33 -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.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Nov 2017 10:57:30 -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::22c; helo=mail-lf0-x22c.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=wDcC4mmdpxdpBgO0Nh4rpPK1WBPB2S5isAhf8doiBII=; b=zuyF4ZwdWnhaYQhy0q8Nzz8EszI8cz5B/ZFU75A22etx2YTFT4EItg2hktJLOrmnQS 7Ne9GgWODvarMnOY+I12X6IQbhIZYkh+gwgSBk174hJXHcmM/N2qORQTzfukeJZBi0yY auRSerCVwRAjj8uPZ9MI9VcCa88WW0+hSJaVHVgRR3I6g5o5cJPdVMJ3F9uNqXt54pAO scz4SRaJ4zHGh8oS+WbYgtxelIMR5HUfMNBnMzcv66h8ApskPfXCfzIb9kW3G92Dicpa L2BTyBV0em2s+p+N9gragXPqFtF0LuP1MIhht3z2IBXlFcjMZnoFPVQUQ/IeosR+hn/G xPiA== 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=wDcC4mmdpxdpBgO0Nh4rpPK1WBPB2S5isAhf8doiBII=; b=fDZQqBbiaHBiXVzFdTtIX1mpFkszHOTfETDTE1mNCi6yWcRRokY8x6VFDfnlXLzs3D 30NevNTlhTTtVz8NV/214JH/qccaH1utN3t0ShtZOSEAT7tlnKWVyvO3rwL1P/8CHvf1 8nodV1iz6vb/u6ZankfjMfJjx6kOQVKfdEU8m5vWtSPQ0HSjSHQ2EsAQ1vwjCvGHr0JE 0Pz3M4fTU/87FHk33ZWTlEHsggBFbO6htHPJJQe1Xtv29AHU9qzB2Kem8ceSek04TGUv ip5klRi7DepigIjWsYV1fAiZNN4nowYwYkmn+wmkjBVtbV5TZe3qaae5OHUGByIiY9iT 2Xjw== X-Gm-Message-State: AMCzsaWad9Az6xHV74ikJkca8802zxCGNu0yL5kmvReIXjGWYw9g5Gy5 iN3w0VpM54TDayKe0ipc/pSoS5mezs0= X-Google-Smtp-Source: ABhQp+TsD86WJk1ZLXG3zCh4wUrPnrHpy4jbKI8Z3HY20XSaTcwhe5yKNXXnf00xzqBdMcnmn4VKZA== X-Received: by 10.46.93.137 with SMTP id v9mr3263264lje.39.1509731851118; Fri, 03 Nov 2017 10:57:31 -0700 (PDT) From: Marcin Wojtas To: edk2-devel@lists.01.org Date: Fri, 3 Nov 2017 18:57:13 +0100 Message-Id: <1509731835-5664-5-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 4/6] Marvell/Applications: SpiTool: Do not override existing slave device 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" Current usage of sf command requires running 'sf probe' prior to executing any other option. Because it is done in two separate steps, it turned out that SpiMasterProtocol->SetupDevice could easily overwrite valid Slave pointer when performing second operation. Fix the issue by allocating Slave device only once and keep it as global variable in the SpiTool application. This patch also updates FirmwareUpdate command to follow the modified SetupDevice operation. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas --- Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c | 4 ++-- Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c | 21 ++++++++++----= ------ Platform/Marvell/Drivers/Spi/MvSpiDxe.c | 17 ++++++++------= -- Platform/Marvell/Drivers/Spi/MvSpiDxe.h | 1 + Platform/Marvell/Include/Protocol/Spi.h | 1 + 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c b/Platf= orm/Marvell/Applications/FirmwareUpdate/FUpdate.c index 750e52a..9ccb1c7 100644 --- a/Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c +++ b/Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c @@ -240,7 +240,7 @@ ShellCommandRunFUpdate ( ) { IN SHELL_FILE_HANDLE FileHandle; - SPI_DEVICE *Slave; + SPI_DEVICE *Slave =3D NULL; UINT64 FileSize; UINTN *FileBuffer =3D NULL; CHAR16 *ProblemParam; @@ -302,7 +302,7 @@ ShellCommandRunFUpdate ( } =20 // Setup and probe SPI flash - Slave =3D SpiMasterProtocol->SetupDevice (SpiMasterProtocol, 0, 0); + Slave =3D SpiMasterProtocol->SetupDevice (SpiMasterProtocol, Slave, 0, 0= ); if (Slave =3D=3D NULL) { Print(L"%s: Cannot allocate SPI device!\n", CMD_NAME_STRING); goto HeaderError; diff --git a/Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c b/Platform= /Marvell/Applications/SpiTool/SpiFlashCmd.c index 68a6cf7..cf91581 100644 --- a/Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c +++ b/Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c @@ -58,6 +58,8 @@ EFI_HANDLE gShellSfHiiHandle =3D NULL; =20 BOOLEAN InitFlag =3D 1; =20 +STATIC SPI_DEVICE *mSlave; + STATIC CONST SHELL_PARAM_ITEM ParamList[] =3D { {L"read", TypeFlag}, {L"readfile", TypeFlag}, @@ -191,7 +193,6 @@ ShellCommandRunSpiFlash ( ) { EFI_STATUS Status; - SPI_DEVICE *Slave; LIST_ENTRY *CheckPackage; EFI_PHYSICAL_ADDRESS Address =3D 0, Offset =3D 0; SHELL_FILE_HANDLE FileHandle =3D NULL; @@ -273,8 +274,8 @@ EFI_STATUS Status; Cs =3D PcdGet32 (PcdSpiFlashCs); =20 // Setup new spi device - Slave =3D SpiMasterProtocol->SetupDevice (SpiMasterProtocol, Cs, Mode); - if (Slave =3D=3D NULL) { + mSlave =3D SpiMasterProtocol->SetupDevice (SpiMasterProtocol, mSlave, Cs= , Mode); + if (mSlave =3D=3D NULL) { Print(L"sf: Cannot allocate SPI device!\n"); return SHELL_ABORTED; } @@ -282,9 +283,11 @@ EFI_STATUS Status; switch (Flag) { case PROBE: // Probe spi bus - Status =3D FlashProbe (Slave); + Status =3D FlashProbe (mSlave); if (EFI_ERROR(Status)) { // No supported spi flash detected + SpiMasterProtocol->FreeDevice(mSlave); + mSlave =3D NULL; return SHELL_ABORTED; } else { return Status; @@ -411,23 +414,21 @@ EFI_STATUS Status; switch (Flag) { case READ: case READ_FILE: - Status =3D SpiFlashProtocol->Read (Slave, Offset, ByteCount, Buffer); + Status =3D SpiFlashProtocol->Read (mSlave, Offset, ByteCount, Buffer); break; case ERASE: - Status =3D SpiFlashProtocol->Erase (Slave, Offset, ByteCount); + Status =3D SpiFlashProtocol->Erase (mSlave, Offset, ByteCount); break; case WRITE: case WRITE_FILE: - Status =3D SpiFlashProtocol->Write (Slave, Offset, ByteCount, Buffer); + Status =3D SpiFlashProtocol->Write (mSlave, Offset, ByteCount, Buffer); break; case UPDATE: case UPDATE_FILE: - Status =3D SpiFlashProtocol->Update (Slave, Offset, ByteCount, Buffer); + Status =3D SpiFlashProtocol->Update (mSlave, Offset, ByteCount, Buffer= ); break; } =20 - SpiMasterProtocol->FreeDevice(Slave); - if (EFI_ERROR (Status)) { Print (L"sf: Error while performing spi transfer\n"); return SHELL_ABORTED; diff --git a/Platform/Marvell/Drivers/Spi/MvSpiDxe.c b/Platform/Marvell/Dri= vers/Spi/MvSpiDxe.c index 3b49147..a7db5f2 100755 --- a/Platform/Marvell/Drivers/Spi/MvSpiDxe.c +++ b/Platform/Marvell/Drivers/Spi/MvSpiDxe.c @@ -296,21 +296,22 @@ SPI_DEVICE * EFIAPI MvSpiSetupSlave ( IN MARVELL_SPI_MASTER_PROTOCOL *This, + IN SPI_DEVICE *Slave, IN UINTN Cs, IN SPI_MODE Mode ) { - SPI_DEVICE *Slave; + if (!Slave) { + Slave =3D AllocateZeroPool (sizeof(SPI_DEVICE)); + if (Slave =3D=3D NULL) { + DEBUG((DEBUG_ERROR, "Cannot allocate memory\n")); + return NULL; + } =20 - Slave =3D AllocateZeroPool (sizeof(SPI_DEVICE)); - if (Slave =3D=3D NULL) { - DEBUG((DEBUG_ERROR, "Cannot allocate memory\n")); - return NULL; + Slave->Cs =3D Cs; + Slave->Mode =3D Mode; } =20 - Slave->Cs =3D Cs; - Slave->Mode =3D Mode; - SpiSetupTransfer (This, Slave); =20 return Slave; diff --git a/Platform/Marvell/Drivers/Spi/MvSpiDxe.h b/Platform/Marvell/Dri= vers/Spi/MvSpiDxe.h index 1401f62..e7e280a 100644 --- a/Platform/Marvell/Drivers/Spi/MvSpiDxe.h +++ b/Platform/Marvell/Drivers/Spi/MvSpiDxe.h @@ -125,6 +125,7 @@ SPI_DEVICE * EFIAPI MvSpiSetupSlave ( IN MARVELL_SPI_MASTER_PROTOCOL * This, + IN SPI_DEVICE *Slave, IN UINTN Cs, IN SPI_MODE Mode ); diff --git a/Platform/Marvell/Include/Protocol/Spi.h b/Platform/Marvell/Inc= lude/Protocol/Spi.h index 6f26a36..98fcc07 100644 --- a/Platform/Marvell/Include/Protocol/Spi.h +++ b/Platform/Marvell/Include/Protocol/Spi.h @@ -88,6 +88,7 @@ typedef SPI_DEVICE * (EFIAPI *MV_SPI_SETUP_DEVICE) ( IN MARVELL_SPI_MASTER_PROTOCOL *This, + IN SPI_DEVICE *Slave, IN UINTN Cs, IN SPI_MODE Mode ); --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel