From: Marcin Wojtas <mw@semihalf.com>
To: edk2-devel@lists.01.org
Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org,
mw@semihalf.com, jsd@semihalf.com, jinghua@marvell.com,
jaz@semihalf.com, davidsn@marvell.com
Subject: [platforms PATCH v2 3/5] Marvell/Drivers: MvSpiFlashDxe: Add progress API
Date: Mon, 4 Jun 2018 07:29:33 +0200 [thread overview]
Message-ID: <1528090175-15791-4-git-send-email-mw@semihalf.com> (raw)
In-Reply-To: <1528090175-15791-1-git-send-email-mw@semihalf.com>
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>
---
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
next prev parent reply other threads:[~2018-06-04 5:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-04 5:29 [platforms PATCH v2 0/5] Armada capsule support Marcin Wojtas
2018-06-04 5:29 ` [platforms PATCH v2 1/5] Marvell/Armada70x0Db: Shift main FV from 0x0 address Marcin Wojtas
2018-06-04 5:29 ` [platforms PATCH v2 2/5] Marvell/Aramda7k8k: Enable PEI booting stage Marcin Wojtas
2018-06-04 5:29 ` Marcin Wojtas [this message]
2018-06-04 5:29 ` [platforms PATCH v2 4/5] Marvell/Armada7k8k: Introduce capsule FW update implementation Marcin Wojtas
2018-06-04 5:29 ` [platforms PATCH v2 5/5] Marvell/Armada7k8k: Wire up capsule support Marcin Wojtas
2018-06-04 10:08 ` Leif Lindholm
2018-06-04 11:44 ` Marcin Wojtas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1528090175-15791-4-git-send-email-mw@semihalf.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox