Hi, This adds support for backend-diskuuid / backend-offset. The corresponding barebox patches can be found here: https://lore.barebox.org/barebox/20220124100458.2924679-1-m.olbrich@pengutronix.de/ The mount point for the ESP is quite standardized. So let barebox-state look there if nothing is found in sysfs/procfs. This way, barebox-state works on EFI without manually specifying the dtb file. Michael Michael Olbrich (4): state: support deep probe state: implement helper to find device path from diskuuid state: support backend-diskuuid / backend-offset state: automatically find state.dtb in the ESP Makefile.am | 1 + src/barebox-state-compat.c | 64 ++++++++++++++++++++++++++++++++++++++ src/barebox-state.c | 24 ++++++++++++++ src/barebox-state/state.c | 53 ++++++++++++++++++++++--------- src/libbb.h | 2 ++ 5 files changed, 129 insertions(+), 15 deletions(-) create mode 100644 src/barebox-state-compat.c -- 2.30.2 _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de
This ports the following barebox commit: |commit ac71031705cedd53570b8b0a4a6b63473f7127c3 |Author: Ahmad Fatoum <a.fatoum@pengutronix.de> |Date: Mon Jun 28 08:45:14 2021 +0200 | | state: support deep probe | | With deep probe, drivers registered before of_populate_initcall must | themselves take care to ensure their dependencies had a chance to probe. | | For barebox-state, this means the backend partition provider must be | probed. Do so by calling of_partition_ensure_probed on it. | | Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> | Link: https://lore.barebox.org/20210628064517.28636-5-a.fatoum@pengutronix.de | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> --- src/barebox-state/state.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c index f528b3e19f21..363ac8a5d485 100644 --- a/src/barebox-state/state.c +++ b/src/barebox-state/state.c @@ -616,6 +616,10 @@ struct state *state_new_from_node(struct device_node *node, bool readonly) } #ifdef __BAREBOX__ + ret = of_partition_ensure_probed(partition_node); + if (ret) + goto out_release_state; + ret = of_find_path_by_node(partition_node, &state->backend_path, 0); #else ret = of_get_devicepath(partition_node, &state->backend_path, &offset, &size); -- 2.30.2 _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> --- I didn't find a good place for this helper. It has nothing to do with device trees and I didn't want to add it to code that is shared with barebox. If there is a better place for it then I don't mind moving it. Michael Makefile.am | 1 + src/barebox-state-compat.c | 64 ++++++++++++++++++++++++++++++++++++++ src/libbb.h | 2 ++ 3 files changed, 67 insertions(+) create mode 100644 src/barebox-state-compat.c diff --git a/Makefile.am b/Makefile.am index d53ee7c6f9c3..a9eb0fd304eb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -55,6 +55,7 @@ barebox_state_SOURCES = \ src/barebox-state/state.c \ src/barebox-state/state.h \ src/barebox-state/state_variables.c \ + src/barebox-state-compat.c \ src/barebox-state.c \ src/barebox-state.h \ \ diff --git a/src/barebox-state-compat.c b/src/barebox-state-compat.c new file mode 100644 index 000000000000..1ed8fefa2253 --- /dev/null +++ b/src/barebox-state-compat.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 Pengutronix, Michael Olbrich <m.olbrich@pengutronix.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <libudev.h> + +int devpath_from_diskuuid(const char *diskuuid, char **devpath) +{ + struct udev *udev; + struct udev_enumerate *enumerate; + struct udev_list_entry *devices, *dev_list_entry; + int ret = 0; + + udev = udev_new(); + if (!udev) { + fprintf(stderr, "Can't create udev\n"); + return -ENODEV; + } + + enumerate = udev_enumerate_new(udev); + udev_enumerate_add_match_subsystem(enumerate, "block"); + udev_enumerate_scan_devices(enumerate); + devices = udev_enumerate_get_list_entry(enumerate); + udev_list_entry_foreach(dev_list_entry, devices) { + const char *path, *devtype, *outpath, *uuid; + struct udev_device *device; + + path = udev_list_entry_get_name(dev_list_entry); + device = udev_device_new_from_syspath(udev, path); + + /* distinguish device (disk) from partitions */ + devtype = udev_device_get_devtype(device); + if (!devtype) + continue; + if (strcmp(devtype, "disk")) + continue; + + uuid = udev_device_get_property_value(device, "ID_PART_TABLE_UUID"); + if (!strcmp(uuid, diskuuid)) { + outpath = udev_device_get_devnode(device); + *devpath = strdup(outpath); + goto out; + } + } + ret = -ENODEV; + +out: + udev_enumerate_unref(enumerate); + udev_unref(udev); + + return ret; +} diff --git a/src/libbb.h b/src/libbb.h index 9f9d32d12d94..5350341d2281 100644 --- a/src/libbb.h +++ b/src/libbb.h @@ -3,4 +3,6 @@ #include <dt/common.h> +int devpath_from_diskuuid(const char *diskuuid, char **devpath); + #endif -- 2.30.2 _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de
On some platforms (e.g. EFI on x86_64) the state backend can only be selected by a partiton UUID. On existing devices with a DOS partition table, there may be no spare partition available for state. This makes it possible to select the disk via UUID. The exact position is defined by an explicitly specified offset. The same patch was submittet to barebox: https://lore.barebox.org/barebox/20220124100458.2924679-4-m.olbrich@pengutronix.de/ Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> --- src/barebox-state/state.c | 55 ++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/barebox-state/state.c b/src/barebox-state/state.c index 363ac8a5d485..f825ee6f1303 100644 --- a/src/barebox-state/state.c +++ b/src/barebox-state/state.c @@ -593,6 +593,7 @@ struct state *state_new_from_node(struct device_node *node, bool readonly) const char *backend_type; const char *storage_type = NULL; const char *alias; + const char *diskuuid; uint32_t stridesize; struct device_node *partition_node; off_t offset = 0; @@ -608,30 +609,48 @@ struct state *state_new_from_node(struct device_node *node, bool readonly) if (IS_ERR(state)) return state; - partition_node = of_parse_phandle(node, "backend", 0); - if (!partition_node) { - dev_err(&state->dev, "Cannot resolve \"backend\" phandle\n"); - ret = -EINVAL; - goto out_release_state; - } + ret = of_property_read_string(node, "backend-diskuuid", &diskuuid); + if (ret == 0) { + u64 off; + + ret = devpath_from_diskuuid(diskuuid, &state->backend_path); + if (ret) { + dev_err(&state->dev, "state failed find backend device for diskuuid='%s'\n", + diskuuid); + goto out_release_state; + } + ret = of_property_read_u64(node, "backend-offset", &off); + if (ret) { + dev_err(&state->dev, "'backend-offset' property undefined\n"); + goto out_release_state; + } + offset = off; + } else { + partition_node = of_parse_phandle(node, "backend", 0); + if (!partition_node) { + dev_err(&state->dev, "Cannot resolve \"backend\" phandle\n"); + ret = -EINVAL; + goto out_release_state; + } #ifdef __BAREBOX__ - ret = of_partition_ensure_probed(partition_node); - if (ret) - goto out_release_state; + ret = of_partition_ensure_probed(partition_node); + if (ret) + goto out_release_state; - ret = of_find_path_by_node(partition_node, &state->backend_path, 0); + ret = of_find_path_by_node(partition_node, &state->backend_path, 0); #else - ret = of_get_devicepath(partition_node, &state->backend_path, &offset, &size); + ret = of_get_devicepath(partition_node, &state->backend_path, &offset, &size); #endif - if (ret) { - if (ret != -EPROBE_DEFER) - dev_err(&state->dev, "state failed to parse path to backend: %s\n", - strerror(-ret)); - goto out_release_state; - } + if (ret) { + if (ret != -EPROBE_DEFER) + dev_err(&state->dev, "state failed to parse path to backend: %s\n", + strerror(-ret)); + goto out_release_state; + } - state->backend_reproducible_name = of_get_reproducible_name(partition_node); + state->backend_reproducible_name = of_get_reproducible_name(partition_node); + } ret = of_property_read_string(node, "backend-type", &backend_type); if (ret) { -- 2.30.2 _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de
Systemd mounts the EFI System Partition (ESP) to /boot or /efi. So look there for the state.dtb when the devicetree in sysfs/procfs is not available. This way barebox-state can be used on EFI systems without manually specifying the devicetree file. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de> --- src/barebox-state.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/barebox-state.c b/src/barebox-state.c index 334aed6f3d43..bf67340d4dc6 100644 --- a/src/barebox-state.c +++ b/src/barebox-state.c @@ -342,6 +342,30 @@ struct state *state_get(const char *name, const char *filename, bool readonly, b } } else { root = of_read_proc_devicetree(); + + /* No device-tree in procfs / sysfs, try dtb file in the ESP */ + if (-PTR_ERR(root) == ENOENT) { + const char *paths[] = { + /* default mount paths used by systemd */ + "/boot/EFI/BAREBOX/state.dtb", + "/efi/EFI/BAREBOX/state.dtb", + NULL + }; + void *fdt; + int i; + + for (i = 0; paths[i]; ++i) { + fdt = read_file(paths[i], NULL); + if (fdt) + break; + } + if (fdt) { + root = of_unflatten_dtb(fdt); + free(fdt); + } + else + root = ERR_PTR(-ENOENT); + } if (IS_ERR(root)) { pr_err("Unable to read devicetree. %s\n", strerror(-PTR_ERR(root))); -- 2.30.2 _______________________________________________ OSS-Tools mailing list OSS-Tools@pengutronix.de
On Mon, Jan 24, 2022 at 12:21:39PM +0100, Michael Olbrich wrote: > Hi, > > This adds support for backend-diskuuid / backend-offset. The corresponding > barebox patches can be found here: > https://lore.barebox.org/barebox/20220124100458.2924679-1-m.olbrich@pengutronix.de/ > > The mount point for the ESP is quite standardized. So let barebox-state > look there if nothing is found in sysfs/procfs. This way, barebox-state > works on EFI without manually specifying the dtb file. > > Michael > > Michael Olbrich (4): > state: support deep probe > state: implement helper to find device path from diskuuid > state: support backend-diskuuid / backend-offset > state: automatically find state.dtb in the ESP Thanks. Applied all of them to the 'next' branch, let me know if there are any new comments on the barebox part of patch 3/4 that need adapting to dt-utils. - Roland -- 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
On Sun, Feb 06, 2022 at 12:37:19AM +0100, Roland Hieber wrote: > On Mon, Jan 24, 2022 at 12:21:39PM +0100, Michael Olbrich wrote: > > This adds support for backend-diskuuid / backend-offset. The corresponding > > barebox patches can be found here: > > https://lore.barebox.org/barebox/20220124100458.2924679-1-m.olbrich@pengutronix.de/ > > > > The mount point for the ESP is quite standardized. So let barebox-state > > look there if nothing is found in sysfs/procfs. This way, barebox-state > > works on EFI without manually specifying the dtb file. > > > > Michael > > > > Michael Olbrich (4): > > state: support deep probe > > state: implement helper to find device path from diskuuid > > state: support backend-diskuuid / backend-offset > > state: automatically find state.dtb in the ESP > > Thanks. Applied all of them to the 'next' branch, let me know if there > are any new comments on the barebox part of patch 3/4 that need adapting > to dt-utils. The binding will be different. I'll come back with new patches when that is finalized. Michael -- 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