[PATCH v3 5/6] ARM: rpi: set host name based on DT compatible

Oleksij Rempel o.rempel at pengutronix.de
Thu Feb 3 02:45:51 PST 2022


The "rpi" host name is not practical if you need to work with different
variants of RPi at same time. Usually, removing barebox_set_hostname()
would let barebox generate it automatically. But in this case, the name
would look less informative. For example "2-model-b".

So, make board code generate something usable, for example
"rpi-2-model-b"

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 arch/arm/boards/raspberry-pi/rpi-common.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c b/arch/arm/boards/raspberry-pi/rpi-common.c
index e68857ded9..6e62d19643 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -378,6 +378,8 @@ static int rpi_devices_probe(struct device_d *dev)
 	const struct rpi_machine_data *dcfg;
 	struct regulator *reg;
 	struct rpi_priv *priv;
+	const char *name, *ptr;
+	char *hostname;
 	int ret;
 
 	priv = xzalloc(sizeof(*priv));
@@ -391,7 +393,12 @@ static int rpi_devices_probe(struct device_d *dev)
 	if (IS_ERR(dcfg))
 		goto free_priv;
 
-	barebox_set_hostname("rpi");
+	/* construct short recognizable host name */
+	name = of_device_get_match_compatible(priv->dev);
+	ptr = strchr(name, ',');
+	hostname = basprintf("rpi-%s", ptr ? ptr + 1 : name);
+	barebox_set_hostname(hostname);
+	free(hostname);
 
 	rpi_add_led();
 	bcm2835_register_fb();
-- 
2.30.2




More information about the barebox mailing list