summaryrefslogtreecommitdiff
path: root/Platform/Marvell
diff options
context:
space:
mode:
authorMarcin Wojtas <mw@semihalf.com>2017-06-26 15:23:26 +0200
committerLeif Lindholm <leif.lindholm@linaro.org>2017-11-07 17:20:21 +0000
commitfedad0018dff31e6581875f9039810cc0319c782 (patch)
tree9079f0081c31b320785d905432034971932d6d38 /Platform/Marvell
parent19eae6ed3397f79b5d9ad682e8adf1cac35e3acb (diff)
downloadedk2-platforms-fedad0018dff31e6581875f9039810cc0319c782.tar.xz
Marvell/Applications: SpiTool: Do not override existing slave device
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 <mw@semihalf.com> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Diffstat (limited to 'Platform/Marvell')
-rw-r--r--Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c4
-rw-r--r--Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c21
-rwxr-xr-xPlatform/Marvell/Drivers/Spi/MvSpiDxe.c17
-rw-r--r--Platform/Marvell/Drivers/Spi/MvSpiDxe.h1
-rw-r--r--Platform/Marvell/Include/Protocol/Spi.h1
5 files changed, 24 insertions, 20 deletions
diff --git a/Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c b/Platform/Marvell/Applications/FirmwareUpdate/FUpdate.c
index 750e52a0ae..9ccb1c749b 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 = NULL;
UINT64 FileSize;
UINTN *FileBuffer = NULL;
CHAR16 *ProblemParam;
@@ -302,7 +302,7 @@ ShellCommandRunFUpdate (
}
// Setup and probe SPI flash
- Slave = SpiMasterProtocol->SetupDevice (SpiMasterProtocol, 0, 0);
+ Slave = SpiMasterProtocol->SetupDevice (SpiMasterProtocol, Slave, 0, 0);
if (Slave == 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 68a6cf756b..cf91581dcf 100644
--- a/Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c
+++ b/Platform/Marvell/Applications/SpiTool/SpiFlashCmd.c
@@ -58,6 +58,8 @@ EFI_HANDLE gShellSfHiiHandle = NULL;
BOOLEAN InitFlag = 1;
+STATIC SPI_DEVICE *mSlave;
+
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"read", TypeFlag},
{L"readfile", TypeFlag},
@@ -191,7 +193,6 @@ ShellCommandRunSpiFlash (
)
{
EFI_STATUS Status;
- SPI_DEVICE *Slave;
LIST_ENTRY *CheckPackage;
EFI_PHYSICAL_ADDRESS Address = 0, Offset = 0;
SHELL_FILE_HANDLE FileHandle = NULL;
@@ -273,8 +274,8 @@ EFI_STATUS Status;
Cs = PcdGet32 (PcdSpiFlashCs);
// Setup new spi device
- Slave = SpiMasterProtocol->SetupDevice (SpiMasterProtocol, Cs, Mode);
- if (Slave == NULL) {
+ mSlave = SpiMasterProtocol->SetupDevice (SpiMasterProtocol, mSlave, Cs, Mode);
+ if (mSlave == 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 = FlashProbe (Slave);
+ Status = FlashProbe (mSlave);
if (EFI_ERROR(Status)) {
// No supported spi flash detected
+ SpiMasterProtocol->FreeDevice(mSlave);
+ mSlave = NULL;
return SHELL_ABORTED;
} else {
return Status;
@@ -411,23 +414,21 @@ EFI_STATUS Status;
switch (Flag) {
case READ:
case READ_FILE:
- Status = SpiFlashProtocol->Read (Slave, Offset, ByteCount, Buffer);
+ Status = SpiFlashProtocol->Read (mSlave, Offset, ByteCount, Buffer);
break;
case ERASE:
- Status = SpiFlashProtocol->Erase (Slave, Offset, ByteCount);
+ Status = SpiFlashProtocol->Erase (mSlave, Offset, ByteCount);
break;
case WRITE:
case WRITE_FILE:
- Status = SpiFlashProtocol->Write (Slave, Offset, ByteCount, Buffer);
+ Status = SpiFlashProtocol->Write (mSlave, Offset, ByteCount, Buffer);
break;
case UPDATE:
case UPDATE_FILE:
- Status = SpiFlashProtocol->Update (Slave, Offset, ByteCount, Buffer);
+ Status = SpiFlashProtocol->Update (mSlave, Offset, ByteCount, Buffer);
break;
}
- 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/Drivers/Spi/MvSpiDxe.c
index 3b491479ec..a7db5f2a2e 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 = AllocateZeroPool (sizeof(SPI_DEVICE));
+ if (Slave == NULL) {
+ DEBUG((DEBUG_ERROR, "Cannot allocate memory\n"));
+ return NULL;
+ }
- Slave = AllocateZeroPool (sizeof(SPI_DEVICE));
- if (Slave == NULL) {
- DEBUG((DEBUG_ERROR, "Cannot allocate memory\n"));
- return NULL;
+ Slave->Cs = Cs;
+ Slave->Mode = Mode;
}
- Slave->Cs = Cs;
- Slave->Mode = Mode;
-
SpiSetupTransfer (This, Slave);
return Slave;
diff --git a/Platform/Marvell/Drivers/Spi/MvSpiDxe.h b/Platform/Marvell/Drivers/Spi/MvSpiDxe.h
index 1401f6207b..e7e280a799 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/Include/Protocol/Spi.h
index 6f26a36b5a..98fcc07f2b 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
);