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: michael.riesch@wolfvision.net, j.zink@pengutronix.de,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [RFT PATCH 3/3] ARM: dts: rk356x: align bootsource_instance numbering and MMC DT aliases
Date: Wed, 20 Jul 2022 07:50:42 +0200	[thread overview]
Message-ID: <20220720055042.3510276-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220720055042.3510276-1-a.fatoum@pengutronix.de>

A common scripting pattern in barebox is continuing boot from
the current bootsource:

  if [ "$bootsource" = "mmc" ]; then
	global.boot.default="mmc${bootsource_instance} ${global.boot.default}"
  fi

This fails on the RK356x boards, because of a mismatch in numbering:
block device numbering is dictated by the mmc* DT aliases and numbering
used for bootsource_instance is taken as is from what the bootrom reports.

On SoCs like i.MX, this is a much rarer issue, because the upstream DT
has predefined aliases in the same order as reported by the bootrom.

In Rockchip DTs on the other hand, aliases are delegated to the board
device trees and all boards we support have aliases in an order
different from what the bootrom numbering.

Fix this by employing the newly supported barebox,bootsource-* mapping
table. As a result $bootsource_instance will change. We fix the upstream
code depending on specific numbering here, but custom scripts and board
code may still be broken.

Co-developed-by: Johannes Zink <j.zink@pengutronix.de>
Signed-off-by: Johannes Zink <j.zink@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/boards/radxa-rock3/board.c               | 2 +-
 arch/arm/boards/rockchip-rk3568-bpi-r2pro/board.c | 2 +-
 arch/arm/boards/rockchip-rk3568-evb/board.c       | 2 +-
 arch/arm/dts/rk3566-quartz64-a.dts                | 1 +
 arch/arm/dts/rk3568-bpi-r2-pro.dts                | 1 +
 arch/arm/dts/rk3568-evb1-v10.dts                  | 1 +
 arch/arm/dts/rk3568-rock-3a.dts                   | 1 +
 arch/arm/dts/rk356x.dtsi                          | 9 +++++++++
 arch/arm/mach-rockchip/rk3568.c                   | 8 +++-----
 9 files changed, 19 insertions(+), 8 deletions(-)
 create mode 100644 arch/arm/dts/rk356x.dtsi

diff --git a/arch/arm/boards/radxa-rock3/board.c b/arch/arm/boards/radxa-rock3/board.c
index aef5ec5df669..2413ea6cacc0 100644
--- a/arch/arm/boards/radxa-rock3/board.c
+++ b/arch/arm/boards/radxa-rock3/board.c
@@ -21,7 +21,7 @@ static int rock3_probe(struct device_d *dev)
 	barebox_set_model(model->name);
 	barebox_set_hostname(model->shortname);
 
-	if (bootsource == BOOTSOURCE_MMC && instance == 1)
+	if (bootsource == BOOTSOURCE_MMC && instance == 0)
 		of_device_enable_path("/chosen/environment-sd");
 	else
 		of_device_enable_path("/chosen/environment-emmc");
diff --git a/arch/arm/boards/rockchip-rk3568-bpi-r2pro/board.c b/arch/arm/boards/rockchip-rk3568-bpi-r2pro/board.c
index e472f13c8bbf..1a5faa8afb12 100644
--- a/arch/arm/boards/rockchip-rk3568-bpi-r2pro/board.c
+++ b/arch/arm/boards/rockchip-rk3568-bpi-r2pro/board.c
@@ -23,7 +23,7 @@ static int rk3568_bpi_r2pro_probe(struct device_d *dev)
 	barebox_set_hostname("bpi-r2pro");
 	machine_is_bpi_r2pro = true;
 
-	if (bootsource == BOOTSOURCE_MMC && instance == 1)
+	if (bootsource == BOOTSOURCE_MMC && instance == 0)
 		of_device_enable_path("/chosen/environment-sd");
 	else
 		of_device_enable_path("/chosen/environment-emmc");
diff --git a/arch/arm/boards/rockchip-rk3568-evb/board.c b/arch/arm/boards/rockchip-rk3568-evb/board.c
index a466d385a223..212c801c93d3 100644
--- a/arch/arm/boards/rockchip-rk3568-evb/board.c
+++ b/arch/arm/boards/rockchip-rk3568-evb/board.c
@@ -23,7 +23,7 @@ static int rk3568_evb_probe(struct device_d *dev)
 	barebox_set_hostname("rk3568-evb");
 	machine_is_rk3568_evb = true;
 
-	if (bootsource == BOOTSOURCE_MMC && instance == 1)
+	if (bootsource == BOOTSOURCE_MMC && instance == 0)
 		of_device_enable_path("/chosen/environment-sd");
 	else
 		of_device_enable_path("/chosen/environment-emmc");
