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 1485BC54EBC for ; Sun, 8 Jan 2023 03:00:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 70A5B856C5; Sun, 8 Jan 2023 03:55:59 +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="RMaFQhOa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0D5238562B; Sun, 8 Jan 2023 03:55:41 +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 24A9E8567E for ; Sun, 8 Jan 2023 03:51:30 +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 g2so3301151ila.4 for ; Sat, 07 Jan 2023 18:51:30 -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=EBOXnyMbLjgzUNWkwLjNYYOa9s36UuENpPqB5HxpSIY=; b=RMaFQhOaUtbUe1VPTTqGopCD5c5AOuuiP33wFVrO/7znMn1r5TorxfmkbA+utVtEVD yGgror6ozZkB9Injgap76bAwbDZUwkaF8xEHHPnNcSI1wjcg8AEZP+azI9BitA+7s5DS ETINuijYoap7zhNOUuvAjpZic//L6OX0v2nos= 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=EBOXnyMbLjgzUNWkwLjNYYOa9s36UuENpPqB5HxpSIY=; b=sNSZ5JaLx3fqCWKhOvzhhM8fdbMdr6PA1gfIOqZhZAhdsuyhUAVorOg1iJYQ0/e4gO 6kT1TSPUNVkS1q/qSxPYionqbJinjbQ21X7hxIKQSctpy78c1JpEPA4eZ4s2TsY1XK5t oT6KgfBnD57D0yIru/CB59S1P1vZnQpun9XEYCWzgl9J76FXuNm33GB9977jLPlLIK9R Fza9LMnH1Cf1tl8raNpd8UNfUhk6MorFy7uL6msscFru15RfptpLA6L32sVDFpfGdlij Pt5VcShwIK5AGeOWnu5X2XTn5BgPApIULDgKT43c/4atL613vcK+EaJB78pH8XDxDdOc UN7Q== X-Gm-Message-State: AFqh2kpykyNSJp7DWbtmiy4lnx9MleiZAjLzdSfyf+n/yc1+P2Bk067f Aw4hH5AUUOYOLJfRanQCqetodlUWqVA40Y6M X-Google-Smtp-Source: AMrXdXug50VNEBgxR8al/jZjkPE0bL6EDYAu6Sapj8shajglubsE74hPVjLJwnGqbTzYQTNzO4c5BQ== X-Received: by 2002:a05:6e02:1566:b0:302:70b8:4cc4 with SMTP id k6-20020a056e02156600b0030270b84cc4mr45184741ilu.10.1673146289633; Sat, 07 Jan 2023 18:51:29 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 18:51:29 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH v2 48/71] bootstd: Support reading the device tree with EFI Date: Sat, 7 Jan 2023 19:50:24 -0700 Message-Id: <20230108025047.522240-49-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 With EFI booting the device tree is required but is not actually specified in any way. The normal method is to use a fdtfile environment variable to get the filename, then look for that file on the media. Implement this in the bootmeth. Signed-off-by: Simon Glass --- (no changes since v1) boot/bootmeth_efi.c | 105 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 6 deletions(-) diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c index 77b4ba22470..53a0489b93c 100644 --- a/boot/bootmeth_efi.c +++ b/boot/bootmeth_efi.c @@ -143,10 +143,32 @@ static int distro_efi_check(struct udevice *dev, struct bootflow_iter *iter) return 0; } +static void distro_efi_get_fdt_name(char *fname, int size) +{ + const char *fdt_fname; + + fdt_fname = env_get("fdtfile"); + if (fdt_fname) { + snprintf(fname, size, "dtb/%s", fdt_fname); + log_debug("Using device tree: %s\n", fname); + } else { + const char *soc = env_get("soc"); + const char *board = env_get("board"); + const char *boardver = env_get("boardver"); + + /* cf the code in label_boot() which seems very complex */ + snprintf(fname, size, "dtb/%s%s%s%s.dtb", + soc ? soc : "", soc ? "-" : "", board ? board : "", + boardver ? boardver : ""); + log_debug("Using default device tree: %s\n", fname); + } +} + static int distro_efi_read_bootflow_file(struct udevice *dev, struct bootflow *bflow) { struct blk_desc *desc = NULL; + ulong fdt_addr, size; char fname[256]; int ret; @@ -170,15 +192,43 @@ static int distro_efi_read_bootflow_file(struct udevice *dev, if (ret) return log_msg_ret("read", -EINVAL); + distro_efi_get_fdt_name(fname, sizeof(fname)); + bflow->fdt_fname = strdup(fname); + if (!bflow->fdt_fname) + return log_msg_ret("fil", -ENOMEM); + + fdt_addr = env_get_hex("fdt_addr_r", 0); + ret = bootmeth_common_read_file(dev, bflow, fname, fdt_addr, &size); + if (!ret) { + bflow->fdt_size = size; + bflow->fdt_addr = fdt_addr; + + /* + * TODO: Apply extension overlay + * + * Here we need to load and apply the extension overlay. This is + * not implemented. See do_extension_apply(). The extension + * stuff needs an implementation in boot/extension.c so it is + * separate from the command code. Really the extension stuff + * should use the device tree and a uclass / driver interface + * rather than implementing its own list + */ + } else { + log_debug("No device tree available\n"); + } + return 0; } static int distro_efi_read_bootflow_net(struct bootflow *bflow) { - const char *addr_str; + char file_addr[17], fname[256]; + char *tftp_argv[] = {"tftp", file_addr, fname, NULL}; + struct cmd_tbl cmdtp = {}; /* dummy */ + const char *addr_str, *fdt_addr_str; int ret, arch, size; + ulong addr, fdt_addr; char str[36]; - ulong addr; ret = get_efi_pxe_vci(str, sizeof(str)); if (ret) @@ -216,6 +266,25 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow) efi_set_bootdev("Net", "", bflow->fname, map_sysmem(addr, 0), bflow->size); + /* read the DT file also */ + fdt_addr_str = env_get("fdt_addr_r"); + if (!fdt_addr_str) + return log_msg_ret("fdt", -EINVAL); + fdt_addr = hextoul(fdt_addr_str, NULL); + sprintf(file_addr, "%lx", fdt_addr); + + distro_efi_get_fdt_name(fname, sizeof(fname)); + bflow->fdt_fname = strdup(fname); + if (!bflow->fdt_fname) + return log_msg_ret("fil", -ENOMEM); + + if (!do_tftpb(&cmdtp, 0, 3, tftp_argv)) { + bflow->fdt_size = env_get_hex("filesize", 0); + bflow->fdt_addr = fdt_addr; + } else { + log_debug("No device tree available\n"); + } + bflow->state = BOOTFLOWST_READY; return 0; @@ -243,15 +312,39 @@ static int distro_efi_read_bootflow(struct udevice *dev, struct bootflow *bflow) int distro_efi_boot(struct udevice *dev, struct bootflow *bflow) { + ulong kernel, fdt; char cmd[50]; + /* A non-zero buffer indicates the kernel is there */ + if (bflow->buf) { + kernel = (ulong)map_to_sysmem(bflow->buf); + + /* + * use the provided device tree if available, else fall back to + * the control FDT + */ + if (bflow->fdt_fname) + fdt = bflow->fdt_addr; + else + fdt = (ulong)map_to_sysmem(gd->fdt_blob); + } else { + /* + * This doesn't actually work for network devices: + * + * do_bootefi_image() No UEFI binary known at 0x02080000 + * + * But this is the same behaviour for distro boot, so it can be + * fixed here. + */ + kernel = env_get_hex("kernel_addr_r", 0); + fdt = env_get_hex("fdt_addr_r", 0); + } + /* * 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. + * 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)); + snprintf(cmd, sizeof(cmd), "bootefi %lx %lx", kernel, fdt); if (run_command(cmd, 0)) return log_msg_ret("run", -EINVAL); -- 2.39.0.314.g84b9a713c41-goog