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

changes v5:
- remove SERIAL_NUMBER_FIXUP Kconfig
- s/of_fixup_machine_compatible/of_prepend_machine_compatible
- remove bogus comment
- check if the passed device tree already is compatible to @compat

changes v4:
- s/code info device/code into device/

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                        |  5 +++
 common/misc.c                         | 39 ++++++++++++++++++++++
 common/oftree.c                       | 48 +++++++++++++++++++++++++++
 include/common.h                      |  6 ++++
 include/of.h                          |  6 ++++
 8 files changed, 128 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] 7+ messages in thread

* [PATCH v5 1/5] common: add $global.serial_number with device tree fixup
  2022-05-03  4:42 [PATCH v5 0/5] add different OF board fixups Oleksij Rempel
@ 2022-05-03  4:42 ` Oleksij Rempel
  2022-05-03  4:42 ` [PATCH v5 2/5] ARM: boards: protonic-imx6: make use of barebox_set_serial_number() Oleksij Rempel
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Oleksij Rempel @ 2022-05-03  4:42 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/misc.c    | 16 ++++++++++++++++
 common/oftree.c  |  5 +++++
 include/common.h |  3 +++
 3 files changed, 24 insertions(+)

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..995e7201bf 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 = getenv("global.serial_number");
+	if (serialno)
+		of_property_write_string(root, "serial-number", serialno);
 
 	node = of_create_node(root, "/chosen");
 	if (!node)
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] 7+ messages in thread

* [PATCH v5 2/5] ARM: boards: protonic-imx6: make use of barebox_set_serial_number()
  2022-05-03  4:42 [PATCH v5 0/5] add different OF board fixups Oleksij Rempel
  2022-05-03  4:42 ` [PATCH v5 1/5] common: add $global.serial_number with device tree fixup Oleksij Rempel
@ 2022-05-03  4:42 ` Oleksij Rempel
  2022-05-03  4:42 ` [PATCH v5 3/5] of: add generic of_fixup_machine_compatible() Oleksij Rempel
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Oleksij Rempel @ 2022-05-03  4:42 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] 7+ messages in thread

* [PATCH v5 3/5] of: add generic of_fixup_machine_compatible()
  2022-05-03  4:42 [PATCH v5 0/5] add different OF board fixups Oleksij Rempel
  2022-05-03  4:42 ` [PATCH v5 1/5] common: add $global.serial_number with device tree fixup Oleksij Rempel
  2022-05-03  4:42 ` [PATCH v5 2/5] ARM: boards: protonic-imx6: make use of barebox_set_serial_number() Oleksij Rempel
@ 2022-05-03  4:42 ` Oleksij Rempel
  2022-05-03  7:03   ` Sascha Hauer
  2022-05-03  4:42 ` [PATCH v5 4/5] ARM: boards: skov-imx6: make use of of_fixup_machine_compatible() Oleksij Rempel
  2022-05-03  4:42 ` [PATCH v5 5/5] ARM: boards: protonic-imx6: add HW revision specific machine compatible Oleksij Rempel
  4 siblings, 1 reply; 7+ messages in thread
From: Oleksij Rempel @ 2022-05-03  4:42 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  | 43 +++++++++++++++++++++++++++++++++++++++++++
 include/common.h |  3 +++
 include/of.h     |  6 ++++++
 5 files changed, 80 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index f7a6a96e87..7385848dfc 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 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 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 995e7201bf..5b183192bc 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -212,6 +212,15 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
 	if (serialno)
 		of_property_write_string(root, "serial-number", serialno);
 
+	if (IS_ENABLED(CONFIG_MACHINE_FIXUP)) {
+		const char *compat;
+
+		compat = getenv("global.of.kernel.add_machine_compatible");
+		if (compat)
+			of_prepend_machine_compatible(root, compat);
+
+	}
+
 	node = of_create_node(root, "/chosen");
 	if (!node)
 		return -ENOMEM;
@@ -483,3 +492,37 @@ int of_autoenable_i2c_by_component(char *path)
 
 	return ret;
 }
+
+int of_prepend_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;
+	}
+
+	if (of_machine_is_compatible(compat)) {
+		pr_warn("Machine is already compatible to %s. Skip compatible modification\n",
+			compat);
+		return 0;
+	}
+
+	curcompat = of_get_property(root, "compatible", &cclen);
+
+	buf = xzalloc(cclen + clen);
+
+	memcpy(buf, compat, clen);
+
+	if (curcompat)
+		memcpy(buf + clen, curcompat, cclen);
+
+	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..cf1087f661 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_prepend_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_prepend_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] 7+ messages in thread

* [PATCH v5 4/5] ARM: boards: skov-imx6: make use of of_fixup_machine_compatible()
  2022-05-03  4:42 [PATCH v5 0/5] add different OF board fixups Oleksij Rempel
                   ` (2 preceding siblings ...)
  2022-05-03  4:42 ` [PATCH v5 3/5] of: add generic of_fixup_machine_compatible() Oleksij Rempel
@ 2022-05-03  4:42 ` Oleksij Rempel
  2022-05-03  4:42 ` [PATCH v5 5/5] ARM: boards: protonic-imx6: add HW revision specific machine compatible Oleksij Rempel
  4 siblings, 0 replies; 7+ messages in thread
From: Oleksij Rempel @ 2022-05-03  4:42 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..bceb215a01 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_prepend_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_prepend_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_prepend_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] 7+ messages in thread

* [PATCH v5 5/5] ARM: boards: protonic-imx6: add HW revision specific machine compatible
  2022-05-03  4:42 [PATCH v5 0/5] add different OF board fixups Oleksij Rempel
                   ` (3 preceding siblings ...)
  2022-05-03  4:42 ` [PATCH v5 4/5] ARM: boards: skov-imx6: make use of of_fixup_machine_compatible() Oleksij Rempel
@ 2022-05-03  4:42 ` Oleksij Rempel
  4 siblings, 0 replies; 7+ messages in thread