diff --git a/arch/arm/dts/rk3566-quartz64-a.dts b/arch/arm/dts/rk3566-quartz64-a.dts
index 8639ca0886f1..0036ef31f13a 100644
--- a/arch/arm/dts/rk3566-quartz64-a.dts
+++ b/arch/arm/dts/rk3566-quartz64-a.dts
@@ -3,6 +3,7 @@
 /dts-v1/;
 
 #include <arm64/rockchip/rk3566-quartz64-a.dts>
+#include "rk356x.dtsi"
 
 / {
 	memory@a00000 {
diff --git a/arch/arm/dts/rk3568-bpi-r2-pro.dts b/arch/arm/dts/rk3568-bpi-r2-pro.dts
index da76ab64c106..8c13ddd5c103 100644
--- a/arch/arm/dts/rk3568-bpi-r2-pro.dts
+++ b/arch/arm/dts/rk3568-bpi-r2-pro.dts
@@ -9,6 +9,7 @@
 #include <dt-bindings/leds/common.h>
 #include <dt-bindings/pinctrl/rockchip.h>
 #include "rk3568.dtsi"
+#include "rk356x.dtsi"
 
 / {
 	model = "Bananapi-R2 Pro (RK3568) DDR4 Board";
diff --git a/arch/arm/dts/rk3568-evb1-v10.dts b/arch/arm/dts/rk3568-evb1-v10.dts
index d2c1fc89a8cb..82186ff86ead 100644
--- a/arch/arm/dts/rk3568-evb1-v10.dts
+++ b/arch/arm/dts/rk3568-evb1-v10.dts
@@ -7,6 +7,7 @@
 /dts-v1/;
 
 #include <arm64/rockchip/rk3568-evb1-v10.dts>
+#include "rk356x.dtsi"
 
 / {
 	chosen: chosen {
diff --git a/arch/arm/dts/rk3568-rock-3a.dts b/arch/arm/dts/rk3568-rock-3a.dts
index 44d4fc9686df..25a0c05737d0 100644
--- a/arch/arm/dts/rk3568-rock-3a.dts
+++ b/arch/arm/dts/rk3568-rock-3a.dts
@@ -3,6 +3,7 @@
 /dts-v1/;
 
 #include <arm64/rockchip/rk3568-rock-3a.dts>
+#include "rk356x.dtsi"
 
 / {
 	chosen: chosen {
diff --git a/arch/arm/dts/rk356x.dtsi b/arch/arm/dts/rk356x.dtsi
new file mode 100644
index 000000000000..254450d78fa8
--- /dev/null
+++ b/arch/arm/dts/rk356x.dtsi
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+
+/ {
+	aliases {
+		barebox,bootsource-mmc0 = &sdhci;
+		barebox,bootsource-mmc1 = &sdmmc0;
+		barebox,bootsource-mmc2 = &sdmmc1;
+	};
+};
diff --git a/arch/arm/mach-rockchip/rk3568.c b/arch/arm/mach-rockchip/rk3568.c
index 2d80bad8a658..19dfa9b87151 100644
--- a/arch/arm/mach-rockchip/rk3568.c
+++ b/arch/arm/mach-rockchip/rk3568.c
@@ -151,18 +151,16 @@ static struct rk_bootsource bootdev_map[] = {
 	[0xa] = { .src = BOOTSOURCE_USB, .instance = 0 },
 };
 
-static enum bootsource rk3568_bootsource(void)
+static void rk3568_bootsource(void)
 {
 	u32 v;
 
 	v = readl(RK3568_IRAM_BASE + 0x10);
 
 	if (v >= ARRAY_SIZE(bootdev_map))
-		return BOOTSOURCE_UNKNOWN;
+		return;
 
-	bootsource_set_raw(bootdev_map[v].src, bootdev_map[v].instance);
-
-	return bootdev_map[v].src;
+	bootsource_set(bootdev_map[v].src, bootdev_map[v].instance);
 }
 
 int rk3568_init(void)
-- 
2.30.2




  parent reply	other threads:[~2022-07-20  5:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-20  5:50 [RFT PATCH 0/3] ARM: Rockchip: align bootsource_instance Ahmad Fatoum
2022-07-20  5:50 ` [RFT PATCH 1/3] bootsource: rename existing bootsource_set to bootsource_set_raw Ahmad Fatoum
2022-07-20  5:50 ` [RFT PATCH 2/3] bootsource: allow DT aliases and bootrom numbering to differ Ahmad Fatoum
2022-07-20  8:32   ` [PATCH] fixup! " Johannes Zink
2022-07-20  9:29     ` Johannes Zink
2022-07-20  5:50 ` Ahmad Fatoum [this message]
2022-07-20  9:30   ` [RFT PATCH 3/3] ARM: dts: rk356x: align bootsource_instance numbering and MMC DT aliases Johannes Zink
2022-07-20 10:45   ` Ahmad Fatoum
2022-08-09  7:41 ` [RFT PATCH 0/3] ARM: Rockchip: align bootsource_instance 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=20220720055042.3510276-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=j.zink@pengutronix.de \
    --cc=michael.riesch@wolfvision.net \
    /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