This overwrites the name loaded from the SPL image. It will be different
if there was previously no name provided, or if a more accurate name was
determined by the board variant selection logic. This means that the DT
name in the SPL header now always matches the DT appended to U-Boot.

Acked-by: Maxime Ripard <mrip...@kernel.org>
Reviewed-by: Andre Przywara <andre.przyw...@arm.com>
Signed-off-by: Samuel Holland <sam...@sholland.org>
---
 board/sunxi/board.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index bff5135c1a1..9d0e29788b1 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -331,6 +331,21 @@ static const char *get_spl_dt_name(void)
        return NULL;
 }
 
+static void set_spl_dt_name(const char *name)
+{
+       struct boot_file_head *spl = get_spl_header(SPL_ENV_HEADER_VERSION);
+
+       if (spl == INVALID_SPL_HEADER)
+               return;
+
+       /* Promote the header version for U-Boot proper, if needed. */
+       if (spl->spl_signature[3] < SPL_DT_HEADER_VERSION)
+               spl->spl_signature[3] = SPL_DT_HEADER_VERSION;
+
+       strcpy((char *)&spl->string_pool, name);
+       spl->dt_name_offset = offsetof(struct boot_file_head, string_pool);
+}
+
 int dram_init(void)
 {
        struct boot_file_head *spl = get_spl_header(SPL_DRAM_HEADER_VERSION);
@@ -904,6 +919,7 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 int board_fit_config_name_match(const char *name)
 {
        const char *best_dt_name = get_spl_dt_name();
+       int ret;
 
 #ifdef CONFIG_DEFAULT_DEVICE_TREE
        if (best_dt_name == NULL)
@@ -941,6 +957,15 @@ int board_fit_config_name_match(const char *name)
        }
 #endif
 
-       return strcmp(name, best_dt_name);
+       ret = strcmp(name, best_dt_name);
+
+       /*
+        * If one of the FIT configurations matches the most accurate DT name,
+        * update the SPL header to provide that DT name to U-Boot proper.
+        */
+       if (ret == 0)
+               set_spl_dt_name(best_dt_name);
+
+       return ret;
 }
 #endif
-- 
2.26.2

Reply via email to