From nobody Wed Dec 25 13:38:37 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 1509422410556845.703808643851; Mon, 30 Oct 2017 21:00:10 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B01712034AB38; Mon, 30 Oct 2017 20:56:14 -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 A862A2034AB33 for ; Mon, 30 Oct 2017 20:56:09 -0700 (PDT) Received: by mail-lf0-x244.google.com with SMTP id a132so17357598lfa.7 for ; Mon, 30 Oct 2017 21:00:01 -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 f21sm107393lja.25.2017.10.30.20.59.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Oct 2017 20:59:58 -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=6l5GSy/1JEXyilT4xEVorKlP3/EuPXxXaZ1m19eF3r4=; b=hU9E/G9wRXc5FzyalsExqmpqef4KW+qFkIzConvAAH9CiP7HKb8glo2VSV1iKIMadU 3ZNf56G2WMiZni9f+uOjkIG+m3kG0lyqQxcoHjukW9rU9yFT3XwD92+MvTYyX3pyZXuC xHO1GaLfaFh4PMtWGE0vtQz0gE2+0jxHB//T91uc3eU92WyNamekw6OVBvfujoSd2CSE WMQxZYiabHCJFLzq6TNK7D1/V32Ub38P/JQy67Qa37lpHRdWB2RTavdc+ByzYtnn36hc sKlHUYvYvCyYVpzOOFW/8Nmxk2K6Ll1+Ryvc/foLdzdniGtURcH0lwPPh9Ywtzt6d/Dm nyNg== 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=6l5GSy/1JEXyilT4xEVorKlP3/EuPXxXaZ1m19eF3r4=; b=hU4QgKMDVGlggOQF/Nkb4I0eIV0mm145jYBIfhYBlVDJbHZH3EK9eqP0DdM272bYW6 XA7qJWbs1+KIVBJKYK96/qbw+0jqotJ8f2/eL4VvHEqal9rIp9Ur9xZ7w/FxpQmTdqbw nMnvO2wKHxwJJh6lJ4WoG7BBCXFQkslFAN0aNsuB0g/T7kKScHEu7TB+sSQolIaRTHjf QeSr8LZjfv+y/D3JtO0qps5lDI0te15A3wyfPdwg0t6GMK6Gms+S9qcgVBl8g/uNyehD D3i6eLswWaieySD1nZTPKh4Cvop3wDBOxjleliXXA8RLP/0KebjkUI3rw7UPnU7ydUJy dHvQ== X-Gm-Message-State: AMCzsaWWUUZnAiT9FY5ldjTWUlYfnEWdwAyTcJOLj/H+aqt9AwfKN6P2 nlZOEtqaPVckRFshX5/AhUzXe92SizI= X-Google-Smtp-Source: ABhQp+SN62obo5kk0Ngy1rZMzgwevxLB1DoJiZLTRxHNOSwh8wxBG0S8ViqRmtreuOy2vcECyaMhsw== X-Received: by 10.46.2.208 with SMTP id y77mr231275lje.183.1509422398976; Mon, 30 Oct 2017 20:59:58 -0700 (PDT) From: Marcin Wojtas To: edk2-devel@lists.01.org Date: Tue, 31 Oct 2017 04:59:33 +0100 Message-Id: <1509422375-20198-5-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509422375-20198-1-git-send-email-mw@semihalf.com> References: <1509422375-20198-1-git-send-email-mw@semihalf.com> Subject: [edk2] [platforms: PATCH 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 | 8 ++++---- Platform/Marvell/Drivers/Spi/MvSpiDxe.c | 17 +++++++++-----= --- Platform/Marvell/Drivers/Spi/MvSpiDxe.h | 1 + Platform/Marvell/Include/Protocol/Spi.h | 1 + 5 files changed, 17 insertions(+), 14 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..1084f68 100644 --- a/Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c +++ b/Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c @@ -191,7 +191,7 @@ ShellCommandRunSpiFlash ( ) { EFI_STATUS Status; - SPI_DEVICE *Slave; + STATIC SPI_DEVICE *Slave; LIST_ENTRY *CheckPackage; EFI_PHYSICAL_ADDRESS Address =3D 0, Offset =3D 0; SHELL_FILE_HANDLE FileHandle =3D NULL; @@ -273,7 +273,7 @@ EFI_STATUS Status; Cs =3D PcdGet32 (PcdSpiFlashCs); =20 // Setup new spi device - Slave =3D SpiMasterProtocol->SetupDevice (SpiMasterProtocol, Cs, Mode); + Slave =3D SpiMasterProtocol->SetupDevice (SpiMasterProtocol, Slave, Cs, = Mode); if (Slave =3D=3D NULL) { Print(L"sf: Cannot allocate SPI device!\n"); return SHELL_ABORTED; @@ -285,6 +285,8 @@ EFI_STATUS Status; Status =3D FlashProbe (Slave); if (EFI_ERROR(Status)) { // No supported spi flash detected + SpiMasterProtocol->FreeDevice(Slave); + Slave =3D NULL; return SHELL_ABORTED; } else { return Status; @@ -426,8 +428,6 @@ EFI_STATUS Status; 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 93a8ec0..0cf7914 100644 --- a/Platform/Marvell/Include/Protocol/Spi.h +++ b/Platform/Marvell/Include/Protocol/Spi.h @@ -87,6 +87,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