[PATCH 03/10] common: add optional systemd.hostname generation
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Apr 11 00:40:38 PDT 2025
To maintain unique hostnames, having barebox fix up its own hostname
appended by "-${global.serial_number} is a sane default. Add a Kconfig
option to enable this.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
common/Kconfig | 10 ++++++++++
common/bootm.c | 9 ++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/common/Kconfig b/common/Kconfig
index 1e04d0403ad0..2d2be0f7c4f6 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1254,6 +1254,16 @@ config MACHINE_ID
Note: if no hashable information is available no machine id will be passed
to the kernel.
+config SERIAL_NUMBER_FIXUP_SYSTEMD_HOSTNAME
+ bool "append board serial number to systemd.hostname= fixup"
+ depends on FLEXIBLE_BOOTARGS
+ help
+ When a systemd.hostname= kernel command line argument is
+ fixed up, append a `-${global.serial_number}' suffix.
+
+ This option without effect if global.bootm.provide_hostname
+ is unset.
+
config SYSTEMD_OF_WATCHDOG
bool "inform devicetree-enabled kernel of used watchdog"
depends on WATCHDOG && OFTREE && FLEXIBLE_BOOTARGS
diff --git a/common/bootm.c b/common/bootm.c
index 5370e1485bc6..a26ea82684a6 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -864,6 +864,7 @@ int bootm_boot(struct bootm_data *bootm_data)
if (bootm_data->provide_hostname) {
const char *hostname = getenv_nonempty("global.hostname");
+ const char *suffix = NULL;
char *hostname_bootarg;
if (!hostname) {
@@ -878,7 +879,13 @@ int bootm_boot(struct bootm_data *bootm_data)
goto err_out;
}
- hostname_bootarg = basprintf("systemd.hostname=%s", hostname);
+ if (IS_ENABLED(CONFIG_SERIAL_NUMBER_FIXUP_SYSTEMD_HOSTNAME))
+ suffix = barebox_get_serial_number();
+
+ hostname_bootarg = basprintf("systemd.hostname=%s%s%s",
+ hostname, suffix ? "-" : "",
+ suffix ?: "");
+
globalvar_add_simple("linux.bootargs.hostname", hostname_bootarg);
free(hostname_bootarg);
}
--
2.39.5
More information about the barebox
mailing list