From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::242; helo=mail-wr0-x242.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x242.google.com (mail-wr0-x242.google.com [IPv6:2a00:1450:400c:c0c::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 717612202E4AF for ; Fri, 16 Mar 2018 09:07:11 -0700 (PDT) Received: by mail-wr0-x242.google.com with SMTP id o1so12233445wro.10 for ; Fri, 16 Mar 2018 09:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5zWoz4XsfNzYO5i7jXhnZx2hjxS46cJVPJpCOxbm2Gs=; b=KQw8rg5K62YAEiZ11U4NGJJ5GmIsjmgI7kOqdr39mMT99aY7OXxPtcSoNnd+Rs0RyE CLFdA5eW1mRhG9XEQZ6b7ZVLrFOymP1RkEpAuyJD/3B85xWcTZtrv/GO+xebrTFhG2ms 1fGwJXPVUTdGfkooHZywaTZSeX7HX2NLqxui0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5zWoz4XsfNzYO5i7jXhnZx2hjxS46cJVPJpCOxbm2Gs=; b=rMqFwZa4dxGea+jTC8cYiiPDRI3P7GuJg+Xe4KRb4Ff2VodscYdLcpV5uRWVryty1i OscN4D5icvS/aeYt9yQ7LSzh1VN2Hp9FuxyHbm7SCuCBoQ2fj/jCTL0TA8qN6JqWbKig T+WK5K7Wjw5anPsvWktPAxCJ/mrU9Z/Zh34TnP5vHo0ozpcvybLzPZsASS7hfOVeo7cw 6c3H6hUMfyR9tTwTIQp8ZHeBTYz5QdT/2CnepD9lSUwjfFMR89je+1M+5+VwvhyOPa5r b4hbQCj08mxVPlnbZHJeNguV2tQq3GyTMFr/NYCA7INLKtFp8SEEzNXZH1CGSN86W6wZ 3SUw== X-Gm-Message-State: AElRT7G7hN23NwjUA9807y4XWRsy+cZC3BeqYsvHWsgdh+H+prgK0shL Lg8VIm7Jbw+dxq0BAlfQ0+DaiQ7OoBs= X-Google-Smtp-Source: AG47ELtNWvQwgndmXoRQ2Mxr212Fp71sCXBjxpf2K51ZAiVbu8J+onj5DKsvxx+GZFtsr1FVIlu+9A== X-Received: by 10.223.135.148 with SMTP id b20mr2170826wrb.100.1521216815075; Fri, 16 Mar 2018 09:13:35 -0700 (PDT) Received: from localhost.localdomain ([105.142.191.63]) by smtp.gmail.com with ESMTPSA id n8sm7876242wrf.12.2018.03.16.09.13.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Mar 2018 09:13:34 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, Ard Biesheuvel Date: Fri, 16 Mar 2018 16:13:19 +0000 Message-Id: <20180316161322.6756-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180316161322.6756-1-ard.biesheuvel@linaro.org> References: <20180316161322.6756-1-ard.biesheuvel@linaro.org> Subject: [RFC PATCH edk2-platforms 3/6] Silicon/SynQuacerPlatformFlashAccessLib: skip empty blocks X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Mar 2018 16:07:12 -0000 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 --- 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