summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2023-05-02 13:13:29 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-05-22 13:29:46 +0200
commitee1da2710f85ea560dd206ef4b6fddc56bde4535 (patch)
treed1dd2bb2c1ac6e42bd4c9aa14fddc7370684b17f /commands
parentd62d399630e24c76cb90e8a19d7e7b95d72258b6 (diff)
downloadbarebox-ee1da2710f85ea560dd206ef4b6fddc56bde4535.tar.gz
barebox-ee1da2710f85ea560dd206ef4b6fddc56bde4535.tar.xz
of: add function to read a file as unflattened device tree
There are several places in the tree that read in a dtb file and unflatten it. Add a of_read_file() helper function for that and use it where appropriately. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/of_diff.c13
-rw-r--r--commands/of_display_timings.c26
-rw-r--r--commands/of_dump.c15
-rw-r--r--commands/of_overlay.c15
-rw-r--r--commands/oftree.c16
5 files changed, 15 insertions, 70 deletions
diff --git a/commands/of_diff.c b/commands/of_diff.c
index 6a78263200..19a4a26d20 100644
--- a/commands/of_diff.c
+++ b/commands/of_diff.c
@@ -16,9 +16,6 @@
static struct device_node *get_tree(const char *filename, struct device_node *root)
{
struct device_node *node;
- void *fdt;
- size_t size;
- int ret;
if (!strcmp(filename, "-")) {
node = of_get_root_node();
@@ -40,15 +37,7 @@ static struct device_node *get_tree(const char *filename, struct device_node *ro
return node;
}
- ret = read_file_2(filename, &size, &fdt, FILESIZE_MAX);
- if (ret)
- return ERR_PTR(ret);
-
- node = of_unflatten_dtb(fdt, size);
-
- free(fdt);
-
- return node;
+ return of_read_file(filename);
}
static int do_of_diff(int argc, char *argv[])
diff --git a/commands/of_display_timings.c b/commands/of_display_timings.c
index aab57b17d6..1fb0c4eb00 100644
--- a/commands/of_display_timings.c
+++ b/commands/of_display_timings.c
@@ -67,29 +67,11 @@ static int do_of_display_timings(int argc, char *argv[])
/* Check if external dtb given */
if (dtbfile) {
- void *fdt;
- size_t size;
-
- fdt = read_file(dtbfile, &size);
- if (!fdt) {
- pr_err("unable to read %s: %s\n", dtbfile,
- strerror(errno));
- return -errno;
- }
-
- if (file_detect_type(fdt, size) != filetype_oftree) {
- pr_err("%s is not a oftree file.\n", dtbfile);
- free(fdt);
- return -EINVAL;
- }
-
- root = of_unflatten_dtb(fdt, size);
-
- free(fdt);
-
- if (IS_ERR(root))
+ root = of_read_file(dtbfile);
+ if (IS_ERR(root)) {
+ printf("Cannot open %s: %pe\n", dtbfile, root);
return PTR_ERR(root);
-
+ }
} else {
root = of_get_root_node();
}
diff --git a/commands/of_dump.c b/commands/of_dump.c
index c2ca8485cd..86755ff1e4 100644
--- a/commands/of_dump.c
+++ b/commands/of_dump.c
@@ -37,7 +37,6 @@ static int do_of_dump(int argc, char *argv[])
int fix = 0;
struct device_node *root = NULL, *node, *of_free = NULL;
char *dtbfile = NULL;
- size_t size;
const char *nodename;
unsigned maxpropsize = ~0;
int names_only = 0, properties_only = 0;
@@ -72,19 +71,9 @@ static int do_of_dump(int argc, char *argv[])
nodename = argv[optind];
if (dtbfile) {
- void *fdt;
-
- fdt = read_file(dtbfile, &size);
- if (!fdt) {
- printf("unable to read %s: %s\n", dtbfile, strerror(errno));
- return -errno;
- }
-
- root = of_unflatten_dtb(fdt, size);
-
- free(fdt);
-
+ root = of_read_file(dtbfile);
if (IS_ERR(root)) {
+ printf("Cannot open %s: %pe\n", dtbfile, root);
ret = PTR_ERR(root);
goto out;
}
diff --git a/commands/of_overlay.c b/commands/of_overlay.c
index b0ca57749b..fda9115a82 100644
--- a/commands/of_overlay.c
+++ b/commands/of_overlay.c
@@ -15,9 +15,7 @@
static int do_of_overlay(int argc, char *argv[])
{
int ret;
- struct fdt_header *fdt;
struct device_node *overlay;
- size_t size;
bool live_tree = false;
int opt;
@@ -37,16 +35,11 @@ static int do_of_overlay(int argc, char *argv[])
return 1;
}
- fdt = read_file(argv[optind], &size);
- if (!fdt) {
- printf("cannot read %s\n", argv[optind]);
- return 1;
- }
-
- overlay = of_unflatten_dtb(fdt, size);
- free(fdt);
- if (IS_ERR(overlay))
+ overlay = of_read_file(argv[optind]);
+ if (IS_ERR(overlay)) {
+ printf("Cannot open %s: %pe\n", argv[optind], overlay);
return PTR_ERR(overlay);
+ }
if (live_tree) {
ret = of_overlay_apply_tree(of_get_root_node(), overlay);
diff --git a/commands/oftree.c b/commands/oftree.c
index 7d4b08c9d3..7b12c86e1d 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -31,7 +31,6 @@
static int do_oftree(int argc, char *argv[])
{
struct fdt_header *fdt = NULL;
- size_t size;
int opt;
int probe = 0;
char *load = NULL;
@@ -76,18 +75,11 @@ static int do_oftree(int argc, char *argv[])
}
if (load) {
- fdt = read_file(load, &size);
- if (!fdt) {
- printf("unable to read %s\n", load);
- return 1;
- }
-
- root = of_unflatten_dtb(fdt, size);
-
- free(fdt);
-
- if (IS_ERR(root))
+ root = of_read_file(load);
+ if (IS_ERR(root)) {
+ printf("Cannot open %s: %pe\n", load, root);
return PTR_ERR(root);
+ }
ret = of_set_root_node(root);
if (ret) {