diff options
author | Michael Olbrich <m.olbrich@pengutronix.de> | 2022-05-11 10:21:25 +0200 |
---|---|---|
committer | Roland Hieber <rhi@pengutronix.de> | 2023-07-31 23:24:26 +0200 |
commit | bfa8e8eab1352ac1462662343773176eb1400f92 (patch) | |
tree | 54aa6abfa680eb7e2ff6d0fd9924b78107fc0136 /src/barebox-state.c | |
parent | f80d96b15978f6c34f8db9ed22612f7801d7d87b (diff) | |
download | dt-utils-bfa8e8eab1352ac1462662343773176eb1400f92.tar.gz dt-utils-bfa8e8eab1352ac1462662343773176eb1400f92.tar.xz |
state: automatically find state.dtb in the ESP
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>
Link: https://lore.pengutronix.de/oss-tools/20220511082125.4187531-4-m.olbrich@pengutronix.de
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Diffstat (limited to 'src/barebox-state.c')
-rw-r--r-- | src/barebox-state.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/barebox-state.c b/src/barebox-state.c index 334aed6..c5acd1f 100644 --- a/src/barebox-state.c +++ b/src/barebox-state.c @@ -342,6 +342,31 @@ 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", + "/boot/efi/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))); |