mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 02/23] bbu: make it possible to check multiple of-compatibles
Date: Mon, 13 Mar 2023 14:41:41 +0100	[thread overview]
Message-ID: <20230228-v2023-02-0-topic-flexspi-v2-2-3d33126d2434@pengutronix.de> (raw)
In-Reply-To: <20230228-v2023-02-0-topic-flexspi-v2-0-3d33126d2434@pengutronix.de>

It is possible that one barebox can rule multiple platforms e.g.
multiple platform revision each has a dedicated device tree and of
compatible. While it is possible to add multiple of-compatibles via
IMD_USED_OF() (see: zii-imx8mq-dev) we didn't allowed it to flash it
without 'force'. Fix this by check all possible IMD_TYPE_OF_COMPATIBLE
image metadata types.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 common/bbu.c | 42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/common/bbu.c b/common/bbu.c
index 3ec17216cb..a9b3fef7a0 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -154,36 +154,44 @@ struct bbu_handler *bbu_find_handler_by_device(const char *devicepath)
 	return NULL;
 }
 
-static int bbu_check_of_compat(struct bbu_data *data)
+static int bbu_check_of_compat(struct bbu_data *data, unsigned short of_compat_nr)
 {
+	const struct imd_header *imd = data->imd_data;
+	const struct imd_header *of_compat;
 	struct device_node *root_node;
 	const char *machine, *str;
 	int ret;
-	const struct imd_header *of_compat;
 
 	if (!IS_ENABLED(CONFIG_OFDEVICE) || !IS_ENABLED(CONFIG_IMD))
 		return 0;
 
-	of_compat = imd_find_type(data->imd_data, IMD_TYPE_OF_COMPATIBLE);
-	if (!of_compat)
-		return 0;
-
 	root_node = of_get_root_node();
 	if (!root_node)
 		return 0;
 
-	str = imd_string_data(of_compat, 0);
-
-	if (of_machine_is_compatible(str)) {
-		pr_info("Devicetree compatible \"%s\" matches current machine\n", str);
-		return 0;
-	}
-
 	ret = of_property_read_string(root_node, "compatible", &machine);
 	if (ret)
 		return 0;
 
-	if (!bbu_force(data, "machine is incompatible with \"%s\", have \"%s\"\n", str, machine))
+	for (; of_compat_nr; of_compat_nr--) {
+		of_compat = imd_find_type(imd, IMD_TYPE_OF_COMPATIBLE);
+		if (!of_compat)
+			return 0;
+
+		str = imd_string_data(of_compat, 0);
+
+		if (of_machine_is_compatible(str)) {
+			pr_info("Devicetree compatible \"%s\" matches current machine\n", str);
+			return 0;
+		}
+
+		pr_debug("machine is incompatible with \"%s\", have \"%s\"\n",
+			 str, machine);
+
+		imd = of_compat;
+	}
+
+	if (!bbu_force(data, "incompatible machine \"%s\"\n", machine))
 		return -EINVAL;
 
 	return 0;
@@ -191,6 +199,7 @@ static int bbu_check_of_compat(struct bbu_data *data)
 
 static int bbu_check_metadata(struct bbu_data *data)
 {
+	unsigned short imd_of_compat_nr = 0;
 	const struct imd_header *imd;
 	int ret;
 	char *str;
@@ -211,6 +220,9 @@ static int bbu_check_metadata(struct bbu_data *data)
 	imd_for_each(data->imd_data, imd) {
 		uint32_t type = imd_read_type(imd);
 
+		if (imd_read_type(imd) == IMD_TYPE_OF_COMPATIBLE)
+			imd_of_compat_nr++;
+
 		if (!imd_is_string(type))
 			continue;
 
@@ -220,7 +232,7 @@ static int bbu_check_metadata(struct bbu_data *data)
 		free(str);
 	}
 
-	ret = bbu_check_of_compat(data);
+	ret = bbu_check_of_compat(data, imd_of_compat_nr);
 	if (ret)
 		return ret;
 

-- 
2.30.2




  parent reply	other threads:[~2023-03-13 13:43 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-13 13:41 [PATCH v2 00/23] FlexSPI image/boot/update support Marco Felsch
2023-03-13 13:41 ` [PATCH v2 01/23] spi: remove flash_platform_data support Marco Felsch
2023-03-13 13:41 ` Marco Felsch [this message]
2023-04-04  7:04   ` [PATCH v2 02/23] bbu: make it possible to check multiple of-compatibles Sascha Hauer
2023-04-04  8:01     ` Marco Felsch
2023-04-04  8:49       ` Sascha Hauer
2023-04-04  9:05         ` Marco Felsch
2023-03-13 13:41 ` [PATCH v2 03/23] ARM: i.MX8MM: add missing IMD_USED_OF image metadata entry Marco Felsch
2023-03-13 13:41 ` [PATCH v2 04/23] ARM: i.MX8MN: add missing IMD_USED_OF image metadata entries Marco Felsch
2023-03-13 13:41 ` [PATCH v2 05/23] mci: imx-esdhc-pbl: fix number of read blocks Marco Felsch
2023-03-13 13:41 ` [PATCH v2 06/23] mci: imx-esdhc-pbl: refactor the esdhc_load_image function Marco Felsch
2023-03-13 13:41 ` [PATCH v2 07/23] mci: imx-esdhc-pbl: move imx_load_image into common xload code Marco Felsch
2023-03-13 13:41 ` [PATCH v2 08/23] ARM: i.MX8M: Add QSPI image load support Marco Felsch
2023-03-13 13:41 ` [PATCH v2 09/23] ARM: i.MX bootsource: set QSPI instance Marco Felsch
2023-03-13 13:41 ` [PATCH v2 10/23] ARM: i.MX8MM bootsource: fix QSPI boot source detection Marco Felsch
2023-03-13 13:41 ` [PATCH v2 11/23] ARM: i.MX8M: Add QSPI boot support Marco Felsch
2023-03-13 13:41 ` [PATCH v2 12/23] scripts: imx-image: convert flag variables into bool Marco Felsch
2023-03-13 13:41 ` [PATCH v2 13/23] scripts: imx-image: header_v2: factor out offset parameter Marco Felsch
2023-03-13 13:41 ` [PATCH v2 14/23] scripts: imx-image: header_v2: add header_len parameter Marco Felsch
2023-03-13 13:41 ` [PATCH v2 15/23] scripts: imx-image: add FlexSPI image support Marco Felsch
2023-03-13 13:41 ` [PATCH v2 16/23] filetype: add NXP FlexSPI filetype Marco Felsch
2023-03-13 13:41 ` [PATCH v2 17/23] ARM: i.MX: bbu: rename IMX_INTERNAL_FLAG_ERASE to IMX_BBU_FLAG_ERASE Marco Felsch
2023-03-13 13:41 ` [PATCH v2 18/23] ARM: i.MX: bbu: add filetype offset Marco Felsch
2023-03-13 13:41 ` [PATCH v2 19/23] ARM: i.MX: bbu: add FlexSPI update handler Marco Felsch
2023-03-13 13:41 ` [PATCH v2 20/23] ARM: i.MX8M: enable FlexSPI image support Marco Felsch
2023-03-13 13:42 ` [PATCH v2 21/23] ARM: i.MX8M: add qspi barebox and barebox-environment partitions Marco Felsch
2023-03-13 13:42 ` [PATCH v2 22/23] ARM: i.MX8M: add QSPI update handler Marco Felsch
2023-03-13 13:42 ` [PATCH v2 23/23] Documentation: i.MX8M: add EVK QSPI NOR barebox installation documentation Marco Felsch
2023-03-17 11:11 ` [PATCH v2 00/23] FlexSPI image/boot/update support Sascha Hauer

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=20230228-v2023-02-0-topic-flexspi-v2-2-3d33126d2434@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=barebox@lists.infradead.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