From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A4EFC77B7C for ; Fri, 12 May 2023 14:07:59 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B3E7886215; Fri, 12 May 2023 16:07:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 7BA5B86216; Fri, 12 May 2023 16:07:54 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 931AA86210 for ; Fri, 12 May 2023 16:07:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF187D75; Fri, 12 May 2023 07:08:34 -0700 (PDT) Received: from donnerap.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 989B33F663; Fri, 12 May 2023 07:07:49 -0700 (PDT) Date: Fri, 12 May 2023 15:07:41 +0100 From: Andre Przywara To: Heinrich Schuchardt Cc: Simon Glass , u-boot@lists.denx.de, Sean Anderson , Ilias Apalodimas Subject: Re: [PATCH] efi: fix semihosting EFI payload booting Message-ID: <20230512150741.63b9487b@donnerap.cambridge.arm.com> In-Reply-To: <34bd1f73-5651-6e07-5831-4dbca6e1d125@gmx.de> References: <20230510141304.3776511-1-andre.przywara@arm.com> <5519d9e0-2aa6-0455-6968-4d71782bfeae@gmx.de> <20230510182626.66590d67@donnerap.cambridge.arm.com> <145c95cf-b1c8-a328-1d45-730a0738498f@gmx.de> <20230511010016.226da4ff@slackpad.lan> <20230511095940.4d0ff1db@slackpad.lan> <34bd1f73-5651-6e07-5831-4dbca6e1d125@gmx.de> Organization: ARM X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On Thu, 11 May 2023 17:23:13 +0200 Heinrich Schuchardt wrote: Hi Heinrich, Ilias, > On 5/11/23 10:59, Andre Przywara wrote: > > On Thu, 11 May 2023 08:22:30 +0200 > > Heinrich Schuchardt wrote: > > > >> On 5/11/23 02:00, Andre Przywara wrote: > >>> On Wed, 10 May 2023 23:19:33 +0200 > >>> Heinrich Schuchardt wrote: > >>> > >>> Hi, > >>> > >>>> On 5/10/23 19:26, Andre Przywara wrote: > >>>>> On Wed, 10 May 2023 17:58:06 +0200 > >>>>> Heinrich Schuchardt wrote: > >>>>> > >>>>> Hi, > >>>>> > >>>>>> On 5/10/23 16:13, Andre Przywara wrote: > >>>>>>> At the moment any naive attempt to boot an EFI payload that has just > >>>>>>> been loaded via "hostfs" (sandbox or semihosting) is met by a rather > >>>>>>> confusing error message: > >>>>>>> =========== > >>>>>>> VExpress64# load hostfs - $kernel_addr_r Image > >>>>>>> 52752896 bytes read in 8 ms (6.1 GiB/s) > >>>>>>> VExpress64# bootefi $kernel_addr_r > >>>>>>> No UEFI binary known at 0x80080000 > >>>>>>> =========== > >>>>>>> Actually explicitly providing the filesize: > >>>>>>> VExpress64# bootefi $kernel_addr_r:$filesize > >>>>>>> works around that problem, but the issue lies deeper: the call to > >>>>>>> efi_set_bootdev() (as done by the generic load code) bails out at some > >>>>>>> point, leaving the image_addr and image_size variables unset, which > >>>>>>> triggers this message. The problem seems to be that "-" is not > >>>>>>> understood by the code creating an UEFI device path. We could try to fix > >>>>>>> just that, but actually semihosting seems to have some explicit support > >>>>>>> in UEFI (at least it does in EDK II): there is a separate GUID for it, > >>>>>>> and hostfs is significantly different in some aspects to justify special > >>>>>>> handling. > >>>>>>> > >>>>>>> Check for the device name being "hostfs" and create a specific UEFI device > >>>>>>> path for semihosting in this case. This uses the GUID used by EDK II for > >>>>>>> almost 15 years. > >>>>>>> This fixes the above load/bootefi sequence without requiring an explicit > >>>>>>> file size argument. > >>>>>>> > >>>>>>> Signed-off-by: Andre Przywara > >>>>>> .... > Now I am able to debug the code. > > I wonder if the file system should be exposed as EFI simple file system > so that EFI applications can access it, e.g. for GRUB to load initrd and > the kernel. Yes, this would be the ultimate goal. There is no file listing functionality in semihosting, which is a bummer, but it should still work if you know the file name. On top of the EDK-II shell or grub being able to load an image, this would also allow to easily specify an initrd via the kernel command line. This works with EDK-II's semihosting support. But I see that this requires more work, IIUC we need to support hostfs explicitly via the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. At the moment this seems to assume that there is some underlying block device, so this might need some refactoring. As it stands right now, your much simpler patch seems to provide the same functionality as mine, so I wonder if we should take this as a kind of quick fix, to allow starting EFI apps loaded via hostfs (including sandbox, btw). Eventually, when introducing proper filesystem protocol support, this patch probably would need to come back. So I leave this up to you, but am fine with your simpler patch. Cheers, Andre > > If we don't want to expose it, this change will be enough: > > diff --git a/lib/efi_loader/efi_device_path.c > b/lib/efi_loader/efi_device_path.c > index e2e98a39be..058bdc1ee5 100644 > --- a/lib/efi_loader/efi_device_path.c > +++ b/lib/efi_loader/efi_device_path.c > @@ -1203,7 +1203,7 @@ efi_status_t efi_dp_from_name(const char *dev, > const char *devnr, > } else if (!strcmp(dev, "Uart")) { > if (device) > *device = efi_dp_from_uart(); > - } else if (!strcmp(dev, "Mem")) { > + } else if (!strcmp(dev, "Mem") || !strcmp(dev, "hostfs") ) { > efi_get_image_parameters(&image_addr, &image_size); > > if (device) > > Best regards > > Heinrich >