devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Trilok Soni <trilok.soni@oss.qualcomm.com>
To: Wasim Nazir <quic_wasimn@quicinc.com>,
	devicetree-compiler@vger.kernel.org
Cc: kernel@quicinc.com, kernel@oss.qualcomm.com,
	Srivatsa Vaddagiri <vatsa@codeaurora.org>
Subject: Re: [PATCH v3 1/4] libfdt: overlay_merge: Introduce fdt_overlay_merge()
Date: Mon, 19 May 2025 10:17:41 -0700	[thread overview]
Message-ID: <4f366bbc-849b-4e8d-8ce2-c8013b8cedd5@oss.qualcomm.com> (raw)
In-Reply-To: <20250519091043.621316-2-quic_wasimn@quicinc.com>

On 5/19/2025 2:10 AM, Wasim Nazir wrote:
> From: Srivatsa Vaddagiri <vatsa@codeaurora.org>
> 
> 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 <vatsa@codeaurora.org>
> Signed-off-by: Wasim Nazir <quic_wasimn@quicinc.com>

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
> 


  reply	other threads:[~2025-05-19 17:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-19  9:10 [PATCH v3 0/4] Introduce fdt_overlay_merge() to allow merge of overlay blobs Wasim Nazir
2025-05-19  9:10 ` [PATCH v3 1/4] libfdt: overlay_merge: Introduce fdt_overlay_merge() Wasim Nazir
2025-05-19 17:17   ` Trilok Soni [this message]
2025-05-30 14:38     ` Wasim Nazir
2025-05-21  4:23   ` David Gibson
2025-05-30 12:28     ` Wasim Nazir
2025-06-03 11:09       ` David Gibson
2025-06-27 10:31         ` Wasim Nazir
2025-06-28 11:02           ` David Gibson
2025-05-19  9:10 ` [PATCH v3 2/4] libfdt: overlay_merge: Rename & copy overlay fragments and their properties Wasim Nazir
2025-05-19  9:10 ` [PATCH v3 3/4] libfdt: overlay_merge: Update phandles, symbols, fixups & local_fixups Wasim Nazir
2025-05-19  9:10 ` [PATCH v3 4/4] fdtoverlaymerge: A tool that merges overlays Wasim Nazir
2025-05-23 13:44   ` Simon Glass
2025-05-30 14:55     ` Wasim Nazir
2025-05-19 17:15 ` [PATCH v3 0/4] Introduce fdt_overlay_merge() to allow merge of overlay blobs Trilok Soni
2025-05-30 14:42   ` Wasim Nazir
2025-05-21  4:20 ` David Gibson
2025-05-30 14:36   ` Wasim Nazir
2025-06-03 11:05     ` David Gibson
2025-06-27 10:15       ` Wasim Nazir
2025-06-28 10:55         ` David Gibson
2025-09-02 10:35           ` Wasim Nazir
2025-09-02 12:49             ` Konrad Dybcio
2025-09-02 12:51               ` Konrad Dybcio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4f366bbc-849b-4e8d-8ce2-c8013b8cedd5@oss.qualcomm.com \
    --to=trilok.soni@oss.qualcomm.com \
    --cc=devicetree-compiler@vger.kernel.org \
    --cc=kernel@oss.qualcomm.com \
    --cc=kernel@quicinc.com \
    --cc=quic_wasimn@quicinc.com \
    --cc=vatsa@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).