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 D41AEC352A1 for ; Wed, 7 Dec 2022 09:05:11 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7FE5885656; Wed, 7 Dec 2022 09:56:49 +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="HhfTq4G7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 031CE85705; Wed, 7 Dec 2022 09:56:46 +0100 (CET) Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) (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 64170856E5 for ; Wed, 7 Dec 2022 09:56:42 +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-pl1-x62d.google.com with SMTP id k7so16417439pll.6 for ; Wed, 07 Dec 2022 00:56:42 -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=rYMVoZl/T+vU0JgMZr5iqJzqXWZoWZkZQQBJUeXHUVM=; b=HhfTq4G7xPn1Z5YNy2hx9+J0DjdVl3Ar888z/xCgv7PsN3NuoRoE++73YNnrpQMnqs h8asQipvUMDOVS4mNeApBOhE/WVyTuhlOw/oykj4XJHh4gr/RZ/GKfaOndPotUiQf52Q NW73LKuL7VztYyk909wlEi5j4YgTQjPixDaY0= 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=rYMVoZl/T+vU0JgMZr5iqJzqXWZoWZkZQQBJUeXHUVM=; b=hq+GJUZCkN/1GVHPBpTVVruC9TV96S93ohNLJecGoXClyQ3iXzz1RvNJ9yNyWmm3eC f6x1u54VFS0mPzHcsvOLRMRq4oUSchy+nzSIEAnIhmaCUdL52p+vj9yZbSXFdJLcS7C2 XdXrVYse4cgg2opGT6NwigRX0qbC1rCd1m8UwfF/mWNizLi3q+EFWolQZGnKxnqQzVNo 9c5YSo7bDm/zgeLqfuKBh2iinRfJmmsZ9Bq5sBGQ//nVD6hhvE72dvP3H/lAGflt+j2G L0ESRkAGa9csobXG9ezBBT24SmZgfaAUxAEzDfL3MlNlLImb9lAxYJTCzMoShsWEGkXq oiig== X-Gm-Message-State: ANoB5pmwcgiy49faow4mb/5opsQmk5psiHINAl806Coh+ZX3PkIdKKuh G3j30JS3SnZOZhIz2jq7SyrkrLvCSQh2FbMD X-Google-Smtp-Source: AA0mqf7/iI6tsy6JhkkIdoBaTxFvGqqe72r7MLP5eZxKUUrjjdXm7GgWMUX8PXxGdLVQm1oWTelyxw== X-Received: by 2002:a17:902:cf05:b0:188:53bd:878a with SMTP id i5-20020a170902cf0500b0018853bd878amr72912123plg.12.1670403400555; Wed, 07 Dec 2022 00:56:40 -0800 (PST) Received: from localhost.localdomain ([27.110.126.54]) by smtp.gmail.com with ESMTPSA id l16-20020a170903121000b0018157b415dbsm14145514plh.63.2022.12.07.00.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 00:56:40 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH 48/71] bootstd: Support reading the device tree with EFI Date: Wed, 7 Dec 2022 21:51:14 +1300 Message-Id: <20221207085137.445249-49-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog In-Reply-To: <20221207085137.445249-1-sjg@chromium.org> References: <20221207085137.445249-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 --- 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.rc0.267.gcb52ba06e7-goog