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 46BA0C54EBC for ; Sun, 8 Jan 2023 03:00:07 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6BF19856B0; Sun, 8 Jan 2023 03:55:45 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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; unprotected) header.d=chromium.org header.i=@chromium.org header.b="fx+DT5qX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B19758561F; Sun, 8 Jan 2023 03:55:32 +0100 (CET) Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E20B385673 for ; Sun, 8 Jan 2023 03:51:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x12e.google.com with SMTP id a9so2670267ilp.6 for ; Sat, 07 Jan 2023 18:51:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SEnmt5SCc3hHtonA1/GNgF230Y9zEeRgxvhrMHVhQG0=; b=fx+DT5qXNUIwdN/xwO0LEG2wQz5zK9+qigBeVyezBC14TbIIdZjF5Wsoz1TG8cBI/w Pxe9BfIfDh5rUlbHrfK0S5yWvt/2MoRYryEBhWnAwhK1raU5CapEIm2wMbgwuRjd4djd JxuiJBE0uMYTT3O3NX64P8p/YopI/BR634Il8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SEnmt5SCc3hHtonA1/GNgF230Y9zEeRgxvhrMHVhQG0=; b=N7FGAbE78WleZbP0Fx3kPVfjlAc90jgVN9T+vpqu8Tv/dO7Zz0qQA2UCbTGI//bfz4 90aW7t8mfZmJ9fCE2qnLB/vAtQ7lQ6XoC/B/Df3xMIfyzcwdPE5eR25o+v/y3WOdIoVL LLn4PvwSFvv+RPRUkkNpcmP/54KhHw8K2qzyCkMecxLYw52WoUXGI06Eu1iGCMzG1tVf khZDrgpS3fZd1oEVvurBbKPY6ht0iWPmieLiO+nyPf3lplKwvAfZQUGG0tS+DzQbE6l2 Z2Lewi8It66AzF/I0ZiheTGnend9iaSHaMiwDvvbnUR4X1UFis19HpoGo4Wr1pmKzwY3 WDrg== X-Gm-Message-State: AFqh2kp1GaXtSw6N58SJyQpVltiD9eodM6emrocVekke93nK3SHPKUsn s/HJxnI9pqB/NaIse8T1ZkoT6nNTA6DvQ+T5 X-Google-Smtp-Source: AMrXdXvSTgQkdAZlpeEnoZB8mac/Gtw8woIjsijT5ZUZAuq3+rAwvCyCzcyMQ7ZIobKKtCazapYrCw== X-Received: by 2002:a92:d2cf:0:b0:30b:e45c:3d1a with SMTP id w15-20020a92d2cf000000b0030be45c3d1amr38398033ilg.23.1673146288442; Sat, 07 Jan 2023 18:51:28 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-71-56-217-229.hsd1.co.comcast.net. [71.56.217.229]) by smtp.gmail.com with ESMTPSA id c17-20020a92bd11000000b00302a00aaefasm1622174ile.26.2023.01.07.18.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 18:51:28 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH v2 46/71] bootstd: Allow reading an EFI file from the network Date: Sat, 7 Jan 2023 19:50:22 -0700 Message-Id: <20230108025047.522240-47-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230108025047.522240-1-sjg@chromium.org> References: <20230108025047.522240-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean At present this bootmeth only supports reading from a filesystem. Add support for reading from a network also, using DHCP with autoload. Signed-off-by: Simon Glass --- (no changes since v1) boot/bootmeth_efi.c | 117 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 109 insertions(+), 8 deletions(-) diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c index f7bb153d9de..77b4ba22470 100644 --- a/boot/bootmeth_efi.c +++ b/boot/bootmeth_efi.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #define EFI_DIRNAME "efi/boot/" @@ -59,6 +60,40 @@ static int get_efi_leafname(char *str, int max_len) return 0; } +static int get_efi_pxe_arch(void) +{ + /* http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml */ + if (IS_ENABLED(CONFIG_ARM64)) + return 0xb; + else if (IS_ENABLED(CONFIG_ARM)) + return 0xa; + else if (IS_ENABLED(CONFIG_X86_64)) + return 0x6; + else if (IS_ENABLED(CONFIG_X86)) + return 0x7; + else if (IS_ENABLED(CONFIG_ARCH_RV32I)) + return 0x19; + else if (IS_ENABLED(CONFIG_ARCH_RV64I)) + return 0x1b; + else if (IS_ENABLED(CONFIG_SANDBOX)) + return 0; /* not used */ + + return -EINVAL; +} + +static int get_efi_pxe_vci(char *str, int max_len) +{ + int ret; + + ret = get_efi_pxe_arch(); + if (ret < 0) + return ret; + + snprintf(str, max_len, "PXEClient:Arch:%05x:UNDI:003000", ret); + + return 0; +} + static int efiload_read_file(struct blk_desc *desc, struct bootflow *bflow) { const struct udevice *media_dev; @@ -101,20 +136,18 @@ static int efiload_read_file(struct blk_desc *desc, struct bootflow *bflow) static int distro_efi_check(struct udevice *dev, struct bootflow_iter *iter) { - int ret; - - /* This only works on block devices */ - ret = bootflow_iter_check_blk(iter); - if (ret) - return log_msg_ret("blk", ret); + /* This only works on block and network devices */ + if (bootflow_iter_check_blk(iter) && bootflow_iter_check_net(iter)) + return log_msg_ret("blk", -ENOTSUPP); return 0; } -static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow) +static int distro_efi_read_bootflow_file(struct udevice *dev, + struct bootflow *bflow) { struct blk_desc *desc = NULL; - char fname[sizeof(EFI_DIRNAME) + 16]; + char fname[256]; int ret; /* We require a partition table */ @@ -140,6 +173,74 @@ static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow) return 0; } +static int distro_efi_read_bootflow_net(struct bootflow *bflow) +{ + const char *addr_str; + int ret, arch, size; + char str[36]; + ulong addr; + + ret = get_efi_pxe_vci(str, sizeof(str)); + if (ret) + return log_msg_ret("vci", ret); + ret = get_efi_pxe_arch(); + if (ret < 0) + return log_msg_ret("arc", ret); + arch = ret; + + ret = env_set("bootp_vci", str); + if (ret) + return log_msg_ret("vcs", ret); + ret = env_set_ulong("bootp_arch", arch); + if (ret) + return log_msg_ret("ars", ret); + + /* figure out the load address */ + addr_str = env_get("kernel_addr_r"); + addr = addr_str ? hextoul(addr_str, NULL) : image_load_addr; + + /* clear any previous bootfile */ + env_set("bootfile", NULL); + + /* read the kernel */ + ret = dhcp_run(addr, NULL, true); + if (ret) + return log_msg_ret("dhc", ret); + + size = env_get_hex("filesize", -1); + if (size <= 0) + return log_msg_ret("sz", -EINVAL); + bflow->size = size; + + /* do the hideous EFI hack */ + efi_set_bootdev("Net", "", bflow->fname, map_sysmem(addr, 0), + bflow->size); + + bflow->state = BOOTFLOWST_READY; + + return 0; +} + +static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow) +{ + const struct udevice *media = dev_get_parent(bflow->dev); + int ret; + + if (IS_ENABLED(CONFIG_CMD_DHCP) && + device_get_uclass_id(media) == UCLASS_ETH) { + /* we only support reading from one device, so ignore 'dev' */ + ret = distro_efi_read_bootflow_net(bflow); + if (ret) + return log_msg_ret("net", ret); + } else { + ret = distro_efi_read_bootflow_file(dev, bflow); + if (ret) + return log_msg_ret("blk", ret); + } + + return 0; +} + int distro_efi_boot(struct udevice *dev, struct bootflow *bflow) { char cmd[50]; -- 2.39.0.314.g84b9a713c41-goog