public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Patryk Duda <pdk@semihalf.com>
To: devel@edk2.groups.io
Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org,
	mw@semihalf.com, jsd@semihalf.com, Patryk Duda <pdk@semihalf.com>
Subject: [edk2-platforms: PATCH 2/2] Marvell/Drivers: MvSpiFlashDxe: Implement progress bar
Date: Mon,  9 Sep 2019 17:52:12 +0200	[thread overview]
Message-ID: <20190909155212.30338-3-pdk@semihalf.com> (raw)
In-Reply-To: <20190909155212.30338-1-pdk@semihalf.com>

This patch implements TFTP-like progress bar in
MvSpiFlashUpdateWithProgress. This is necessary because
CapsuleRuntimeDxe uses DxeRuntimeCapsuleLib which uses
CapsuleProcessLibNull implementation of capsule process.

Signed-off-by: Patryk Duda <pdk@semihalf.com>
---
 Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf |  1 +
 Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.h   |  1 +
 Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c   | 57 ++++++++++++++++----
 3 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf
index c6e93b82a1..088e9592e2 100644
--- a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf
+++ b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.inf
@@ -23,6 +23,7 @@
   DebugLib
   MemoryAllocationLib
   NorFlashInfoLib
+  PrintLib
   TimerLib
   UefiBootServicesTableLib
   UefiDriverEntryPoint
diff --git a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.h b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.h
index 21877ba2a6..d51892c439 100755
--- a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.h
+++ b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.h
@@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #include <Library/IoLib.h>
 #include <Library/PcdLib.h>
+#include <Library/PrintLib.h>
 #include <Library/UefiLib.h>
 #include <Library/DebugLib.h>
 #include <Library/MemoryAllocationLib.h>
diff --git a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c
index db12adb764..91e195b97c 100755
--- a/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c
+++ b/Silicon/Marvell/Drivers/Spi/MvSpiFlashDxe/MvSpiFlashDxe.c
@@ -6,6 +6,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 *******************************************************************************/
 #include "MvSpiFlashDxe.h"
 
+// Frame for the progression slider
+STATIC CONST CHAR16 mProgressFrame[] = L"[                                        ]";
+
+// Number of steps in the progression slider
+#define PROGRESS_SLIDER_STEPS  ((sizeof (mProgressFrame) / sizeof (CHAR16)) - 3)
+
+// Size in number of characters plus one (final zero) of the message to
+// indicate the progress of update. The format is "[(progress slider:
+// 40 characters)] (nb of KBytes written so far: 7 characters) Kb". There
+// are thus the number of characters in mProgressFrame[] plus 11 characters
+// (2 // spaces, "Kb" and seven characters for the number of KBytes).
+#define PROGRESS_MESSAGE_SIZE  ((sizeof (mProgressFrame) / sizeof (CHAR16)) + 12)
+
+// String to delete progress message to be able to update it :
+// (PROGRESS_MESSAGE_SIZE-1) '\b'
+STATIC CONST CHAR16 mProgressDelete[] = L"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
+                                         "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
+                                         "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
+
 STATIC EFI_EVENT            mMvSpiFlashVirtualAddrChangeEvent;
 MARVELL_SPI_MASTER_PROTOCOL *SpiMasterProtocol;
 SPI_FLASH_INSTANCE  *mSpiFlashInstance;
@@ -380,12 +399,15 @@ MvSpiFlashUpdateWithProgress (
   IN UINTN                                          EndPercentage
   )
 {
+  CHAR16 ProgressBar[PROGRESS_MESSAGE_SIZE];
+  UINTN ProgressIndex;
   EFI_STATUS Status;
   UINTN SectorSize;
   UINTN SectorNum;
   UINTN ToUpdate;
-  UINTN Index;
   UINT8 *TmpBuf;
+  UINTN Index;
+  UINTN Step;
 
   SectorSize = Slave->Info->SectorSize;
   SectorNum = (ByteCount / SectorSize) + 1;
@@ -397,12 +419,9 @@ MvSpiFlashUpdateWithProgress (
     return EFI_OUT_OF_RESOURCES;
   }
 
-  for (Index = 0; Index < SectorNum; Index++) {
-    if (Progress != NULL) {
-      Progress (StartPercentage +
-                ((Index * (EndPercentage - StartPercentage)) / SectorNum));
-    }
+  Print(L"%s       0 Kb", mProgressFrame);
 
+  for (Index = 0; Index < SectorNum; Index++) {
     // In the last chunk update only an actual number of remaining bytes.
     if (Index + 1 == SectorNum) {
       ToUpdate = ByteCount % SectorSize;
@@ -418,12 +437,32 @@ MvSpiFlashUpdateWithProgress (
       DEBUG ((DEBUG_ERROR, "%a: Error while updating\n", __FUNCTION__));
       return Status;
     }
+
+    ProgressBar[0] = L'\0';
+    Step = ((Index * SectorSize + ToUpdate) * PROGRESS_SLIDER_STEPS) / ByteCount;
+
+    Print (L"%s", mProgressDelete);
+
+    Status = StrCpyS (ProgressBar, PROGRESS_MESSAGE_SIZE, mProgressFrame);
+    if (EFI_ERROR(Status)) {
+      return Status;
+    }
+    for (ProgressIndex = 1; ProgressIndex < Step; ProgressIndex++) {
+      ProgressBar[ProgressIndex] = L'=';
+    }
+    ProgressBar[Step] = L'>';
+    UnicodeSPrint (
+      ProgressBar + (sizeof (mProgressFrame) / sizeof (CHAR16)) - 1,
+      sizeof (ProgressBar) - sizeof (mProgressFrame),
+      L" %7d Kb",
+      (Index * SectorSize + ToUpdate) / 1024
+      );
+
+    Print(L"%s", ProgressBar);
   }
   FreePool (TmpBuf);
 
-  if (Progress != NULL) {
-    Progress (EndPercentage);
-  }
+  Print (L"\n");
 
   return EFI_SUCCESS;
 }
-- 
2.21.0


  parent reply	other threads:[~2019-09-09 15:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-09 15:52 [edk2-platforms: PATCH 0/2] Armada 7k8k SPI flash driver improvements Patryk Duda
2019-09-09 15:52 ` [edk2-platforms: PATCH 1/2] Marvell/Drivers: MvSpiFlashDxe: Fix sector number obtaining Patryk Duda
2019-09-28 22:37   ` Leif Lindholm
2019-09-09 15:52 ` Patryk Duda [this message]
2019-09-28 22:47   ` [edk2-platforms: PATCH 2/2] Marvell/Drivers: MvSpiFlashDxe: Implement progress bar Leif Lindholm
2019-09-10  6:23 ` [edk2-platforms: PATCH 0/2] Armada 7k8k SPI flash driver improvements Marcin Wojtas
2019-09-27 14:48   ` Patryk Duda

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=20190909155212.30338-3-pdk@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