]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
boot: add support for fdt_fixup command in environment
authorMatthias Schiffer <matthias.schiffer@ew.tq-group.com>
Mon, 11 Dec 2023 11:03:17 +0000 (12:03 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 21 Dec 2023 16:59:49 +0000 (11:59 -0500)
The "fdt" command is convenient for making small changes to the OS FDT,
especially during development. This is easy when the kernel and FDT are
loaded separately, but can be cumbersome for FIT images, requiring to
unpack the image, manually apply overlays, etc.

Add an option to execute a command "fdt_fixup" from the environment at
the beginning of image_setup_libfdt() (after overlays are applied, and
before the other fixups).

Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
boot/Kconfig
boot/image-fdt.c

index 987ca73141174a9cfe4c51f82728c5435e5ce5fb..9f5b8a0cb2c8b686ddd7d42951359c396db052db 100644 (file)
@@ -1514,6 +1514,15 @@ if OF_LIBFDT
 
 menu "Devicetree fixup"
 
+config OF_ENV_SETUP
+       bool "Run a command from environment to set up device tree before boot"
+       depends on CMD_FDT
+       help
+         This causes U-Boot to run a command from the environment variable
+         fdt_fixup before booting into the operating system, which can use the
+         fdt command to modify the device tree. The device tree is then passed
+         to the OS.
+
 config OF_BOARD_SETUP
        bool "Set up board-specific details in device tree before boot"
        help
index 2b166c0ff94949c9a931e94a69b6fec33e721e4d..75bdd55f326ea7b6c6dd2812dd79906a8c78830c 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <common.h>
+#include <command.h>
 #include <fdt_support.h>
 #include <fdtdec.h>
 #include <env.h>
@@ -576,9 +577,22 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob,
 {
        ulong *initrd_start = &images->initrd_start;
        ulong *initrd_end = &images->initrd_end;
-       int ret = -EPERM;
-       int fdt_ret;
-       int of_size;
+       int ret, fdt_ret, of_size;
+
+       if (IS_ENABLED(CONFIG_OF_ENV_SETUP)) {
+               const char *fdt_fixup;
+
+               fdt_fixup = env_get("fdt_fixup");
+               if (fdt_fixup) {
+                       set_working_fdt_addr(map_to_sysmem(blob));
+                       ret = run_command_list(fdt_fixup, -1, 0);
+                       if (ret)
+                               printf("WARNING: fdt_fixup command returned %d\n",
+                                      ret);
+               }
+       }
+
+       ret = -EPERM;
 
        if (fdt_root(blob) < 0) {
                printf("ERROR: root node setup failed\n");