mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fixup! bootsource: add optional read of /chosen/bootsource
@ 2025-04-10 11:25 Ahmad Fatoum
  2025-04-11  7:13 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-04-10 11:25 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

bootsource: read out /chosen/bootsource earlier

While late initcall is early enough for shell scripts to see a correct
$bootsource, it's usually too late for board code.

As device trees are registered in core_initcall usually, let's parse the
property at postcore time instead.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/base.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 324565068771..8184b284099e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -3592,29 +3592,28 @@ const char *of_get_machine_compatible(void)
 }
 EXPORT_SYMBOL(of_get_machine_compatible);
 
-static void of_init_bootsource(void)
+static int of_init_early_vars(void)
 {
 	struct device_node *bootsource;
 
 	if (!IS_ENABLED(CONFIG_BAREBOX_DT_2ND))
-		return;
+		return 0;
 
 	bootsource = of_find_node_by_chosen("bootsource", NULL);
-	if (!bootsource)
-		return;
+	if (bootsource)
+		bootsource_of_node_set(bootsource);
 
-	bootsource_of_node_set(bootsource);
+	return 0;
 }
+postcore_initcall(of_init_early_vars);
 
-static int of_init_vars(void)
+static int of_init_late_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_vars);
+late_initcall(of_init_late_vars);
-- 
2.39.5




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

* Re: [PATCH] fixup! bootsource: add optional read of /chosen/bootsource
  2025-04-10 11:25 [PATCH] fixup! bootsource: add optional read of /chosen/bootsource Ahmad Fatoum
@ 2025-04-11  7:13 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-04-11  7:13 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Apr 10, 2025 at 01:25:30PM +0200, Ahmad Fatoum wrote:
> bootsource: read out /chosen/bootsource earlier
> 
> While late initcall is early enough for shell scripts to see a correct
> $bootsource, it's usually too late for board code.
> 
> As device trees are registered in core_initcall usually, let's parse the
> property at postcore time instead.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/of/base.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 324565068771..8184b284099e 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -3592,29 +3592,28 @@ const char *of_get_machine_compatible(void)
>  }
>  EXPORT_SYMBOL(of_get_machine_compatible);
>  
> -static void of_init_bootsource(void)
> +static int of_init_early_vars(void)
>  {
>  	struct device_node *bootsource;
>  
>  	if (!IS_ENABLED(CONFIG_BAREBOX_DT_2ND))
> -		return;
> +		return 0;
>  
>  	bootsource = of_find_node_by_chosen("bootsource", NULL);
> -	if (!bootsource)
> -		return;
> +	if (bootsource)
> +		bootsource_of_node_set(bootsource);
>  
> -	bootsource_of_node_set(bootsource);
> +	return 0;
>  }
> +postcore_initcall(of_init_early_vars);
>  
> -static int of_init_vars(void)
> +static int of_init_late_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_vars);
> +late_initcall(of_init_late_vars);
> -- 
> 2.39.5
> 
> 
> 

-- 
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] 2+ messages in thread

end of thread, other threads:[~2025-04-11  7:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-10 11:25 [PATCH] fixup! bootsource: add optional read of /chosen/bootsource Ahmad Fatoum
2025-04-11  7:13 ` Sascha Hauer

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