From patchwork Wed Nov 21 11:58:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 151673 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1829013ljp; Wed, 21 Nov 2018 03:58:52 -0800 (PST) X-Google-Smtp-Source: AJdET5fZu2MUoeUbpgICEf2D41gktI/LMH9oWFPhn8ZptRNYZEoIts2fE2/DkrJXqlXM1woTQKLz X-Received: by 2002:a62:8145:: with SMTP id t66mr6532382pfd.55.1542801532329; Wed, 21 Nov 2018 03:58:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542801532; cv=none; d=google.com; s=arc-20160816; b=m5qzHrrH4OW1yDD9QSqrpNhwveCjUwGxhondI5nJHyrtLGFrtDSzU0D2S/QXqfGJl5 O6siIbOnuJQOm3oCb/HZ+EoQ+rxRXSiPUWG3RDXaw6dI77mqKzKsrNVx03bjcVh7l+Nh BN9lMEPVqF0i3ZlOOen0znQ/weJlkHWl+WTcwgIUQz5ylgxnsfQm5JiWWH0OLOnAJN4C Wc+W5De7NfocF2V16uwUKlC4fWpQqkPNdbG2B0PP8Wr66NBVedCGvUobL0612Z/WLkLi UhpExtiL/5knylaQXbyw3BX+VRLSCaA/yjlR+p5A8QVhNawo/p5lEoabxP7uuAitGL4g qPVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=Wrr+gww9vlGJsiebKI2crB90CJb2UflLKUwli8zrWpw=; b=PHb5Zdk0n2d/1JnvnsiJVDZYQsW4PYv2ucTyX5KgIF2RCxnwDKiuiVGcBys9QfvLR3 Ix3CbiJz8LFXJT0HZX+YccsNE4ne7mNpe5qaeMq9p/PB8dnvKlx4p0WYX5BV33dRls/3 ENnv21llvxPkZdvY1orp7bD2EI1jGjbs9iFExSHcnaQ/DwrwPnrn04rP918kqL9kNu/C N+0Ch6lWh8HT3gyb3x+7vV4Tslv6w+WEHfABOrtcDWWsEMxWdUSIHrfBbR9qcT02nn5j nkDmIf33dfdHTOD4rJe5nWedrSZsUwhTcupViP4XWpS5oqXBcgN2EJdFWva8rgLWh4cD nMZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Np8+jRRv; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id g6si32684857pgr.472.2018.11.21.03.58.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Nov 2018 03:58:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Np8+jRRv; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 58E7D21193786; Wed, 21 Nov 2018 03:58:45 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::544; helo=mail-ed1-x544.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) (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 BB6032119377D for ; Wed, 21 Nov 2018 03:58:43 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id j6so4646337edp.9 for ; Wed, 21 Nov 2018 03:58:43 -0800 (PST) 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=4OacAZxi6bwjmYfaG2QlW79iKsCN+Q3rSHDaCWjt5+M=; b=Np8+jRRvLbwjY+1XDYo9rkMrap/RpKKULsXq37oWvteGS7qAiWjCi4V1wBfh8j+feR XaeaeLgsRCkw5Pmf4GwgIJi2Ez+YIQpEcneTMaqM+Sw4yS8QmKpz3/480BWrj60TSGXi yH5rJ20TYnwHfbDysI5tc65jT6GntzQkubJz0= 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=4OacAZxi6bwjmYfaG2QlW79iKsCN+Q3rSHDaCWjt5+M=; b=HCv2mIVU0tCkPVGrh+BXqRoTlxEjWPZcmSTXsEj7Jcf5OwTINsIjsEAMjSfB9mqUAT LoB4jLJ0BXg+UtegGVYHXKKGS2wVGhtSwx0DlVmUVPFRyIUKE/aTaDhKmSHS4Tx8mWUt 4QKl4K5qoGbM9cXuLLsnPgPN2P/7XamYu6ZmgW791EhLgOvAdtolRRK5SNWkRzJYSmPx FBlzb1gJx3bGFPBIIhOmFKA0oNSyieQf4Dtq6L9CPjSwumnbjHt19ttgCZxrwHRvo2T+ BuLAsI4D8jtKFyE7+lljr3NBWnBMNNveLOtFrfjCUuG27v6c81ToLTcQWB4vrOx9XmOu xjXQ== X-Gm-Message-State: AA+aEWbB9N5pI9I9XvGsxmkUCnqZ9E7hm6iCbz1LXWMv+X8L3H0iHh1B hmD8nYCRxYi653uX6DsFc+PWw7e7PB2SEQ== X-Received: by 2002:a50:aa31:: with SMTP id o46mr903937edc.23.1542801521970; Wed, 21 Nov 2018 03:58:41 -0800 (PST) Received: from mba13.wifi.ns.nl (dhcp-077-251-017-237.chello.nl. [77.251.17.237]) by smtp.gmail.com with ESMTPSA id x90sm4090716ede.35.2018.11.21.03.58.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Nov 2018 03:58:41 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Wed, 21 Nov 2018 12:58:27 +0100 Message-Id: <20181121115828.3026-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181121115828.3026-1-ard.biesheuvel@linaro.org> References: <20181121115828.3026-1-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 4/5] ArmVirtPkg/NorFlashQemuLib: discover NOR flash banks dynamically X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lersek@redhat.com, nariman.poushin@linaro.org MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" NorFlashQemuLib is one of the last remaining drivers in ArmVirtPkg that are not based on the device tree received from QEMU. For ArmVirtQemu, this does not really matter, given that the NOR flash banks are always the same: the PEI code is linked to execute in place from flash bank #0, and the fixed varstore PCDs refer to flash bank #1 directly. However, ArmVirtQemuKernel can execute at any offset, permitting it to be used as an intermediary loader when running QEMU with secure world emulation enabled, in which case NOR flash bank #0 is secure only and contains the secure world firmware. In this case, NorFlashQemuLib should not expose the first flash bank at all. To prevent introducing too much internal knowledge about which flash bank is accessible under which circumstances, let's switch to using the DTB to decide which flash banks to expose to the NOR flash driver. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c | 78 ++++++++++++++------ ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf | 12 +++ 2 files changed, 69 insertions(+), 21 deletions(-) -- 2.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Laszlo Ersek diff --git a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c index e3bbae5b06c5..2678f57eaaad 100644 --- a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c +++ b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c @@ -1,6 +1,6 @@ /** @file - Copyright (c) 2014, Linaro Ltd. All rights reserved.
+ Copyright (c) 2014-2018, Linaro Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -12,13 +12,16 @@ **/ +#include +#include #include +#include + +#include #define QEMU_NOR_BLOCK_SIZE SIZE_256KB -#define QEMU_NOR0_BASE 0x0 -#define QEMU_NOR0_SIZE SIZE_64MB -#define QEMU_NOR1_BASE 0x04000000 -#define QEMU_NOR1_SIZE SIZE_64MB + +#define MAX_FLASH_BANKS 4 EFI_STATUS NorFlashPlatformInitialization ( @@ -28,21 +31,7 @@ NorFlashPlatformInitialization ( return EFI_SUCCESS; } -NOR_FLASH_DESCRIPTION mNorFlashDevices[] = { - { - QEMU_NOR0_BASE, - QEMU_NOR0_BASE, - QEMU_NOR0_SIZE, - QEMU_NOR_BLOCK_SIZE, - {0xF9B94AE2, 0x8BA6, 0x409B, {0x9D, 0x56, 0xB9, 0xB4, 0x17, 0xF5, 0x3C, 0xB3}} - }, { - QEMU_NOR1_BASE, - QEMU_NOR1_BASE, - QEMU_NOR1_SIZE, - QEMU_NOR_BLOCK_SIZE, - {0x8047DB4B, 0x7E9C, 0x4C0C, {0x8E, 0xBC, 0xDF, 0xBB, 0xAA, 0xCA, 0xCE, 0x8F}} - } -}; +NOR_FLASH_DESCRIPTION mNorFlashDevices[MAX_FLASH_BANKS]; EFI_STATUS NorFlashPlatformGetDevices ( @@ -50,7 +39,54 @@ NorFlashPlatformGetDevices ( OUT UINT32 *Count ) { + FDT_CLIENT_PROTOCOL *FdtClient; + INT32 Node; + EFI_STATUS Status; + EFI_STATUS FindNodeStatus; + CONST UINT32 *Reg; + UINT32 PropSize; + UINT32 Num; + UINT64 Base; + UINT64 Size; + + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, + (VOID **)&FdtClient); + ASSERT_EFI_ERROR (Status); + + Num = 0; + for (FindNodeStatus = FdtClient->FindCompatibleNode (FdtClient, + "cfi-flash", &Node); + !EFI_ERROR (FindNodeStatus) && Num < MAX_FLASH_BANKS; + FindNodeStatus = FdtClient->FindNextCompatibleNode (FdtClient, + "cfi-flash", Node, &Node)) { + + Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", + (CONST VOID **)&Reg, &PropSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: GetNodeProperty () failed (Status == %r)\n", + __FUNCTION__, Status)); + continue; + } + + ASSERT ((PropSize % (4 * sizeof (UINT32))) == 0); + + while (PropSize >= (4 * sizeof (UINT32)) && Num < MAX_FLASH_BANKS) { + Base = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0])); + Size = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2])); + Reg += 4; + + mNorFlashDevices[Num].DeviceBaseAddress = (UINTN)Base; + mNorFlashDevices[Num].RegionBaseAddress = (UINTN)Base; + mNorFlashDevices[Num].Size = (UINTN)Size; + mNorFlashDevices[Num].BlockSize = QEMU_NOR_BLOCK_SIZE; + Num++; + + PropSize -= 4 * sizeof (UINT32); + } + } + *NorFlashDescriptions = mNorFlashDevices; - *Count = ARRAY_SIZE (mNorFlashDevices); + *Count = Num; + return EFI_SUCCESS; } diff --git a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf index 126d1671f544..d86ff36dbd58 100644 --- a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf +++ b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf @@ -28,3 +28,15 @@ [Packages] MdePkg/MdePkg.dec ArmPlatformPkg/ArmPlatformPkg.dec + ArmVirtPkg/ArmVirtPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiBootServicesTableLib + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Depex] + gFdtClientProtocolGuid