summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/cpu/dtb.c8
-rw-r--r--arch/kvx/lib/dtb.c12
-rw-r--r--arch/mips/boot/dtb.c8
-rw-r--r--arch/openrisc/lib/dtb.c8
-rw-r--r--arch/riscv/boot/dtb.c14
-rw-r--r--arch/sandbox/board/dtb.c5
-rw-r--r--drivers/of/base.c28
-rw-r--r--include/of.h2
8 files changed, 36 insertions, 49 deletions
diff --git a/arch/arm/cpu/dtb.c b/arch/arm/cpu/dtb.c
index 8094eeb..35f251d 100644
--- a/arch/arm/cpu/dtb.c
+++ b/arch/arm/cpu/dtb.c
@@ -26,13 +26,7 @@ static int of_arm_init(void)
return 0;
}
- root = of_unflatten_dtb(fdt);
- if (!IS_ERR(root)) {
- of_set_root_node(root);
- of_fix_tree(root);
- if (IS_ENABLED(CONFIG_OFDEVICE))
- of_probe();
- }
+ barebox_register_fdt(fdt);
return 0;
}
diff --git a/arch/kvx/lib/dtb.c b/arch/kvx/lib/dtb.c
index 17dcab1..54ffdda 100644
--- a/arch/kvx/lib/dtb.c
+++ b/arch/kvx/lib/dtb.c
@@ -12,17 +12,7 @@ static int of_kvx_init(void)
int ret;
struct device_node *root;
- root = of_unflatten_dtb(boot_dtb);
- if (IS_ERR(root)) {
- ret = PTR_ERR(root);
- panic("Failed to parse DTB: %d\n", ret);
- }
-
- ret = of_set_root_node(root);
- if (ret)
- panic("Failed to set of root node\n");
-
- of_probe();
+ barebox_register_fdt(boot_dtb);
return 0;
}
diff --git a/arch/mips/boot/dtb.c b/arch/mips/boot/dtb.c
index 5e31627..2aff4ad 100644
--- a/arch/mips/boot/dtb.c
+++ b/arch/mips/boot/dtb.c
@@ -42,13 +42,7 @@ static int of_mips_init(void)
if (!fdt)
fdt = __dtb_start;
- root = of_unflatten_dtb(fdt);
- if (!IS_ERR(root)) {
- pr_debug("using internal DTB\n");
- of_set_root_node(root);
- if (IS_ENABLED(CONFIG_OFDEVICE))
- of_probe();
- }
+ barebox_register_fdt(fdt);
return 0;
}
diff --git a/arch/openrisc/lib/dtb.c b/arch/openrisc/lib/dtb.c
index 2dd8e4e..61cf35d 100644
--- a/arch/openrisc/lib/dtb.c
+++ b/arch/openrisc/lib/dtb.c
@@ -28,13 +28,7 @@ static int of_openrisc_init(void)
if (root)
return 0;
- root = of_unflatten_dtb(__dtb_start);
- if (!IS_ERR(root)) {
- pr_debug("using internal DTB\n");
- of_set_root_node(root);
- if (IS_ENABLED(CONFIG_OFDEVICE))
- of_probe();
- }
+ barebox_register_fdt(__dtb_start);
return 0;
}
diff --git a/arch/riscv/boot/dtb.c b/arch/riscv/boot/dtb.c
index 5d73413..b9b68fc 100644
--- a/arch/riscv/boot/dtb.c
+++ b/arch/riscv/boot/dtb.c
@@ -18,19 +18,7 @@ extern char __dtb_start[];
static int of_riscv_init(void)
{
- struct device_node *root;
-
- root = of_get_root_node();
- if (root)
- return 0;
-
- root = of_unflatten_dtb(__dtb_start);
- if (!IS_ERR(root)) {
- pr_debug("using internal DTB\n");
- of_set_root_node(root);
- if (IS_ENABLED(CONFIG_OFDEVICE))
- of_probe();
- }
+ barebox_register_fdt(__dtb_start);
return 0;
}
diff --git a/arch/sandbox/board/dtb.c b/arch/sandbox/board/dtb.c
index d11bde0..da24521 100644
--- a/arch/sandbox/board/dtb.c
+++ b/arch/sandbox/board/dtb.c
@@ -54,10 +54,7 @@ static int of_sandbox_init(void)
if (IS_ERR(root))
return PTR_ERR(root);
- of_set_root_node(root);
- of_fix_tree(root);
- if (IS_ENABLED(CONFIG_OFDEVICE))
- of_probe();
+ barebox_register_of(root);
return 0;
}
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 0a2632f..6e2fb8b 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1567,6 +1567,34 @@ int of_set_root_node(struct device_node *node)
return 0;
}
+void barebox_register_of(struct device_node *root)
+{
+ if (root_node)
+ return;
+
+ of_fix_tree(root);
+ of_set_root_node(root);
+
+ if (IS_ENABLED(CONFIG_OFDEVICE))
+ of_probe();
+}
+
+void barebox_register_fdt(const void *dtb)
+{
+ struct device_node *root;
+
+ if (root_node)
+ return;
+
+ root = of_unflatten_dtb(dtb);
+ if (IS_ERR(root)) {
+ pr_err("Cannot unflatten dtb: %s\n", strerrorp(root));
+ return;
+ }
+
+ barebox_register_of(root);
+}
+
/**
* of_device_is_available - check if a device is available for use
*
diff --git a/include/of.h b/include/of.h
index b9b3a10..fc36f7a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -252,6 +252,8 @@ extern int of_modalias_node(struct device_node *node, char *modalias, int len);
extern struct device_node *of_get_root_node(void);
extern int of_set_root_node(struct device_node *node);
+extern void barebox_register_of(struct device_node *root);
+extern void barebox_register_fdt(const void *dtb);
extern struct device_d *of_platform_device_create(struct device_node *np,
struct device_d *parent);