mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v3 0/5] add different OF board fixups
@ 2022-04-27 12:14 Oleksij Rempel
  2022-04-27 12:14 ` [PATCH v3 1/5] common: add $global.serial_number with device tree fixup Oleksij Rempel
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Oleksij Rempel @ 2022-04-27 12:14 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

changes v3:
- rename global.of_machine_compatible to global.of.kernel.add_machine_compatible

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 (4):
  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()
  ARM: boards: protonic-imx6: add HW revision specific machine
    compatible

 arch/arm/boards/protonic-imx6/board.c | 42 ++++++++++------------
 arch/arm/boards/skov-imx6/board.c     | 40 ++-------------------
 arch/arm/mach-imx/Kconfig             |  2 ++
 common/Kconfig                        | 10 ++++++
 common/misc.c                         | 39 +++++++++++++++++++++
 common/oftree.c                       | 50 +++++++++++++++++++++++++++
 include/common.h                      |  6 ++++
 include/of.h                          |  6 ++++
 8 files changed, 135 insertions(+), 60 deletions(-)

-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 1/5] common: add $global.serial_number with device tree fixup
  2022-04-27 12:14 [PATCH v3 0/5] add different OF board fixups Oleksij Rempel
@ 2022-04-27 12:14 ` Oleksij Rempel
  2022-04-28 12:59   ` Jules Maselbas
                     ` (2 more replies)
  2022-04-27 12:14 ` [PATCH v3 2/5] ARM: boards: protonic-imx6: make use of barebox_set_serial_number() Oleksij Rempel
                   ` (3 subsequent siblings)
  4 siblings, 3 replies; 11+ messages in thread
From: Oleksij Rempel @ 2022-04-27 12:14 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum, Oleksij Rempel

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 2/5] ARM: boards: protonic-imx6: make use of barebox_set_serial_number()
  2022-04-27 12:14 [PATCH v3 0/5] add different OF board fixups Oleksij Rempel
  2022-04-27 12:14 ` [PATCH v3 1/5] common: add $global.serial_number with device tree fixup Oleksij Rempel
@ 2022-04-27 12:14 ` Oleksij Rempel
  2022-04-27 12:14 ` [PATCH v3 3/5] of: add generic of_fixup_machine_compatible() Oleksij Rempel
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Oleksij Rempel @ 2022-04-27 12:14 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 3/5] of: add generic of_fixup_machine_compatible()
  2022-04-27 12:14 [PATCH v3 0/5] add different OF board fixups Oleksij Rempel
  2022-04-27 12:14 ` [PATCH v3 1/5] common: add $global.serial_number with device tree fixup Oleksij Rempel
  2022-04-27 12:14 ` [PATCH v3 2/5] ARM: boards: protonic-imx6: make use of barebox_set_serial_number() Oleksij Rempel
@ 2022-04-27 12:14 ` Oleksij Rempel
  2022-04-29  8:07   ` Sascha Hauer
  2022-04-27 12:14 ` [PATCH v3 4/5] ARM: boards: skov-imx6: make use of of_fixup_machine_compatible() Oleksij Rempel
  2022-04-27 12:14 ` [PATCH v3 5/5] ARM: boards: protonic-imx6: add HW revision specific machine compatible Oleksij Rempel
  4 siblings, 1 reply; 11+ messages in thread
From: Oleksij Rempel @ 2022-04-27 12:14 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Add generic function to extend/fixup machine compatible.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 common/Kconfig   |  5 +++++
 common/misc.c    | 23 +++++++++++++++++++++++
 common/oftree.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 include/common.h |  3 +++
 include/of.h     |  6 ++++++
 5 files changed, 78 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..0f6de3e9e5 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,28 @@ const char *barebox_get_serial_number(void)
 
 BAREBOX_MAGICVAR(global.serial_number, "Board serial number");
 
+void barebox_set_of_machine_compatible(const char *__compatible)
+{
+	free(of_machine_compatible);
+	of_machine_compatible = xstrdup(__compatible);
+}
+
+const char *barebox_get_of_machine_compatible(void)
+{
+	return of_machine_compatible;
+}
+
+static int of_kernel_init(void)
+{
+	globalvar_add_simple_string("of.kernel.add_machine_compatible",
+				    &of_machine_compatible);
+
+	return 0;
+}
+device_initcall(of_kernel_init);
+
+BAREBOX_MAGICVAR(global.of.kernel.add_machine_compatible, "Additional machine/board compatible");
+
 void __noreturn panic(const char *fmt, ...)
 {
 	va_list args;
diff --git a/common/oftree.c b/common/oftree.c
index c6d75055cc..76239476e0 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.kernel.add_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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 4/5] ARM: boards: skov-imx6: make use of of_fixup_machine_compatible()
  2022-04-27 12:14 [PATCH v3 0/5] add different OF board fixups Oleksij Rempel
                   ` (2 preceding siblings ...)
  2022-04-27 12:14 ` [PATCH v3 3/5] of: add generic of_fixup_machine_compatible() Oleksij Rempel
@ 2022-04-27 12:14 ` Oleksij Rempel
  2022-04-27 12:14 ` [PATCH v3 5/5] ARM: boards: protonic-imx6: add HW revision specific machine compatible Oleksij Rempel
  4 siblings, 0 replies; 11+ messages in thread
From: Oleksij Rempel @ 2022-04-27 12:14 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 5/5] ARM: boards: protonic-imx6: add HW revision specific machine compatible
  2022-04-27 12:14 [PATCH v3 0/5] add different OF board fixups Oleksij Rempel
                   ` (3 preceding siblings ...)
  2022-04-27 12:14 ` [PATCH v3 4/5] ARM: boards: skov-imx6: make use of of_fixup_machine_compatible() Oleksij Rempel
@ 2022-04-27 12:14 ` Oleksij Rempel
  4 siblings, 0 replies; 11+ messages in thread
