From: Maxime Ripard Date: Tue, 5 Jul 2016 08:26:45 +0000 (+0200) Subject: cmd: fdt: add fdt overlay application subcommand X-Git-Tag: v2016.09-rc2~19 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e6628ad7b99b285b25147366c68a7b956e362878;p=oweals%2Fu-boot.git cmd: fdt: add fdt overlay application subcommand The device tree overlays are a good way to deal with user-modifyable boards or boards with some kind of an expansion mechanism where we can easily plug new board in (like the BBB or the raspberry pi). However, so far, the usual mechanism to deal with it was to have in Linux some driver detecting the expansion boards plugged in and then request these overlays using the firmware interface. That works in most cases, but in some cases, you might want to have the overlays applied before the userspace comes in. Either because the new board requires some kind of an early initialization, or because your root filesystem is accessed through that expansion board. The easiest solution in such a case is to simply have the component before Linux applying that overlay, removing all these drawbacks. Reviewed-by: Stefan Agner Acked-by: Pantelis Antoniou Acked-by: Simon Glass Signed-off-by: Maxime Ripard --- diff --git a/cmd/fdt.c b/cmd/fdt.c index 0f5923e75a..58af7727ba 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -639,6 +639,27 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #endif } +#ifdef CONFIG_OF_LIBFDT_OVERLAY + /* apply an overlay */ + else if (strncmp(argv[1], "ap", 2) == 0) { + unsigned long addr; + struct fdt_header *blob; + + if (argc != 3) + return CMD_RET_USAGE; + + if (!working_fdt) + return CMD_RET_FAILURE; + + addr = simple_strtoul(argv[2], NULL, 16); + blob = map_sysmem(addr, 0); + if (!fdt_valid(&blob)) + return CMD_RET_FAILURE; + + if (fdt_overlay_apply(working_fdt, blob)) + return CMD_RET_FAILURE; + } +#endif /* resize the fdt */ else if (strncmp(argv[1], "re", 2) == 0) { fdt_shrink_to_minimum(working_fdt); @@ -1025,6 +1046,9 @@ static int fdt_print(const char *pathp, char *prop, int depth) #ifdef CONFIG_SYS_LONGHELP static char fdt_help_text[] = "addr [-c] [] - Set the [control] fdt location to \n" +#ifdef CONFIG_OF_LIBFDT_OVERLAY + "fdt apply - Apply overlay to the DT\n" +#endif #ifdef CONFIG_OF_BOARD_SETUP "fdt boardsetup - Do board-specific set up\n" #endif diff --git a/lib/libfdt/fdt_overlay.c b/lib/libfdt/fdt_overlay.c index c45e8b25fb..1dac8fd483 100644 --- a/lib/libfdt/fdt_overlay.c +++ b/lib/libfdt/fdt_overlay.c @@ -142,10 +142,10 @@ static int overlay_update_local_node_references(void *fdto, adj_val += delta; adj_val = cpu_to_fdt32(adj_val); - ret = fdt_setprop_inplace_namelen_by_index(fdto, tree_node, - name, strlen(name), - index, &adj_val, - sizeof(adj_val)); + ret = fdt_setprop_inplace_namelen_partial(fdto, tree_node, + name, strlen(name), + index, &adj_val, + sizeof(adj_val)); if (ret) return ret; } @@ -220,9 +220,9 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto, return fixup_off; phandle = cpu_to_fdt32(phandle); - return fdt_setprop_inplace_namelen_by_index(fdto, fixup_off, - name, name_len, index, - &phandle, sizeof(phandle)); + return fdt_setprop_inplace_namelen_partial(fdto, fixup_off, + name, name_len, index, + &phandle, sizeof(phandle)); }; static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,