mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFT PATCH 0/3] ARM: Rockchip: align bootsource_instance
@ 2022-07-20  5:50 Ahmad Fatoum
  2022-07-20  5:50 ` [RFT PATCH 1/3] bootsource: rename existing bootsource_set to bootsource_set_raw Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2022-07-20  5:50 UTC (permalink / raw)
  To: barebox; +Cc: michael.riesch, j.zink

[ "$bootsource" = mmc ] && boot mmc$bootsource_instance on the Rockchip
board doesn't do what one would expect, because the bootrom has
different numbering for the MMC devices than what the upstream board
device trees use for their aliases. This series resolves that.

@Johannes, could you give this a test on the ROCK-3A?

Thanks,
Ahmad Fatoum (3):
  bootsource: rename existing bootsource_set to bootsource_set_raw
  bootsource: allow DT aliases and bootrom numbering to differ
  ARM: dts: rk356x: align bootsource_instance numbering and MMC DT
    aliases

 .../devicetree/bindings/barebox/aliases.rst   |  36 ++++++
 arch/arm/boards/radxa-rock3/board.c           |   2 +-
 .../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-at91/sama5d2.c                  |   4 +-
 arch/arm/mach-imx/boot.c                      |   6 +-
 arch/arm/mach-layerscape/boot.c               |   4 +-
 arch/arm/mach-mxs/imx.c                       |   3 +-
 arch/arm/mach-omap/am33xx_generic.c           |   3 +-
 arch/arm/mach-omap/omap3_generic.c            |   3 +-
 arch/arm/mach-omap/omap4_generic.c            |   3 +-
 arch/arm/mach-rockchip/rk3288.c               |   3 +-
 arch/arm/mach-rockchip/rk3568.c               |   9 +-
 arch/arm/mach-socfpga/arria10-bootsource.c    |   3 +-
 arch/arm/mach-socfpga/cyclone5-bootsource.c   |   6 +-
 arch/arm/mach-stm32mp/init.c                  |   3 +-
 arch/arm/mach-zynq/zynq.c                     |   2 +-
 arch/arm/mach-zynqmp/zynqmp.c                 |   3 +-
 common/bootsource.c                           | 110 +++++++++++++-----
 drivers/block/efi-block-io.c                  |   2 +-
 drivers/efi/efi-device.c                      |   3 +-
 include/bootsource.h                          |  40 ++++++-
 27 files changed, 192 insertions(+), 73 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/barebox/aliases.rst
 create mode 100644 arch/arm/dts/rk356x.dtsi

-- 
2.30.2




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [RFT PATCH 1/3] bootsource: rename existing bootsource_set to bootsource_set_raw
  2022-07-20  5:50 [RFT PATCH 0/3] ARM: Rockchip: align bootsource_instance Ahmad Fatoum
@ 2022-07-20  5:50 ` Ahmad Fatoum
  2022-07-20  5:50 ` [RFT PATCH 2/3] bootsource: allow DT aliases and bootrom numbering to differ Ahmad Fatoum
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2022-07-20  5:50 UTC (permalink / raw)
  To: barebox; +Cc: michael.riesch, j.zink, Ahmad Fatoum

Patterns like [ "$bootsource" = mmc ] && boot mmc$bootsource_instance
expect that ${bootsource_instance} and MMC aliases align, which may not
always be the case. In preparation for adding a new bootsource_set
function that consults an optional mapping table from bootrom
bootsource_instance to board-specific device numbering, rename all
existing instances to bootsource_set_raw. While at it, clean up the
legacy split into bootsource_set and bootsource_set_instance and have
the new bootsource_set_raw accept both arguments at once.

No functional change intended.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/mach-at91/sama5d2.c                | 4 ++--
 arch/arm/mach-imx/boot.c                    | 6 ++----
 arch/arm/mach-layerscape/boot.c             | 4 ++--
 arch/arm/mach-mxs/imx.c                     | 3 +--
 arch/arm/mach-omap/am33xx_generic.c         | 3 +--
 arch/arm/mach-omap/omap3_generic.c          | 3 +--
 arch/arm/mach-omap/omap4_generic.c          | 3 +--
 arch/arm/mach-rockchip/rk3288.c             | 3 +--
 arch/arm/mach-rockchip/rk3568.c             | 3 +--
 arch/arm/mach-socfpga/arria10-bootsource.c  | 3 +--
 arch/arm/mach-socfpga/cyclone5-bootsource.c | 6 ++----
 arch/arm/mach-stm32mp/init.c                | 3 +--
 arch/arm/mach-zynq/zynq.c                   | 2 +-
 arch/arm/mach-zynqmp/zynqmp.c               | 3 +--
 common/bootsource.c                         | 9 +++++----
 drivers/block/efi-block-io.c                | 2 +-
 drivers/efi/efi-device.c                    | 3 +--
 include/bootsource.h                        | 4 ++--
 18 files changed, 27 insertions(+), 40 deletions(-)

diff --git a/arch/arm/mach-at91/sama5d2.c b/arch/arm/mach-at91/sama5d2.c
index a4aa8a23399d..b05d6a56bdd8 100644
--- a/arch/arm/mach-at91/sama5d2.c
+++ b/arch/arm/mach-at91/sama5d2.c
@@ -62,8 +62,8 @@ static int sama5d2_bootsource_init(void)
 
 	at91_bootsource = __sama5d2_stashed_bootrom_r4;
 
-	bootsource_set(sama5_bootsource(at91_bootsource));
-	bootsource_set_instance(sama5_bootsource_instance(at91_bootsource));
+	bootsource_set_raw(sama5_bootsource(at91_bootsource),
+			   sama5_bootsource_instance(at91_bootsource));
 
 	return 0;
 }
diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 16a377341c8b..8c9febb50a65 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -34,8 +34,7 @@ imx_boot_save_loc(void (*get_boot_source)(enum bootsource *, int *))
 
 	get_boot_source(&src, &instance);
 
-	bootsource_set(src);
-	bootsource_set_instance(instance);
+	bootsource_set_raw(src, instance);
 }
 
 
@@ -309,8 +308,7 @@ void imx53_boot_save_loc(void)
 
 	imx53_get_boot_source(&src, &instance);
 
-	bootsource_set(src);
-	bootsource_set_instance(instance);
+	bootsource_set_raw(src, instance);
 }
 
 #define IMX6_SRC_SBMR1	0x04
diff --git a/arch/arm/mach-layerscape/boot.c b/arch/arm/mach-layerscape/boot.c
index c804977d228d..c6f816444ad5 100644
--- a/arch/arm/mach-layerscape/boot.c
+++ b/arch/arm/mach-layerscape/boot.c
@@ -32,8 +32,8 @@ static int ls1046a_bootsource_init(void)
 	if (!of_machine_is_compatible("fsl,ls1046a"))
 		return 0;
 
-	bootsource_set(ls1046_bootsource_get());
+	bootsource_set_raw(ls1046_bootsource_get(), BOOTSOURCE_INSTANCE_UNKNOWN);
 
 	return 0;
 }
-coredevice_initcall(ls1046a_bootsource_init);
\ No newline at end of file
+coredevice_initcall(ls1046a_bootsource_init);
diff --git a/arch/arm/mach-mxs/imx.c b/arch/arm/mach-mxs/imx.c
index 5af9cca4e9fb..a8a950091821 100644
--- a/arch/arm/mach-mxs/imx.c
+++ b/arch/arm/mach-mxs/imx.c
@@ -158,8 +158,7 @@ static void mxs_boot_save_loc(void)
 	case 0x9: src = BOOTSOURCE_MMC; break;		/* "SSP SD/MMC #0" */
 	}
 
-	bootsource_set(src);
-	bootsource_set_instance(instance);
+	bootsource_set_raw(src, instance);
 }
 
 static int mxs_init(void)
diff --git a/arch/arm/mach-omap/am33xx_generic.c b/arch/arm/mach-omap/am33xx_generic.c
index bfe5b3dc73dc..7f9a2bcf3710 100644
--- a/arch/arm/mach-omap/am33xx_generic.c
+++ b/arch/arm/mach-omap/am33xx_generic.c
@@ -153,8 +153,7 @@ static int am33xx_bootsource(void)
 	default:
 		src = BOOTSOURCE_UNKNOWN;
 	}
-	bootsource_set(src);
-	bootsource_set_instance(instance);
+	bootsource_set_raw(src, instance);
 	return 0;
 }
 
diff --git a/arch/arm/mach-omap/omap3_generic.c b/arch/arm/mach-omap/omap3_generic.c
index 69f2d51a62b5..cb6105cc042f 100644
--- a/arch/arm/mach-omap/omap3_generic.c
+++ b/arch/arm/mach-omap/omap3_generic.c
@@ -475,8 +475,7 @@ static int omap3_bootsource(void)
 		src = BOOTSOURCE_UNKNOWN;
 	}
 
-	bootsource_set(src);
-	bootsource_set_instance(0);
+	bootsource_set_raw(src, 0);
 
 	return 0;
 }
diff --git a/arch/arm/mach-omap/omap4_generic.c b/arch/arm/mach-omap/omap4_generic.c
index 6d165b7f684d..7c8374eba762 100644
--- a/arch/arm/mach-omap/omap4_generic.c
+++ b/arch/arm/mach-omap/omap4_generic.c
@@ -498,8 +498,7 @@ static int omap4_bootsource(void)
 		src = BOOTSOURCE_UNKNOWN;
 	}
 
-	bootsource_set(src);
-	bootsource_set_instance(0);
+	bootsource_set_raw(src, 0);
 
 	omap_vector_init();
 
diff --git a/arch/arm/mach-rockchip/rk3288.c b/arch/arm/mach-rockchip/rk3288.c
index 2a1d4ab7a240..f623af6731c1 100644
--- a/arch/arm/mach-rockchip/rk3288.c
+++ b/arch/arm/mach-rockchip/rk3288.c
@@ -69,8 +69,7 @@ static int rk3288_env_init(void)
 	const char *envpath = "/chosen/environment-emmc";
 	int ret;
 
-	bootsource_set(BOOTSOURCE_MMC);
-	bootsource_set_instance(0);
+	bootsource_set_raw(BOOTSOURCE_MMC, 0);
 
 	ret = of_device_enable_path(envpath);
 	if (ret < 0)
diff --git a/arch/arm/mach-rockchip/rk3568.c b/arch/arm/mach-rockchip/rk3568.c
index 234c6d22d171..2d80bad8a658 100644
--- a/arch/arm/mach-rockchip/rk3568.c
+++ b/arch/arm/mach-rockchip/rk3568.c
@@ -160,8 +160,7 @@ static enum bootsource rk3568_bootsource(void)
 	if (v >= ARRAY_SIZE(bootdev_map))
 		return BOOTSOURCE_UNKNOWN;
 
-	bootsource_set(bootdev_map[v].src);
-	bootsource_set_instance(bootdev_map[v].instance);
+	bootsource_set_raw(bootdev_map[v].src, bootdev_map[v].instance);
 
 	return bootdev_map[v].src;
 }
diff --git a/arch/arm/mach-socfpga/arria10-bootsource.c b/arch/arm/mach-socfpga/arria10-bootsource.c
index 3319dc4bf968..9055570c0764 100644
--- a/arch/arm/mach-socfpga/arria10-bootsource.c
+++ b/arch/arm/mach-socfpga/arria10-bootsource.c
@@ -55,8 +55,7 @@ static int arria10_boot_save_loc(void)
 
 	src = arria10_get_bootsource();
 
-	bootsource_set(src);
-	bootsource_set_instance(0);
+	bootsource_set_raw(src, 0);
 
 	return 0;
 }
diff --git a/arch/arm/mach-socfpga/cyclone5-bootsource.c b/arch/arm/mach-socfpga/cyclone5-bootsource.c
index 717a00342506..ab18d033022f 100644
--- a/arch/arm/mach-socfpga/cyclone5-bootsource.c
+++ b/arch/arm/mach-socfpga/cyclone5-bootsource.c
@@ -50,8 +50,7 @@ static int cyclone5_boot_save_loc(void)
 		break;
 	}
 
-	bootsource_set(src);
-	bootsource_set_instance(0);
+	bootsource_set_raw(src, 0);
 
 	return 0;
 }
@@ -84,8 +83,7 @@ static int arria10_boot_save_loc(void)
 		break;
 	}
 
-	bootsource_set(src);
-	bootsource_set_instance(0);
+	bootsource_set_raw(src, 0);
 
 	return 0;
 }
diff --git a/arch/arm/mach-stm32mp/init.c b/arch/arm/mach-stm32mp/init.c
index bcd04b210a50..938dea3c3d5d 100644
--- a/arch/arm/mach-stm32mp/init.c
+++ b/arch/arm/mach-stm32mp/init.c
@@ -98,8 +98,7 @@ static void setup_boot_mode(void)
 	pr_debug("[boot_ctx=0x%x] => mode=0x%x, instance=%d\n",
 		 boot_ctx, boot_mode, instance);
 
-	bootsource_set(src);
-	bootsource_set_instance(instance);
+	bootsource_set_raw(src, instance);
 }
 
 static int __stm32mp_cputype;
diff --git a/arch/arm/mach-zynq/zynq.c b/arch/arm/mach-zynq/zynq.c
index 806aeb913055..5abd52f6a21f 100644
--- a/arch/arm/mach-zynq/zynq.c
+++ b/arch/arm/mach-zynq/zynq.c
@@ -71,7 +71,7 @@ static int zynq_init(void)
 
 	restart_handler_register_fn("soc", zynq_restart_soc);
 
-	bootsource_set(zynq_bootsource_get());
+	bootsource_set_raw(zynq_bootsource_get(), BOOTSOURCE_INSTANCE_UNKNOWN);
 
 	return 0;
 }
diff --git a/arch/arm/mach-zynqmp/zynqmp.c b/arch/arm/mach-zynqmp/zynqmp.c
index 610d4bba6eaf..312325956a99 100644
--- a/arch/arm/mach-zynqmp/zynqmp.c
+++ b/arch/arm/mach-zynqmp/zynqmp.c
@@ -148,8 +148,7 @@ static int zynqmp_init(void)
 	int boot_instance;
 
 	zynqmp_get_bootsource(&boot_src, &boot_instance);
-	bootsource_set(boot_src);
-	bootsource_set_instance(boot_instance);
+	bootsource_set_raw(boot_src, boot_instance);
 
 	reset_source_set(zynqmp_get_reset_src());
 
diff --git a/common/bootsource.c b/common/bootsource.c
index 79dacfd1d07d..c37da38f7f99 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -101,7 +101,7 @@ void bootsource_set_alias_name(const char *name)
 	bootsource_alias_name = name;
 }
 
-void bootsource_set(enum bootsource src)
+void bootsource_set_raw(enum bootsource src, int instance)
 {
 	if (src >= ARRAY_SIZE(bootsource_str))
 		src = BOOTSOURCE_UNKNOWN;
@@ -109,9 +109,11 @@ void bootsource_set(enum bootsource src)
 	bootsource = src;
 
 	setenv("bootsource", bootsource_str[src]);
+
+	bootsource_set_raw_instance(instance);
 }
 
-void bootsource_set_instance(int instance)
+void bootsource_set_raw_instance(int instance)
 {
 	bootsource_instance = instance;
 
@@ -137,8 +139,7 @@ BAREBOX_MAGICVAR(bootsource_instance, "The instance of the source barebox has be
 
 static int bootsource_init(void)
 {
-	bootsource_set(bootsource);
-	bootsource_set_instance(bootsource_instance);
+	bootsource_set_raw(bootsource, bootsource_instance);
 	export("bootsource");
 	export("bootsource_instance");
 
diff --git a/drivers/block/efi-block-io.c b/drivers/block/efi-block-io.c
index 120e4d8f1ad2..b78117d445bf 100644
--- a/drivers/block/efi-block-io.c
+++ b/drivers/block/efi-block-io.c
@@ -188,7 +188,7 @@ static int efi_bio_probe(struct efi_device *efidev)
 		return ret;
 
 	if (efi_get_bootsource() == efidev)
-		bootsource_set_instance(instance);
+		bootsource_set_raw_instance(instance);
 
 	parse_partition_table(&priv->blk);
 
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index f91d09e8eaa5..af5406afa682 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -426,8 +426,7 @@ static void efi_set_bootsource(void)
 
 out:
 
-	bootsource_set(src);
-	bootsource_set_instance(instance);
+	bootsource_set_raw(src, instance);
 }
 
 static int efi_init_devices(void)
diff --git a/include/bootsource.h b/include/bootsource.h
index 646b0e91c13e..390d6f5d2b3a 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -26,8 +26,8 @@ enum bootsource {
 
 enum bootsource bootsource_get(void);
 int bootsource_get_instance(void);
-void bootsource_set(enum bootsource src);
-void bootsource_set_instance(int instance);
+void bootsource_set_raw(enum bootsource src, int instance);
+void bootsource_set_raw_instance(int instance);
 void bootsource_set_alias_name(const char *name);
 char *bootsource_get_alias_name(void);
 
-- 
2.30.2




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [RFT PATCH 2/3] bootsource: allow DT aliases and bootrom numbering to differ
  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 ` Ahmad Fatoum
  2022-07-20  8:32   ` [PATCH] fixup! " Johannes Zink
  2022-07-20  5:50 ` [RFT PATCH 3/3] ARM: dts: rk356x: align bootsource_instance numbering and MMC DT aliases Ahmad Fatoum
  2022-08-09  7:41 ` [RFT PATCH 0/3] ARM: Rockchip: align bootsource_instance Sascha Hauer
  3 siblings, 1 reply; 9+ messages in thread
From: Ahmad Fatoum @ 2022-07-20  5:50 UTC (permalink / raw)
  To: barebox; +Cc: michael.riesch, j.zink, Ahmad Fatoum

So far, we had no explicit mapping table between bootsource_instance
and device id numbering in barebox and mostly depended on DT aliases
reflecting the numbering of the bootrom. Add a new bootsource_set()
that optionally consults a mapping table in the DT to arrive at the
correct numbers.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 .../devicetree/bindings/barebox/aliases.rst   |  36 +++++++
 common/bootsource.c                           | 101 +++++++++++++-----
 include/bootsource.h                          |  40 ++++++-
 3 files changed, 149 insertions(+), 28 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/barebox/aliases.rst

diff --git a/Documentation/devicetree/bindings/barebox/aliases.rst b/Documentation/devicetree/bindings/barebox/aliases.rst
new file mode 100644
index 000000000000..527cc85ef696
--- /dev/null
+++ b/Documentation/devicetree/bindings/barebox/aliases.rst
@@ -0,0 +1,36 @@
+barebox DT aliases
+==================
+
+barebox can use the properties in the ``/aliases`` node to arrive
+at deterministic names for devices, e.g.::
+
+.. code-block:: none
+   / {
+   	aliases {
+   		mmc0 = &sdhci;
+   		wdog0 = &iwdg;
+   	};
+   };
+
+will assign the MMC device created from probing the node at ``&sdhci``
+the name ``/dev/mmc0``. Similarly, the watchdog device created from
+probing the node at ``&iwdg`` will be named ``wdog0``.
+
+By default, barebox will assume the aliases in the DT to align with
+the bootsource communicated by the firmware. If this is not the case,
+a device tree override is possible via an
+``/aliases/barebox,bootsource-${bootsource}${bootsource_instance}``
+property:
+
+.. code-block:: none
+
+  &{/aliases} {
+	mmc0 = &sdmmc0;
+	mmc1 = &sdhci;
+	barebox,bootsource-mmc0 = &sdhci;
+	barebox,bootsource-mmc1 = &sdmmc0;
+  };
+
+This will ensure that when booting from MMC, ``/dev/mmc${bootsource_instance}``
+will point at the correct boot device, despite bootrom and board DT alias
+order being different.
diff --git a/common/bootsource.c b/common/bootsource.c
index c37da38f7f99..d74c5e5cbe9f 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -33,6 +33,34 @@ static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
 static int bootsource_instance = BOOTSOURCE_INSTANCE_UNKNOWN;
 const char *bootsource_alias_name = NULL;
 
+const char *bootsource_get_alias_stem(enum bootsource bs)
+{
+	switch (bs) {
+		/*
+		 * For I2C and SPI EEPROMs we set the stem to be 'i2c'
+		 * and 'spi' correspondingly. The resulting alias will
+		 * be pointing at the controller said EEPROM is
+		 * attached to.
+		 *
+		 * NOTE: This code assumes single bootable EEPROM per
+		 * controller
+		 */
+	case BOOTSOURCE_I2C_EEPROM:
+		return bootsource_str[BOOTSOURCE_I2C];
+	case BOOTSOURCE_SPI_EEPROM:
+	case BOOTSOURCE_SPI_NOR:
+		return bootsource_str[BOOTSOURCE_SPI];
+	case BOOTSOURCE_SERIAL:	/* FALLTHROUGH */
+	case BOOTSOURCE_I2C:	/* FALLTHROUGH */
+	case BOOTSOURCE_MMC:	/* FALLTHROUGH */
+	case BOOTSOURCE_SPI:	/* FALLTHROUGH */
+	case BOOTSOURCE_CAN:
+		return bootsource_str[bootsource];
+	default:
+		return NULL;
+	}
+}
+
 /**
  * bootsource_get_alias_name() - Get the name of the bootsource alias
  *
@@ -58,33 +86,9 @@ char *bootsource_get_alias_name(void)
 	if (bootsource_alias_name)
 		return strdup(bootsource_alias_name);
 
-	switch (bootsource) {
-		/*
-		 * For I2C and SPI EEPROMs we set the stem to be 'i2c'
-		 * and 'spi' correspondingly. The resulting alias will
-		 * be pointing at the controller said EEPROM is
-		 * attached to.
-		 *
-		 * NOTE: This code assumes single bootable EEPROM per
-		 * controller
-		 */
-	case BOOTSOURCE_I2C_EEPROM:
-		stem = bootsource_str[BOOTSOURCE_I2C];
-		break;
-	case BOOTSOURCE_SPI_EEPROM:
-	case BOOTSOURCE_SPI_NOR:
-		stem = bootsource_str[BOOTSOURCE_SPI];
-		break;
-	case BOOTSOURCE_SERIAL:	/* FALLTHROUGH */
-	case BOOTSOURCE_I2C:	/* FALLTHROUGH */
-	case BOOTSOURCE_MMC:	/* FALLTHROUGH */
-	case BOOTSOURCE_SPI:	/* FALLTHROUGH */
-	case BOOTSOURCE_CAN:
-		stem = bootsource_str[bootsource];
-		break;
-	default:
+	stem = bootsource_get_alias_stem(bootsource);
+	if (!stem)
 		return NULL;
-	}
 
 	/*
 	 * We expect SoC specific bootsource detection code to properly
@@ -123,6 +127,51 @@ void bootsource_set_raw_instance(int instance)
 		pr_setenv("bootsource_instance", "%d", instance);
 }
 
+int bootsource_of_alias_xlate(enum bootsource bs, int instance)
+{
+	char alias[sizeof("barebox,bootsource-harddisk4294967295")];
+	const char *bootsource_stem;
+	struct device_node *np;
+	int alias_id;
+
+	if (!IS_ENABLED(CONFIG_OFDEVICE))
+		return BOOTSOURCE_INSTANCE_UNKNOWN;
+
+	if (bs == BOOTSOURCE_UNKNOWN ||
+	    instance == BOOTSOURCE_INSTANCE_UNKNOWN)
+		return BOOTSOURCE_INSTANCE_UNKNOWN;
+
+	bootsource_stem = bootsource_get_alias_stem(bs);
+	if (!bootsource_stem)
+		return BOOTSOURCE_INSTANCE_UNKNOWN;
+
+	scnprintf(alias, sizeof(alias), "barebox,bootsource-%s%u",
+		  bootsource_stem, instance);
+
+	np = of_find_node_by_alias(NULL, alias);
+	if (!np)
+		return BOOTSOURCE_INSTANCE_UNKNOWN;
+
+	alias_id = of_alias_get_id(np, bootsource_stem);
+	if (alias_id < 0)
+		return BOOTSOURCE_INSTANCE_UNKNOWN;
+
+	return alias_id;
+}
+
+int bootsource_set(enum bootsource bs, int instance)
+{
+	int alias_id;
+
+	alias_id = bootsource_of_alias_xlate(bs, instance);
+	if (alias_id == BOOTSOURCE_INSTANCE_UNKNOWN)
+		alias_id = instance;
+
+	bootsource_set_raw(bs, alias_id);
+
+	return alias_id;
+}
+
 enum bootsource bootsource_get(void)
 {
 	return bootsource;
diff --git a/include/bootsource.h b/include/bootsource.h
index 390d6f5d2b3a..9ca4fcc525b5 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -26,9 +26,45 @@ enum bootsource {
 
 enum bootsource bootsource_get(void);
 int bootsource_get_instance(void);
-void bootsource_set_raw(enum bootsource src, int instance);
-void bootsource_set_raw_instance(int instance);
 void bootsource_set_alias_name(const char *name);
 char *bootsource_get_alias_name(void);
+const char *bootsource_get_alias_stem(enum bootsource bs);
+int bootsource_of_alias_xlate(enum bootsource bs, int instance);
+
+/**
+ * bootsource_set - set bootsource with optional DT mapping table
+ * @bs:	bootrom reported bootsource
+ * @instance: bootrom reported instance
+ *
+ * Returns computed bootsource instace
+ *
+ * Normal bootsource_set_raw_instance() expects numbering used by
+ * bootrom for instance to align with DT aliases, e.g.
+ * $bootsource = "mmc" && $bootsource_instance = 1 -> /aliases/mmc1
+ * bootsource_set() will instead consult
+ * /aliases/barebox,bootsource-mmc1 which may point at a different
+ * device than mmc1. In absence of appropriate barebox,bootsource-*
+ * alias, instance is set without translation.
+ */
+int bootsource_set(enum bootsource bs, int instance);
+
+/**
+ * bootsource_set_raw - set bootsource as-is
+ * @bs:	bootsource to report
+ * @instance: bootsource instance to report
+ *
+ * This sets bootsource and bootsource_instance directly.
+ * Preferably, use bootsource_set in new code.
+ */
+void bootsource_set_raw(enum bootsource src, int instance);
+
+/**
+ * bootsource_set_raw_instance - set bootsource_instance as-is
+ * @bs:	bootrom reported bootsource
+ * @instance: bootrom reported instance
+ *
+ * This directly sets bootsource_instance without changing bootsource.
+ */
+void bootsource_set_raw_instance(int instance);
 
 #endif	/* __BOOTSOURCE_H__ */
-- 
2.30.2




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [RFT PATCH 3/3] ARM: dts: rk356x: align bootsource_instance numbering and MMC DT aliases
  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  5:50 ` Ahmad Fatoum
  2022-07-20  9:30   ` 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
  3 siblings, 2 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2022-07-20  5:50 UTC (permalink / raw)
  To: barebox; +Cc: michael.riesch, j.zink, Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] fixup! bootsource: allow DT aliases and bootrom numbering to differ
  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   ` Johannes Zink
  2022-07-20  9:29     ` Johannes Zink
  0 siblings, 1 reply; 9+ messages in thread
From: Johannes Zink @ 2022-07-20  8:32 UTC (permalink / raw)
  To: barebox; +Cc: afa, Johannes Zink

bootsource was used when src should have been instead. While at it,
rename bs to src for alignment with other functions.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Johannes Zink <j.zink@pengutronix.de>
---
 common/bootsource.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/common/bootsource.c b/common/bootsource.c
index d74c5e5cb..70bac945d 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -33,9 +33,9 @@ static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
 static int bootsource_instance = BOOTSOURCE_INSTANCE_UNKNOWN;
 const char *bootsource_alias_name = NULL;
 
-const char *bootsource_get_alias_stem(enum bootsource bs)
+const char *bootsource_get_alias_stem(enum bootsource src)
 {
-	switch (bs) {
+	switch (src) {
 		/*
 		 * For I2C and SPI EEPROMs we set the stem to be 'i2c'
 		 * and 'spi' correspondingly. The resulting alias will
@@ -55,7 +55,7 @@ const char *bootsource_get_alias_stem(enum bootsource bs)
 	case BOOTSOURCE_MMC:	/* FALLTHROUGH */
 	case BOOTSOURCE_SPI:	/* FALLTHROUGH */
 	case BOOTSOURCE_CAN:
-		return bootsource_str[bootsource];
+		return bootsource_str[src];
 	default:
 		return NULL;
 	}
@@ -127,7 +127,7 @@ void bootsource_set_raw_instance(int instance)
 		pr_setenv("bootsource_instance", "%d", instance);
 }
 
-int bootsource_of_alias_xlate(enum bootsource bs, int instance)
+int bootsource_of_alias_xlate(enum bootsource src, int instance)
 {
 	char alias[sizeof("barebox,bootsource-harddisk4294967295")];
 	const char *bootsource_stem;
@@ -137,11 +137,11 @@ int bootsource_of_alias_xlate(enum bootsource bs, int instance)
 	if (!IS_ENABLED(CONFIG_OFDEVICE))
 		return BOOTSOURCE_INSTANCE_UNKNOWN;
 
-	if (bs == BOOTSOURCE_UNKNOWN ||
+	if (src == BOOTSOURCE_UNKNOWN ||
 	    instance == BOOTSOURCE_INSTANCE_UNKNOWN)
 		return BOOTSOURCE_INSTANCE_UNKNOWN;
 
-	bootsource_stem = bootsource_get_alias_stem(bs);
+	bootsource_stem = bootsource_get_alias_stem(src);
 	if (!bootsource_stem)
 		return BOOTSOURCE_INSTANCE_UNKNOWN;
 
@@ -159,15 +159,15 @@ int bootsource_of_alias_xlate(enum bootsource bs, int instance)
 	return alias_id;
 }
 
-int bootsource_set(enum bootsource bs, int instance)
+int bootsource_set(enum bootsource src, int instance)
 {
 	int alias_id;
 
-	alias_id = bootsource_of_alias_xlate(bs, instance);
+	alias_id = bootsource_of_alias_xlate(src, instance);
 	if (alias_id == BOOTSOURCE_INSTANCE_UNKNOWN)
 		alias_id = instance;
 
-	bootsource_set_raw(bs, alias_id);
+	bootsource_set_raw(src, alias_id);
 
 	return alias_id;
 }
-- 
2.30.2




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] fixup! bootsource: allow DT aliases and bootrom numbering to differ
  2022-07-20  8:32   ` [PATCH] fixup! " Johannes Zink