From: Oleksij Rempel @ 2022-04-27 12:14 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

Currently we use generic/pinned machine compatible for different HW
revisions. With this patch we extend this compatible string with HW
revision specific.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 arch/arm/boards/protonic-imx6/board.c | 22 ++++++++++++++++++----
 arch/arm/mach-imx/Kconfig             |  1 +
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index 0fadd148b4..cdbb8debe6 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -126,6 +126,22 @@ static const struct gpio prt_imx6_kvg_gpios[] = {
 	},
 };
 
+static int prt_of_fixup_hwrev(struct prt_imx6_priv *priv)
+{
+	const char *compat;
+	char *buf;
+
+	compat = of_device_get_match_compatible(priv->dev);
+
+	buf = xasprintf("%s-m%u-r%u", compat, priv->hw_id,
+			priv->hw_rev);
+	barebox_set_of_machine_compatible(buf);
+
+	free(buf);
+
+	return 0;
+}
+
 static int prt_imx6_read_rfid(struct prt_imx6_priv *priv, void *buf,
 			      size_t size)
 {
@@ -797,7 +813,6 @@ exit_get_dcfg:
 static int prt_imx6_probe(struct device_d *dev)
 {
 	struct prt_imx6_priv *priv;
-	const char *name, *ptr;
 	struct param_d *p;
 	int ret;
 
@@ -806,9 +821,7 @@ static int prt_imx6_probe(struct device_d *dev)
 		return -ENOMEM;
 
 	priv->dev = dev;
-	name = of_device_get_match_compatible(priv->dev);
-	ptr = strchr(name, ',');
-	priv->name =  ptr ? ptr + 1 : name;
+	priv->name = of_get_machine_compatible();
 
 	pr_info("Detected machine type: %s\n", priv->name);
 
@@ -818,6 +831,7 @@ static int prt_imx6_probe(struct device_d *dev)
 
 	pr_info("  HW type:     %d\n", priv->hw_id);
 	pr_info("  HW revision: %d\n", priv->hw_rev);
+	prt_of_fixup_hwrev(priv);
 
 	ret = prt_imx6_get_dcfg(priv);
 	if (ret)
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index ee313a1502..147cd000f9 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -351,6 +351,7 @@ config MACH_PROTONIC_IMX6
 	select ARCH_IMX6UL
 	select ARM_USE_COMPRESSED_DTB
 	select SERIAL_NUMBER_FIXUP
+	select MACHINE_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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/5] common: add $global.serial_number with device tree fixup
  2022-04-27 12:14 ` [PATCH v3 1/5] common: add $global.serial_number with device tree fixup Oleksij Rempel
@ 2022-04-28 12:59   ` Jules Maselbas
  2022-04-28 13:16   ` Ulrich Ölmann
  2022-04-29  7:35   ` Sascha Hauer
  2 siblings, 0 replies; 11+ messages in thread
From: Jules Maselbas @ 2022-04-28 12:59 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox, Ahmad Fatoum

Hi,

On Wed, Apr 27, 2022 at 02:14:09PM +0200, Oleksij Rempel wrote:
> 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.

Very nice! This will be usefull :)

> 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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/5] common: add $global.serial_number with device tree fixup
  2022-04-27 12:14 ` [PATCH v3 1/5] common: add $global.serial_number with device tree fixup Oleksij Rempel
  2022-04-28 12:59   ` Jules Maselbas
@ 2022-04-28 13:16   ` Ulrich Ölmann
  2022-04-29  4:52     ` Oleksij Rempel
  2022-04-29  7:35   ` Sascha Hauer
  2 siblings, 1 reply; 11+ messages in thread
From: Ulrich Ölmann @ 2022-04-28 13:16 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: Ahmad Fatoum, barebox

Hi Oleksij,

On Wed, Apr 27 2022 at 14:14 +0200, Oleksij Rempel <o.rempel@pengutronix.de> wrote:
> 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

this should be

  s/code info device/code into device/

right?

Best regards
Ulrich


> +
>  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_ */


-- 
Pengutronix e.K.                           | Ulrich Ölmann               |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/5] common: add $global.serial_number with device tree fixup
  2022-04-28 13:16   ` Ulrich Ölmann
