u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Tom Rini <trini@konsulko.com>, Simon Glass <sjg@chromium.org>,
	Alexandru Gagniuc <mr.nuke.me@gmail.com>,
	Andre Przywara <andre.przywara@arm.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Joe Hershberger <joe.hershberger@ni.com>,
	Joel Stanley <joel@jms.id.au>, Marek Vasut <marex@denx.de>,
	Philippe Reynes <philippe.reynes@softathome.com>,
	Sean Anderson <sean.anderson@seco.com>
Subject: [PATCH 27/45] image: Allow loading a FIT config for a particular phase
Date: Sun, 25 Sep 2022 09:02:30 -0600	[thread overview]
Message-ID: <20220925150248.2524421-28-sjg@chromium.org> (raw)
In-Reply-To: <20220925150248.2524421-1-sjg@chromium.org>

Add support for filtering out FIT configs by phase. Rather than adding yet
another argument to this already overloaded function, use a composite
value, where the phase is only added in if needed.

Tests for this come in a little later, as part of the updated VPL test.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 boot/image-fit.c | 67 ++++++++++++++++++++++++++++++++++++++++++++----
 include/image.h  | 12 ++++++---
 2 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/boot/image-fit.c b/boot/image-fit.c
index 94074515258..c325116b82f 100644
--- a/boot/image-fit.c
+++ b/boot/image-fit.c
@@ -803,6 +803,40 @@ int fit_image_get_comp(const void *fit, int noffset, uint8_t *comp)
 	return 0;
 }
 
+/**
+ * fit_image_get_phase() - get the phase for a configuration node
+ * @fit: pointer to the FIT format image header
+ * @offset: configuration-node offset
+ * @phasep: returns the phase
+ *
+ * Finds the phase property in a given configuration node. If the property is
+ * found, its (string) value is translated to the numeric id which is returned
+ * to the caller.
+ *
+ * Returns: 0 on success, -ENOENT if missing, -EINVAL for invalid value
+ */
+int fit_image_get_phase(const void *fit, int offset, enum image_phase_t *phasep)
+{
+	const void *data;
+	int len, ret;
+
+	/* Get phase name from property data */
+	data = fdt_getprop(fit, offset, FIT_PHASE_PROP, &len);
+	if (!data) {
+		fit_get_debug(fit, offset, FIT_PHASE_PROP, len);
+		*phasep = 0;
+		return -ENOENT;
+	}
+
+	/* Translate phase name to id */
+	ret = genimg_get_phase_id(data);
+	if (ret < 0)
+		return ret;
+	*phasep = ret;
+
+	return 0;
+}
+
 static int fit_image_get_address(const void *fit, int noffset, char *name,
 			  ulong *load)
 {
@@ -1687,7 +1721,8 @@ int fit_check_format(const void *fit, ulong size)
 	return 0;
 }
 
