mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] bootsource: retire bootsource_set_alias_name
@ 2025-04-09 13:19 Ahmad Fatoum
  2025-04-09 13:19 ` [PATCH 2/2] bootsource: add optional read of /chosen/bootsource Ahmad Fatoum
  2025-04-10  6:34 ` [PATCH 1/2] bootsource: retire bootsource_set_alias_name Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-04-09 13:19 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

This function was never used in upstream board code since it was
introduced, so drop it.

This avoids it interfering with the addition of bootsource_of_node_set
in the follow-up commit.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/bootsource.c  | 14 --------------
 include/bootsource.h |  1 -
 2 files changed, 15 deletions(-)

diff --git a/common/bootsource.c b/common/bootsource.c
index e78237ff36b8..14e6565e3789 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -32,7 +32,6 @@ static const char *bootsource_str[BOOTSOURCE_MAX] = {
 
 static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
 static int bootsource_instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-const char *bootsource_alias_name = NULL;
 
 const char *bootsource_to_string(enum bootsource src)
 {
@@ -84,14 +83,6 @@ const char *bootsource_get_alias_name(void)
 	const char *stem;
 	int ret;
 
-	/*
-	 * If alias name was overridden via
-	 * bootsource_set_alias_name() return that value without
-	 * asking any questions.
-	 */
-	if (bootsource_alias_name)
-		return bootsource_alias_name;
-
 	stem = bootsource_get_alias_stem(bootsource);
 	if (!stem)
 		return NULL;
@@ -140,11 +131,6 @@ struct cdev *bootsource_of_cdev_find(void)
 	return cdev;
 }
 
-void bootsource_set_alias_name(const char *name)
-{
-	bootsource_alias_name = name;
-}
-
 void bootsource_set_raw(enum bootsource src, int instance)
 {
 	if (src >= BOOTSOURCE_MAX)
diff --git a/include/bootsource.h b/include/bootsource.h
index c9c58daf096c..1b3df84f4ddb 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -28,7 +28,6 @@ enum bootsource {
 enum bootsource bootsource_get(void);
 enum bootsource bootsource_get_device(void);
 int bootsource_get_instance(void);
-void bootsource_set_alias_name(const char *name);
 const char *bootsource_get_alias_name(void);
 const char *bootsource_to_string(enum bootsource src);
 const char *bootsource_get_alias_stem(enum bootsource bs);
-- 
2.39.5




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

* [PATCH 2/2] bootsource: add optional read of /chosen/bootsource
  2025-04-09 13:19 [PATCH 1/2] bootsource: retire bootsource_set_alias_name Ahmad Fatoum
@ 2025-04-09 13:19 ` Ahmad Fatoum
  2025-04-10  6:34 ` [PATCH 1/2] bootsource: retire bootsource_set_alias_name Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-04-09 13:19 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

barebox currently /chosen properties like bootsource and earlycon,
although they can be useful in a second-stage boot scenario.

For example, on the STM32MP15, the TAMP register used to communicate
boot source from the BootROM is also used to override the reboot mode
prior to a warm reboot. As reboot modes are automatically cleared after
readout, this means that a chainloaded barebox will not be able to
determine the bootsource if the reboot mode driver is enabled.

To address this limitation, teach barebox to consume /chosen/bootsource.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/Kconfig       | 17 +++++++++++++++++
 common/bootsource.c  | 28 ++++++++++++++++++++++++++++
 drivers/of/base.c    | 21 +++++++++++++++++++--
 include/bootsource.h |  1 +
 4 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 8134e13bbeb2..1e04d0403ad0 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1210,6 +1210,23 @@ config BOOT_DEFAULTS
 	  target, which will expand to the device that barebox has
 	  booted from if that could be determined.
 
+config BAREBOX_DT_2ND
+	bool "Consume DT bindings relevant only when barebox is booted by barebox"
+	depends on OFDEVICE
+	default BOARD_GENERIC_DT
+	help
+	  Barebox fixes up a number of device tree properties into the kernel
+	  device tree that it does not itself consume.
+	  Say y here for barebox to not only provide, but also consume
+	  these device tree bindings.
+
+	  This is currently:
+
+	    /chosen/bootsource: Maintain the bootsource, even if SoC
+	    bootsource info is lost.
+
+	  If unsure, say n.
+
 config RESET_SOURCE
 	bool "detect Reset cause"
 	depends on GLOBALVAR
diff --git a/common/bootsource.c b/common/bootsource.c
index 14e6565e3789..f608019bb758 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -9,6 +9,7 @@
 #include <bootsource.h>
 #include <environment.h>
 #include <magicvar.h>
+#include <string.h>
 #include <init.h>
 
 static const char *bootsource_str[BOOTSOURCE_MAX] = {
@@ -153,6 +154,33 @@ void bootsource_set_raw_instance(int instance)
 		pr_setenv("bootsource_instance", "%d", instance);
 }
 
+int bootsource_of_node_set(struct device_node *np)
+{
+	const char *alias;
+
+	alias = of_alias_get(np);
+	if (!alias)
+		return -EINVAL;
+
+	for (int bootsrc = 0; bootsrc < ARRAY_SIZE(bootsource_str); bootsrc++) {
+		int ret, instance;
+		size_t prefixlen;
+
+		prefixlen = str_has_prefix(alias, bootsource_str[bootsrc]);
+		if (!prefixlen)
+			continue;
+
+		ret = kstrtoint(alias + prefixlen, 10, &instance);
+		if (ret)
+			return ret;
+
+		bootsource_set_raw(bootsrc, instance);
+		return 0;
+	}
+
+	return -ENODEV;
+}
+
 int bootsource_of_alias_xlate(enum bootsource src, int instance)
 {
 	char chosen[sizeof("barebox,bootsource-harddisk4294967295")];
diff --git a/drivers/of/base.c b/drivers/of/base.c
index dfe4861c9eb6..324565068771 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -14,6 +14,7 @@
 #include <malloc.h>
 #include <init.h>
 #include <memory.h>
+#include <bootsource.h>
 #include <linux/sizes.h>
 #include <of_graph.h>
 #include <string.h>
@@ -3591,13 +3592,29 @@ const char *of_get_machine_compatible(void)
 }
 EXPORT_SYMBOL(of_get_machine_compatible);
 
-static int of_init_hostname(void)
+static void of_init_bootsource(void)
+{
+	struct device_node *bootsource;
+
+	if (!IS_ENABLED(CONFIG_BAREBOX_DT_2ND))
+		return;
+
+	bootsource = of_find_node_by_chosen("bootsource", NULL);
+	if (!bootsource)
+		return;
+
+	bootsource_of_node_set(bootsource);
+}
+
+static int of_init_vars(void)
 {
 	const char *name;
 
 	name = of_get_machine_compatible();
 	barebox_set_hostname_no_overwrite(name ?: "barebox");
 
+	of_init_bootsource();
+
 	return 0;
 }
-late_initcall(of_init_hostname);
+late_initcall(of_init_vars);
diff --git a/include/bootsource.h b/include/bootsource.h
index 1b3df84f4ddb..ce0c92d0fef9 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -33,6 +33,7 @@ const char *bootsource_to_string(enum bootsource src);
 const char *bootsource_get_alias_stem(enum bootsource bs);
 int bootsource_of_alias_xlate(enum bootsource bs, int instance);
 struct device_node *bootsource_of_node_get(struct device_node *root);
+int bootsource_of_node_set(struct device_node *np);
 struct cdev *bootsource_of_cdev_find(void);
 
 /**
-- 
2.39.5




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

* Re: [PATCH 1/2] bootsource: retire bootsource_set_alias_name
  2025-04-09 13:19 [PATCH 1/2] bootsource: retire bootsource_set_alias_name Ahmad Fatoum
  2025-04-09 13:19 ` [PATCH 2/2] bootsource: add optional read of /chosen/bootsource Ahmad Fatoum
@ 2025-04-10  6:34 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-04-10  6:34 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Wed, 09 Apr 2025 15:19:25 +0200, Ahmad Fatoum wrote:
> This function was never used in upstream board code since it was
> introduced, so drop it.
> 
> This avoids it interfering with the addition of bootsource_of_node_set
> in the follow-up commit.
> 
> 
> [...]

Applied, thanks!

[1/2] bootsource: retire bootsource_set_alias_name
      https://git.pengutronix.de/cgit/barebox/commit/?id=7e664e579c88 (link may not be stable)
[2/2] bootsource: add optional read of /chosen/bootsource
      https://git.pengutronix.de/cgit/barebox/commit/?id=a3278b10dffb (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2025-04-10  6:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-09 13:19 [PATCH 1/2] bootsource: retire bootsource_set_alias_name Ahmad Fatoum
2025-04-09 13:19 ` [PATCH 2/2] bootsource: add optional read of /chosen/bootsource Ahmad Fatoum
2025-04-10  6:34 ` [PATCH 1/2] bootsource: retire bootsource_set_alias_name Sascha Hauer

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