From nobody Sun Dec 22 15:34:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1528384108583759.3682516444537; Thu, 7 Jun 2018 08:08:28 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8C71C2115F510; Thu, 7 Jun 2018 08:08:27 -0700 (PDT) Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) (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 465F82115C30A for ; Thu, 7 Jun 2018 08:08:26 -0700 (PDT) Received: by mail-wr0-x241.google.com with SMTP id l10-v6so10240296wrn.2 for ; Thu, 07 Jun 2018 08:08:26 -0700 (PDT) Received: from dogfood.home (LFbn-NIC-1-75-91.w2-15.abo.wanadoo.fr. [2.15.165.91]) by smtp.gmail.com with ESMTPSA id v14-v6sm27935985wro.33.2018.06.07.08.08.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 08:08:23 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::241; helo=mail-wr0-x241.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org 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=V0E2QmeeQzMrbdsglLTijrpPO86evB7iDFSC/lSn0nQ=; b=Os6DTnbtTCjiIiYoy2DzqYMR/xHAiJ0D7+NVHlS78aL0ctY/i6AeSzUSS9SHpQIfo7 rPHJ1acQWBHx616EjBaNvNjOMn9p81iXDsEb0SIMhbu4XWaXC+IdwDyc9x0+nFV3mEyy PBPLV1UWYk44WqhHod7mLEOyL6rFWcw5oFm+w= 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=V0E2QmeeQzMrbdsglLTijrpPO86evB7iDFSC/lSn0nQ=; b=Ry4NE8uXD5iU5oQg61SBFAQQ3TJdEpiCqCxVmVaNJjAEZnnLosmnsA4xEzyl2dKOqj uc57jZjmN4nqB1he1h4uJZLVET5rKGmM+Pi9jxHwamp+fHCwYAedA8WF4890wDPHiugW GDQOr4XQNZaFSHTLdvi/ZDMM8RueCngOBfm1+nVRRWQRBxSITYr1v6CWNpWF282f7bSv 6LDUqlhbroGIPXYkGmZbGoYy55IhEWfYzwJ0okaT09//wvctcDlirmuC9dSMAh1kMDu2 FxOlZ4kQSB4dfH6UylVAe8S98jR7TlVubU2ADokft6lQQ6f45mVUNYbHEANxOhOQGMYA pVAA== X-Gm-Message-State: APt69E3gnMFjgJWmHzdK5L0vOo5NHHht+6WTIX0H+oSWPgrT8wb95sHn BPkyQJ+qXBqM2riuNKrO3FVT7CCFWsg= X-Google-Smtp-Source: ADUXVKLoUx7OXz08jSrHyRRELEu0MBdQw8WCl4c5+ECw+4asXeuggV/uBkAczPvVvz0vlGSr/9aaWQ== X-Received: by 2002:adf:ad2f:: with SMTP id p44-v6mr2120460wrc.164.1528384104580; Thu, 07 Jun 2018 08:08:24 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 7 Jun 2018 17:08:17 +0200 Message-Id: <20180607150818.14393-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180607150818.14393-1-ard.biesheuvel@linaro.org> References: <20180607150818.14393-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH edk2-platforms 1/2] Silicon/SynQuacerPlatformFlashAccessLib: relax FV address check X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In commit 913fdda9f4b9 ("Silicon/SynQuacerPlatformFlashAccessLib: don't dereference FVB header fields"), we dropped all accesses to FVB header field, which was necessary because the flash partition may not in fact contain such a header. Instead, only an exact match on the base address of the FV compared to the base address of the capsule payload would result in a match, making it difficult to create capsules that only update a subset of the flash contents. Given that the FVB protocol provides a GetBlockSize() method that also returns the number of consecutive blocks of that size, and does not rely on the FVB header contents, we can actually infer the size of the flash partition, and use it to decide whether a capsule payload targets an area that is covered by this partition entirely. This optimization allows us to extend the FV description to include the SCP firmware partition without requiring us to actually provide a payload for that partition immediately, which is useful as a preparatory step. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/SynQua= cerPlatformFlashAccessLib.c | 53 +++++++++----------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAcce= ssLib/SynQuacerPlatformFlashAccessLib.c b/Silicon/Socionext/SynQuacer/Libra= ry/SynQuacerPlatformFlashAccessLib/SynQuacerPlatformFlashAccessLib.c index ebb6ce189aa5..a6843c949a28 100644 --- a/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/S= ynQuacerPlatformFlashAccessLib.c +++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerPlatformFlashAccessLib/S= ynQuacerPlatformFlashAccessLib.c @@ -44,8 +44,10 @@ STATIC EFI_STATUS GetFvbByAddress ( IN EFI_PHYSICAL_ADDRESS Address, + IN UINTN Length, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **OutFvb, - OUT EFI_PHYSICAL_ADDRESS *FvbBaseAddress + OUT EFI_LBA *Lba, + OUT UINTN *BlockSize ) { EFI_STATUS Status; @@ -54,6 +56,8 @@ GetFvbByAddress ( UINTN Index; EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; EFI_FVB_ATTRIBUTES_2 Attributes; + EFI_PHYSICAL_ADDRESS FvbBaseAddress; + UINTN NumberOfBlocks; =20 // // Locate all handles with Firmware Volume Block protocol @@ -84,7 +88,7 @@ GetFvbByAddress ( // // Checks if the address range of this handle contains parameter Addre= ss // - Status =3D Fvb->GetPhysicalAddress (Fvb, FvbBaseAddress); + Status =3D Fvb->GetPhysicalAddress (Fvb, &FvbBaseAddress); if (EFI_ERROR (Status)) { continue; } @@ -102,8 +106,25 @@ GetFvbByAddress ( continue; } =20 - if (Address =3D=3D *FvbBaseAddress) { + Status =3D Fvb->GetBlockSize (Fvb, 0, BlockSize, &NumberOfBlocks); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: failed to get FVB blocksize - %r, ignoring\= n", + __FUNCTION__, Status)); + continue; + } + + if ((Length % *BlockSize) !=3D 0) { + DEBUG ((DEBUG_INFO, + "%a: Length 0x%lx is not a multiple of the blocksize 0x%lx, ignori= ng\n", + __FUNCTION__, Length, *BlockSize)); + Status =3D EFI_INVALID_PARAMETER; + continue; + } + + if (Address >=3D FvbBaseAddress && + (Address + Length) <=3D (FvbBaseAddress + *BlockSize * NumberOfBlo= cks)) { *OutFvb =3D Fvb; + *Lba =3D (Address - FvbBaseAddress) / *BlockSize; Status =3D EFI_SUCCESS; break; } @@ -190,9 +211,7 @@ PerformFlashWriteWithProgress ( EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb; EFI_STATUS Status; UINTN BlockSize; - UINTN NumberOfBlocks; EFI_LBA Lba; - EFI_PHYSICAL_ADDRESS FvbBaseAddress; UINTN NumBytes; UINTN Remaining; =20 @@ -216,7 +235,7 @@ PerformFlashWriteWithProgress ( // that covers the system firmware // Fvb =3D NULL; - Status =3D GetFvbByAddress (FlashAddress, &Fvb, &FvbBaseAddress); + Status =3D GetFvbByAddress (FlashAddress, Length, &Fvb, &Lba, &BlockSize= ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: failed to locate FVB handle for address 0x%llx - %r\n", @@ -224,28 +243,6 @@ PerformFlashWriteWithProgress ( return Status; } =20 - Status =3D Fvb->GetBlockSize(Fvb, 0, &BlockSize, &NumberOfBlocks); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: failed to get FVB blocksize - %r\n", - __FUNCTION__, Status)); - return Status; - } - - if ((Length % BlockSize) !=3D 0) { - DEBUG ((DEBUG_ERROR, - "%a: Length 0x%lx is not a multiple of the blocksize 0x%lx\n", - __FUNCTION__, Length, BlockSize)); - return EFI_INVALID_PARAMETER; - } - - Lba =3D (FlashAddress - FvbBaseAddress) / BlockSize; - if (Lba > NumberOfBlocks - 1) { - DEBUG ((DEBUG_ERROR, - "%a: flash device with non-uniform blocksize not supported\n", - __FUNCTION__)); - return EFI_UNSUPPORTED; - } - // // Remap the region as device rather than uncached. // --=20 2.17.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel