From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:4001:c06::231; helo=mail-io0-x231.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-io0-x231.google.com (mail-io0-x231.google.com [IPv6:2607:f8b0:4001:c06::231]) (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 89B1221F2E107 for ; Wed, 11 Apr 2018 09:10:58 -0700 (PDT) Received: by mail-io0-x231.google.com with SMTP id y128so2962207iod.4 for ; Wed, 11 Apr 2018 09:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=HkutwdctaIl+wU3YozA2BlpJtn0nxE7l4tsfzLx4XX0=; b=iidwlNP4yS4Z3Ew4O7BvOmmPJYydmJY/JTvnmljfMqt3Vry3QVmera9hfhx/G/xfoz QC8WAmADNBtqov+D610QTIJaodk/AgWyCxsKnzbqZOhz63gO81WNbtejklB1TMr7tiCn pllPGO5/hSEgyldw/0x5gIWXPK//901mdXV5w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=HkutwdctaIl+wU3YozA2BlpJtn0nxE7l4tsfzLx4XX0=; b=bWr4KwRRZsmVxHx0p9VM2RgQLV0wcHMCUd/sD0PqdRPOETsOnTanY0iymrZm7iSH88 Ew/5NLtrHnWJMyJNNOPUxzn14HoCw72sDMq+58bOR2XrLl33Q67cM9olXKUhdc10PAgl DiY6EkD4ZsFdmwiLcGLeDoq1+XRgcka7ecjqFhQXXnGv/n2F1/f4LqnykwKQyVzr5Z2y Owgwxjcv6Antqn/ckZprbvE5mqKYDuZSOe15FFcNu8FvgMQqOrRc11KcQfPZQfZmsvnW VycaNhP0RI9zHLYEKCIYqno8adwoKUeJHAulDHrEPkMU0LwsoYtGVOMySco22zsOM8t0 V8JA== X-Gm-Message-State: ALQs6tDI+Ai4Hqp6drhA5sGqkbMiL9sQ20LGi+SkYz1tajg4gRNvsiVX FDf3gN2wPdF76q5W6UHnZBrOttM6jSYjmDiH4S28TA== X-Google-Smtp-Source: AIpwx4+SI5l363GV0uBYrG8utORh/3MGZGyqcYk+bjRrXTUXp6RlhFJI916BFUCl/4a6zHzUu9G/VXpVK+OUuy8OdUM= X-Received: by 10.107.69.23 with SMTP id s23mr757608ioa.173.1523463057172; Wed, 11 Apr 2018 09:10:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.187.67 with HTTP; Wed, 11 Apr 2018 09:10:56 -0700 (PDT) In-Reply-To: References: From: Ard Biesheuvel Date: Wed, 11 Apr 2018 18:10:56 +0200 Message-ID: To: Supreeth Venkatesh , Leif Lindholm Cc: Laszlo Ersek , Steve Capper , "edk2-devel@lists.01.org" , Nariman Poushin Subject: Re: Boot failure for ArmVExpress-FVP-AArch64, CpuArch protocol does not appear to be registered 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: , X-List-Received-Date: Wed, 11 Apr 2018 16:10:58 -0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On 11 April 2018 at 17:34, Supreeth Venkatesh wrote: > Laszlo/Steve, > > I ran into the same problem on ArmVExpress-FVP-AArch64 while running mana= gement mode. > I have fixed this problem in this patch by reordering driver load order h= ere: > https://lists.01.org/pipermail/edk2-devel/2018-April/023550.html > > Not sure whether Leif/Ard/Laszlo agree with this. > Nope, sorry. PI has an elaborate scheme involving dependency expressions to manage load order of modules, and tweaking the order they appear in the flash volume to get things working again is not the way to address this. Ironically, though, it seems my patch 61a7b0ec634fa3288f47929ba3ced05ff48de739 (which introduces an AFTER xxx depex) is the culprit here, and so I should probably take some responsibility to get things working again. I will look into replacing the NorFlashDxe DEPEX with something more suitable to address this issue, but I am a bit swamped at the moment, so if anyone else beats me to it, I won't complain. --=20 Ard. > -----Original Message----- > From: edk2-devel On Behalf Of Laszlo Er= sek > Sent: Wednesday, April 11, 2018 7:26 AM > To: Steve Capper ; edk2-devel@lists.01.org > Cc: Ard Biesheuvel ; Leif Lindholm ; Nariman Poushin > Subject: Re: [edk2] Boot failure for ArmVExpress-FVP-AArch64, CpuArch pro= tocol does not appear to be registered > > Hi Steve, > > On 04/11/18 12:30, Steve Capper wrote: >> Hello, >> I am trying to debug a boot problem for a recent build of EDK2 in an >> Arm FVP model. >> >> I built EDK2 from the following branches: >> Edk2: a146c532c754106431b063fec9985a838afd82be >> Edk2-platforms: e74f53df8b18e4aed0c9df0942ce0c30f78a68e2 >> >> Toolchain: Debian Stretch latest (though I have also tried Linaro s >> GCC 5 latest). >> >> Build command: >> GCC5_AARCH64_PREFIX=3Daarch64-linux-gnu- build -a AARCH64 -t GCC5 -b >> DEBUG -p Platform/ARM/VExpressPkg/ArmVExpress-FVP-AArch64.dsc >> >> The boot log can be found in the attached file. I *think* this is due >> to the Cpu Arch protocol not actually being ready when >> CoreConvertSpace is called by the SetMemoryAttributes from the >> NorFlash code. >> >> I have found that this code path fails: >> https://github.com/tianocore/edk2/blob/a146c532c754106431b063fec9985a8 >> 38afd82be/MdeModulePkg/Core/Dxe/Gcd/Gcd.c#L893 >> >> The only modification I have made is to edk2-platforms to get more >> debug output (PcdDebugPrintErrorLevel). >> >> Unfortunately, I'm not sure how to fix this? > > This is a bit of a problem. > > The gDS->SetMemorySpaceAttributes() DXE service is allowed to fail if the= CPU architectural protocol has not been installed yet. This is documented = in the Platform Init spec (although riddled by a few typos -- EFI_NOT_AVAIL= ABLE_YET is documented under the preceding > GetMemorySpaceDescriptor() section, and not in the correct > SetMemorySpaceAttributes() section). > > The usual solution for DXE drivers is to add an explicit dependency on gE= fiCpuArchProtocolGuid to the DEPEX section in the INF file. You can see an = example in commit f9a8be423cdd > ("ArmVirtualizationPkg/PciHostBridgeDxe: MMIO aperture must not be uncach= ed", 2015-02-23). > > And that's where the issue is. If you check the [Depex] section in "ArmPl= atformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf", you find > >> [Depex] >> # >> # NorFlashDxe must be loaded before VariableRuntimeDxe in case empty f= lash needs populating with default values >> # >> BEFORE gVariableRuntimeDxeFileGuid > > Why is BEFORE technically an issue here? Because, it cannot be combined w= ith other depex opcodes. From the PI spec: > >> If this opcode is present in a dependency expression, it must be the >> first and only opcode in the expression. If is appears in any other >> location in the dependency expression, then the dependency expression >> is evaluated to FALSE. > > So we can't simply combine the existent BEFORE depex with "AND gEfiCpuArc= hProtocolGuid", like you see in the commit f9a8be423cdd example above. > > Now, more to the point, a "BEFORE" depex is *always* a hack. From the PI > spec: > >> This opcode tells the DXE Dispatcher that the DXE driver that is >> associated with this dependency expression must be dispatched just >> before the DXE driver with the file name specified by GUID. This means >> that as soon as the dependency expression for the DXE driver specified >> by GUID evaluates to TRUE, then this DXE driver must be placed in the >> dispatch queue just before the DXE driver with the file name specified >> by GUID. > > Sometimes there's really no way around such a hack, to express an inter-m= odule dependency, but even then, there is a better way to implement it. Nam= ely, > - a custom protocol GUID can be invented, > - the pre-requisite module can install a NULL protocol interface with > that GUID, > - and > - either the protocol GUID can be added directly to the [depex] > section of the dependent module (if the latter module is under the > platform's control), > - or the platform DSC file can hook a NULL-class library instance into > the dependent module, such that the lib instance makes the dependent > module *inherit* a [depex] on the protocol GUID. > > In other words, if we want to order the dispatch of a platform-independen= t module (that lives in another Package), due to platform-specific circumst= ances, behind another module that our platform owns, then we can change our= platform DSC to "imbue" the module with a dependency on a custom protocol = GUID. We can then install that NULL protocol in our own module. Under this = scheme the usual dependency resolution will order things the right way, and= all the depex-es remain composable with other GUIDs. > > OK -- so *should* we rewrite this BEFORE depex, like described above? I d= on't think so. In my opinion, the *idea* of this dependency is wrong. > The BEFORE depex was introduced in commit 6acb379fbcf8 > ("ArmPlatformPkg/CTA9x4: Remove Variable Storage FD file from FDF", 2011-= 03-31), and the idea there was to replace the build-time pre-formatting of = the flash variable store with runtime formatting. You might ask why this re= placement needed an explicit ordering hint between drivers (i.e. why any DE= PEXes had to be touched at all). Here's why: > > - For *writing* non-volatile UEFI variables, a platform-independent > protocol dependency chain already exists. At the least abstract level, > we have the FVB (firmware volume block) protocol service, e.g. > NorFlashDxe. At the next level, we have the platform-independent FTW > (fault tolerant write) driver. Finally, at the top (the most abstract > level), we have the non-volatile variable write service / driver. > > - However, for *reading* non-volatile UEFI variables, no such dependency > chain exists. The variable driver (the top level from the previous > bullet) will just go ahead and read various headers from the flash > chip. If those headers are not correctly formatted, the variable > driver blows up and the platform will not boot. To solve this issue, > platform FDF files usually pre-format a variable store template at > build-time, which will at once satisfy the "read-side startup" of the > variable driver. > > Unfortunately, this requires FDF files to contain various ugly hexdumps, = and people are tempted to replace those with runtime formatting of the vars= tore headers. In turn though, they have to employ hacks for ordering the va= riable driver behind their runtime formatting. Hence the BEFORE depex. :( > > So, what can we do? Given that NorFlashDxe is used by several platforms, = the ugly BEFORE depex should be removed. Once BEFORE is removed, you can si= mply add "gEfiCpuArchProtocolGuid", and then the current issue will be solv= ed. But, what shall take the place of BEFORE? > > Using ArmVirtQemu as an example platform, the answer is "nothing", becaus= e ArmVirtQemu already pre-formats the varstore template -- please see "ArmV= irtPkg/VarStore.fdf.inc". For all other platforms that don't do this -- and= I don't see "Platform/ARM/VExpressPkg/ArmVExpress-FVP-AArch64.fdf" doing i= t --, there are two choices: > > - build a varstore template in *all* of the platform FDF files where the > platform DSC file includes the NorFlashDxe driver -- in this case, the > BEFORE needs no replacement, it can simply be dropped, > > - or implement the custom NULL protocol trick that I described above. > Platforms that don't actually *depend* on this trick, such as > ArmVirtQemu, will simply ignore the new protocol instance in the > protocol database. > > For the second option, there are several examples under OvmfPkg and ArmVi= rtPkg. One is: > > - "MdeModulePkg/Include/Guid/PlatformHasAcpi.h" defines the custom > "gEdkiiPlatformHasAcpiGuid". > > - "ArmVirtPkg/ArmVirtQemu.dsc" includes the > "ArmVirtPkg/PlatformHasAcpiDtDxe" platform driver, which installs a > NULL protocol interface with the above custom GUID under certain > circumstances. > > - "EmbeddedPkg/Library/PlatformHasAcpiLib" is a library instance that > does nothing; it just has an empty constructor function, and a > dependency on the GUID. > > - "ArmVirtPkg/ArmVirt.dsc.inc" hooks the library into > "MdeModulePkg/Universal/Acpi/AcpiTableDxe", imbuing the latter with a > dependency on the protocol GUID. > > As a result, "MdeModulePkg/Universal/Acpi/AcpiTableDxe" will not be dispa= tched until (and, unless!) "ArmVirtPkg/PlatformHasAcpiDtDxe" > installs the GUID. If the GUID is never installed, then "MdeModulePkg/Uni= versal/Acpi/AcpiTableDxe" will never be dispatched. > > Summary: > (1) introduce a custom GUID for "NorFlashDxe has formatted the variable > store headers for the variable driver to read"; > (2) install the GUID in NorFlashDxe once it's done verifying and/or > formatting the headers; > (3) introduce a custom library instance with an empty constructor > function, and a DEPEX on the GUID; > (4) hook the library instance into > "MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf" > in all the platform DSC files where the platform build does not > pre-format a varstore template in the FDF file; > (5) replace the BEFORE depex with gEfiCpuArchProtocolGuid. > > Thanks, > Laszlo > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel > IMPORTANT NOTICE: The contents of this email and any attachments are conf= idential and may also be privileged. If you are not the intended recipient,= please notify the sender immediately and do not disclose the contents to a= ny other person, use it for any purpose, or store or copy the information i= n any medium. Thank you.