changes v2: - protonic: use only allowed chars for generated compatible - protonic: make use of of_get_machine_compatible() to get board name - of_fixup_machine_compatible: make curcompat optional - add $global.of_machine_compatible Add optional fixups for board serial-number and machine compatible. Ahmad Fatoum (1): common: add $global.serial_number with device tree fixup Oleksij Rempel (3): ARM: boards: protonic-imx6: make use of barebox_set_serial_number() of: add generic of_fixup_machine_compatible() ARM: boards: skov-imx6: make use of of_fixup_machine_compatible() arch/arm/boards/protonic-imx6/board.c | 20 +---------- arch/arm/boards/skov-imx6/board.c | 40 ++------------------- arch/arm/mach-imx/Kconfig | 1 + common/Kconfig | 10 ++++++ common/misc.c | 33 ++++++++++++++++++ common/oftree.c | 50 +++++++++++++++++++++++++++ include/common.h | 6 ++++ include/of.h | 6 ++++ 8 files changed, 110 insertions(+), 56 deletions(-) -- 2.30.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
From: Ahmad Fatoum <a.fatoum@pengutronix.de> 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> --- common/Kconfig | 5 +++++ common/misc.c | 16 ++++++++++++++++ common/oftree.c | 9 +++++++++ include/common.h | 3 +++ 4 files changed, 33 insertions(+) diff --git a/common/Kconfig b/common/Kconfig index f7a6a96e87..d08302a573 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -1066,6 +1066,11 @@ config MACHINE_ID Note: if no hashable information is available no machine id will be passed to the kernel. +config SERIAL_NUMBER_FIXUP + bool "fix up board serial number" + help + fixup serial number supplied by board code info device tree + config SYSTEMD_OF_WATCHDOG bool "inform devicetree-enabled kernel of used watchdog" depends on WATCHDOG && OFTREE && FLEXIBLE_BOOTARGS 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..c6d75055cc 100644 --- a/common/oftree.c +++ b/common/oftree.c @@ -207,6 +207,15 @@ static int of_fixup_bootargs(struct device_node *root, void *unused) int instance = reset_source_get_instance(); struct device_d *dev; + if (IS_ENABLED(CONFIG_SERIAL_NUMBER_FIXUP)) { + const char *serialno; + + serialno = getenv("global.serial_number"); + if (serialno) + of_property_write_string(root, "serial-number", serialno); + + } + node = of_create_node(root, "/chosen"); if (!node) return -ENOMEM; diff --git a/include/common.h b/include/common.h index 4167d4676e..967502a7ab 100644 --- a/include/common.h +++ b/include/common.h @@ -126,4 +126,7 @@ const char *barebox_get_hostname(void); void barebox_set_hostname(const char *); void barebox_set_hostname_no_overwrite(const char *); +const char *barebox_get_serial_number(void); +void barebox_set_serial_number(const char *); + #endif /* __COMMON_H_ */ -- 2.30.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
Replace board specific serial-number fixup with common barebox_set_serial_number(). Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> --- arch/arm/boards/protonic-imx6/board.c | 20 +------------------- arch/arm/mach-imx/Kconfig | 1 + 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c index 52cf39917a..0fadd148b4 100644 --- a/arch/arm/boards/protonic-imx6/board.c +++ b/arch/arm/boards/protonic-imx6/board.c @@ -196,30 +196,12 @@ static int prt_imx6_set_mac(struct prt_imx6_priv *priv, return 0; } -static int prt_of_fixup_serial(struct device_node *dstroot, void *arg) -{ - struct device_node *srcroot = arg; - const char *ser; - int len; - - ser = of_get_property(srcroot, "serial-number", &len); - return of_set_property(dstroot, "serial-number", ser, len, 1); -} - -static void prt_oftree_fixup_serial(const char *serial) -{ - struct device_node *root = of_get_root_node(); - - of_set_property(root, "serial-number", serial, strlen(serial) + 1, 1); - of_register_fixup(prt_of_fixup_serial, root); -} - static int prt_imx6_set_serial(struct prt_imx6_priv *priv, struct prti6q_rfid_contents *rfid) { rfid->serial[9] = 0; /* Failsafe */ dev_info(priv->dev, "Serial number: %s\n", rfid->serial); - prt_oftree_fixup_serial(rfid->serial); + barebox_set_serial_number(rfid->serial); return 0; } diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index 6b962dcf7e..ee313a1502 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -350,6 +350,7 @@ config MACH_PROTONIC_IMX6 select ARCH_IMX6 select ARCH_IMX6UL select ARM_USE_COMPRESSED_DTB + select SERIAL_NUMBER_FIXUP config MACH_PROTONIC_IMX8M bool "Protonic-Holland i.MX8Mx based boards" -- 2.30.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
Add generic function to extend/fixup machine compatible. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> --- common/Kconfig | 5 +++++ common/misc.c | 17 +++++++++++++++++ common/oftree.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/common.h | 3 +++ include/of.h | 6 ++++++ 5 files changed, 72 insertions(+) diff --git a/common/Kconfig b/common/Kconfig index d08302a573..9b65b728c0 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -1066,6 +1066,11 @@ config MACHINE_ID Note: if no hashable information is available no machine id will be passed to the kernel. +config MACHINE_FIXUP + bool "fix up machine compatible" + help + fixup machine compatible supplied by board code info device tree + config SERIAL_NUMBER_FIXUP bool "fix up board serial number" help diff --git a/common/misc.c b/common/misc.c index 3b3bc05bfd..28c6d9f29d 100644 --- a/common/misc.c +++ b/common/misc.c @@ -150,6 +150,7 @@ BAREBOX_MAGICVAR(global.model, "Product name of this hardware"); static char *hostname; static char *serial_number; +static char *of_machine_compatible; /* * The hostname is supposed to be the shortname of a board. It should @@ -195,6 +196,22 @@ const char *barebox_get_serial_number(void) BAREBOX_MAGICVAR(global.serial_number, "Board serial number"); +void barebox_set_of_machine_compatible(const char *__compatible) +{ + globalvar_add_simple_string("of_machine_compatible", + &of_machine_compatible); + + free(of_machine_compatible); + of_machine_compatible = xstrdup(__compatible); +} + +const char *barebox_get_of_machine_compatible(void) +{ + return of_machine_compatible; +} + +BAREBOX_MAGICVAR(global.of_machine_compatible, "Extra OF board compatible"); + void __noreturn panic(const char *fmt, ...) { va_list args; diff --git a/common/oftree.c b/common/oftree.c index c6d75055cc..f17eedc66f 100644 --- a/common/oftree.c +++ b/common/oftree.c @@ -216,6 +216,15 @@ static int of_fixup_bootargs(struct device_node *root, void *unused) } + if (IS_ENABLED(CONFIG_MACHINE_FIXUP)) { + const char *compat; + + compat = getenv("global.of_machine_compatible"); + if (compat) + of_fixup_machine_compatible(root, compat); + + } + node = of_create_node(root, "/chosen"); if (!node) return -ENOMEM; @@ -487,3 +496,35 @@ int of_autoenable_i2c_by_component(char *path) return ret; } + +int of_fixup_machine_compatible(struct device_node *root, const char *compat) +{ + int cclen = 0, clen = strlen(compat) + 1; + const char *curcompat; + void *buf; + + if (!root) { + root = of_get_root_node(); + if (!root) + return -ENODEV; + } + + curcompat = of_get_property(root, "compatible", &cclen); + + buf = xzalloc(cclen + clen); + + memcpy(buf, compat, clen); + + if (curcompat) + memcpy(buf + clen, curcompat, cclen); + + /* + * Prepend the compatible from board entry to the machine compatible. + * Used to match bootspec entries against it. + */ + of_set_property(root, "compatible", buf, cclen + clen, true); + + free(buf); + + return 0; +} diff --git a/include/common.h b/include/common.h index 967502a7ab..bd12035688 100644 --- a/include/common.h +++ b/include/common.h @@ -129,4 +129,7 @@ void barebox_set_hostname_no_overwrite(const char *); const char *barebox_get_serial_number(void); void barebox_set_serial_number(const char *); +void barebox_set_of_machine_compatible(const char *); +const char *barebox_get_of_machine_compatible(void); + #endif /* __COMMON_H_ */ diff --git a/include/of.h b/include/of.h index cf9950e9b3..9f514c5ec2 100644 --- a/include/of.h +++ b/include/of.h @@ -316,6 +316,7 @@ struct device_node *of_find_node_by_path_or_alias(struct device_node *root, const char *str); int of_autoenable_device_by_path(char *path); int of_autoenable_i2c_by_component(char *path); +int of_fixup_machine_compatible(struct device_node *root, const char *compat); #else static inline bool of_node_name_eq(const struct device_node *np, const char *name) { @@ -834,6 +835,11 @@ static inline int of_autoenable_i2c_by_component(char *path) return -ENODEV; } +static int of_fixup_machine_compatible(struct device_node *root, + const char *compat) +{ + return -ENODEV; +} #endif -- 2.30.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
Replace board specific fixup_machine_compatible() with generic of_fixup_machine_compatible() Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> --- arch/arm/boards/skov-imx6/board.c | 40 +++---------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/arch/arm/boards/skov-imx6/board.c b/arch/arm/boards/skov-imx6/board.c index 2702bc1de9..53c213f33b 100644 --- a/arch/arm/boards/skov-imx6/board.c +++ b/arch/arm/boards/skov-imx6/board.c @@ -312,55 +312,21 @@ static int skov_board_no = -1; static bool skov_have_switch = true; static const char *no_switch_suffix = "-noswitch"; -static void fixup_machine_compatible(const char *compat, - struct device_node *root) -{ - int cclen = 0, clen = strlen(compat) + 1; - const char *curcompat; - void *buf; - - if (!root) { - root = of_get_root_node(); - if (!root) - return; - } - - curcompat = of_get_property(root, "compatible", &cclen); - - buf = xzalloc(cclen + clen); - - memcpy(buf, compat, clen); - memcpy(buf + clen, curcompat, cclen); - - /* - * Prepend the compatible from board entry to the machine compatible. - * Used to match bootspec entries against it. - */ - of_set_property(root, "compatible", buf, cclen + clen, true); - - free(buf); -} - static void fixup_noswitch_machine_compatible(struct device_node *root) { const char *compat = imx6_variants[skov_board_no].dts_compatible; const char *generic = "skov,imx6"; - size_t size, size_generic; char *buf; - size = strlen(compat) + strlen(no_switch_suffix) + 1; - size_generic = strlen(generic) + strlen(no_switch_suffix) + 1; - size = max(size, size_generic); - /* add generic compatible, so systemd&co can make right decisions */ buf = xasprintf("%s%s", generic, no_switch_suffix); - fixup_machine_compatible(buf, root); + of_fixup_machine_compatible(root, buf); /* add specific compatible as fallback, in case this board has new * challenges. */ buf = xasprintf("%s%s", compat, no_switch_suffix); - fixup_machine_compatible(buf, root); + of_fixup_machine_compatible(root, buf); free(buf); } @@ -648,7 +614,7 @@ static int skov_imx6_probe(struct device_d *dev) globalvar_add_simple("board.dts", variant->dts_compatible); globalvar_add_simple("board.display", variant->display ?: NULL); - fixup_machine_compatible(variant->dts_compatible, NULL); + of_fixup_machine_compatible(NULL, variant->dts_compatible); skov_init_board(variant); -- 2.30.2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
Hi, On 27.04.22 11:37, Oleksij Rempel wrote: > > + if (IS_ENABLED(CONFIG_MACHINE_FIXUP)) { > + const char *compat; > + > + compat = getenv("global.of_machine_compatible"); > + if (compat) > + of_fixup_machine_compatible(root, compat); That's not what I had in mind. I meant for the variable to affect bootspec use, i.e. fixup barebox device tree. This here just adds an extra compatible to the kernel device tree. Cheers, Ahmad -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
On Wed, Apr 27, 2022 at 11:46:20AM +0200, Ahmad Fatoum wrote: > Hi, > > On 27.04.22 11:37, Oleksij Rempel wrote: > > > > + if (IS_ENABLED(CONFIG_MACHINE_FIXUP)) { > > + const char *compat; > > + > > + compat = getenv("global.of_machine_compatible"); > > + if (compat) > > + of_fixup_machine_compatible(root, compat); > > That's not what I had in mind. I meant for the variable to affect bootspec > use, i.e. fixup barebox device tree. This here just adds an extra compatible > to the kernel device tree. This is what is needed for my use case/customer. As soon as other use case will be needed, we can extend it. Regards, Oleksij -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
On 27.04.22 11:51, Oleksij Rempel wrote: > On Wed, Apr 27, 2022 at 11:46:20AM +0200, Ahmad Fatoum wrote: >> Hi, >> >> On 27.04.22 11:37, Oleksij Rempel wrote: >>> >>> + if (IS_ENABLED(CONFIG_MACHINE_FIXUP)) { >>> + const char *compat; >>> + >>> + compat = getenv("global.of_machine_compatible"); >>> + if (compat) >>> + of_fixup_machine_compatible(root, compat); >> >> That's not what I had in mind. I meant for the variable to affect bootspec >> use, i.e. fixup barebox device tree. This here just adds an extra compatible >> to the kernel device tree. > > This is what is needed for my use case/customer. As soon as other use > case will be needed, we can extend it. Neither the name $global.of_machine_compatible nor the description "Extra OF board compatible" suggest that this will fixup kernel DTs instead of rewriting barebox' own machine compatible, which is what springs to my mind when seeing this variable. I am fine if you only implement what you need, but that name is unsuitable for your use case IMO. > > Regards, > Oleksij -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox