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

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

 include/asm-generic/global_data.h |  4 ++++
 include/fdtdec.h                  | 36 +++++++++++++++++++++++++++++++
 lib/fdtdec.c                      | 21 +++++++++++++-----
 3 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/include/asm-generic/global_data.h 
b/include/asm-generic/global_data.h
index 6aba74dac10..d998581e179 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -265,6 +265,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 24992baed8b..b4e452326b3 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -49,6 +49,35 @@ struct fdt_memory {
 
 struct bd_info;
 
+/**
+ * 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_PASSAGE: From the standard passage (passed in from previous
+ *     phase/stage). This is the normal approach if prior-stage firmware is
+ *     used, such as TF-A
+ * @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_PASSAGE,
+       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
@@ -1209,4 +1238,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 4ca56e06b2f..0a6e195f8ba 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1621,6 +1621,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;
        }
 }
 
@@ -1629,10 +1630,13 @@ 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;
+       }
 
        /* Passed in via the standard passage */
        if (IS_ENABLED(CONFIG_OF_PASSAGE) && gd->passage_dtb_off) {
@@ -1657,6 +1661,7 @@ int fdtdec_setup(void)
                }
                if (fdt) {
                        gd->fdt_blob = fdt;
+                       gd->fdt_src = FDTSRC_PASSAGE;
                        log_debug("passage: Found control dtb at %p\n", fdt);
                }
        }
@@ -1666,12 +1671,18 @@ int fdtdec_setup(void)
                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.33.1.1089.g2158813163f-goog

Reply via email to