There is a function inside the board file to autodetect which device tree is needed by U-Boot to properly load its own device tree, but it currently defaults to always loading RZ/G2M for Linux. This is not correct for other SoC variants. Add board_late_init function to query the SoC name and use that to determine which device tree is loaded for booting Linux.
Signed-off-by: Adam Ford <aford...@gmail.com> diff --git a/board/beacon/beacon-rzg2m/beacon-rzg2m.c b/board/beacon/beacon-rzg2m/beacon-rzg2m.c index 99fe1edfb3..6d37ff6ac9 100644 --- a/board/beacon/beacon-rzg2m/beacon-rzg2m.c +++ b/board/beacon/beacon-rzg2m/beacon-rzg2m.c @@ -6,6 +6,7 @@ #include <common.h> #include <asm/global_data.h> #include <asm/io.h> +#include <env.h> DECLARE_GLOBAL_DATA_PTR; @@ -17,6 +18,38 @@ int board_init(void) return 0; } +#if IS_ENABLED(CONFIG_BOARD_LATE_INIT) +static u8 get_SoC_letter(void) +{ + const u8 *name = rzg_get_cpu_name(); + + if (*name) + return name[6]; + + return 0; +} + +int board_late_init(void) +{ + /* If already defined, exit */ + if (!env_get("fdt_file")) { + switch (get_SoC_letter()) { + case 'A': + env_set("fdt_file", "r8a774a1-beacon-rzg2m-kit.dtb"); + break; + case 'B': + env_set("fdt_file", "r8a774b1-beacon-rzg2n-kit.dtb"); + break; + case 'E': + env_set("fdt_file", "r8a774e1-beacon-rzg2h-kit.dtb"); + break; + } + } + + return 0; +} +#endif /* CONFIG_BOARD_LATE_INIT */ + #if IS_ENABLED(CONFIG_MULTI_DTB_FIT) int board_fit_config_name_match(const char *name) { diff --git a/configs/rzg2_beacon_defconfig b/configs/rzg2_beacon_defconfig index 534f641e84..6894448b22 100644 --- a/configs/rzg2_beacon_defconfig +++ b/configs/rzg2_beacon_defconfig @@ -21,6 +21,7 @@ CONFIG_USE_BOOTCOMMAND=y CONFIG_BOOTCOMMAND="mmc dev ${mmcdev}; if mmc rescan; then if run loadbootscript; then run bootscript; else if run loadimage; then run mmcboot; else run netboot; fi; fi; else booti ${loadaddr} - ${fdt_addr}; fi" CONFIG_DEFAULT_FDT_FILE="r8a774a1-beacon-rzg2m-kit.dtb" # CONFIG_BOARD_EARLY_INIT_F is not set +CONFIG_BOARD_LATE_INIT=y CONFIG_SYS_MALLOC_BOOTPARAMS=y CONFIG_HUSH_PARSER=y CONFIG_SYS_MAXARGS=64 diff --git a/include/configs/beacon-rzg2m.h b/include/configs/beacon-rzg2m.h index 65c01835cc..493b98fbdf 100644 --- a/include/configs/beacon-rzg2m.h +++ b/include/configs/beacon-rzg2m.h @@ -18,7 +18,6 @@ "fdt_addr=0x48000000\0" \ "loadaddr=0x48080000\0" \ "boot_fdt=try\0" \ - "fdt_file=" CONFIG_DEFAULT_FDT_FILE "\0" \ "initrd_addr=0x43800000\0" \ "mmcdev=1\0" \ "mmcpart=1\0" \ -- 2.40.1