From: Srivatsa Vaddagiri <vatsa@xxxxxxxxxxxxxx> fdt_overlay_merge() merges two overlay blobs. This is largely expected to be used offline on a build machine to combine two or more overlay blobs into one. This is intended to help maintain device-tree overlay code in multiple source repositories, but merge their binary forms (overlay blobs) into one so that bootloader's task of searching for all relevant overlay blobs is simplified. This patch introduces fdt_overlay_merge() which is exactly identical to fdt_overlay_apply(). Subsequent patches will introduce required changes to merge overlay blobs. Signed-off-by: Srivatsa Vaddagiri <vatsa@xxxxxxxxxxxxxx> --- libfdt/fdt_overlay.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ libfdt/libfdt.h | 18 ++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/libfdt/fdt_overlay.c b/libfdt/fdt_overlay.c index b310e49..65d7a29 100644 --- a/libfdt/fdt_overlay.c +++ b/libfdt/fdt_overlay.c @@ -879,3 +879,56 @@ err: return ret; } + +int fdt_overlay_merge(void *fdt, void *fdto, int *fdto_nospace) +{ + uint32_t delta = fdt_get_max_phandle(fdt); + int ret; + + FDT_CHECK_HEADER(fdt); + FDT_CHECK_HEADER(fdto); + + *fdto_nospace = 0; + + ret = overlay_adjust_local_phandles(fdto, delta); + if (ret) + goto err; + + ret = overlay_update_local_references(fdto, delta); + if (ret) + goto err; + + ret = overlay_fixup_phandles(fdt, fdto); + if (ret) + goto err; + + ret = overlay_merge(fdt, fdto); + if (ret) + goto err; + + ret = overlay_symbol_update(fdt, fdto); + if (ret) + goto err; + + /* + * The overlay has been damaged, erase its magic. + */ + fdt_set_magic(fdto, ~0); + + return 0; + +err: + /* + * The overlay might have been damaged, erase its magic. + */ + fdt_set_magic(fdto, ~0); + + /* + * The base device tree might have been damaged, erase its + * magic. + */ + if (!*fdto_nospace) + fdt_set_magic(fdt, ~0); + + return ret; +} diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h index 544d3ef..950388e 100644 --- a/libfdt/libfdt.h +++ b/libfdt/libfdt.h @@ -2067,6 +2067,24 @@ int fdt_del_node(void *fdt, int nodeoffset); */ int fdt_overlay_apply(void *fdt, void *fdto); +/** + * fdt_overlay_merge - Merge two overlays into one + * @fdt: pointer to the first device tree overlay blob + * @fdto: pointer to the second device tree overlay blob + * @fdto_nospace: indicates if FDT_ERR_NOSPACE error code applies to @fdto + * + * fdt_overlay_merge() will merge second overlay blob into first overlay blob. + * + * Expect the first device tree to be modified, even if the function + * returns an error. + * + * returns: + * 0, on success + * -FDT_ERR_NOSPACE, there's not enough space in first device tree blob + * -FDT_ERR_BADVALUE + */ +int fdt_overlay_merge(void *fdt, void *fdto, int *fdto_nospace); + /**********************************************************************/ /* Debugging / informational functions */ /**********************************************************************/ -- 2.7.4