@ 2022-07-20  9:29     ` Johannes Zink
  0 siblings, 0 replies; 9+ messages in thread
From: Johannes Zink @ 2022-07-20  9:29 UTC (permalink / raw)
  To: barebox

On Wed, 2022-07-20 at 10:32 +0200, Johannes Zink wrote:
> bootsource was used when src should have been instead. While at it,
> rename bs to src for alignment with other functions.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> Signed-off-by: Johannes Zink <j.zink@pengutronix.de>
> ---
>  common/bootsource.c | 18 +++++++++---------
>  1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/common/bootsource.c b/common/bootsource.c
> index d74c5e5cb..70bac945d 100644
> --- a/common/bootsource.c
> +++ b/common/bootsource.c
> @@ -33,9 +33,9 @@ static enum bootsource bootsource =
> BOOTSOURCE_UNKNOWN;
>  static int bootsource_instance = BOOTSOURCE_INSTANCE_UNKNOWN;
>  const char *bootsource_alias_name = NULL;
>  
> -const char *bootsource_get_alias_stem(enum bootsource bs)
> +const char *bootsource_get_alias_stem(enum bootsource src)
>  {
> -       switch (bs) {
> +       switch (src) {
>                 /*
>                  * For I2C and SPI EEPROMs we set the stem to be
> 'i2c'
>                  * and 'spi' correspondingly. The resulting alias
> will
> @@ -55,7 +55,7 @@ const char *bootsource_get_alias_stem(enum
> bootsource bs)
>         case BOOTSOURCE_MMC:    /* FALLTHROUGH */
>         case BOOTSOURCE_SPI:    /* FALLTHROUGH */
>         case BOOTSOURCE_CAN:
> -               return bootsource_str[bootsource];
> +               return bootsource_str[src];
>         default:
>                 return NULL;
>         }
> @@ -127,7 +127,7 @@ void bootsource_set_raw_instance(int instance)
>                 pr_setenv("bootsource_instance", "%d", instance);
>  }
>  
> -int bootsource_of_alias_xlate(enum bootsource bs, int instance)
> +int bootsource_of_alias_xlate(enum bootsource src, int instance)
>  {
>         char alias[sizeof("barebox,bootsource-harddisk4294967295")];
>         const char *bootsource_stem;
> @@ -137,11 +137,11 @@ int bootsource_of_alias_xlate(enum bootsource
> bs, int instance)
>         if (!IS_ENABLED(CONFIG_OFDEVICE))
>                 return BOOTSOURCE_INSTANCE_UNKNOWN;
>  
> -       if (bs == BOOTSOURCE_UNKNOWN ||
> +       if (src == BOOTSOURCE_UNKNOWN ||
>             instance == BOOTSOURCE_INSTANCE_UNKNOWN)
>                 return BOOTSOURCE_INSTANCE_UNKNOWN;
>  
> -       bootsource_stem = bootsource_get_alias_stem(bs);
> +       bootsource_stem = bootsource_get_alias_stem(src);
>         if (!bootsource_stem)
>                 return BOOTSOURCE_INSTANCE_UNKNOWN;
>  
> @@ -159,15 +159,15 @@ int bootsource_of_alias_xlate(enum bootsource
> bs, int instance)
>         return alias_id;
>  }
>  
> -int bootsource_set(enum bootsource bs, int instance)
> +int bootsource_set(enum bootsource src, int instance)
>  {
>         int alias_id;
>  
> -       alias_id = bootsource_of_alias_xlate(bs, instance);
> +       alias_id = bootsource_of_alias_xlate(src, instance);
>         if (alias_id == BOOTSOURCE_INSTANCE_UNKNOWN)
>                 alias_id = instance;
>  
> -       bootsource_set_raw(bs, alias_id);
> +       bootsource_set_raw(src, alias_id);
>  
>         return alias_id;
>  }

Tested-by: Johannes Zink <j.zink@pengutronix.de> # Radxa Rockpi3A
(RK3568)

-- 
Pengutronix e.K.                | Johannes Zink                  |
Steuerwalder Str. 21            | https://www.pengutronix.de/    |
31137 Hildesheim, Germany       | Phone: +49-5121-206917-0       |
Amtsgericht Hildesheim, HRA 2686| Fax:   +49-5121-206917-5555    |




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH 3/3] ARM: dts: rk356x: align bootsource_instance numbering and MMC DT aliases
  2022-07-20  5:50 ` [RFT PATCH 3/3] ARM: dts: rk356x: align bootsource_instance numbering and MMC DT aliases Ahmad Fatoum