-int fit_conf_find_compat(const void *fit, const void *fdt)
+int fit_conf_find_compat(const void *fit, const void *fdt,
+			 enum image_phase_t phase)
 {
 	int ndepth = 0;
 	int noffset, confs_noffset, images_noffset;
@@ -1726,6 +1761,27 @@ int fit_conf_find_compat(const void *fit, const void *fdt)
 		if (ndepth > 1)
 			continue;
 
+		if (phase) {
+			enum image_phase_t conf_phase;
+			int ret;
+
+			ret = fit_image_get_phase(fit, noffset, &conf_phase);
+			if (ret == -EINVAL) {
+				log_debug("Invalid phase in node '%s'\n",
+					  fdt_get_name(fit, noffset, NULL));
+				continue;
+			} else if (ret) {
+				log_debug("Missing phase in node '%s'\n",
+					  fdt_get_name(fit, noffset, NULL));
+				continue;
+			} else if (conf_phase != phase) {
+				log_debug("Phase %s mismatch in node '%s'\n",
+					  genimg_get_phase_name(conf_phase),
+					  fdt_get_name(fit, noffset, NULL));
+				continue;
+			}
+		}
+
 		/* If there's a compat property in the config node, use that. */
 		if (fdt_getprop(fit, noffset, "compatible", NULL)) {
 			fdt = fit;		  /* search in FIT image */
@@ -1954,9 +2010,10 @@ static const char *fit_get_image_type_property(int type)
 
 int fit_image_load(struct bootm_headers *images, ulong addr,
 		   const char **fit_unamep, const char **fit_uname_configp,
-		   int arch, int image_type, int bootstage_id,
+		   int arch, int ph_type, int bootstage_id,
 		   enum fit_load_op load_op, ulong *datap, ulong *lenp)
 {
+	int image_type = image_ph_type(ph_type);
 	int cfg_noffset, noffset;
 	const char *fit_uname;
 	const char *fit_uname_config;
@@ -2000,10 +2057,10 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
 		 */
 		bootstage_mark(bootstage_id + BOOTSTAGE_SUB_NO_UNIT_NAME);
 		if (IS_ENABLED(CONFIG_FIT_BEST_MATCH) && !fit_uname_config) {
-			cfg_noffset = fit_conf_find_compat(fit, gd_fdt_blob());
+			cfg_noffset = fit_conf_find_compat(fit, gd_fdt_blob(),
+						image_ph_phase(ph_type));
 		} else {
-			cfg_noffset = fit_conf_get_node(fit,
-							fit_uname_config);
+			cfg_noffset = fit_conf_get_node(fit, fit_uname_config);
 		}
 		if (cfg_noffset < 0) {
 			puts("Could not find configuration node\n");
diff --git a/include/image.h b/include/image.h
index 09821dce642..2aef364e836 100644
--- a/include/image.h
+++ b/include/image.h
@@ -691,9 +691,10 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr,
  *			name (e.g. "conf-1") or NULL to use the default. On
  *			exit points to the selected configuration name.
  * @param arch		Expected architecture (IH_ARCH_...)
- * @param image_type	Required image type (IH_TYPE_...). If this is
+ * @param image_ph_type	Required image type (IH_TYPE_...). If this is
  *			IH_TYPE_KERNEL then we allow IH_TYPE_KERNEL_NOLOAD
- *			also.
+ *			also. If a phase is required, this is included also,
+ *			see image_phase_and_type()
  * @param bootstage_id	ID of starting bootstage to use for progress updates.
  *			This will be added to the BOOTSTAGE_SUB values when
  *			calling bootstage_mark()
@@ -704,7 +705,7 @@ int boot_get_fdt_fit(struct bootm_headers *images, ulong addr,
  */
 int fit_image_load(struct bootm_headers *images, ulong addr,
 		   const char **fit_unamep, const char **fit_uname_configp,
-		   int arch, int image_type, int bootstage_id,
+		   int arch, int image_ph_type, int bootstage_id,
 		   enum fit_load_op load_op, ulong *datap, ulong *lenp);
 
 /**
@@ -1210,6 +1211,8 @@ int fit_check_format(const void *fit, ulong size);
  * fit_conf_find_compat
  * @fit: pointer to the FIT format image header
  * @fdt: pointer to the device tree to compare against
+ * @phase: U-Boot phase to look for. If not IH_PHASE_NONE then only
+ * configurations with the given phase will be considered
  *
  * fit_conf_find_compat() attempts to find the configuration whose fdt is the
  * most compatible with the passed in device tree.
@@ -1249,7 +1252,8 @@ int fit_check_format(const void *fit, ulong size);
  *     offset to the configuration to use if one was found
  *     -1 otherwise
  */
-int fit_conf_find_compat(const void *fit, const void *fdt);
+int fit_conf_find_compat(const void *fit, const void *fdt,
+			 enum image_phase_t phase);
 
 /**
  * fit_conf_get_node - get node offset for configuration of a given unit name
-- 
2.37.3.998.g577e59143f-goog


  parent reply	other threads:[~2022-09-25 15:09 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-25 15:02 [PATCH 00/45] vbe: Implement the full firmware flow Simon Glass
2022-09-25 15:02 ` [PATCH 01/45] Rename CONFIG_SYS_TEXT_BASE to CONFIG_TEXT_BASE Simon Glass
2022-09-25 15:02 ` [PATCH 02/45] disk: Drop debug messages in part_efi Simon Glass
2022-09-26  6:11   ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 03/45] bloblist: Drop debugging Simon Glass
2022-09-25 15:02 ` [PATCH 04/45] rsa: Avoid warning in padding_pss_verify() Simon Glass
2022-09-26  6:23   ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 05/45] spl: Use binman suffix allow symbols of any SPL etype Simon Glass
2022-09-25 15:02 ` [PATCH 06/45] spl: Split up the board_init_r() function Simon Glass
2022-09-25 15:02 ` [PATCH 07/45] spl: Refactor controls for console output Simon Glass
2022-09-29 15:16   ` Tom Rini
2022-09-25 15:02 ` [PATCH 08/45] spl: Add a separate silence option for SPL Simon Glass
2022-09-25 15:02 ` [PATCH 09/45] CI: Install pyelftools for builds Simon Glass
2022-09-26  6:29   ` Heinrich Schuchardt
2022-09-28 10:20     ` Simon Glass
2022-09-29 15:05       ` Tom Rini
2022-09-29 23:55         ` Simon Glass
2022-09-30 12:56           ` Tom Rini
2022-09-30 13:28             ` Simon Glass
2022-09-25 15:02 ` [PATCH 10/45] binman: Allow obtaining a symbol value Simon Glass
2022-09-25 15:02 ` [PATCH 11/45] binman: Split out looking up a symbol into a function Simon Glass
2022-09-25 15:02 ` [PATCH 12/45] binman: Handle writing ELF symbols in the Entry class Simon Glass
2022-09-25 15:02 ` [PATCH 13/45] binman: Support writing symbols into ELF files Simon Glass
2022-09-25 15:02 ` [PATCH 14/45] dm: blk: Add udevice functions Simon Glass
2022-09-26  0:17   ` AKASHI Takahiro
2022-09-28 10:20     ` Simon Glass
2022-09-29  0:51       ` AKASHI Takahiro
2022-09-29  2:35         ` Simon Glass
2022-09-30  1:54           ` AKASHI Takahiro
2022-09-25 15:02 ` [PATCH 15/45] dm: usb: Update the test to cover reading and writing Simon Glass
2022-09-25 15:02 ` [PATCH 16/45] dm: blk: mmc: Tidy up some Makefile rules for SPL Simon Glass
2022-09-25 15:02 ` [PATCH 17/45] dm: mmc: Allow sandbox emulator to build without writes Simon Glass
2022-09-25 15:02 ` [PATCH 18/45] sandbox: Drop message about writing sandbox state Simon Glass
2022-09-26  6:31   ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 19/45] sandbox: Generalise SPL booting Simon Glass
2022-09-25 15:02 ` [PATCH 20/45] sandbox: Add a way to specify the sandbox executable Simon Glass
2022-09-26  6:49   ` Heinrich Schuchardt
2022-11-07 23:35     ` Simon Glass
2022-09-25 15:02 ` [PATCH 21/45] bootstd: Add a way to set up a bootflow Simon Glass
2022-09-25 15:02 ` [PATCH 22/45] image: Move comment for fit_conf_find_compat() Simon Glass
2022-09-26  6:54   ` Heinrich Schuchardt
2022-09-25 15:02 ` [PATCH 23/45] test: Report skippped tests Simon Glass
2022-09-25 15:02 ` [PATCH 24/45] test: Update tests to use the skip feature Simon Glass
2022-09-25 15:02 ` [PATCH 25/45] test: Support tests which can only be run manually Simon Glass
2022-09-26  6:56   ` Heinrich Schuchardt
2022-09-28 10:20     ` Simon Glass
2022-09-25 15:02 ` [PATCH 26/45] image: Add the concept of a phase to FIT Simon Glass
2022-09-25 15:02 ` Simon Glass [this message]
2022-09-25 15:02 ` [PATCH 28/45] image: Correct strncpy() warning with image_set_name() Simon Glass
2022-09-25 15:02 ` [PATCH 29/45] vbe: Rename vbe_fixup to vbe_request Simon Glass
2022-09-25 15:02 ` [PATCH 30/45] vbe: Use a warning for a failed requests Simon Glass
2022-09-25 15:02 ` [PATCH 31/45] spl: Allow multiple loaders of the same type Simon Glass
2022-09-30 16:28   ` Tom Rini
2022-09-30 16:37     ` Simon Glass
2022-09-30 16:39       ` Tom Rini
2022-09-30 16:45         ` Simon Glass
2022-09-30 16:50           ` Tom Rini
2022-09-30 16:55             ` Simon Glass
2022-09-25 15:02 ` [PATCH 32/45] sandbox: Support obtaining the next phase from an image Simon Glass
2022-09-25 15:02 ` [PATCH 33/45] vbe: Support selecting operations by SPL phase Simon Glass
2022-09-25 15:02 ` [PATCH 34/45] vbe: Support reading the next SPL phase via VBE Simon Glass
2022-09-25 15:02 ` [PATCH 35/45] vbe: Move OS implementation into a separate file Simon Glass
2022-09-25 15:02 ` [PATCH 36/45] vbe: Drop the U-Boot prefix from the version Simon Glass
2022-09-25 15:02 ` [PATCH 37/45] vbe: Add Kconfig options for VPL Simon Glass
2022-09-25 15:02 ` [PATCH 38/45] vbe: Add info about the VBE device to the fwupd node Simon Glass
2022-09-25 15:02 ` [PATCH 39/45] sandbox: Add a binman image for VPL Simon Glass
2022-09-25 15:02 ` [PATCH 40/45] vbe: Correct pylint warnings in test_vbe Simon Glass
2022-09-25 15:02 ` [PATCH 41/45] vbe: Use a manual test Simon Glass
2022-09-25 15:02 ` [PATCH 42/45] vbe: Record which phases loaded using VBE Simon Glass
2022-09-25 15:02 ` [PATCH 43/45] vbe: Add docs and a test for the VBE command Simon Glass
2022-09-25 15:02 ` [PATCH 44/45] vbe: Add a subcommand to show the VBE state Simon Glass
2022-09-25 15:02 ` [PATCH 45/45] vbe: Add a test for the VBE flow into U-Boot proper Simon Glass

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=20220925150248.2524421-28-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=andre.przywara@arm.com \
    --cc=jan.kiszka@siemens.com \
    --cc=joe.hershberger@ni.com \
    --cc=joel@jms.id.au \
    --cc=marex@denx.de \
    --cc=mr.nuke.me@gmail.com \
    --cc=philippe.reynes@softathome.com \
    --cc=sean.anderson@seco.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --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;
as well as URLs for NNTP newsgroup(s).