diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-05-03 11:12:16 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-05-05 09:15:13 +0200 |
commit | f6756e9ce6f26dc22506e25bd5cf1a4f6a173636 (patch) | |
tree | 31db79dd7986bddcfc67bcb6cd136689f0380c4c /common | |
parent | 2d7b49c1e7ee5ff5cd67be3ebf100d7b3c9ae293 (diff) | |
download | barebox-f6756e9ce6f26dc22506e25bd5cf1a4f6a173636.tar.gz barebox-f6756e9ce6f26dc22506e25bd5cf1a4f6a173636.tar.xz |
common: add $global.serial_number with device tree fixup
This new variable can be set by boards from C code or from the
environment to change the serial number fixed up into the kernel device
tree.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.barebox.org/20220503091220.3871612-2-o.rempel@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/misc.c | 16 | ||||
-rw-r--r-- | common/oftree.c | 5 |
2 files changed, 21 insertions, 0 deletions
diff --git a/common/misc.c b/common/misc.c index 226635f0d4..3b3bc05bfd 100644 --- a/common/misc.c +++ b/common/misc.c @@ -149,6 +149,7 @@ EXPORT_SYMBOL(barebox_get_model); BAREBOX_MAGICVAR(global.model, "Product name of this hardware"); static char *hostname; +static char *serial_number; /* * The hostname is supposed to be the shortname of a board. It should @@ -179,6 +180,21 @@ EXPORT_SYMBOL(barebox_set_hostname_no_overwrite); BAREBOX_MAGICVAR(global.hostname, "shortname of the board. Also used as hostname for DHCP requests"); +void barebox_set_serial_number(const char *__serial_number) +{ + globalvar_add_simple_string("serial_number", &serial_number); + + free(serial_number); + serial_number = xstrdup(__serial_number); +} + +const char *barebox_get_serial_number(void) +{ + return serial_number; +} + +BAREBOX_MAGICVAR(global.serial_number, "Board serial number"); + void __noreturn panic(const char *fmt, ...) { va_list args; diff --git a/common/oftree.c b/common/oftree.c index bce0ff09d6..51f825c3f3 100644 --- a/common/oftree.c +++ b/common/oftree.c @@ -206,6 +206,11 @@ static int of_fixup_bootargs(struct device_node *root, void *unused) int err; int instance = reset_source_get_instance(); struct device_d *dev; + const char *serialno; + + serialno = barebox_get_serial_number(); + if (serialno) + of_property_write_string(root, "serial-number", serialno); node = of_create_node(root, "/chosen"); if (!node) |