[PATCH master 2/2] bootsource: use /chosen instead of /aliases/barebox,bootsource-

Ahmad Fatoum ahmad at a3f.at
Mon Feb 20 23:07:35 PST 2023


Aliases were a bad choice for this as barebox could end up calling MMC
devices /dev/barebox,bootsource-mmc0, which was not intended.

Move over to using chosen instead.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 .../devicetree/bindings/barebox/aliases.rst     | 17 +++++++++++------
 arch/arm/dts/rk356x.dtsi                        |  2 +-
 common/bootsource.c                             |  6 +++---
 include/bootsource.h                            |  2 +-
 4 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/Documentation/devicetree/bindings/barebox/aliases.rst b/Documentation/devicetree/bindings/barebox/aliases.rst
index e6face2c3314..8d226cfab6eb 100644
--- a/Documentation/devicetree/bindings/barebox/aliases.rst
+++ b/Documentation/devicetree/bindings/barebox/aliases.rst
@@ -20,16 +20,21 @@ 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}``
+``/chosen/barebox,bootsource-${bootsource}${bootsource_instance}``
 property:
 
 .. code-block:: none
 
-  &{/aliases} {
-	mmc0 = &sdmmc0;
-	mmc1 = &sdhci;
-	barebox,bootsource-mmc0 = &sdhci;
-	barebox,bootsource-mmc1 = &sdmmc0;
+   / {
+   	aliases {
+		mmc0 = &sdmmc0;
+		mmc1 = &sdhci;
+	};
+
+   	chosen {
+		barebox,bootsource-mmc0 = &sdhci;
+		barebox,bootsource-mmc1 = &sdmmc0;
+	};
   };
 
 This will ensure that when booting from MMC, ``/dev/mmc${bootsource_instance}``
diff --git a/arch/arm/dts/rk356x.dtsi b/arch/arm/dts/rk356x.dtsi
index 254450d78fa8..6a9cd14d2d5a 100644
--- a/arch/arm/dts/rk356x.dtsi
+++ b/arch/arm/dts/rk356x.dtsi
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
 
 / {
-	aliases {
+	chosen {
 		barebox,bootsource-mmc0 = &sdhci;
 		barebox,bootsource-mmc1 = &sdmmc0;
 		barebox,bootsource-mmc2 = &sdmmc1;
diff --git a/common/bootsource.c b/common/bootsource.c
index 66bddf2dacf4..da528a5b9b19 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -137,7 +137,7 @@ void bootsource_set_raw_instance(int instance)
 
 int bootsource_of_alias_xlate(enum bootsource src, int instance)
 {
-	char alias[sizeof("barebox,bootsource-harddisk4294967295")];
+	char chosen[sizeof("barebox,bootsource-harddisk4294967295")];
 	const char *bootsource_stem;
 	struct device_node *np;
 	int alias_id;
@@ -153,10 +153,10 @@ int bootsource_of_alias_xlate(enum bootsource src, int instance)
 	if (!bootsource_stem)
 		return BOOTSOURCE_INSTANCE_UNKNOWN;
 
-	scnprintf(alias, sizeof(alias), "barebox,bootsource-%s%u",
+	scnprintf(chosen, sizeof(chosen), "barebox,bootsource-%s%u",
 		  bootsource_stem, instance);
 
-	np = of_find_node_by_alias(NULL, alias);
+	np = of_find_node_by_chosen(chosen, NULL);
 	if (!np)
 		return BOOTSOURCE_INSTANCE_UNKNOWN;
 
diff --git a/include/bootsource.h b/include/bootsource.h
index 381776a85a4c..05935b64a763 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -46,7 +46,7 @@ int bootsource_of_alias_xlate(enum bootsource bs, int instance);
  * 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.
+ * chosen property, instance is set without translation.
  */
 int bootsource_set(enum bootsource bs, int instance);
 
-- 
2.38.3




More information about the barebox mailing list