@ 2022-07-20  9:30   ` Johannes Zink
  2022-07-20 10:45   ` Ahmad Fatoum
  1 sibling, 0 replies; 9+ messages in thread
From: Johannes Zink @ 2022-07-20  9:30 UTC (permalink / raw)
  To: barebox

On Wed, 2022-07-20 at 07:50 +0200, Ahmad Fatoum wrote:
> 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)

Tested-by: Johannes Zink <j.zink@pengutronix.de> # Radxa Rockpi3A
(RK3568)

-- 
Pengutronix e.K.                | Johannes Zink                  |
Steuerwalder Str. 21            | https://www.pengutronix.de/    |
31137 Hildesheim, Germany       | Phone: +49-5121-206917-0       |
Amtsgericht Hildesheim, HRA 2686| Fax:   +49-5121-206917-5555    |




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH 3/3] ARM: dts: rk356x: align bootsource_instance numbering and MMC DT aliases
  2022-07-20  5:50 ` [RFT PATCH 3/3] ARM: dts: rk356x: align bootsource_instance numbering and MMC DT aliases Ahmad Fatoum
  2022-07-20  9:30   ` Johannes Zink
@ 2022-07-20 10:45   ` Ahmad Fatoum
  1 sibling, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2022-07-20 10:45 UTC (permalink / raw)
  To: barebox, Frank Wunderlich; +Cc: michael.riesch, j.zink

Hello Frank,

On 20.07.22 07:50, Ahmad Fatoum wrote:
> 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"

Heads up: This will change $bootsource_instance on the Banana Pi once merged.
If you remove arch/arm/dts/rk3568.dtsi and use the now upstream DTs
instead, you should end up with /dev/mmc0 and /dev/mmc1 where $bootsource_instance
would identify which one of them was used for booting when $bootsource = mmc.

Cheers,
Ahmad


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [RFT PATCH 0/3] ARM: Rockchip: align bootsource_instance
  2022-07-20  5:50 [RFT PATCH 0/3] ARM: Rockchip: align bootsource_instance Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2022-07-20  5:50 ` [RFT PATCH 3/3] ARM: dts: rk356x: align bootsource_instance numbering and MMC DT aliases Ahmad Fatoum
