[edk2,RFC,edk2-platforms,3/6] Silicon/SynQuacerPlatformFlashAccessLib: skip empty blocks

Message ID 20180316161322.6756-4-ard.biesheuvel@linaro.org
State New
Headers show
Series
  • expand capsule to include SCP firmware
Related show

Commit Message

Ard Biesheuvel March 16, 2018, 4:13 p.m.
Before adding more payload to the capsule which may be only partially
occupied, add some logic to skip writing these blocks after erasing
them.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c | 41 +++++++++++++++++---
 1 file changed, 36 insertions(+), 5 deletions(-)

-- 
2.15.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Patch

diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
index 82fe3f74aa7f..0131e33a4fe7 100644
--- a/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
+++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c
@@ -115,6 +115,35 @@  GetFvbByAddress (
   return Status;
 }
 
+/**
+  Check whether a buffer has any data in it, i.e., bytes with value != 0xff
+
+  @param[in] Buffer       Address of the buffer
+  @param[in] Length       Size of the buffer
+
+  @retval TRUE            A non-0xff byte was found
+  @retval FALSE           Buffer has 0xff bytes only
+
+**/
+STATIC
+BOOLEAN
+BufferHasData (
+  IN  VOID      *Buffer,
+  IN  UINTN     Length
+  )
+{
+  UINT8   *Data;
+  UINTN   Index;
+
+  Data = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (Data[Index] != 0xff) {
+      return TRUE;
+    }
+  }
+  return FALSE;
+}
+
 /**
   Perform flash write operation.
 
@@ -257,11 +286,13 @@  PerformFlashWrite (
       __FUNCTION__, BlockSize, Lba));
 
     NumBytes = BlockSize;
-    Status = Fvb->Write (Fvb, Lba, 0, &NumBytes, Buffer);
-    if (EFI_ERROR (Status)) {
-      DEBUG ((DEBUG_ERROR,
-        "%a: write of LBA 0x%lx failed - %r (NumBytes == 0x%lx)\n",
-        __FUNCTION__, Lba, Status, NumBytes));
+    if (BufferHasData (Buffer, NumBytes)) {
+      Status = Fvb->Write (Fvb, Lba, 0, &NumBytes, Buffer);
+      if (EFI_ERROR (Status)) {
+        DEBUG ((DEBUG_ERROR,
+          "%a: write of LBA 0x%lx failed - %r (NumBytes == 0x%lx)\n",
+          __FUNCTION__, Lba, Status, NumBytes));
+      }
     }
 
     if (HaveBootGraphics) {