* [OSS-Tools] [PATCH dt-utils v5 0/2] barebox-state: get devicetree from file @ 2019-10-24 14:24 Ahmad Fatoum 2019-10-24 14:24 ` [OSS-Tools] [PATCH v5 1/2] libdt: support upper-case hexadecimals in value of partuuid property Ahmad Fatoum ` (3 more replies) 0 siblings, 4 replies; 6+ messages in thread From: Ahmad Fatoum @ 2019-10-24 14:24 UTC (permalink / raw) To: oss-tools For use on systems that don't normally have a device tree, like x86, it would be nice to be able to pass barebox_state the path to a device tree blob directly, which is what this patch set does. Cheers Ahmad Changes in v5: - Rebased onto current master - Added commit to handle non-lower-case partuuids - Fixed use after free by not allocating dynamic memory Ahmad Fatoum (1): libdt: support upper-case hexadecimals in value of partuuid property Steffen Trumtrar (1): barebox-state: get devicetree from file src/barebox-state.c | 41 +++++++++++++++++++++++++++++++++-------- src/barebox-state.h | 2 +- src/keystore-blob.c | 2 +- src/libdt.c | 12 +++++++++++- 4 files changed, 46 insertions(+), 11 deletions(-) -- 2.23.0 _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de ^ permalink raw reply [flat|nested] 6+ messages in thread
* [OSS-Tools] [PATCH v5 1/2] libdt: support upper-case hexadecimals in value of partuuid property 2019-10-24 14:24 [OSS-Tools] [PATCH dt-utils v5 0/2] barebox-state: get devicetree from file Ahmad Fatoum @ 2019-10-24 14:24 ` Ahmad Fatoum 2019-10-24 14:24 ` [OSS-Tools] [PATCH v5 2/2] barebox-state: get devicetree from file Ahmad Fatoum ` (2 subsequent siblings) 3 siblings, 0 replies; 6+ messages in thread From: Ahmad Fatoum @ 2019-10-24 14:24 UTC (permalink / raw) To: oss-tools barebox/next now has a commit[1] to support the hexadecimal numbers in the partition UUID to be upper case as well. This aligns its behavior with the Linux kernel, where the PARTUUID kernel argument flag also supports[2] lower and upper case UUIDs. The UUIDs used in the /dev/disk/by-partuuid/* symlinks created by udev come from libblkid, which formats the UUID hexadecimals as lower case[3], so we only need to lower case the property value inside dt-utils to have it support upper case part UUIDs as well. [1]: "fs: devfs-core: do a case-insensitive compare of partuuids", https://www.spinics.net/lists/u-boot-v2/msg39590.html [2]: v5.4-rc4, init/do_mounts.c: match_dev_by_uuid() [3]: util-linux v2.34, $(egrep -r '%[^\s"]+X' libblkid/) Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- src/libdt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libdt.c b/src/libdt.c index bdfd409b1aab..01f0a6941aa2 100644 --- a/src/libdt.c +++ b/src/libdt.c @@ -2423,7 +2423,17 @@ int of_get_devicepath(struct device_node *partition_node, char **devpath, off_t /* when partuuid is specified short-circuit the search for the cdev */ ret = of_property_read_string(partition_node, "partuuid", &uuid); if (!ret) { - *devpath = basprintf("/dev/disk/by-partuuid/%s", uuid); + const char prefix[] = "/dev/disk/by-partuuid/"; + size_t prefix_len = sizeof(prefix) - 1; + char *lc_uuid, *s; + + lc_uuid = xzalloc(prefix_len + strlen(uuid) + 1); + s = memcpy(lc_uuid, prefix, prefix_len) + prefix_len; + + while (*uuid) + *s++ = tolower(*uuid++); + + *devpath = lc_uuid; return 0; } -- 2.23.0 _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de ^ permalink raw reply [flat|nested] 6+ messages in thread
* [OSS-Tools] [PATCH v5 2/2] barebox-state: get devicetree from file 2019-10-24 14:24 [OSS-Tools] [PATCH dt-utils v5 0/2] barebox-state: get devicetree from file Ahmad Fatoum 2019-10-24 14:24 ` [OSS-Tools] [PATCH v5 1/2] libdt: support upper-case hexadecimals in value of partuuid property Ahmad Fatoum @ 2019-10-24 14:24 ` Ahmad Fatoum 2020-07-09 13:20 ` [OSS-Tools] [PATCH dt-utils v5 0/2] " Ahmad Fatoum 2021-03-16 14:18 ` Roland Hieber 3 siblings, 0 replies; 6+ messages in thread From: Ahmad Fatoum @ 2019-10-24 14:24 UTC (permalink / raw) To: oss-tools; +Cc: Steffen Trumtrar From: Steffen Trumtrar <s.trumtrar@pengutronix.de> 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> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> --- src/barebox-state.c | 41 +++++++++++++++++++++++++++++++++-------- src/barebox-state.h | 2 +- src/keystore-blob.c | 2 +- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/barebox-state.c b/src/barebox-state.c index 946a8dba6d8c..c7f6dee90d4a 100644 --- a/src/barebox-state.c +++ b/src/barebox-state.c @@ -306,17 +306,36 @@ 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; struct state *state; int ret; - 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); @@ -368,6 +387,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 }, {"force", no_argument, 0, 'f' }, @@ -386,6 +406,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" "-f, --force do not check for state manipulation via the HMAC\n" @@ -425,12 +446,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) { @@ -479,6 +501,9 @@ int main(int argc, char *argv[]) ++nr_states; break; } + case 'i': + dtb = optarg; + break; case ':': case '?': default: @@ -519,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)) { diff --git a/src/barebox-state.h b/src/barebox-state.h index bd89cf48c6a3..a0f49a549649 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 f71ff5d9d5cb..ed6ecb4eaa25 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; -- 2.23.0 _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [OSS-Tools] [PATCH dt-utils v5 0/2] barebox-state: get devicetree from file 2019-10-24 14:24 [OSS-Tools] [PATCH dt-utils v5 0/2] barebox-state: get devicetree from file Ahmad Fatoum 2019-10-24 14:24 ` [OSS-Tools] [PATCH v5 1/2] libdt: support upper-case hexadecimals in value of partuuid property Ahmad Fatoum 2019-10-24 14:24 ` [OSS-Tools] [PATCH v5 2/2] barebox-state: get devicetree from file Ahmad Fatoum @ 2020-07-09 13:20 ` Ahmad Fatoum 2020-07-09 13:37 ` Roland Hieber 2021-03-16 14:18 ` Roland Hieber 3 siblings, 1 reply; 6+ messages in thread From: Ahmad Fatoum @ 2020-07-09 13:20 UTC (permalink / raw) To: Ahmad Fatoum, oss-tools, Roland Hieber On 10/24/19 4:24 PM, Ahmad Fatoum wrote: > For use on systems that don't normally have a device tree, like x86, > it would be nice to be able to pass barebox_state the path to a device > tree blob directly, which is what this patch set does. Gentle ping. > > Cheers > Ahmad > > Changes in v5: > - Rebased onto current master > - Added commit to handle non-lower-case partuuids > - Fixed use after free by not allocating dynamic memory > > Ahmad Fatoum (1): > libdt: support upper-case hexadecimals in value of partuuid property > > Steffen Trumtrar (1): > barebox-state: get devicetree from file > > src/barebox-state.c | 41 +++++++++++++++++++++++++++++++++-------- > src/barebox-state.h | 2 +- > src/keystore-blob.c | 2 +- > src/libdt.c | 12 +++++++++++- > 4 files changed, 46 insertions(+), 11 deletions(-) > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [OSS-Tools] [PATCH dt-utils v5 0/2] barebox-state: get devicetree from file 2020-07-09 13:20 ` [OSS-Tools] [PATCH dt-utils v5 0/2] " Ahmad Fatoum @ 2020-07-09 13:37 ` Roland Hieber 0 siblings, 0 replies; 6+ messages in thread From: Roland Hieber @ 2020-07-09 13:37 UTC (permalink / raw) To: Ahmad Fatoum; +Cc: oss-tools On Thu, Jul 09, 2020 at 03:20:02PM +0200, Ahmad Fatoum wrote: > On 10/24/19 4:24 PM, Ahmad Fatoum wrote: > > For use on systems that don't normally have a device tree, like x86, > > it would be nice to be able to pass barebox_state the path to a device > > tree blob directly, which is what this patch set does. > > Gentle ping. Yes, sorry. It's planned for next week. > > Cheers > > Ahmad > > > > Changes in v5: > > - Rebased onto current master > > - Added commit to handle non-lower-case partuuids > > - Fixed use after free by not allocating dynamic memory > > > > Ahmad Fatoum (1): > > libdt: support upper-case hexadecimals in value of partuuid property > > > > Steffen Trumtrar (1): > > barebox-state: get devicetree from file > > > > src/barebox-state.c | 41 +++++++++++++++++++++++++++++++++-------- > > src/barebox-state.h | 2 +- > > src/keystore-blob.c | 2 +- > > src/libdt.c | 12 +++++++++++- > > 4 files changed, 46 insertions(+), 11 deletions(-) > > > > -- > Pengutronix e.K. | | > Steuerwalder Str. 21 | http://www.pengutronix.de/ | > 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | > Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | > > _______________________________________________ > OSS-Tools mailing list > OSS-Tools@pengutronix.de > -- Roland Hieber, Pengutronix e.K. | r.hieber@pengutronix.de | Steuerwalder Str. 21 | https://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [OSS-Tools] [PATCH dt-utils v5 0/2] barebox-state: get devicetree from file 2019-10-24 14:24 [OSS-Tools] [PATCH dt-utils v5 0/2] barebox-state: get devicetree from file Ahmad Fatoum ` (2 preceding siblings ...) 2020-07-09 13:20 ` [OSS-Tools] [PATCH dt-utils v5 0/2] " Ahmad Fatoum @ 2021-03-16 14:18 ` Roland Hieber 3 siblings, 0 replies; 6+ messages in thread From: Roland Hieber @ 2021-03-16 14:18 UTC (permalink / raw) To: Ahmad Fatoum; +Cc: oss-tools On Thu, Oct 24, 2019 at 04:24:49PM +0200, Ahmad Fatoum wrote: > For use on systems that don't normally have a device tree, like x86, > it would be nice to be able to pass barebox_state the path to a device > tree blob directly, which is what this patch set does. > > Cheers > Ahmad > > Changes in v5: > - Rebased onto current master > - Added commit to handle non-lower-case partuuids > - Fixed use after free by not allocating dynamic memory > > Ahmad Fatoum (1): > libdt: support upper-case hexadecimals in value of partuuid property > > Steffen Trumtrar (1): > barebox-state: get devicetree from file Thanks, applied. - Roland > > src/barebox-state.c | 41 +++++++++++++++++++++++++++++++++-------- > src/barebox-state.h | 2 +- > src/keystore-blob.c | 2 +- > src/libdt.c | 12 +++++++++++- > 4 files changed, 46 insertions(+), 11 deletions(-) > > -- > 2.23.0 > > > _______________________________________________ > OSS-Tools mailing list > OSS-Tools@pengutronix.de > -- Roland Hieber, Pengutronix e.K. | r.hieber@pengutronix.de | Steuerwalder Str. 21 | https://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-03-16 14:18 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-10-24 14:24 [OSS-Tools] [PATCH dt-utils v5 0/2] barebox-state: get devicetree from file Ahmad Fatoum 2019-10-24 14:24 ` [OSS-Tools] [PATCH v5 1/2] libdt: support upper-case hexadecimals in value of partuuid property Ahmad Fatoum 2019-10-24 14:24 ` [OSS-Tools] [PATCH v5 2/2] barebox-state: get devicetree from file Ahmad Fatoum 2020-07-09 13:20 ` [OSS-Tools] [PATCH dt-utils v5 0/2] " Ahmad Fatoum 2020-07-09 13:37 ` Roland Hieber 2021-03-16 14:18 ` Roland Hieber
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox