Message ID | 20221209100549.153336-1-christian.storm@siemens.com |
---|---|
State | Accepted |
Headers | show |
Series | [v2,1/3] bootloader: Add is_bootloader() to distinguish bootloaders | expand |
Hi Christian, On 09.12.22 05:05, Christian Storm wrote: > Add bool is_bootloader(const char *name) to distinguish the > currently selected bootloader and add central bootloader > name #define's as well to the documentation to help in > maintaining the uniqueness of bootloader names. > > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > Resent v1. > > bootloader/ebg.c | 2 +- > bootloader/grub.c | 2 +- > bootloader/none.c | 2 +- > bootloader/uboot.c | 2 +- > core/bootloader.c | 7 +++++++ > doc/source/bootloader_interface.rst | 12 +++++++++++- > include/bootloader.h | 16 ++++++++++++++++ > 7 files changed, 38 insertions(+), 5 deletions(-) > > diff --git a/bootloader/ebg.c b/bootloader/ebg.c > index 00dc5c5..4194a38 100644 > --- a/bootloader/ebg.c > +++ b/bootloader/ebg.c > @@ -236,5 +236,5 @@ static bootloader* probe(void) > __attribute__((constructor)) > static void ebg_probe(void) > { > - (void)register_bootloader("ebg", probe()); > + (void)register_bootloader(BOOTLOADER_EBG, probe()); > } > diff --git a/bootloader/grub.c b/bootloader/grub.c > index 21bb6ac..7bda742 100644 > --- a/bootloader/grub.c > +++ b/bootloader/grub.c > @@ -353,5 +353,5 @@ static bootloader grub = { > __attribute__((constructor)) > static void grub_probe(void) > { > - (void)register_bootloader("grub", &grub); > + (void)register_bootloader(BOOTLOADER_GRUB, &grub); > } > diff --git a/bootloader/none.c b/bootloader/none.c > index d9d1c0b..d996da3 100644 > --- a/bootloader/none.c > +++ b/bootloader/none.c > @@ -54,5 +54,5 @@ static bootloader none = { > __attribute__((constructor)) > static void none_probe(void) > { > - (void)register_bootloader("none", &none); > + (void)register_bootloader(BOOTLOADER_NONE, &none); > } > diff --git a/bootloader/uboot.c b/bootloader/uboot.c > index ed4c516..2720b1e 100644 > --- a/bootloader/uboot.c > +++ b/bootloader/uboot.c > @@ -144,5 +144,5 @@ static bootloader* probe(void) > __attribute__((constructor)) > static void uboot_probe(void) > { > - (void)register_bootloader("uboot", probe()); > + (void)register_bootloader(BOOTLOADER_UBOOT, probe()); > } > diff --git a/core/bootloader.c b/core/bootloader.c > index b8678b8..c02b249 100644 > --- a/core/bootloader.c > +++ b/core/bootloader.c > @@ -55,6 +55,13 @@ int set_bootloader(const char *name) > return -ENOENT; > } > > +bool is_bootloader(const char *name) { > + if (!name || !current) { > + return false; > + } > + return strcmp(current->name, name) == 0; > +} > + > const char* get_bootloader(void) > { > return current ? current->name : NULL; > diff --git a/doc/source/bootloader_interface.rst b/doc/source/bootloader_interface.rst > index 9066c74..b8c0182 100644 > --- a/doc/source/bootloader_interface.rst > +++ b/doc/source/bootloader_interface.rst > @@ -82,9 +82,19 @@ registers this bootloader to SWUpdate at run-time: > __attribute__((constructor)) > static void trunk_probe(void) > { > - (void)register_bootloader("trunk", &trunk); > + (void)register_bootloader(BOOTLOADER_TRUNK, &trunk); > } > > +with > + > +.. code-block:: c > + > + #define BOOTLOADER_TRUNK "trunk" > + > +added to ``include/bootloader.h`` as a single central "trunk" bootloader > +name definition aiding in maintaining the uniqueness of bootloader names. > + > + > .. attention:: Take care to uniquely name the bootloader. > > > diff --git a/include/bootloader.h b/include/bootloader.h > index 8315759..529ec12 100644 > --- a/include/bootloader.h > +++ b/include/bootloader.h > @@ -6,6 +6,12 @@ > */ > > #pragma once > +#include <stdbool.h> > + > +#define BOOTLOADER_EBG "ebg" > +#define BOOTLOADER_NONE "none" > +#define BOOTLOADER_GRUB "grub" > +#define BOOTLOADER_UBOOT "uboot" > > #define load_symbol(handle, container, fname) \ > *(void**)(container) = dlsym(handle, fname); \ > @@ -50,6 +56,16 @@ int set_bootloader(const char *name); > */ > const char* get_bootloader(void); > > +/* > + * is_bootloader - Test whether bootloader is currently selected > + * > + * @name : bootloader name to check if it's the currently selected one > + * > + * Return: > + * true if name is currently selected bootloader, false otherwise > + */ > +bool is_bootloader(const char *name); > + > /* > * print_registered_bootloaders - print registered bootloaders > */ Applied to -master, thanks ! Best regards, Stefano Babic
diff --git a/bootloader/ebg.c b/bootloader/ebg.c index 00dc5c5..4194a38 100644 --- a/bootloader/ebg.c +++ b/bootloader/ebg.c @@ -236,5 +236,5 @@ static bootloader* probe(void) __attribute__((constructor)) static void ebg_probe(void) { - (void)register_bootloader("ebg", probe()); + (void)register_bootloader(BOOTLOADER_EBG, probe()); } diff --git a/bootloader/grub.c b/bootloader/grub.c index 21bb6ac..7bda742 100644 --- a/bootloader/grub.c +++ b/bootloader/grub.c @@ -353,5 +353,5 @@ static bootloader grub = { __attribute__((constructor)) static void grub_probe(void) { - (void)register_bootloader("grub", &grub); + (void)register_bootloader(BOOTLOADER_GRUB, &grub); } diff --git a/bootloader/none.c b/bootloader/none.c index d9d1c0b..d996da3 100644 --- a/bootloader/none.c +++ b/bootloader/none.c @@ -54,5 +54,5 @@ static bootloader none = { __attribute__((constructor)) static void none_probe(void) { - (void)register_bootloader("none", &none); + (void)register_bootloader(BOOTLOADER_NONE, &none); } diff --git a/bootloader/uboot.c b/bootloader/uboot.c index ed4c516..2720b1e 100644 --- a/bootloader/uboot.c +++ b/bootloader/uboot.c @@ -144,5 +144,5 @@ static bootloader* probe(void) __attribute__((constructor)) static void uboot_probe(void) { - (void)register_bootloader("uboot", probe()); + (void)register_bootloader(BOOTLOADER_UBOOT, probe()); } diff --git a/core/bootloader.c b/core/bootloader.c index b8678b8..c02b249 100644 --- a/core/bootloader.c +++ b/core/bootloader.c @@ -55,6 +55,13 @@ int set_bootloader(const char *name) return -ENOENT; } +bool is_bootloader(const char *name) { + if (!name || !current) { + return false; + } + return strcmp(current->name, name) == 0; +} + const char* get_bootloader(void) { return current ? current->name : NULL; diff --git a/doc/source/bootloader_interface.rst b/doc/source/bootloader_interface.rst index 9066c74..b8c0182 100644 --- a/doc/source/bootloader_interface.rst +++ b/doc/source/bootloader_interface.rst @@ -82,9 +82,19 @@ registers this bootloader to SWUpdate at run-time: __attribute__((constructor)) static void trunk_probe(void) { - (void)register_bootloader("trunk", &trunk); + (void)register_bootloader(BOOTLOADER_TRUNK, &trunk); } +with + +.. code-block:: c + + #define BOOTLOADER_TRUNK "trunk" + +added to ``include/bootloader.h`` as a single central "trunk" bootloader +name definition aiding in maintaining the uniqueness of bootloader names. + + .. attention:: Take care to uniquely name the bootloader. diff --git a/include/bootloader.h b/include/bootloader.h index 8315759..529ec12 100644 --- a/include/bootloader.h +++ b/include/bootloader.h @@ -6,6 +6,12 @@ */ #pragma once +#include <stdbool.h> + +#define BOOTLOADER_EBG "ebg" +#define BOOTLOADER_NONE "none" +#define BOOTLOADER_GRUB "grub" +#define BOOTLOADER_UBOOT "uboot" #define load_symbol(handle, container, fname) \ *(void**)(container) = dlsym(handle, fname); \ @@ -50,6 +56,16 @@ int set_bootloader(const char *name); */ const char* get_bootloader(void); +/* + * is_bootloader - Test whether bootloader is currently selected + * + * @name : bootloader name to check if it's the currently selected one + * + * Return: + * true if name is currently selected bootloader, false otherwise + */ +bool is_bootloader(const char *name); + /* * print_registered_bootloaders - print registered bootloaders */
Add bool is_bootloader(const char *name) to distinguish the currently selected bootloader and add central bootloader name #define's as well to the documentation to help in maintaining the uniqueness of bootloader names. Signed-off-by: Christian Storm <christian.storm@siemens.com> --- Resent v1. bootloader/ebg.c | 2 +- bootloader/grub.c | 2 +- bootloader/none.c | 2 +- bootloader/uboot.c | 2 +- core/bootloader.c | 7 +++++++ doc/source/bootloader_interface.rst | 12 +++++++++++- include/bootloader.h | 16 ++++++++++++++++ 7 files changed, 38 insertions(+), 5 deletions(-)