sunxi: board: Save the chosen DT name in the SPL header
authorSamuel Holland <samuel@sholland.org>
Sat, 24 Oct 2020 15:21:53 +0000 (10:21 -0500)
committerAndre Przywara <andre.przywara@arm.com>
Tue, 17 Nov 2020 00:42:20 +0000 (00:42 +0000)
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 <mripard@kernel.org>
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
[Andre: move function under CONFIG_SPL_LOAD_FIT guard]
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
board/sunxi/board.c

index 3243e16a841acc0c7608f52c59063027d8608fc9..42fc6024d39580e50badde2e4eaf704669cf4ace 100644 (file)
@@ -903,9 +903,26 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 }
 
 #ifdef CONFIG_SPL_LOAD_FIT
+
+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 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)
@@ -943,6 +960,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