From: Fabian Pfitzner <f.pfitzner@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: Fabian Pfitzner <f.pfitzner@pengutronix.de>
Subject: [PATCH 1/2] bootsource: add bootsource instance index variable
Date: Wed, 20 May 2026 10:32:59 +0200 [thread overview]
Message-ID: <20260520-fpf-bootsource-instance-index-v1-1-29942f0e8f2f@pengutronix.de> (raw)
In-Reply-To: <20260520-fpf-bootsource-instance-index-v1-0-29942f0e8f2f@pengutronix.de>
The bootsource instance index variable shows us,
from which image on the instance we have booted from.
This is a useful information, when there a multiple boot images contained
on one flash (e. g. primary and recovery).
Add a C interface to set and get the bootsource instance:
int bootsource_get_instance_index(void);
void bootsource_set_instance_index(int index);
Also export the shell variable "bootsource_instance_index".
Signed-off-by: Fabian Pfitzner <f.pfitzner@pengutronix.de>
---
Documentation/user/variables.rst | 1 +
common/bootsource.c | 20 ++++++++++++++++++++
include/bootsource.h | 11 +++++++++++
3 files changed, 32 insertions(+)
diff --git a/Documentation/user/variables.rst b/Documentation/user/variables.rst
index 61808f1d72de29477b02b53ad11ecf530b4ebc80..c8b34679068cff4356fec306942b85561187652f 100644
--- a/Documentation/user/variables.rst
+++ b/Documentation/user/variables.rst
@@ -112,6 +112,7 @@ of all active variables with special meaning along with a short description:
bootargs Linux Kernel parameters
bootsource The source barebox has been booted from
bootsource_instance The instance of the source barebox has been booted from
+ bootsource_instance_index Tells us whether we have booted from primary(0) or secondary(1)
global.boot.default default boot order
...
diff --git a/common/bootsource.c b/common/bootsource.c
index f608019bb758f820eea19213c75b389df6b4158c..53549d4171ff33bfcdd7436261cd8f4d3598099a 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -33,6 +33,7 @@ static const char *bootsource_str[BOOTSOURCE_MAX] = {
static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
static int bootsource_instance = BOOTSOURCE_INSTANCE_UNKNOWN;
+static int bootsource_instance_index = BOOTSOURCE_INSTANCE_INDEX_UNKNOWN;
const char *bootsource_to_string(enum bootsource src)
{
@@ -226,6 +227,17 @@ int bootsource_set(enum bootsource src, int instance)
return alias_id;
}
+void bootsource_set_instance_index(int index)
+{
+ if (index < 0 || index > 1)
+ pr_err("Invalid index: %d, expected either 0 or 1", index);
+
+ char str[1];
+
+ sprintf(str, "%d", index);
+ setenv("bootsource_instance_index", str);
+}
+
enum bootsource bootsource_get(void)
{
return bootsource;
@@ -240,11 +252,19 @@ int bootsource_get_instance(void)
BAREBOX_MAGICVAR(bootsource_instance, "The instance of the source barebox has been booted from");
+int bootsource_get_instance_index(void)
+{
+ return bootsource_instance_index;
+}
+
+BAREBOX_MAGICVAR(bootsource_instance_index, "Tells us whether we have booted from primary(0) or secondary(1)");
+
static int bootsource_init(void)
{
bootsource_set_raw(bootsource, bootsource_instance);
export("bootsource");
export("bootsource_instance");
+ export("bootsource_instance_index");
return 0;
}
diff --git a/include/bootsource.h b/include/bootsource.h
index 0d3cb7a333075305a6ae4ee24a66163fe2fa0360..fc53e2e345b87333120cb82b030b37a882e201c0 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -24,11 +24,13 @@ enum bootsource {
};
#define BOOTSOURCE_INSTANCE_UNKNOWN -1
+#define BOOTSOURCE_INSTANCE_INDEX_UNKNOWN -1
enum bootsource bootsource_get(void);
enum bootsource bootsource_get_device(void);
int bootsource_get_instance(void);
const char *bootsource_get_alias_name(void);
+int bootsource_get_instance_index(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);
@@ -72,4 +74,13 @@ void bootsource_set_raw(enum bootsource src, int instance);
*/
void bootsource_set_raw_instance(int instance);
+/**
+ * bootsource_set_instance_index - set bootsource_instance_index as-is
+ * @index: bootrom reported index
+ *
+ * Set the index that depicts the boot image we have booted from.
+ * This is either 0 (primary) or 1 (secondary)
+ */
+void bootsource_set_instance_index(int index);
+
#endif /* __BOOTSOURCE_H__ */
--
2.47.3
next prev parent reply other threads:[~2026-05-20 8:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 8:32 [PATCH 0/2] Implement recovery boot detection for SPI flash Fabian Pfitzner
2026-05-20 8:32 ` Fabian Pfitzner [this message]
2026-05-21 12:02 ` [PATCH 1/2] bootsource: add bootsource instance index variable Sascha Hauer
2026-05-20 8:33 ` [PATCH 2/2] arch: arm: imx: detect secondary boot Fabian Pfitzner
2026-05-21 12:27 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260520-fpf-bootsource-instance-index-v1-1-29942f0e8f2f@pengutronix.de \
--to=f.pfitzner@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox