diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-12-09 08:29:00 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-12-09 08:46:35 +0100 |
commit | 2ace85e0ef891874c808322c249615a460c0cd38 (patch) | |
tree | f1abb67274588e4983e6684065cb1195970a760c /common | |
parent | 4fca6dbea1fa79b853c41a4d503d29778cbe6490 (diff) | |
download | barebox-2ace85e0ef891874c808322c249615a460c0cd38.tar.gz barebox-2ace85e0ef891874c808322c249615a460c0cd38.tar.xz |
bootsource: export bootsource_to_string()
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>
Link: https://lore.barebox.org/20221209072900.3769403-1-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/Makefile | 2 | ||||
-rw-r--r-- | common/bootsource.c | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/common/Makefile b/common/Makefile index 35f2120496..25f5653f90 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 70bac945de..66bddf2dac 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); } |