u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: "Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Sean Anderson" <seanga2@gmail.com>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Tom Rini" <trini@konsulko.com>,
	"Mark Kettenis" <mark.kettenis@xs4all.nl>,
	"François Ozog" <francois.ozog@linaro.org>,
	"Simon Glass" <sjg@chromium.org>,
	"Jerry Van Baren" <vanbaren@cideas.com>
Subject: [PATCH v8 26/32] fdt: Record where the devicetree came from
Date: Thu, 16 Dec 2021 20:59:33 -0700	[thread overview]
Message-ID: <20211216205905.v8.26.I60f02bbc201166267fc11bf3159d1a93764d201f@changeid> (raw)
In-Reply-To: <20211217035939.670884-1-sjg@chromium.org>

Keep track of where the devicetree came from, so we can report this later.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v7)

Changes in v7:
- Drop FDTSRC_PASSAGE for now

 include/asm-generic/global_data.h |  4 ++++
 include/fdtdec.h                  | 32 +++++++++++++++++++++++++++++++
 lib/fdtdec.c                      | 20 ++++++++++++++-----
 3 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 99daa20c765..104282bd479 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -244,6 +244,10 @@ struct global_data {
 	 * @fdt_size: space reserved for relocated device space
 	 */
 	unsigned long fdt_size;
+	/**
+	 * @fdt_src: Source of FDT
+	 */
+	enum fdt_source_t fdt_src;
 #if CONFIG_IS_ENABLED(OF_LIVE)
 	/**
 	 * @of_root: root node of the live tree
diff --git a/include/fdtdec.h b/include/fdtdec.h
index 68a36f10583..09525ce510a 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -55,6 +55,31 @@ struct bd_info;
 #define SPL_BUILD	0
 #endif
 
+/**
+ * enum fdt_source_t - indicates where the devicetree came from
+ *
+ * These are listed in approximate order of desirability after FDTSRC_NONE
+ *
+ * @FDTSRC_SEPARATE: Appended to U-Boot. This is the normal approach if U-Boot
+ *	is the only firmware being booted
+ * @FDTSRC_FIT: Found in a multi-dtb FIT. This should be used when U-Boot must
+ *	select a devicetree from many options
+ * @FDTSRC_BOARD: Located by custom board code. This should only be used when
+ *	the prior stage does not support FDTSRC_PASSAGE
+ * @FDTSRC_EMBED: Embedded into U-Boot executable. This should onyl be used when
+ *	U-Boot is packaged as an ELF file, e.g. for debugging purposes
+ * @FDTSRC_ENV: Provided by the fdtcontroladdr environment variable. This should
+ *	be used for debugging/development only
+ * @FDTSRC_NONE: No devicetree at all
+ */
+enum fdt_source_t {
+	FDTSRC_SEPARATE,
+	FDTSRC_FIT,
+	FDTSRC_BOARD,
+	FDTSRC_EMBED,
+	FDTSRC_ENV,
+};
+
 /*
  * Information about a resource. start is the first address of the resource
  * and end is the last address (inclusive). The length of the resource will
@@ -1215,4 +1240,11 @@ int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
 			   phys_addr_t *basep, phys_size_t *sizep,
 			   struct bd_info *bd);
 
+/**
+ * fdtdec_get_srcname() - Get the name of where the devicetree comes from
+ *
+ * @return source name
+ */
+const char *fdtdec_get_srcname(void);
+
 #endif
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 31a509bc221..8cfa958fb96 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1618,6 +1618,7 @@ static void setup_multi_dtb_fit(void)
 	if (blob) {
 		gd_set_multi_dtb_fit(gd->fdt_blob);
 		gd->fdt_blob = blob;
+		gd->fdt_src = FDTSRC_FIT;
 	}
 }
 
@@ -1626,22 +1627,31 @@ int fdtdec_setup(void)
 	int ret;
 
 	/* The devicetree is typically appended to U-Boot */
-	if (IS_ENABLED(CONFIG_OF_SEPARATE))
+	if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
 		gd->fdt_blob = fdt_find_separate();
-	else /* embed dtb in ELF file for testing / development */
+		gd->fdt_src = FDTSRC_SEPARATE;
+	} else { /* embed dtb in ELF file for testing / development */
 		gd->fdt_blob = dtb_dt_embedded();
+		gd->fdt_src = FDTSRC_EMBED;
+	}
 
 	/* Allow the board to override the fdt address. */
 	if (IS_ENABLED(CONFIG_OF_BOARD)) {
 		gd->fdt_blob = board_fdt_blob_setup(&ret);
 		if (ret)
 			return ret;
+		gd->fdt_src = FDTSRC_BOARD;
 	}
 
+	/* Allow the early environment to override the fdt address */
 	if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
-		/* Allow the early environment to override the fdt address */
-		gd->fdt_blob = map_sysmem(env_get_ulong("fdtcontroladdr", 16,
-			       (unsigned long)map_to_sysmem(gd->fdt_blob)), 0);
+		ulong addr;
+
+		addr = env_get_hex("fdtcontroladdr", 0);
+		if (addr) {
+			gd->fdt_blob = map_sysmem(addr, 0);
+			gd->fdt_src = FDTSRC_ENV;
+		}
 	}
 
 	if (CONFIG_IS_ENABLED(MULTI_DTB_FIT))
