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 C930BC61DA4 for ; Wed, 22 Feb 2023 19:17:57 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D95E185B82; Wed, 22 Feb 2023 20:17: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="cZFdYhgh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 96D4485B84; Wed, 22 Feb 2023 20:17:20 +0100 (CET) Received: from mail-il1-x129.google.com (mail-il1-x129.google.com [IPv6:2607:f8b0:4864:20::129]) (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 3C69185B40 for ; Wed, 22 Feb 2023 20:17:12 +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-x129.google.com with SMTP id o8so1245137ilt.13 for ; Wed, 22 Feb 2023 11:17:11 -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=mvgnWkZ9OGuEtQD4IKHlde8xtpSEKrjo7p9ZdyLnO94=; b=cZFdYhghk6RXAcz9ZSTxErd0hPtxtBthz+4sa9+GIXuhqVugmoZU5ZJTm1f5ckyjCD ulEhoK0RwzwwJ+6C9kFOcR4xOtrNlWLDVV+qjkNOtpDUjqYdRp3Lf+rmJ2ZQlsuqr+tX H+Ms+M2UMKiMdCplxqBQiYFmjrogOjBHjf6RY= 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=mvgnWkZ9OGuEtQD4IKHlde8xtpSEKrjo7p9ZdyLnO94=; b=0lKebPgDa2M3yiQP4XsErpIsQpUPukZXEqQrawQUCPh7TIGk6WTvhUCA3cKX3cuU4W duIp2epvh55Evqso1OGOIuStWd9xOc1noBQCD15Z+sWn8x7Rm7Ui3S3hhnQY8uYt3mfz byqeHwl8sz74XTDIENyMNUb8dylxPS2crq0pxoOU0Pn+xclNMrGt0fbXv3vyVDjVMvnZ YOUQGUcXLKtTv9MJacFOvC4jqDbL2NwUe0I+xCLK+G9vX8HtpzWORP2LXzNLmBpkFtex ZZGWgsjX54fASWfclSUGFeMXXPVsi4A51QdDz9COy96o4Pmi8osI/RWuSfxNQanq+0II W3tg== X-Gm-Message-State: AO0yUKWJ+5UGDOBxVuzmUB8eIRwQLvasItKQujVFyP8GR1rjun+lesoB C5GD0TS8pbg6hti5yVdZ1Kq8rnALlLQK0pQW X-Google-Smtp-Source: AK7set9dScREzYeS090JXdsh9h8wwlRwQaIZCB4b8fb/NPMKUbeGl42h9qQBVU9mpkpgUdSzWw/0Uw== X-Received: by 2002:a92:760c:0:b0:315:40d1:62a3 with SMTP id r12-20020a92760c000000b0031540d162a3mr8115057ilc.24.1677093429277; Wed, 22 Feb 2023 11:17:09 -0800 (PST) Received: from kea.bld.corp.google.com ([2620:15c:183:200:ba91:a998:7b71:c020]) by smtp.gmail.com with ESMTPSA id n22-20020a02a916000000b003c2b76fcdf2sm1529291jam.52.2023.02.22.11.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 11:17:09 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Mark Kettenis , Tom Rini , Simon Glass Subject: [PATCH v4 2/2] bootstd: Replicate the dtb-filename quirks of distroboot Date: Wed, 22 Feb 2023 12:17:04 -0700 Message-Id: <20230222191704.1309987-2-sjg@chromium.org> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog In-Reply-To: <20230222191704.1309987-1-sjg@chromium.org> References: <20230222191704.1309987-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 For EFI, the distro boot scripts search in three different directories for the .dtb file. The SOC-based filename fallback is supported only for 32-bit ARM. Adjust the code to mirror this behaviour. Also some boards can use a prior-stage FDT if one is not found in the normal way. Support this and show a message in that case. Signed-off-by: Simon Glass Suggested-by: Mark Kettenis --- Changes in v4: - Update commit message to avoid mentioning a warning - Rebase to -master instead of -next Changes in v3: - Change the message from a warning to a statement Changes in v2: - Allow use of the prior-stage FDT if nothing else is found - Warn about using a prior-stage FDT boot/bootflow.c | 3 ++ boot/bootmeth_efi.c | 70 +++++++++++++++++++++++++++++++++++++++------ include/bootflow.h | 14 +++++++++ 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/boot/bootflow.c b/boot/bootflow.c index 70d5fc52387..8f2cb876bb4 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -467,6 +467,9 @@ int bootflow_run_boot(struct bootflow_iter *iter, struct bootflow *bflow) printf("** Booting bootflow '%s' with %s\n", bflow->name, bflow->method->name); + if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE) && + (bflow->flags & BOOTFLOWF_USE_PRIOR_FDT)) + printf("Using prior-stage device tree\n"); ret = bootflow_boot(bflow); if (!IS_ENABLED(CONFIG_BOOTSTD_FULL)) { printf("Boot failed (err=%d)\n", ret); diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c index 67c972e3fe4..6a97ac02ff5 100644 --- a/boot/bootmeth_efi.c +++ b/boot/bootmeth_efi.c @@ -147,25 +147,60 @@ 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) +/** + * distro_efi_get_fdt_name() - Get the filename for reading the .dtb file + * + * @fname: Place to put filename + * @size: Max size of filename + * @seq: Sequence number, to cycle through options (0=first) + * Returns: 0 on success, -ENOENT if the "fdtfile" env var does not exist, + * -EINVAL if there are no more options, -EALREADY if the control FDT should be + * used + */ +static int distro_efi_get_fdt_name(char *fname, int size, int seq) { const char *fdt_fname; + const char *prefix; + + /* select the prefix */ + switch (seq) { + case 0: + /* this is the default */ + prefix = "/dtb"; + break; + case 1: + prefix = ""; + break; + case 2: + prefix = "/dtb/current"; + break; + default: + return log_msg_ret("pref", -EINVAL); + } fdt_fname = env_get("fdtfile"); if (fdt_fname) { - snprintf(fname, size, "dtb/%s", fdt_fname); + snprintf(fname, size, "%s/%s", prefix, fdt_fname); log_debug("Using device tree: %s\n", fname); - } else { + } else if (IS_ENABLED(CONFIG_OF_HAS_PRIOR_STAGE)) { + strcpy(fname, ""); + return log_msg_ret("pref", -EALREADY); + /* Use this fallback only for 32-bit ARM */ + } else if (IS_ENABLED(CONFIG_ARM) && !IS_ENABLED(CONFIG_ARM64)) { 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", + snprintf(fname, size, "%s/%s%s%s%s.dtb", prefix, soc ? soc : "", soc ? "-" : "", board ? board : "", boardver ? boardver : ""); log_debug("Using default device tree: %s\n", fname); + } else { + return log_msg_ret("env", -ENOENT); } + + return 0; } static int distro_efi_read_bootflow_file(struct udevice *dev, @@ -174,7 +209,7 @@ static int distro_efi_read_bootflow_file(struct udevice *dev, struct blk_desc *desc = NULL; ulong fdt_addr, size; char fname[256]; - int ret; + int ret, seq; /* We require a partition table */ if (!bflow->part) @@ -196,13 +231,26 @@ 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)); + fdt_addr = env_get_hex("fdt_addr_r", 0); + + /* try the various available names */ + ret = -ENOENT; + for (seq = 0; ret; seq++) { + ret = distro_efi_get_fdt_name(fname, sizeof(fname), seq); + if (ret == -EALREADY) { + bflow->flags = BOOTFLOWF_USE_PRIOR_FDT; + break; + } + if (ret) + return log_msg_ret("nam", ret); + ret = bootmeth_common_read_file(dev, bflow, fname, fdt_addr, + &size); + } + 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; @@ -277,7 +325,11 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow) fdt_addr = hextoul(fdt_addr_str, NULL); sprintf(file_addr, "%lx", fdt_addr); - distro_efi_get_fdt_name(fname, sizeof(fname)); + /* We only allow the first prefix with PXE */ + ret = distro_efi_get_fdt_name(fname, sizeof(fname), 0); + if (ret) + return log_msg_ret("nam", ret); + bflow->fdt_fname = strdup(fname); if (!bflow->fdt_fname) return log_msg_ret("fil", -ENOMEM); diff --git a/include/bootflow.h b/include/bootflow.h index e5fdf5f29d1..f20f575030f 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -36,6 +36,18 @@ enum bootflow_state_t { BOOTFLOWST_COUNT }; +/** + * enum bootflow_flags_t - flags for bootflows + * + * @BOOTFLOWF_USE_PRIOR_FDT: Indicates that an FDT was not found by the bootmeth + * and it is using the prior-stage FDT, which is the U-Boot control FDT. + * This is only possible with the EFI bootmeth (distro-efi) and only when + * CONFIG_OF_HAS_PRIOR_STAGE is enabled + */ +enum bootflow_flags_t { + BOOTFLOWF_USE_PRIOR_FDT = 1 << 0, +}; + /** * struct bootflow - information about a bootflow * @@ -68,6 +80,7 @@ enum bootflow_state_t { * @fdt_fname: Filename of FDT file * @fdt_size: Size of FDT file * @fdt_addr: Address of loaded fdt + * @flags: Flags for the bootflow (see enum bootflow_flags_t) */ struct bootflow { struct list_head bm_node; @@ -90,6 +103,7 @@ struct bootflow { char *fdt_fname; int fdt_size; ulong fdt_addr; + int flags; }; /** -- 2.39.2.637.g21b0678d19-goog