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 40510C433F5 for ; Wed, 19 Jan 2022 11:45:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D5E538303A; Wed, 19 Jan 2022 12:45:47 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="UaD/89j6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 17D848338F; Wed, 19 Jan 2022 12:45:46 +0100 (CET) Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BB1A481B4B for ; Wed, 19 Jan 2022 12:45:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1642592738; bh=LwMvDE22yMLQbew4UXm9ev7dt7L167F/7H06T2nEGyI=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=UaD/89j6dP+prGt1PGGZE+b4iu5bo28t4i3R8O4QLTAyAdvgRglK7DIwvVVxmmNCJ k0keVhKfvihyBdQ/ixdbIYzpZVH+CTgSd4zI/gFf8hYG4iKTDXMO6Yr0BsbISGqA3o n93PEkpLZOkQVmlujBVEGMVsahUWdALpt+Ll2Vu4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.123.94] ([88.152.144.107]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M9nxn-1nDA5E35TJ-005qEH; Wed, 19 Jan 2022 12:45:37 +0100 Message-ID: <3b6ddf64-5dd5-8da9-3113-bda8ec3be809@gmx.de> Date: Wed, 19 Jan 2022 12:45:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v3 22/31] bootstd: Add an implementation of EFI boot Content-Language: en-US To: Simon Glass , U-Boot Mailing List Cc: Ilias Apalodimas , Daniel Schwierzeck , Dennis Gilmore , Steffen Jaeckel , Lukas Auer , Michal Simek , Tom Rini References: <20220119014315.1938157-1-sjg@chromium.org> <20220119014315.1938157-14-sjg@chromium.org> From: Heinrich Schuchardt In-Reply-To: <20220119014315.1938157-14-sjg@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:rrzjwTMViKP6H8pYPJ49cdHOOOox3LZkuVuaPXFbEr6rYVHx26z 31+rZoEItfn7VBaYQ3A9GCudEuQx3KfHVQD/XMC6GbFLd3FJnLl3WLMlPUBGTjuhSUWEKo7 7cqQQL+y5dNZRRInt13FxPXXhQVeA7oxhdTADR/QoPxj/r//kAiETEA9vqy8mcqIyB8S3Ez PIdTy5el/BOipGBi/Gmxw== X-UI-Out-Filterresults: notjunk:1;V03:K0:LppnAJ2A/aU=:JN0+2kTwbX92H1IYbeugUF iGClD8KsJuJrKnx3IXIRHk1Uu0IbaJm6xivVDYpgSVOrWRCLvaRPOzErzj6c3DIEQy4esgZQT umblc43M9phfdUnymPU/CPnKaz4zYgZOT2QvUOus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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.2 at phobos.denx.de X-Virus-Status: Clean On 1/19/22 02:43, Simon Glass wrote: > Add a bootmeth driver which handles EFI boot, using EFI_LOADER. > > In effect, this provides the same functionality as the 'bootefi' command > and shares the same code. But the interface into it is via a bootmeth, > so it does not require any special scripts, etc. > > For now this requires the 'bootefi' command be enabled. Future work may > tidy this up so that it can be used without CONFIG_CMDLINE being enabled= . > > There was much discussion about whether this is needed, but it seems > that it is, at least for now. > > Signed-off-by: Simon Glass > --- > > Changes in v3: > - Add a log category > - Use a short name when BOOTSTD_FULL is not enabled > - Align the EFI load address > - Use common bootmeth functions > > boot/Kconfig | 21 +++++ > boot/Makefile | 1 + > boot/bootmeth_efi.c | 183 ++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 205 insertions(+) > create mode 100644 boot/bootmeth_efi.c > > diff --git a/boot/Kconfig b/boot/Kconfig > index 61df705141d..0fee35070b0 100644 > --- a/boot/Kconfig > +++ b/boot/Kconfig > @@ -338,6 +338,27 @@ config BOOTMETH_DISTRO_PXE > > This provides a way to try out standard boot on an existing boot fl= ow. > > +config BOOTMETH_EFILOADER > + bool "Bootdev support for EFI boot" > + depends on CMD_BOOTEFI > + default y > + help > + Enables support for EFI boot using bootdevs. This makes the > + bootdevs look for a 'boot.efi' on each filesystem > + they scan. The resulting file is booted after enabling U-Boot's > + EFI loader support. > + > + The depends on the architecture of the board: > + > + aa64 - aarch64 (ARM 64-bit) > + arm - ARM 32-bit > + ia32 - x86 32-bit > + x64 - x86 64-bit > + riscv32 - RISC-V 32-bit > + riscv64 - RISC-V 64-bit > + > + This provides a way to try out standard boot on an existing boot flo= w. > + > endif > > config LEGACY_IMAGE_FORMAT > diff --git a/boot/Makefile b/boot/Makefile > index 170fcac8ec4..c2345435201 100644 > --- a/boot/Makefile > +++ b/boot/Makefile > @@ -30,6 +30,7 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) +=3D bootstd-uclass.o > > obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO) +=3D bootmeth_distro.o > obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_DISTRO_PXE) +=3D bootmeth_pxe.o > +obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_EFILOADER) +=3D bootmeth_efi.o > > obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) +=3D image-fdt.o > obj-$(CONFIG_$(SPL_TPL_)FIT_SIGNATURE) +=3D fdt_region.o > diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c > new file mode 100644 > index 00000000000..4c0c3494c3b > --- /dev/null > +++ b/boot/bootmeth_efi.c > @@ -0,0 +1,183 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Bootmethod for distro boot via EFI > + * > + * Copyright 2021 Google LLC > + * Written by Simon Glass > + */ > + > +#define LOG_CATEGORY UCLASS_BOOTSTD > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define EFI_DIRNAME "efi/boot/" > + > +/** > + * get_efi_leafname() - Get the leaf name for the EFI file we expect > + * > + * @str: Place to put leaf name for this architecture, e.g. "bootaa64.e= fi". > + * Must have at least 16 bytes of space > + * @max_len: Length of @str, must be >=3D16 > + */ > +static int get_efi_leafname(char *str, int max_len) > +{ > + const char *base; > + > + if (max_len < 16) > + return log_msg_ret("spc", -ENOSPC); > + if (IS_ENABLED(CONFIG_ARM64)) > + base =3D "bootaa64"; > + else if (IS_ENABLED(CONFIG_ARM)) > + base =3D "bootarm"; > + else if (IS_ENABLED(CONFIG_X86_RUN_32BIT)) > + base =3D "bootia32"; > + else if (IS_ENABLED(CONFIG_X86_RUN_64BIT)) > + base =3D "bootx64"; > + else if (IS_ENABLED(CONFIG_ARCH_RV32I)) > + base =3D "bootriscv32"; > + else if (IS_ENABLED(CONFIG_ARCH_RV64I)) > + base =3D "bootriscv64"; > + else if (IS_ENABLED(CONFIG_SANDBOX)) > + base =3D "bootsbox"; > + else > + return -EINVAL; > + > + strcpy(str, base); > + strcat(str, ".efi"); > + > + return 0; > +} > + > +static int efiload_read_file(struct blk_desc *desc, struct bootflow *bf= low) > +{ > + const struct udevice *media_dev; > + int size =3D bflow->size; > + char devnum_str[9]; > + char dirname[200]; > + char *last_slash; > + int ret; > + > + ret =3D bootmeth_alloc_file(bflow, 0x2000000, 0x10000); > + if (ret) > + return log_msg_ret("read", ret); > + > + /* > + * This is a horrible hack to tell EFI about this boot device. Once we > + * unify EFI with the rest of U-Boot we can clean this up. The same ha= ck > + * exists in multiple places, e.g. in the fs, tftp and load commands. > + * > + * Once we can clean up the EFI code to make proper use of driver mode= l, > + * this can go away. > + */ > + media_dev =3D dev_get_parent(bflow->dev); > + snprintf(devnum_str, sizeof(devnum_str), "%x", dev_seq(media_dev)); > + > + strlcpy(dirname, bflow->fname, sizeof(dirname)); > + last_slash =3D strrchr(dirname, '/'); > + if (last_slash) > + *last_slash =3D '\0'; > + > + log_debug("setting bootdev %s, %s\n", dev_get_uclass_name(media_dev), > + bflow->fname); > + efi_set_bootdev(dev_get_uclass_name(media_dev), devnum_str, > + bflow->fname, bflow->buf, size); > + > + return 0; > +} > + > +static int distro_efi_check(struct udevice *dev, struct bootflow_iter *= iter) > +{ > + int ret; > + > + /* This only works on block devices */ > + ret =3D bootflow_iter_uses_blk_dev(iter); > + if (ret) > + return log_msg_ret("blk", ret); > + > + return 0; > +} > + > +static int distro_efi_read_bootflow(struct udevice *dev, struct bootflo= w *bflow) > +{ > + struct blk_desc *desc =3D dev_get_uclass_plat(bflow->blk); > + char fname[sizeof(EFI_DIRNAME) + 16]; > + int ret; > + > + /* We require a partition table */ > + if (!bflow->part) > + return -ENOENT; > + > + strcpy(fname, EFI_DIRNAME); > + ret =3D get_efi_leafname(fname + strlen(fname), > + sizeof(fname) - strlen(fname)); > + if (ret) > + return log_msg_ret("leaf", ret); > + > + ret =3D bootmeth_try_file(bflow, desc, NULL, fname); > + if (ret) > + return log_msg_ret("try", ret); > + > + ret =3D efiload_read_file(desc, bflow); > + if (ret) > + return log_msg_ret("read", -EINVAL); > + > + return 0; > +} > + > +int distro_efi_boot(struct udevice *dev, struct bootflow *bflow) > +{ > + char cmd[50]; > + > + /* > + * At some point we can add a real interface to bootefi so we can call > + * this directly. For now, go through the CLI like distro boot. > + */ > + snprintf(cmd, sizeof(cmd), "bootefi %lx %lx", > + (ulong)map_to_sysmem(bflow->buf), > + (ulong)map_to_sysmem(gd->fdt_blob)); > + if (run_command(cmd, 0)) > + return log_msg_ret("run", -EINVAL); > + > + return 0; > +} > + > +static int distro_bootmeth_efi_bind(struct udevice *dev) > +{ > + struct bootmeth_uc_plat *plat =3D dev_get_uclass_plat(dev); > + > + plat->desc =3D IS_ENABLED(CONFIG_BOOTSTD_FULL) ? > + "EFI boot from a .efi file" : "EFI"; nits: %s/a/an/ > + > + return 0; > +} > + > +static struct bootmeth_ops distro_efi_bootmeth_ops =3D { > + .check =3D distro_efi_check, > + .read_bootflow =3D distro_efi_read_bootflow, > + .read_file =3D bootmeth_common_read_file, > + .boot =3D distro_efi_boot, > +}; Where is the device tree read? Best regards Heinrich > + > +static const struct udevice_id distro_efi_bootmeth_ids[] =3D { > + { .compatible =3D "u-boot,distro-efi" }, > + { } > +}; > + > +U_BOOT_DRIVER(bootmeth_efi) =3D { > + .name =3D "bootmeth_efi", > + .id =3D UCLASS_BOOTMETH, > + .of_match =3D distro_efi_bootmeth_ids, > + .ops =3D &distro_efi_bootmeth_ops, > + .bind =3D distro_bootmeth_efi_bind, > +};