@ 2022-04-29  4:52     ` Oleksij Rempel
  0 siblings, 0 replies; 11+ messages in thread
From: Oleksij Rempel @ 2022-04-29  4:52 UTC (permalink / raw)
  To: Ulrich Ölmann; +Cc: Ahmad Fatoum, barebox

Hi Ulrich,

On Thu, Apr 28, 2022 at 03:16:05PM +0200, Ulrich Ölmann wrote:
> Hi Oleksij,
> 
> On Wed, Apr 27 2022 at 14:14 +0200, Oleksij Rempel <o.rempel@pengutronix.de> wrote:
> > 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
> 
> this should be
> 
>   s/code info device/code into device/
> 
> right?

Right. Thank you!

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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/5] common: add $global.serial_number with device tree fixup
  2022-04-27 12:14 ` [PATCH v3 1/5] common: add $global.serial_number with device tree fixup Oleksij Rempel
  2022-04-28 12:59   ` Jules Maselbas
  2022-04-28 13:16   ` Ulrich Ölmann
@ 2022-04-29  7:35   ` Sascha Hauer
  2 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2022-04-29  7:35 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox, Ahmad Fatoum

On Wed, Apr 27, 2022 at 02:14:09PM +0200, Oleksij Rempel wrote:
> 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

I Don't think we need a Kconfig option for this.

Sascha

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 3/5] of: add generic of_fixup_machine_compatible()
  2022-04-27 12:14 ` [PATCH v3 3/5] of: add generic of_fixup_machine_compatible() Oleksij Rempel
@ 2022-04-29  8:07   ` Sascha Hauer
  0 siblings, 0 replies; 11+ messages in thread
From: Sascha Hauer @ 2022-04-29  8:07 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox

On Wed, Apr 27, 2022 at 02:14:11PM +0200, Oleksij Rempel wrote:
> Add generic function to extend/fixup machine compatible.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  common/Kconfig   |  5 +++++
>  common/misc.c    | 23 +++++++++++++++++++++++
>  common/oftree.c  | 41 +++++++++++++++++++++++++++++++++++++++++
>  include/common.h |  3 +++
>  include/of.h     |  6 ++++++
>  5 files changed, 78 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

s/info/into/

> +
>  config SERIAL_NUMBER_FIXUP
>  	bool "fix up board serial number"
>  	help
> diff --git a/common/misc.c b/common/misc.c
> index 3b3bc05bfd..0f6de3e9e5 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,28 @@ const char *barebox_get_serial_number(void)
>  
>  BAREBOX_MAGICVAR(global.serial_number, "Board serial number");
>  
> +void barebox_set_of_machine_compatible(const char *__compatible)
> +{
> +	free(of_machine_compatible);
> +	of_machine_compatible = xstrdup(__compatible);
> +}
> +
> +const char *barebox_get_of_machine_compatible(void)
> +{
> +	return of_machine_compatible;
> +}
> +
> +static int of_kernel_init(void)
> +{
> +	globalvar_add_simple_string("of.kernel.add_machine_compatible",
> +				    &of_machine_compatible);
> +
> +	return 0;
> +}
> +device_initcall(of_kernel_init);
> +
> +BAREBOX_MAGICVAR(global.of.kernel.add_machine_compatible, "Additional machine/board compatible");
> +
>  void __noreturn panic(const char *fmt, ...)
>  {
>  	va_list args;
> diff --git a/common/oftree.c b/common/oftree.c
> index c6d75055cc..76239476e0 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.kernel.add_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.
> +	 */

This sentence doesn't make sense in the context this function is called
in this patch. In this patch this function is called in a of_fixup which
fixes up the kernel device tree, but the sentence above reads as it
should be called on the barebox internal device tree.

maybe of_prepend_machine_compatible() would be a better name for this
function.

Also, should we check if the passed device tree already is compatible to
@compat before we potentially add the same compatible again?

Sascha

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-04-29  8:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 12:14 [PATCH v3 0/5] add different OF board fixups Oleksij Rempel
2022-04-27 12:14 ` [PATCH v3 1/5] common: add $global.serial_number with device tree fixup Oleksij Rempel
2022-04-28 12:59   ` Jules Maselbas
2022-04-28 13:16   ` Ulrich Ölmann
2022-04-29  4:52     ` Oleksij Rempel
2022-04-29  7:35   ` Sascha Hauer
2022-04-27 12:14 ` [PATCH v3 2/5] ARM: boards: protonic-imx6: make use of barebox_set_serial_number() Oleksij Rempel
2022-04-27 12:14 ` [PATCH v3 3/5] of: add generic of_fixup_machine_compatible() Oleksij Rempel
2022-04-29  8:07   ` Sascha Hauer
2022-04-27 12:14 ` [PATCH v3 4/5] ARM: boards: skov-imx6: make use of of_fixup_machine_compatible() Oleksij Rempel
2022-04-27 12:14 ` [PATCH v3 5/5] ARM: boards: protonic-imx6: add HW revision specific machine compatible Oleksij Rempel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox