All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adam Ford <aford173@gmail.com>
To: u-boot@lists.denx.de
Cc: marex@denx.de, aford@beaconembedded.com, Adam Ford <aford173@gmail.com>
Subject: [PATCH 3/3] arm: rmobile: rzg2_beacon: Auto select Linux device tree by SoC
Date: Wed, 25 Oct 2023 18:13:11 -0500	[thread overview]
Message-ID: <20231025231311.8701-3-aford173@gmail.com> (raw)
In-Reply-To: <20231025231311.8701-1-aford173@gmail.com>

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 <aford173@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


  parent reply	other threads:[~2023-10-25 23:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-25 23:13 [PATCH 1/3] configs: rzg2_beacon: Disable the ability to remove devices Adam Ford
2023-10-25 23:13 ` [PATCH 2/3] configs: rzg2_beacon: Realign ENV location and offset Adam Ford
2023-10-31 15:13   ` Adam Ford
2023-11-19 20:05     ` Marek Vasut
2023-10-25 23:13 ` Adam Ford [this message]
2023-10-26  6:40   ` [PATCH 3/3] arm: rmobile: rzg2_beacon: Auto select Linux device tree by SoC Marek Vasut
2023-10-27  2:12     ` Adam Ford
2023-11-19 20:06       ` Marek Vasut
2023-10-26  6:39 ` [PATCH 1/3] configs: rzg2_beacon: Disable the ability to remove devices Marek Vasut
2023-10-27  2:11   ` Adam Ford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231025231311.8701-3-aford173@gmail.com \
    --to=aford173@gmail.com \
    --cc=aford@beaconembedded.com \
    --cc=marex@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.