summaryrefslogtreecommitdiffstats
path: root/common/oftree.c
diff options
context:
space:
mode:
authorOleksij Rempel <o.rempel@pengutronix.de>2022-05-03 11:12:18 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-05-05 09:15:13 +0200
commit81dd24a0946c694f3d40dadc0e01254ce15a79bb (patch)
tree225f2df2dd3ef864a5c98e1cd6fad78dba56f4ae /common/oftree.c
parentf721a1d58387569e460edae8a3df0692007103fe (diff)
downloadbarebox-81dd24a0946c694f3d40dadc0e01254ce15a79bb.tar.gz
barebox-81dd24a0946c694f3d40dadc0e01254ce15a79bb.tar.xz
of: add generic of_prepend_machine_compatible()
Add generic function to extend/fixup machine compatible. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20220503091220.3871612-4-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/oftree.c')
-rw-r--r--common/oftree.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/common/oftree.c b/common/oftree.c
index 51f825c3f3..91b3fcc9fa 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -207,11 +207,16 @@ static int of_fixup_bootargs(struct device_node *root, void *unused)
int instance = reset_source_get_instance();
struct device_d *dev;
const char *serialno;
+ const char *compat;
serialno = barebox_get_serial_number();
if (serialno)
of_property_write_string(root, "serial-number", serialno);
+ compat = barebox_get_of_machine_compatible();
+ if (compat)
+ of_prepend_machine_compatible(root, compat);
+
node = of_create_node(root, "/chosen");
if (!node)
return -ENOMEM;
@@ -483,3 +488,34 @@ 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_device_is_compatible(root, 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;
+}