@@ -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());
}
@@ -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);
}
@@ -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);
}
@@ -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());
}
@@ -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;
@@ -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.
@@ -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> --- 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(-)