In order to support new API of the PlatformFlashAccessLib, which
passes and optional Progress() function, introduce new callback
for updating data in the SPI flash, that can utilize it.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
---
Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c | 60 ++++++++++++++++++++
Silicon/Marvell/Include/Protocol/SpiFlash.h | 14 +++++
2 files changed, 74 insertions(+)
diff --git a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c
index a2ce975..d81f6e3 100755
--- a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c
+++ b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c
@@ -397,6 +397,65 @@ MvSpiFlashUpdate (
}
EFI_STATUS
+MvSpiFlashUpdateWithProgress (
+ IN SPI_DEVICE *Slave,
+ IN UINT32 Offset,
+ IN UINTN ByteCount,
+ IN UINT8 *Buffer,
+ IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OPTIONAL
+ IN UINTN StartPercentage,
+ IN UINTN EndPercentage
+ )
+{
+ EFI_STATUS Status;
+ UINTN SectorSize;
+ UINTN SectorNum;
+ UINTN ToUpdate;
+ UINTN Index;
+ UINT8 *TmpBuf;
+
+ SectorSize = Slave->Info->SectorSize;
+ SectorNum = ByteCount / SectorSize;
+ ToUpdate = SectorSize;
+
+ TmpBuf = (UINT8 *)AllocateZeroPool (SectorSize);
+ if (TmpBuf == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ for (Index = 0; Index < SectorNum; Index++) {
+ if (Progress != NULL) {
+ Progress (StartPercentage +
+ ((Index * (EndPercentage - StartPercentage)) / SectorNum));
+ }
+
+ // In the last chunk update only an actual number of remaining bytes.
+ if (Index + 1 == SectorNum) {
+ ToUpdate = ByteCount % SectorSize;
+ }
+
+ Status = MvSpiFlashUpdateBlock (Slave,
+ Offset + Index * SectorSize,
+ ToUpdate,
+ Buffer + Index * SectorSize,
+ TmpBuf,
+ SectorSize);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Error while updating\n", __FUNCTION__));
+ return Status;
+ }
+ }
+ FreePool (TmpBuf);
+
+ if (Progress != NULL) {
+ Progress (EndPercentage);
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
EFIAPI
MvSpiFlashReadId (
IN SPI_DEVICE *SpiDev,
@@ -500,6 +559,7 @@ MvSpiFlashInitProtocol (
SpiFlashProtocol->Write = MvSpiFlashWrite;
SpiFlashProtocol->Erase = MvSpiFlashErase;
SpiFlashProtocol->Update = MvSpiFlashUpdate;
+ SpiFlashProtocol->UpdateWithProgress = MvSpiFlashUpdateWithProgress;
return EFI_SUCCESS;
}
diff --git a/Silicon/Marvell/Include/Protocol/SpiFlash.h b/Silicon/Marvell/Include/Protocol/SpiFlash.h
index 4ba29ba..e703330 100644
--- a/Silicon/Marvell/Include/Protocol/SpiFlash.h
+++ b/Silicon/Marvell/Include/Protocol/SpiFlash.h
@@ -34,6 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef __MV_SPI_FLASH__
#define __MV_SPI_FLASH__
+#include <Protocol/FirmwareManagement.h>
#include <Protocol/Spi.h>
extern EFI_GUID gMarvellSpiFlashProtocolGuid;
@@ -89,6 +90,18 @@ EFI_STATUS
IN UINT8 *Buffer
);
+typedef
+EFI_STATUS
+(EFIAPI *MV_SPI_FLASH_UPDATE_WITH_PROGRESS) (
+ IN SPI_DEVICE *Slave,
+ IN UINT32 Offset,
+ IN UINTN ByteCount,
+ IN UINT8 *Buffer,
+ IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OPTIONAL
+ IN UINTN StartPercentage,
+ IN UINTN EndPercentage
+ );
+
struct _MARVELL_SPI_FLASH_PROTOCOL {
MV_SPI_FLASH_INIT Init;
MV_SPI_FLASH_READ_ID ReadId;
@@ -96,6 +109,7 @@ struct _MARVELL_SPI_FLASH_PROTOCOL {
MV_SPI_FLASH_WRITE Write;
MV_SPI_FLASH_ERASE Erase;
MV_SPI_FLASH_UPDATE Update;
+ MV_SPI_FLASH_UPDATE_WITH_PROGRESS UpdateWithProgress;
};
#endif // __MV_SPI_FLASH__
--
2.7.4
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel