summaryrefslogtreecommitdiffstats
path: root/common/bootsource.c
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2013-04-03 10:12:13 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-04-04 10:54:27 +0200
commit5d8240619c62dee029eb3976d597175fe8dcefc3 (patch)
tree9638620d432db7377ed9ba616cc4f1c369dba9c4 /common/bootsource.c
parent54c3870f5426bab88f2f4ae456a9c88b996969ac (diff)
downloadbarebox-5d8240619c62dee029eb3976d597175fe8dcefc3.tar.gz
barebox-5d8240619c62dee029eb3976d597175fe8dcefc3.tar.xz
bootsource: add support for bootsource instance information
Add a C interface to set and get the bootsource instance: int bootsource_get_instance(void); void bootsource_set_instance(int instance); Also export the shell variable "bootsource_instance". Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/bootsource.c')
-rw-r--r--common/bootsource.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/common/bootsource.c b/common/bootsource.c
index 5f1d40c1d8..7367215a5f 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -34,6 +34,7 @@ static const char *bootsource_str[] = {
};
static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
+static int bootsource_instance = BOOTSOURCE_INSTANCE_UNKNOWN;
void bootsource_set(enum bootsource src)
{
@@ -45,6 +46,20 @@ void bootsource_set(enum bootsource src)
setenv("bootsource", bootsource_str[src]);
}
+void bootsource_set_instance(int instance)
+{
+ char buf[32];
+
+ bootsource_instance = instance;
+
+ if (instance < 0)
+ sprintf(buf, "unknown");
+ else
+ snprintf(buf, sizeof(buf), "%d", instance);
+
+ setenv("bootsource_instance", buf);
+}
+
enum bootsource bootsource_get(void)
{
return bootsource;
@@ -52,10 +67,19 @@ enum bootsource bootsource_get(void)
BAREBOX_MAGICVAR(bootsource, "The source barebox has been booted from");
+int bootsource_get_instance(void)
+{
+ return bootsource_instance;
+}
+
+BAREBOX_MAGICVAR(bootsource_instance, "The instance of the source barebox has been booted from");
+
static int bootsource_init(void)
{
bootsource_set(bootsource);
+ bootsource_set_instance(bootsource_instance);
export("bootsource");
+ export("bootsource_instance");
return 0;
}