From: Oleksij Rempel @ 2022-05-03  4:42 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] 7+ messages in thread

* Re: [PATCH v5 3/5] of: add generic of_fixup_machine_compatible()
  2022-05-03  4:42 ` [PATCH v5 3/5] of: add generic of_fixup_machine_compatible() Oleksij Rempel
@ 2022-05-03  7:03   ` Sascha Hauer
  0 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2022-05-03  7:03 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox

On Tue, May 03, 2022 at 06:42:04AM +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  | 43 +++++++++++++++++++++++++++++++++++++++++++
>  include/common.h |  3 +++
>  include/of.h     |  6 ++++++
>  5 files changed, 80 insertions(+)
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index f7a6a96e87..7385848dfc 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

Once again: s/info/into/


> +
>  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 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 995e7201bf..5b183192bc 100644
> --- a/common/oftree.c
> +++ b/common/oftree.c
> @@ -212,6 +212,15 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
>  	if (serialno)
>  		of_property_write_string(root, "serial-number", serialno);
>  
> +	if (IS_ENABLED(CONFIG_MACHINE_FIXUP)) {

The variable itself is added unconditionally, but it's used only when
CONFIG_MACHINE_FIXUP is enabled. This seems inconsistent. I don't think
we need this option, so drop it.

> +		const char *compat;
> +
> +		compat = getenv("global.of.kernel.add_machine_compatible");

You introduced barebox_get_of_machine_compatible() with this patch.
Please use it.

> +		if (compat)
> +			of_prepend_machine_compatible(root, compat);
> +
> +	}
> +
>  	node = of_create_node(root, "/chosen");
>  	if (!node)
>  		return -ENOMEM;
> @@ -483,3 +492,37 @@ int of_autoenable_i2c_by_component(char *path)
>  
>  	return ret;
>  }
> +
> +int of_prepend_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;
> +	}
> +
> +	if (of_machine_is_compatible(compat)) {

You have to check the device tree you are adding the compatible to, not
the barebox internal device tree. These are not necessarily the same.

> +		pr_warn("Machine is already compatible to %s. Skip compatible modification\n",
> +			compat);

This might be a regular usecase, I don't think we need to warn here.

> +		return 0;
> +	}
> +
> +	curcompat = of_get_property(root, "compatible", &cclen);
> +
> +	buf = xzalloc(cclen + clen);
> +
> +	memcpy(buf, compat, clen);
> +
> +	if (curcompat)
> +		memcpy(buf + clen, curcompat, cclen);
> +
> +	of_set_property(root, "compatible", buf, cclen + clen, true);
> +
> +	free(buf);
> +
> +	return 0;
> +}

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] 7+ messages in thread

end of thread, other threads:[~2022-05-03  7:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-03  4:42 [PATCH v5 0/5] add different OF board fixups Oleksij Rempel
2022-05-03  4:42 ` [PATCH v5 1/5] common: add $global.serial_number with device tree fixup Oleksij Rempel
2022-05-03  4:42 ` [PATCH v5 2/5] ARM: boards: protonic-imx6: make use of barebox_set_serial_number() Oleksij Rempel
2022-05-03  4:42 ` [PATCH v5 3/5] of: add generic of_fixup_machine_compatible() Oleksij Rempel
2022-05-03  7:03   ` Sascha Hauer
2022-05-03  4:42 ` [PATCH v5 4/5] ARM: boards: skov-imx6: make use of of_fixup_machine_compatible() Oleksij Rempel
2022-05-03  4:42 ` [PATCH v5 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