summaryrefslogtreecommitdiffstats
path: root/src/barebox-state.c
diff options
context:
space:
mode:
authorSteffen Trumtrar <s.trumtrar@pengutronix.de>2017-06-30 16:53:34 +0200
committerSteffen Trumtrar <s.trumtrar@pengutronix.de>2017-07-03 12:51:57 +0200
commit405590bdb7ae434798010458e810c415e4e99db4 (patch)
tree7f3dda1ceec3f97b9ef01166debfef5e32099823 /src/barebox-state.c
parent26148417fab419a0c7f301fb8f2be015324d5374 (diff)
downloaddt-utils-405590bdb7ae434798010458e810c415e4e99db4.tar.gz
dt-utils-405590bdb7ae434798010458e810c415e4e99db4.tar.xz
barebox-state: get devicetree from filev2017.03.0/topic/efi-state
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Diffstat (limited to 'src/barebox-state.c')
-rw-r--r--src/barebox-state.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/barebox-state.c b/src/barebox-state.c
index e68b8cb..3622e76 100644
--- a/src/barebox-state.c
+++ b/src/barebox-state.c
@@ -308,7 +308,7 @@ static int state_set_var(struct state *state, const char *var, const char *val)
}
-struct state *state_get(const char *name, bool readonly, bool auth)
+struct state *state_get(const char *name, const char *filename, bool readonly, bool auth)
{
struct device_node *root, *node, *partition_node;
char *path;
@@ -320,11 +320,19 @@ struct state *state_get(const char *name, bool readonly, bool auth)
off_t offset;
size_t size;
- root = of_read_proc_devicetree();
- if (IS_ERR(root)) {
- pr_err("Unable to read devicetree. %s\n",
- strerror(-PTR_ERR(root)));
- return ERR_CAST(root);
+ if (filename) {
+ void *fdt;
+
+ fdt = read_file(filename, NULL);
+ if (fdt)
+ root = of_unflatten_dtb(fdt);
+ } else {
+ root = of_read_proc_devicetree();
+ if (IS_ERR(root)) {
+ pr_err("Unable to read devicetree. %s\n",
+ strerror(-PTR_ERR(root)));
+ return ERR_CAST(root);
+ }
}
of_set_root_node(root);
@@ -387,6 +395,7 @@ static struct option long_options[] = {
{"get", required_argument, 0, 'g' },
{"set", required_argument, 0, 's' },
{"name", required_argument, 0, 'n' },
+ {"input", required_argument, 0, 'i' },
{"dump", no_argument, 0, 'd' },
{"dump-shell", no_argument, 0, OPT_DUMP_SHELL },
{"verbose", no_argument, 0, 'v' },
@@ -402,6 +411,7 @@ static void usage(char *name)
"-g, --get <variable> get the value of a variable\n"
"-s, --set <variable>=<value> set the value of a variable\n"
"-n, --name <name> specify the state to use (default=\"state\"). Multiple states are allowed.\n"
+"-i, --input <name> load the devicetree from a file instead of using the system devicetree.\n"
"-d, --dump dump the state\n"
"--dump-shell dump the state suitable for shell sourcing\n"
"-v, --verbose increase verbosity\n"
@@ -439,12 +449,13 @@ int main(int argc, char *argv[])
bool readonly = true;
int pr_level = 5;
int auth = 1;
+ const char *dtb = NULL;
INIT_LIST_HEAD(&sg_list);
INIT_LIST_HEAD(&state_list.list);
while (1) {
- c = getopt_long(argc, argv, "hg:s:dvn:qf", long_options, &option_index);
+ c = getopt_long(argc, argv, "hg:s:i:dvn:qf", long_options, &option_index);
if (c < 0)
break;
switch (c) {
@@ -490,6 +501,9 @@ int main(int argc, char *argv[])
++nr_states;
break;
}
+ case 'i':
+ dtb = strdup(optarg);
+ break;
case ':':
case '?':
default:
@@ -530,7 +544,7 @@ int main(int argc, char *argv[])
}
list_for_each_entry(state, &state_list.list, list) {
- state->state = state_get(state->name, readonly, auth);
+ state->state = state_get(state->name, dtb, readonly, auth);
if (!IS_ERR(state->state) && !state->name)
state->name = state->state->name;
if (IS_ERR(state->state)) {