mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Holger Assmann <h.assmann@pengutronix.de>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v3 4/4] ARM: i.MX8MP: tqma8mpxl: fix bbu registration for other boards using SoM
Date: Mon,  2 Dec 2024 12:24:37 +0100	[thread overview]
Message-ID: <20241202112437.535013-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241202112437.535013-1-a.fatoum@pengutronix.de>

The board code matches against the SoM compatible and there are two
upstream device trees making use of the SoM.

Both device trees reorder the device tree aliases to be different from
the SoC ordering specified in dts/src/arm64/freescale/imx8mp.dtsi.

This is partially addressed by the /chosen/barebox,bootsource-mmcX
properties in arch/arm/dts/imx8mp.dtsi.

What's not addressed is the name of the eMMC device in /dev: This is
currently hardcoded to /dev/mmc0, but any other board that includes the
same SoM and doesn't override the SoCs aliases will have the eMMC
instead at /dev/mmc2, breaking the barebox update handler.

One way to workaround this would be reverting commit 9f3f4af8cf56
("ARM: i.MX8MP: tqma8mpxl: match board code against SoM compatible") and
expect that other boards take care of registering the bbu handler themselves.

What is implemented here is an alternative that could also be useful to
other boards: Given that /chosen/environment-sd/device-path already points
at the SD and /chosen/environment-mmc/device-path already points at the eMMC,
let's just get the alias for the nodes they point at and use these to
dynamically derive the device's name in /dev.

Doing it this way requires only that there are any aliases for the MMCs at all
(which should be the case as the upstream SoC dtsi has them) and doesn't
suffer from probe order issues.

Fixes: 9f3f4af8cf56 ("ARM: i.MX8MP: tqma8mpxl: match board code against SoM compatible")
Reported-by: Holger Assmann <h.assmann@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v2 -> v3:
  - no change
v1 -> v2:
  - restore of_device_enable_path instead of wrong of_device_enable_by_alias
    on the MMC alias
---
 arch/arm/boards/tqma8mpxl/board.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boards/tqma8mpxl/board.c b/arch/arm/boards/tqma8mpxl/board.c
index 8b67acb91c55..459e180a570c 100644
--- a/arch/arm/boards/tqma8mpxl/board.c
+++ b/arch/arm/boards/tqma8mpxl/board.c
@@ -14,22 +14,31 @@
 #include <mach/imx/iomux-mx8mp.h>
 #include <gpio.h>
 #include <envfs.h>
+#include <string.h>
 
 static int tqma8mpxl_probe(struct device *dev)
 {
+	const char *emmc, *sd;
 	int emmc_bbu_flag = 0;
 	int sd_bbu_flag = 0;
 
-	if (bootsource_get() == BOOTSOURCE_MMC && bootsource_get_instance() == 1) {
+	sd = of_env_get_device_alias_by_path("/chosen/environment-sd");
+	emmc = of_env_get_device_alias_by_path("/chosen/environment-emmc");
+
+	if (streq_ptr(bootsource_get_alias_name(), sd)) {
 		of_device_enable_path("/chosen/environment-sd");
 		sd_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
-	} else {
+	} else if (emmc) {
 		of_device_enable_path("/chosen/environment-emmc");
 		emmc_bbu_flag = BBU_HANDLER_FLAG_DEFAULT;
 	}
 
-	imx8m_bbu_internal_mmc_register_handler("SD", "/dev/mmc1.barebox", sd_bbu_flag);
-	imx8m_bbu_internal_mmcboot_register_handler("eMMC", "/dev/mmc0", emmc_bbu_flag);
+	if (sd)
+		imx8m_bbu_internal_mmc_register_handler("SD",
+			basprintf("/dev/%s.barebox", sd), sd_bbu_flag);
+	if (emmc)
+		imx8m_bbu_internal_mmcboot_register_handler("eMMC",
+			basprintf("/dev/%s", emmc), emmc_bbu_flag);
 
 	return 0;
 }
-- 
2.39.5




  parent reply	other threads:[~2024-12-02 11:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-02 11:24 [PATCH v3 1/4] of: add helpers to get alias from device node path + property name Ahmad Fatoum
2024-12-02 11:24 ` [PATCH v3 2/4] environment: implement of_env_get_device_alias_by_path helper Ahmad Fatoum
2024-12-02 11:24 ` [PATCH v3 3/4] bootsource: have bootsource_get_alias_name return const char * Ahmad Fatoum
2024-12-02 11:24 ` Ahmad Fatoum [this message]
2024-12-02 12:39 ` [PATCH v3 1/4] of: add helpers to get alias from device node path + property name 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=20241202112437.535013-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=h.assmann@pengutronix.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