From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::442; helo=mail-wr1-x442.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) (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 6AAEA21193076 for ; Mon, 19 Nov 2018 11:25:00 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id t3so3092015wrr.3 for ; Mon, 19 Nov 2018 11:25:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=5fXVeD6WH/j5wcid6y2Rc+dSg4UzIOcHJ6QHeALcRT0=; b=bgevb1xFXBqn0cgiO7pc+fRVFgKWaBL5AmQtsHMyVgZjCiJyfaeckaK8UaA8Rb9GgQ eLb3JE0KvDAME9JWG5tkkFjWRAepSkpFHCG/oMBfaB0Q3Qc8w7AqkpzteU9L1nkZ/+vq 4yEII8FU3ixCHzKpbizrjDVx+Tdiiou79kars= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=5fXVeD6WH/j5wcid6y2Rc+dSg4UzIOcHJ6QHeALcRT0=; b=D4kx2RY9WoT5kO6UevezQpEV8zdGV1vdpzbwi5LxGXKTnVPgmiaOGaa4G9BqFEe6Nh Im3nt3kVXp/lGxi84qJglClP10dzWHXHi28p0rtCM44byPp0WsDmJQbXZcheFjyWcvZR 9zyPRXMC5pyfXYW/ybr8Fineh60jxHPRcNBVWk1XsI7ZjkRExhneeZpbt38rkaWns4Ry 25miwyli+lVf8jBM/BMP5gb13H1d0dQycLcPIeiVFqCbyVB5wi7MRMULCLRNH8aD050R dDQSGP3AYqr8WeTcki+ACWTyOs+iXTqdyO+BYNk95G45zyyZkrO2L6XGim3cLYcl3qs0 ylKQ== X-Gm-Message-State: AGRZ1gJ3xUc7b5Guz24CVzhGzeRj6fpJgDKY4ZuC9KF+AnDE6ZbekpUA rGCLqhSu8yz//OiAxp+eBIVB6Q== X-Google-Smtp-Source: AJdET5eVVQ03/gg0879HocbMNe11TL65aOPH1AIB4l01s1nu3pjThUgGe6wR6xmcnjG/Nw6vbhBc8w== X-Received: by 2002:adf:b745:: with SMTP id n5-v6mr20227731wre.274.1542655498878; Mon, 19 Nov 2018 11:24:58 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id 11-v6sm26295384wms.24.2018.11.19.11.24.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Nov 2018 11:24:58 -0800 (PST) Date: Mon, 19 Nov 2018 19:24:56 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: "edk2-devel@lists.01.org" , Laszlo Ersek , Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= , Hongbo Zhang Message-ID: <20181119192456.67cvm64mhvqyyquc@bivouac.eciton.net> References: <20181117004524.31851-1-ard.biesheuvel@linaro.org> <20181117004524.31851-3-ard.biesheuvel@linaro.org> <20181119191044.4uqakfz5dfmxdctz@bivouac.eciton.net> MIME-Version: 1.0 In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH 2/2] 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: , X-List-Received-Date: Mon, 19 Nov 2018 19:25:00 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Nov 19, 2018 at 11:16:09AM -0800, Ard Biesheuvel wrote: > On Mon, 19 Nov 2018 at 11:10, Leif Lindholm wrote: > > > > On Fri, Nov 16, 2018 at 05:29:05PM -0800, Ard Biesheuvel wrote: > > > On Fri, 16 Nov 2018 at 16:45, Ard Biesheuvel wrote: > > > > > > > > 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, and flash bank > > > > > > #0 is configured as secure-only when running with support for EL3 enabled. > > > > Never gets old :) > > No this is entirely reasonable: it makes perfect sense for a NOR flash > at address 0x0 to be secure only on a system that implements EL3, > since mach-virt's default reset vector is 0x0. *cough* sorry, I was referring to the leading #. > > > > 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. > > > > Does this mean we as a side effect get rid of the limitation that the > > pflash image needs to be exactly 64MB. Or does that require further > > changes on the QEMU side? > > No that is a QEMU thing. OK, thanks for confirming. But this should mean that we don't need any changes on the guest sides if/when we do fix this in QEMU? / Leif > > If it does, please add a comment to the commit message. > > Either way: > > Reviewed-by: Leif Lindholm > > > > Thanks > > > > > > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > > > Signed-off-by: Ard Biesheuvel > > > > --- > > > > ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c | 84 +++++++++++++++----- > > > > ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf | 12 +++ > > > > 2 files changed, 75 insertions(+), 21 deletions(-) > > > > > > > > diff --git a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c > > > > index e3bbae5b06c5..dc0a15e77170 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,60 @@ NorFlashPlatformGetDevices ( > > > > OUT UINT32 *Count > > > > ) > > > > { > > > > + FDT_CLIENT_PROTOCOL *FdtClient; > > > > + INT32 Node; > > > > + EFI_STATUS Status; > > > > + EFI_STATUS FindNodeStatus; > > > > + CONST UINT64 *Reg; > > > > + UINT32 RegSize; > > > > + CONST CHAR8 *NodeStatus; > > > > + UINTN Num; > > > > + > > > > + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, > > > > + (VOID **)&FdtClient); > > > > + ASSERT_EFI_ERROR (Status); > > > > + > > > > + Num = 0; > > > > + for (FindNodeStatus = FdtClient->FindCompatibleNode (FdtClient, > > > > + "cfi-flash", &Node); > > > > + !EFI_ERROR (FindNodeStatus); > > > > + FindNodeStatus = FdtClient->FindNextCompatibleNode (FdtClient, > > > > + "cfi-flash", Node, &Node)) { > > > > + > > > > + Status = FdtClient->GetNodeProperty (FdtClient, Node, "status", > > > > + (CONST VOID **)&NodeStatus, NULL); > > > > + if (!EFI_ERROR (Status) && AsciiStrnCmp (NodeStatus, "ok", 2) != 0) { > > > > + continue; > > > > + } > > > > + > > > > + Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", > > > > + (CONST VOID **)&Reg, &RegSize); > > > > + if (EFI_ERROR (Status)) { > > > > + DEBUG ((EFI_D_ERROR, "%a: GetNodeProperty () failed (Status == %r)\n", > > > > + __FUNCTION__, Status)); > > > > + continue; > > > > + } > > > > + > > > > + ASSERT ((RegSize % (2 * sizeof(UINT64))) == 0); > > > > + > > > > + while (RegSize > 0) { > > > > + mNorFlashDevices[Num].DeviceBaseAddress = (UINTN)SwapBytes64 (Reg[0]); > > > > + mNorFlashDevices[Num].RegionBaseAddress = (UINTN)SwapBytes64 (Reg[0]); > > > > + mNorFlashDevices[Num].Size = (UINTN)SwapBytes64 (Reg[1]); > > > > + mNorFlashDevices[Num].BlockSize = QEMU_NOR_BLOCK_SIZE; > > > > + > > > > + Num++; > > > > + Reg += 2; > > > > + RegSize -= 2 * sizeof(UINT64); > > > > + > > > > + if (Num >= MAX_FLASH_BANKS) { > > > > + goto Finished; > > > > + } > > > > + } > > > > + } > > > > + > > > > +Finished: > > > > *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 > > > > -- > > > > 2.17.1 > > > >