Re: [PATCH v3 1/4] libfdt: overlay_merge: Introduce fdt_overlay_merge()

Trilok Soni <[email protected]>
Newsgroups org.kernel.vger.devicetree-compiler
Message-ID <[email protected]>
On 5/19/2025 2:10 AM, Wasim Nazir wrote:
> From: Srivatsa Vaddagiri <[email protected]>
> 
> fdt_overlay_merge() merges two overlay blobs. It is largely expected to be
> used offline on a build machine to combine two or more overlay blobs into one.
> 
> It 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.
> 
> Introduce fdt_overlay_merge() which is identical to fdt_overlay_apply().
> Subsequent patches will introduce required changes to merge overlay blobs.
> 
> Signed-off-by: Srivatsa Vaddagiri <[email protected]>
> Signed-off-by: Wasim Nazir <[email protected]>

It will be nice to switch to oss.qualcomm.com, since we will soon mandating it. 

> ---
>  libfdt/fdt_overlay.c | 59 ++++++++++++++++++++++++++++++++++++++++++++
>  libfdt/libfdt.h      | 18 ++++++++++++++
>  2 files changed, 77 insertions(+)
> 
> diff --git a/libfdt/fdt_overlay.c b/libfdt/fdt_overlay.c
> index e6b9eb643958..8690ed55c8f6 100644
> --- a/libfdt/fdt_overlay.c
> +++ b/libfdt/fdt_overlay.c
> @@ -1098,3 +1098,62 @@ 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_RO_PROBE(fdt);
> +	FDT_RO_PROBE(fdto);
> +
> +	*fdto_nospace = 0;
> +
> +	ret = overlay_adjust_local_phandles(fdto, delta);
> +	if (ret) {
> +		if (ret == -FDT_ERR_NOSPACE)
> +			*fdto_nospace = 1;
> +		goto err;
> +	}
> +
> +	ret = overlay_update_local_references(fdto, delta);
> +	if (ret) {
> +		if (ret == -FDT_ERR_NOSPACE)
> +			*fdto_nospace = 1;
> +		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 b5e72001d115..664b141d5334 100644
> --- a/libfdt/libfdt.h
> +++ b/libfdt/libfdt.h
> @@ -2313,6 +2313,24 @@ int fdt_overlay_apply(void *fdt, void *fdto);
>  int fdt_overlay_target_offset(const void *fdt, const void *fdto,
>  			      int fragment_offset, char const **pathp);
> 
> +/**
> + * 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.49.0
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.