-- 
2.34.1.173.g76aa8bc2d0-goog


  parent reply	other threads:[~2021-12-17  4:04 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-17  3:59 [PATCH v8 00/32] fdt: Make OF_BOARD a boolean option Simon Glass
2021-12-17  3:59 ` [PATCH v8 01/32] arm: qemu: Mention -nographic in the docs Simon Glass
2021-12-24 14:34   ` Tom Rini
2021-12-17  3:59 ` [PATCH v8 02/32] arm: riscv: qemu: Explain how to extract the generated dt Simon Glass
2021-12-17  3:59 ` [PATCH v8 03/32] arm: qemu: Add a devicetree file for qemu_arm Simon Glass
2021-12-17  3:59 ` [PATCH v8 04/32] arm: qemu: Add a devicetree file for qemu_arm64 virt Simon Glass
2021-12-17  3:59 ` [PATCH v8 05/32] riscv: qemu: Split devicetree files for qemu_riscv32/64 Simon Glass
2021-12-17  3:59 ` [PATCH v8 06/32] arm: rpi: Sync rpi dts files from Linux Simon Glass
2021-12-17  3:59 ` [PATCH v8 07/32] arm: vexpress: Add a devicetree files for juno Simon Glass
2021-12-18  3:30   ` Linus Walleij
2021-12-17  3:59 ` [PATCH v8 08/32] arm: xenguest_arm64: Add a empty devicetree file Simon Glass
2021-12-17  3:59 ` [PATCH v8 09/32] arm: octeontx: Add an " Simon Glass
2021-12-17  3:59 ` [PATCH v8 10/32] arm: xilinx_versal_virt: Add a " Simon Glass
2021-12-17  3:59 ` [PATCH v8 11/32] arm: bcm7xxx: " Simon Glass
2021-12-17  3:59 ` [PATCH v8 12/32] arm: qemu-ppce500: " Simon Glass
2021-12-17  3:59 ` [PATCH v8 13/32] arm: highbank: Add devicetree files Simon Glass
2021-12-17  3:59 ` [PATCH v8 14/32] fdt: Make OF_BOARD a bool option Simon Glass
2021-12-17  3:59 ` [PATCH v8 15/32] fdt: Drop CONFIG_BINMAN_STANDALONE_FDT Simon Glass
2021-12-17  3:59 ` [PATCH v8 16/32] fdt: Make it easier to debug u-boot.dtsi files Simon Glass
2021-12-17  3:59 ` [PATCH v8 17/32] fdt: Move MULTI_DTB_FIT handling out of fdtdec_setup() Simon Glass
2021-12-17  3:59 ` [PATCH v8 18/32] fdt: Drop #ifdefs with MULTI_DTB_FIT Simon Glass
2021-12-17  3:59 ` [PATCH v8 19/32] fdt: Drop CONFIG_SPL_BUILD check in fdtdec_setup() Simon Glass
2021-12-17  3:59 ` [PATCH v8 20/32] fdt: Drop #ifdef around board_fdt_blob_setup() Simon Glass
2021-12-17  3:59 ` [PATCH v8 21/32] fdt: Use if() for fdtcontroladdr check Simon Glass
2021-12-17  3:59 ` [PATCH v8 22/32] fdt: Drop OF_CONTROL check in fdtdec_setup() Simon Glass
2021-12-17  3:59 ` [PATCH v8 23/32] fdt: Drop remaining preprocessor macros " Simon Glass
2021-12-17  3:59 ` [PATCH v8 24/32] fdt: Don't call board_fdt_blob_setup() without OF_BOARD Simon Glass
2021-12-17  3:59 ` [PATCH v8 25/32] dm: core: Allow getting some basic stats Simon Glass
2021-12-17  3:59 ` Simon Glass [this message]
2021-12-17  3:59 ` [PATCH v8 27/32] fdt: Report the devicetree source Simon Glass
2021-12-17  3:59 ` [PATCH v8 28/32] fdt: Add a Kconfig for boards with a prior stage Simon Glass
2021-12-17  3:59 ` [PATCH v8 29/32] fdt: Enable OF_HAS_PRIOR_STAGE for most boards with OF_BOARD Simon Glass
2021-12-17  3:59 ` [PATCH v8 30/32] fdt: Makefile: Ensure that OF_BOARD is used when needed Simon Glass
2021-12-24 14:34   ` Tom Rini
2021-12-17  3:59 ` [PATCH v8 31/32] fdt: Avoid emitting an device tree when not needed Simon Glass
2021-12-17  3:59 ` [PATCH v8 32/32] fdt: Show a runtime warning based on devicetree source Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211216205905.v8.26.I60f02bbc201166267fc11bf3159d1a93764d201f@changeid \
    --to=sjg@chromium.org \
    --cc=francois.ozog@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=seanga2@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=vanbaren@cideas.com \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).