From: David Lechner <dlechner@baylibre.com>
To: Carlo Caione <ccaione@baylibre.com>, u-boot@lists.u-boot-project.org
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
E Shattow <e@freeshell.de>, Ahmad Fatoum <a.fatoum@barebox.org>,
Julien Masson <jmasson@baylibre.com>,
Vitor Sato Eschholz <vsatoes@baylibre.com>,
Randolph Sapp <rs@ti.com>, Anton Ivanov <anton@binarly.io>,
Daniel Golle <daniel@makrotopia.org>,
Aristo Chen <aristo.chen@canonical.com>,
Jonas Karlman <jonas@kwiboo.se>,
Jerome Forissier <jerome.forissier@arm.com>,
Johan Jonker <jbx6244@gmail.com>,
James Hilliard <james.hilliard1@gmail.com>,
Alexey Charkov <alchark@flipper.net>,
Vincent Jardin <vjardin@free.fr>,
Peter Robinson <pbrobinson@gmail.com>
Subject: Re: [PATCH v3 4/5] cmd: fdt: add 'fdt fit' to prepare a devicetree for other boot commands
Date: Mon, 9 Nov 2026 11:27:53 -0600 [thread overview]
Message-ID: <875b8e1f-a929-4c83-9846-2147be2cfb30@baylibre.com> (raw)
In-Reply-To: <20261026-ccaione-upstream-fdt-fit-v3-4-6c5d86c3007f@baylibre.com>
On 10/26/26 7:18 AM, Carlo Caione wrote:
> A board may keep its devicetree and overlays in a FIT while booting
> a kernel or EFI application from elsewhere. Boot scripts need a way
> to verify and assemble that devicetree without asking bootm to boot
> the FIT.
>
...
> +/*
> + * fdt fit <addr>[#<conf>] <dest> [<length>]
> + *
> + * Load the devicetree of a FIT configuration, with its overlays applied, and
> + * copy it to <dest>. Images are always verified, so the configuration must
> + * also satisfy any required signature in the control devicetree. Unlike bootm,
> + * image load addresses are ignored and configurations cannot be chained.
> + */
> +static int fdt_fit(int argc, char *const argv[])
> +{
> + struct bootm_headers images = { .verify = 1 };
> + const char *conf = NULL;
> + ulong addr, dest, data, len;
> + bool owned;
> + void *fdt;
> + int ret;
> +
> + if (argc < 2 || argc > 3)
> + return CMD_RET_USAGE;
> +
> + if (!fit_parse_conf(argv[0], image_load_addr, &addr, &conf))
> + addr = hextoul(argv[0], NULL);
> + dest = hextoul(argv[1], NULL);
> +
> + /* Only a single configuration authenticates the whole combination */
> + if (conf && strchr(conf, '#')) {
> + puts("Chained configurations are not supported\n");
> + return CMD_RET_FAILURE;
> + }
> +
> + if (boot_get_fdt_fit(&images, addr, NULL, &conf, IH_ARCH_DEFAULT,
> + FIT_LOAD_PREPARE, &data, &len, &owned) < 0)
> + return CMD_RET_FAILURE;
> +
> + fdt = map_sysmem(data, len);
> + ret = CMD_RET_FAILURE;
> + if (fdt_check_full(fdt, len)) {
> + puts("Invalid FDT in FIT\n");
> + goto out;
> + }
> +
> + len = fdt_totalsize(fdt);
> + if (argc > 2) {
> + ulong newlen = hextoul(argv[2], NULL);
> +
> + if (newlen < len) {
> + printf("New length 0x%lX < existing length 0x%lX, aborting.\n",
> + newlen, len);
> + goto out;
> + }
> + len = newlen;
> + }
> +
> + if (CONFIG_IS_ENABLED(LMB) && lmb_read_check(dest, len)) {
> + puts("ERROR: trying to overwrite reserved memory...\n");
> + goto out;
> + }
> +
> + ret = fdt_open_into(fdt, map_sysmem(dest, len), len);
nit: its a bit awkward to use ret for both CMD_RET_ and other error type.
Would suggest to replace this one with e.g. err.
> + if (ret) {
> + printf("libfdt fdt_open_into(): %s\n", fdt_strerror(ret));
> + ret = CMD_RET_FAILURE;
Then we don't have to rember to restore the value that was already in ret
here.
> + goto out;
> + }
> + ret = CMD_RET_SUCCESS;
> +
> +out:
> + if (owned)
> + free(fdt);
> +
> + return ret;
> +}
> +
next prev parent reply other threads:[~2026-11-09 17:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 12:18 [PATCH v3 0/5] Prepare devicetrees from FIT configurations with fdt fit Carlo Caione
2026-10-26 12:18 ` [PATCH v3 1/5] boot: fit: tell callers when a devicetree buffer must be freed Carlo Caione
2026-11-09 17:27 ` David Lechner
2026-10-26 12:18 ` [PATCH v3 2/5] boot: fit: reject configurations with missing or invalid overlays Carlo Caione
2026-10-26 12:18 ` [PATCH v3 3/5] boot: fit: let callers choose where to place the devicetree Carlo Caione
2026-10-26 12:18 ` [PATCH v3 4/5] cmd: fdt: add 'fdt fit' to prepare a devicetree for other boot commands Carlo Caione
2026-11-09 17:27 ` David Lechner [this message]
2026-10-26 12:18 ` [PATCH v3 5/5] test: py: cover fdt fit preparation and failure handling Carlo Caione
2026-11-09 17:28 ` David Lechner
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=875b8e1f-a929-4c83-9846-2147be2cfb30@baylibre.com \
--to=dlechner@baylibre.com \
--cc=a.fatoum@barebox.org \
--cc=alchark@flipper.net \
--cc=anton@binarly.io \
--cc=aristo.chen@canonical.com \
--cc=ccaione@baylibre.com \
--cc=daniel@makrotopia.org \
--cc=e@freeshell.de \
--cc=ilias.apalodimas@linaro.org \
--cc=james.hilliard1@gmail.com \
--cc=jbx6244@gmail.com \
--cc=jerome.forissier@arm.com \
--cc=jmasson@baylibre.com \
--cc=jonas@kwiboo.se \
--cc=pbrobinson@gmail.com \
--cc=rs@ti.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
--cc=vjardin@free.fr \
--cc=vsatoes@baylibre.com \
--cc=xypron.glpk@gmx.de \
/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