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

Ard Biesheuvel posted 6 patches 7 years, 11 months ago
[edk2] [RFC PATCH edk2-platforms 3/6] Silicon/SynQuacerPlatformFlashAccessLib: skip empty blocks
Posted by Ard Biesheuvel 7 years, 11 months ago
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(-)

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) {
-- 
2.15.1

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