[PATCH 1/2] bootsource: add bootsource instance index variable
Sascha Hauer
s.hauer at pengutronix.de
Thu May 21 05:02:13 PDT 2026
On 2026-05-20 10:32, Fabian Pfitzner wrote:
> 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 at 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);
The string is too small. You need another byte for the '\0'
Sascha
--
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 |
More information about the barebox
mailing list