@ 2022-08-09  7:41 ` Sascha Hauer
  3 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2022-08-09  7:41 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox, michael.riesch, j.zink

On Wed, Jul 20, 2022 at 07:50:39AM +0200, Ahmad Fatoum wrote:
> [ "$bootsource" = mmc ] && boot mmc$bootsource_instance on the Rockchip
> board doesn't do what one would expect, because the bootrom has
> different numbering for the MMC devices than what the upstream board
> device trees use for their aliases. This series resolves that.
> 
> @Johannes, could you give this a test on the ROCK-3A?
> 
> Thanks,
> Ahmad Fatoum (3):
>   bootsource: rename existing bootsource_set to bootsource_set_raw
>   bootsource: allow DT aliases and bootrom numbering to differ
>   ARM: dts: rk356x: align bootsource_instance numbering and MMC DT
>     aliases

Applied, thanks

Sascha

> 
>  .../devicetree/bindings/barebox/aliases.rst   |  36 ++++++
>  arch/arm/boards/radxa-rock3/board.c           |   2 +-
>  .../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-at91/sama5d2.c                  |   4 +-
>  arch/arm/mach-imx/boot.c                      |   6 +-
>  arch/arm/mach-layerscape/boot.c               |   4 +-
>  arch/arm/mach-mxs/imx.c                       |   3 +-
>  arch/arm/mach-omap/am33xx_generic.c           |   3 +-
>  arch/arm/mach-omap/omap3_generic.c            |   3 +-
>  arch/arm/mach-omap/omap4_generic.c            |   3 +-
>  arch/arm/mach-rockchip/rk3288.c               |   3 +-
>  arch/arm/mach-rockchip/rk3568.c               |   9 +-
>  arch/arm/mach-socfpga/arria10-bootsource.c    |   3 +-
>  arch/arm/mach-socfpga/cyclone5-bootsource.c   |   6 +-
>  arch/arm/mach-stm32mp/init.c                  |   3 +-
>  arch/arm/mach-zynq/zynq.c                     |   2 +-
>  arch/arm/mach-zynqmp/zynqmp.c                 |   3 +-
>  common/bootsource.c                           | 110 +++++++++++++-----
>  drivers/block/efi-block-io.c                  |   2 +-
>  drivers/efi/efi-device.c                      |   3 +-
>  include/bootsource.h                          |  40 ++++++-
>  27 files changed, 192 insertions(+), 73 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/barebox/aliases.rst
>  create mode 100644 arch/arm/dts/rk356x.dtsi
> 
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-08-09  7:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [RFT PATCH 3/3] ARM: dts: rk356x: align bootsource_instance numbering and MMC DT aliases Ahmad Fatoum
2022-07-20  9:30   ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox