summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2023-03-07 13:48:29 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2023-03-15 09:17:48 +0100
commita49a52dab6f99dec1557c530dacb392cb945bc12 (patch)
tree355c42dcf99c943b4c8eb7009248475c1ff9e25a /commands
parent2366fa3a808e296de826feb8b890aff5652114db (diff)
downloadbarebox-a49a52dab6f99dec1557c530dacb392cb945bc12.tar.gz
barebox-a49a52dab6f99dec1557c530dacb392cb945bc12.tar.xz
of_overlay: Add option to apply overlay to live tree
The of_overlay command currently only supports applying overlays to the Linux device tree. Add an option to apply an overlay to the live tree. Using this option will apply the overlay and also triggers rescanning the device tree in case new devices have been added. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/of_overlay.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/commands/of_overlay.c b/commands/of_overlay.c
index b3660b4bf1..37d29b88e5 100644
--- a/commands/of_overlay.c
+++ b/commands/of_overlay.c
@@ -17,10 +17,25 @@ static int do_of_overlay(int argc, char *argv[])
struct fdt_header *fdt;
struct device_node *overlay;
size_t size;
+ bool live_tree = false;
+ int opt;
- if (argc != 2)
+ while ((opt = getopt(argc, argv, "l")) > 0) {
+ switch (opt) {
+ case 'l':
+ live_tree = true;
+ break;
+ }
+ }
+
+ if (argc != optind + 1)
return COMMAND_ERROR_USAGE;
+ if (live_tree && !IS_ENABLED(CONFIG_OF_OVERLAY_LIVE)) {
+ printf("Support for live tree overlays is disabled. Enable CONFIG_OF_OVERLAY_LIVE\n");
+ return 1;
+ }
+
fdt = read_file(argv[optind], &size);
if (!fdt) {
printf("cannot read %s\n", argv[optind]);
@@ -32,7 +47,14 @@ static int do_of_overlay(int argc, char *argv[])
if (IS_ERR(overlay))
return PTR_ERR(overlay);
- ret = of_register_overlay(overlay);
+ if (live_tree) {
+ ret = of_overlay_apply_tree(of_get_root_node(), overlay);
+ if (!ret)
+ ret = of_probe();
+ } else {
+ ret = of_register_overlay(overlay);
+ }
+
if (ret) {
printf("cannot apply oftree overlay: %s\n", strerror(-ret));
goto err;
@@ -45,9 +67,22 @@ err:
return ret;
}
+BAREBOX_CMD_HELP_START(of_overlay)
+BAREBOX_CMD_HELP_TEXT("Register a device tree overlay file (dtbo) with barebox.")
+BAREBOX_CMD_HELP_TEXT("By default the overlay is registered as a fixup and the")
+BAREBOX_CMD_HELP_TEXT("overlay will then be applied to the Linux device tree.")
+BAREBOX_CMD_HELP_TEXT("With -l given the overlay is applied to the barebox live")
+BAREBOX_CMD_HELP_TEXT("tree instead. This involves probing new devices added in")
+BAREBOX_CMD_HELP_TEXT("the overlay file.")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-l", "apply to barebox live tree")
+BAREBOX_CMD_HELP_END
+
BAREBOX_CMD_START(of_overlay)
.cmd = do_of_overlay,
- BAREBOX_CMD_DESC("register device tree overlay as fixup")
- BAREBOX_CMD_OPTS("FILE")
+ BAREBOX_CMD_DESC("register device tree overlay")
+ BAREBOX_CMD_OPTS("[-l] FILE")
BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_HELP(cmd_of_overlay_help)
BAREBOX_CMD_END