summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Trumtrar <s.trumtrar@pengutronix.de>2017-06-30 16:53:34 +0200
committerEnrico Jorns <ejo@pengutronix.de>2019-10-21 11:07:19 +0200
commitf8fb4d0a34c291067cc40664a1403457e7a8ec60 (patch)
tree7173cdac56cf79122d51b91ab47cf31f88fc38e6
parent28ac0503b161bc99108580c4996210f7bec498d7 (diff)
downloaddt-utils-v2019.01.0/topic/efi-state.tar.gz
barebox-state: get devicetree from filev2019.01.0/topic/efi-state
Adds a -i/--input argument to barebox-state to allow passing a devicetree as a file instead of using it from the system. This can be used for example on systems that do not use device trees (such as x86) but where we want to use a dtb blob for describing the state storage and format. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
-rw-r--r--src/barebox-state.c42
-rw-r--r--src/barebox-state.h2
-rw-r--r--src/keystore-blob.c2
3 files changed, 36 insertions, 10 deletions
diff --git a/src/barebox-state.c b/src/barebox-state.c
index f8b8df6..41efd90 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;
char *path;
@@ -317,11 +317,30 @@ struct state *state_get(const char *name, bool readonly, bool auth)
const char *backend_type = NULL;
struct state_variable *v;
- 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) {
+ pr_err("Unable to read devicetree file '%s'\n",
+ filename);
+ return ERR_PTR(-ENOENT);
+ }
+
+ root = of_unflatten_dtb(fdt);
+ free(fdt);
+ if (IS_ERR(root)) {
+ pr_err("Unable to read devicetree. %s\n",
+ strerror(-PTR_ERR(root)));
+ return ERR_CAST(root);
+ }
+ } 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);
@@ -372,6 +391,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' },
@@ -387,6 +407,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"
@@ -424,12 +445,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) {
@@ -475,6 +497,9 @@ int main(int argc, char *argv[])
++nr_states;
break;
}
+ case 'i':
+ dtb = strdup(optarg);
+ break;
case ':':
case '?':
default:
@@ -515,13 +540,14 @@ 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)) {
ret = 1;
goto out_unlock;
}
+ free(dtb);
}
if (do_dump) {
diff --git a/src/barebox-state.h b/src/barebox-state.h
index bd89cf4..a0f49a5 100644
--- a/src/barebox-state.h
+++ b/src/barebox-state.h
@@ -1,7 +1,7 @@
#ifndef __BAREBOX_STATE__
#define __BAREBOX_STATE__
-struct state *state_get(const char *name, bool readonly, bool auth);
+struct state *state_get(const char *name, const char *file, bool readonly, bool auth);
char *state_get_var(struct state *state, const char *var);
#endif /* __BAREBOX_STATE__ */
diff --git a/src/keystore-blob.c b/src/keystore-blob.c
index 028dd8b..4572431 100644
--- a/src/keystore-blob.c
+++ b/src/keystore-blob.c
@@ -30,7 +30,7 @@ int keystore_get_secret(const char *name, const unsigned char **key, int *key_le
if (!state) {
struct state *tmp;
- tmp = state_get(keystore_state_name, true, false);
+ tmp = state_get(keystore_state_name, NULL, true, false);
if (IS_ERR(tmp))
return PTR_ERR(tmp);
state = tmp;