diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2021-07-18 07:13:02 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-07-18 07:13:02 +0200 |
commit | 8a5144d02a0146c4f0ec577232c0a102d12c8ee7 (patch) | |
tree | 85b0459bb60bfaa2a765e21bb7e19a0edc6c2d6a /commands | |
parent | 2551aad17a15fe06ae3b76b12b5df2207c1e11f6 (diff) | |
parent | 368deb2baa56a6ab0f4ec7d7a42559c4db14b063 (diff) | |
download | barebox-8a5144d02a0146c4f0ec577232c0a102d12c8ee7.tar.gz barebox-8a5144d02a0146c4f0ec577232c0a102d12c8ee7.tar.xz |
Merge branch 'for-next/firmware'
Diffstat (limited to 'commands')
-rw-r--r-- | commands/of_diff.c | 6 | ||||
-rw-r--r-- | commands/of_display_timings.c | 2 | ||||
-rw-r--r-- | commands/of_dump.c | 4 | ||||
-rw-r--r-- | commands/of_overlay.c | 34 | ||||
-rw-r--r-- | commands/of_property.c | 74 | ||||
-rw-r--r-- | commands/oftree.c | 2 |
6 files changed, 70 insertions, 52 deletions
diff --git a/commands/of_diff.c b/commands/of_diff.c index ec039776cf..fa99fcd641 100644 --- a/commands/of_diff.c +++ b/commands/of_diff.c @@ -25,7 +25,7 @@ static struct device_node *get_tree(const char *filename, struct device_node *ro if (!node) return ERR_PTR(-ENOENT); - return of_copy_node(NULL, node); + return of_dup(node); } if (!strcmp(filename, "+")) { @@ -33,7 +33,7 @@ static struct device_node *get_tree(const char *filename, struct device_node *ro if (!node) return ERR_PTR(-ENOENT); - node = of_copy_node(NULL, root); + node = of_dup(root); of_fix_tree(node); @@ -44,7 +44,7 @@ static struct device_node *get_tree(const char *filename, struct device_node *ro if (ret) return ERR_PTR(ret); - node = of_unflatten_dtb(fdt); + node = of_unflatten_dtb(fdt, size); free(fdt); diff --git a/commands/of_display_timings.c b/commands/of_display_timings.c index 27b91f311a..4e5ec223b7 100644 --- a/commands/of_display_timings.c +++ b/commands/of_display_timings.c @@ -83,7 +83,7 @@ static int do_of_display_timings(int argc, char *argv[]) return -EINVAL; } - root = of_unflatten_dtb(fdt); + root = of_unflatten_dtb(fdt, size); free(fdt); diff --git a/commands/of_dump.c b/commands/of_dump.c index 2089c07ef7..5223ba63ad 100644 --- a/commands/of_dump.c +++ b/commands/of_dump.c @@ -71,7 +71,7 @@ static int do_of_dump(int argc, char *argv[]) return -errno; } - root = of_unflatten_dtb(fdt); + root = of_unflatten_dtb(fdt, size); free(fdt); @@ -88,7 +88,7 @@ static int do_of_dump(int argc, char *argv[]) /* create a copy of internal devicetree */ void *fdt; fdt = of_flatten_dtb(root); - root = of_unflatten_dtb(fdt); + root = of_unflatten_dtb(fdt, fdt_totalsize(fdt)); free(fdt); diff --git a/commands/of_overlay.c b/commands/of_overlay.c index aa4b6484ca..b3660b4bf1 100644 --- a/commands/of_overlay.c +++ b/commands/of_overlay.c @@ -13,41 +13,25 @@ static int do_of_overlay(int argc, char *argv[]) { - int opt, ret; + int ret; struct fdt_header *fdt; struct device_node *overlay; - const char *search_path = NULL; + size_t size; - while ((opt = getopt(argc, argv, "S:")) > 0) { - switch (opt) { - case 'S': - search_path = optarg; - break; - default: - return COMMAND_ERROR_USAGE; - } - } - - if (argc != optind + 1) + if (argc != 2) return COMMAND_ERROR_USAGE; - fdt = read_file(argv[optind], NULL); + fdt = read_file(argv[optind], &size); if (!fdt) { printf("cannot read %s\n", argv[optind]); return 1; } - overlay = of_unflatten_dtb(fdt); + overlay = of_unflatten_dtb(fdt, size); free(fdt); if (IS_ERR(overlay)) return PTR_ERR(overlay); - if (search_path) { - ret = of_firmware_load_overlay(overlay, search_path); - if (ret) - goto err; - } - ret = of_register_overlay(overlay); if (ret) { printf("cannot apply oftree overlay: %s\n", strerror(-ret)); @@ -61,15 +45,9 @@ err: return ret; } -BAREBOX_CMD_HELP_START(of_overlay) -BAREBOX_CMD_HELP_TEXT("Options:") -BAREBOX_CMD_HELP_OPT("-S path", "load firmware using this search path") -BAREBOX_CMD_HELP_END - BAREBOX_CMD_START(of_overlay) .cmd = do_of_overlay, BAREBOX_CMD_DESC("register device tree overlay as fixup") - BAREBOX_CMD_OPTS("[-S path] FILE") + BAREBOX_CMD_OPTS("FILE") BAREBOX_CMD_GROUP(CMD_GRP_MISC) - BAREBOX_CMD_HELP(cmd_of_overlay_help) BAREBOX_CMD_END diff --git a/commands/of_property.c b/commands/of_property.c index 3d5097165b..063e97775c 100644 --- a/commands/of_property.c +++ b/commands/of_property.c @@ -4,6 +4,7 @@ /* of_property.c - device tree property handling support */ #include <common.h> +#include <libfile.h> #include <environment.h> #include <fdt.h> #include <of.h> @@ -18,7 +19,7 @@ #include <init.h> #include <xfuncs.h> -static int of_parse_prop_cells(char * const *newval, int count, char *data, int *len) +static int of_parse_prop_cells(struct device_node *root, char * const *newval, int count, char *data, int *len) { char *cp; unsigned long tmp; /* holds converted values */ @@ -60,7 +61,7 @@ static int of_parse_prop_cells(char * const *newval, int count, char *data, int str = xzalloc(len + 1); strncpy(str, cp, len); - n = of_find_node_by_path_or_alias(NULL, str); + n = of_find_node_by_path_or_alias(root, str); if (!n) printf("Cannot find node '%s'\n", str); @@ -164,7 +165,7 @@ static int of_parse_prop_string(char * const *newval, int count, char *data, int * data: A bytestream to be placed in the property * len: The length of the resulting bytestream */ -static int of_parse_prop(char * const *newval, int count, char *data, int *len) +static int of_parse_prop(struct device_node *root, char * const *newval, int count, char *data, int *len) { char *newp; /* temporary newval char pointer */ @@ -177,7 +178,7 @@ static int of_parse_prop(char * const *newval, int count, char *data, int *len) switch (*newp) { case '<': - return of_parse_prop_cells(newval, count, data, len); + return of_parse_prop_cells(root, newval, count, data, len); case '[': return of_parse_prop_stream(newval, count, data, len); default: @@ -302,8 +303,13 @@ static int do_of_property(int argc, char *argv[]) int set = 0; int fixup = 0; char *path, *propname; + char *dtbfile = NULL; + int ret = 0; + size_t size; + struct fdt_header *fdt = NULL; + struct device_node *root = NULL; - while ((opt = getopt(argc, argv, "dsf")) > 0) { + while ((opt = getopt(argc, argv, "dsfe:")) > 0) { switch (opt) { case 'd': delete = 1; @@ -314,6 +320,9 @@ static int do_of_property(int argc, char *argv[]) case 'f': fixup = 1; break; + case 'e': + dtbfile = optarg; + break; default: return COMMAND_ERROR_USAGE; } @@ -327,8 +336,22 @@ static int do_of_property(int argc, char *argv[]) debug("path: %s propname: %s\n", path, propname); + if ( !(set || delete)) + return COMMAND_ERROR_USAGE; + + if (dtbfile) { + fdt = read_file(dtbfile, &size); + if (!fdt) { + printf("unable to read %s: %m\n", dtbfile); + return -errno; + } + + root = of_unflatten_dtb(fdt, size); + + free(fdt); + } + if (set) { - int ret; int len; void *data; @@ -340,10 +363,10 @@ static int do_of_property(int argc, char *argv[]) if (!data) return -ENOMEM; - ret = of_parse_prop(&argv[optind + 2], argc - optind - 2, data, &len); + ret = of_parse_prop(root, &argv[optind + 2], argc - optind - 2, data, &len); if (ret) { free(data); - return ret; + goto out; } if (fixup) { @@ -351,21 +374,37 @@ static int do_of_property(int argc, char *argv[]) if (ret) free(data); } else { - ret = do_of_property_set_now(NULL, path, propname, data, len); + ret = do_of_property_set_now(root, path, propname, data, len); free(data); } - return ret; - } + if (ret) + goto out; - if (delete) { + } else if (delete) { if (fixup) - return do_of_property_delete_fixup(path, propname); + ret = do_of_property_delete_fixup(path, propname); else - return do_of_property_delete_now(NULL, path, propname); + ret = do_of_property_delete_now(root, path, propname); + + if (ret) + goto out; + } + + if (root && !fixup) { + fdt = of_flatten_dtb(root); + + ret = write_file(dtbfile, fdt, fdt32_to_cpu(fdt->totalsize)); + + free(fdt); } - return COMMAND_ERROR_USAGE; +out: + + if (root) + of_delete_node(root); + + return ret; } BAREBOX_CMD_HELP_START(of_property) @@ -373,6 +412,7 @@ BAREBOX_CMD_HELP_TEXT("Options:") BAREBOX_CMD_HELP_OPT ("-s", "set property to value") BAREBOX_CMD_HELP_OPT ("-d", "delete property") BAREBOX_CMD_HELP_OPT ("-f", "set/delete as a fixup (defer the action until booting)") +BAREBOX_CMD_HELP_OPT ("-e dtb", "set/delete/fixup from external dtb") BAREBOX_CMD_HELP_TEXT("") BAREBOX_CMD_HELP_TEXT("Valid formats for values:") BAREBOX_CMD_HELP_TEXT("<0x00112233 4 05> - an array of cells. cells not beginning with a digit are") @@ -384,8 +424,8 @@ BAREBOX_CMD_HELP_END BAREBOX_CMD_START(of_property) .cmd = do_of_property, BAREBOX_CMD_DESC("handle device tree properties") - BAREBOX_CMD_OPTS("[-sd] [-f] NODE [PROPERTY] [VALUES]") + BAREBOX_CMD_OPTS("[-sd] [-e] [-f] NODE [PROPERTY] [VALUES]") BAREBOX_CMD_GROUP(CMD_GRP_MISC) - BAREBOX_CMD_COMPLETE(devicetree_complete) + BAREBOX_CMD_COMPLETE(devicetree_file_complete) BAREBOX_CMD_HELP(cmd_of_property_help) BAREBOX_CMD_END diff --git a/commands/oftree.c b/commands/oftree.c index 1d902f2830..7d4b08c9d3 100644 --- a/commands/oftree.c +++ b/commands/oftree.c @@ -82,7 +82,7 @@ static int do_oftree(int argc, char *argv[]) return 1; } - root = of_unflatten_dtb(fdt); + root = of_unflatten_dtb(fdt, size); free(fdt); |