mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] bootsource: export bootsource_to_string()
@ 2022-12-09  7:29 Ahmad Fatoum
  2022-12-09  7:46 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2022-12-09  7:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

bootsource_str which translates enum bootsource to a string is not
exported to other parts of barebox. Define a new bootsource_to_string()
that provides access. This can be useful for board code debugging
prints, especially in PBL, where the $bootsource environment variable
is not available.

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

diff --git a/common/Makefile b/common/Makefile
index 35f2120496ea..25f5653f906a 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -11,7 +11,7 @@ obj-y				+= startup.o
 obj-y				+= misc.o
 obj-pbl-y			+= memsize.o
 obj-y				+= resource.o
-obj-y				+= bootsource.o
+obj-pbl-y			+= bootsource.o
 obj-$(CONFIG_ELF)		+= elf.o
 obj-y				+= restart.o
 obj-y				+= poweroff.o
diff --git a/common/bootsource.c b/common/bootsource.c
index 70bac945de5a..66bddf2dacf4 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -10,7 +10,7 @@
 #include <magicvar.h>
 #include <init.h>
 
-static const char *bootsource_str[] = {
+static const char *bootsource_str[BOOTSOURCE_MAX] = {
 	[BOOTSOURCE_UNKNOWN] = "unknown",
 	[BOOTSOURCE_NAND] = "nand",
 	[BOOTSOURCE_NOR] = "nor",
@@ -33,6 +33,14 @@ 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)
+{
+	if (src >= ARRAY_SIZE(bootsource_str))
+		return NULL;
+
+	return bootsource_str[src];
+}
+
 const char *bootsource_get_alias_stem(enum bootsource src)
 {
 	switch (src) {
@@ -107,12 +115,12 @@ void bootsource_set_alias_name(const char *name)
 
 void bootsource_set_raw(enum bootsource src, int instance)
 {
-	if (src >= ARRAY_SIZE(bootsource_str))
+	if (src >= BOOTSOURCE_MAX)
 		src = BOOTSOURCE_UNKNOWN;
 
 	bootsource = src;
 
-	setenv("bootsource", bootsource_str[src]);
+	setenv("bootsource", bootsource_to_string(src));
 
 	bootsource_set_raw_instance(instance);
 }
diff --git a/include/bootsource.h b/include/bootsource.h
index 9ca4fcc525b5..381776a85a4c 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -20,6 +20,7 @@ enum bootsource {
 	BOOTSOURCE_NET,
 	BOOTSOURCE_CAN,
 	BOOTSOURCE_JTAG,
+	BOOTSOURCE_MAX,
 };
 
 #define BOOTSOURCE_INSTANCE_UNKNOWN	-1
@@ -28,6 +29,7 @@ enum bootsource bootsource_get(void);
 int bootsource_get_instance(void);
 void bootsource_set_alias_name(const char *name);
 char *bootsource_get_alias_name(void);
+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);
 
-- 
2.30.2




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

* Re: [PATCH] bootsource: export bootsource_to_string()
  2022-12-09  7:29 [PATCH] bootsource: export bootsource_to_string() Ahmad Fatoum
@ 2022-12-09  7:46 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-12-09  7:46 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Fri, Dec 09, 2022 at 08:29:00AM +0100, Ahmad Fatoum wrote:
> bootsource_str which translates enum bootsource to a string is not
> exported to other parts of barebox. Define a new bootsource_to_string()
> that provides access. This can be useful for board code debugging
> prints, especially in PBL, where the $bootsource environment variable
> is not available.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  common/Makefile      |  2 +-
>  common/bootsource.c  | 14 +++++++++++---
>  include/bootsource.h |  2 ++
>  3 files changed, 14 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/Makefile b/common/Makefile
> index 35f2120496ea..25f5653f906a 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -11,7 +11,7 @@ obj-y				+= startup.o
>  obj-y				+= misc.o
>  obj-pbl-y			+= memsize.o
>  obj-y				+= resource.o
> -obj-y				+= bootsource.o
> +obj-pbl-y			+= bootsource.o
>  obj-$(CONFIG_ELF)		+= elf.o
>  obj-y				+= restart.o
>  obj-y				+= poweroff.o
> diff --git a/common/bootsource.c b/common/bootsource.c
> index 70bac945de5a..66bddf2dacf4 100644
> --- a/common/bootsource.c
> +++ b/common/bootsource.c
> @@ -10,7 +10,7 @@
>  #include <magicvar.h>
>  #include <init.h>
>  
> -static const char *bootsource_str[] = {
> +static const char *bootsource_str[BOOTSOURCE_MAX] = {
>  	[BOOTSOURCE_UNKNOWN] = "unknown",
>  	[BOOTSOURCE_NAND] = "nand",
>  	[BOOTSOURCE_NOR] = "nor",
> @@ -33,6 +33,14 @@ 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)
> +{
> +	if (src >= ARRAY_SIZE(bootsource_str))
> +		return NULL;
> +
> +	return bootsource_str[src];
> +}
> +
>  const char *bootsource_get_alias_stem(enum bootsource src)
>  {
>  	switch (src) {
> @@ -107,12 +115,12 @@ void bootsource_set_alias_name(const char *name)
>  
>  void bootsource_set_raw(enum bootsource src, int instance)
>  {
> -	if (src >= ARRAY_SIZE(bootsource_str))
> +	if (src >= BOOTSOURCE_MAX)
>  		src = BOOTSOURCE_UNKNOWN;
>  
>  	bootsource = src;
>  
> -	setenv("bootsource", bootsource_str[src]);
> +	setenv("bootsource", bootsource_to_string(src));
>  
>  	bootsource_set_raw_instance(instance);
>  }
> diff --git a/include/bootsource.h b/include/bootsource.h
> index 9ca4fcc525b5..381776a85a4c 100644
> --- a/include/bootsource.h
> +++ b/include/bootsource.h
> @@ -20,6 +20,7 @@ enum bootsource {
>  	BOOTSOURCE_NET,
>  	BOOTSOURCE_CAN,
>  	BOOTSOURCE_JTAG,
> +	BOOTSOURCE_MAX,
>  };
>  
>  #define BOOTSOURCE_INSTANCE_UNKNOWN	-1
> @@ -28,6 +29,7 @@ enum bootsource bootsource_get(void);
>  int bootsource_get_instance(void);
>  void bootsource_set_alias_name(const char *name);
>  char *bootsource_get_alias_name(void);
> +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);
>  
> -- 
> 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] 2+ messages in thread

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-09  7:29 [PATCH] bootsource: export bootsource_to_string() Ahmad Fatoum
2022-12-09  7:46 ` Sascha Hauer

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