]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sunxi: board: Add a helper to get the SPL DT name
authorSamuel Holland <samuel@sholland.org>
Sat, 24 Oct 2020 15:21:50 +0000 (10:21 -0500)
committerAndre Przywara <andre.przywara@arm.com>
Tue, 17 Nov 2020 00:42:20 +0000 (00:42 +0000)
This moves the validity checking and typecasts all to one place away
from the string comparison logic, and it detangles the compile-time
and runtime control flow.

The new helper will also be used by U-Boot proper in a future commit.

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: protect new function with CONFIG_SPL_LOAD_FIT]
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
board/sunxi/board.c

index d7dfcc78eabdb1d37a46844fa2b46c85dd446535..078a881e5727b006059e7bd39a61fd82602ed5aa 100644 (file)
@@ -319,6 +319,19 @@ static struct boot_file_head * get_spl_header(uint8_t req_version)
        return spl;
 }
 
+#ifdef CONFIG_SPL_LOAD_FIT
+static const char *get_spl_dt_name(void)
+{
+       struct boot_file_head *spl = get_spl_header(SPL_DT_HEADER_VERSION);
+
+       /* Check if there is a DT name stored in the SPL header. */
+       if (spl != INVALID_SPL_HEADER && spl->dt_name_offset)
+               return (char *)spl + spl->dt_name_offset;
+
+       return NULL;
+}
+#endif
+
 int dram_init(void)
 {
        struct boot_file_head *spl = get_spl_header(SPL_DRAM_HEADER_VERSION);
@@ -891,20 +904,17 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 #ifdef CONFIG_SPL_LOAD_FIT
 int board_fit_config_name_match(const char *name)
 {
-       struct boot_file_head *spl = get_spl_header(SPL_DT_HEADER_VERSION);
-       const char *best_dt_name = (const char *)spl;
+       const char *best_dt_name = get_spl_dt_name();
 
-       /* Check if there is a DT name stored in the SPL header and use that. */
-       if (spl != INVALID_SPL_HEADER && spl->dt_name_offset) {
-               best_dt_name += spl->dt_name_offset;
-       } else {
 #ifdef CONFIG_DEFAULT_DEVICE_TREE
+       if (best_dt_name == NULL)
                best_dt_name = CONFIG_DEFAULT_DEVICE_TREE;
-#else
-               return 0;
 #endif
-       };
 
+       if (best_dt_name == NULL) {
+               /* No DT name was provided, so accept the first config. */
+               return 0;
+       }
 #ifdef CONFIG_PINE64_DT_SELECTION
 /* Differentiate the two Pine64 board DTs by their DRAM size. */
        if (strstr(name, "-pine64") && strstr(best_dt_name, "-pine64")) {