File: bootloader.h

package info (click to toggle)
swupdate 2025.12%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,004 kB
  • sloc: ansic: 66,621; python: 6,291; makefile: 791; sh: 538; javascript: 229
file content (117 lines) | stat: -rw-r--r-- 2,401 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * (C) Copyright 2017
 * Stefano Babic <stefano.babic@swupdate.org>
 *
 * SPDX-License-Identifier:     GPL-2.0-only
 */

#pragma once
#include <stdbool.h>

#define BOOTLOADER_EBG   "ebg"
#define BOOTLOADER_NONE  "none"
#define BOOTLOADER_GRUB  "grub"
#define BOOTLOADER_UBOOT "uboot"
#define BOOTLOADER_CBOOT "cboot"

#define load_symbol(handle, container, fname) \
	*(void**)(container) = dlsym(handle, fname); \
	if (dlerror() != NULL) { \
		(void)dlclose(handle); \
		return NULL; \
	}

typedef struct {
	int (*env_set)(const char *, const char *);
	int (*env_unset)(const char *);
	char* (*env_get)(const char *);
	int (*apply_list)(const char *);
} bootloader;

/*
 * register_bootloader - register bootloader.
 *
 * @name : bootloader's name to register.
 * @bootloader : struct bootloader with bootloader details.
 *
 * Return:
 *   0 on success, -ENOMEM on error.
 */
int register_bootloader(const char *name, bootloader *bl);

/*
 * set_bootloader - set bootloader to use.
 *
 * @name : bootloader's name to set.
 *
 * Return:
 *   0 on success, -ENOENT on error.
 */
int set_bootloader(const char *name);

/*
 * get_bootloader - get set bootloader's name
 *
 * Return:
 *   name on success, NULL on error.
 */
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
 */
void print_registered_bootloaders(void);


/*
 * bootloader_env_set - modify a variable
 *
 * @name : variable
 * @value : value to be set
 *
 * Return:
 *   0 on success
 */
extern int (*bootloader_env_set)(const char *, const char *);

/*
 * bootloader_env_unset - drop a variable
 *
 * @name : variable
 *
 * Return:
 *   0 on success
 */
extern int (*bootloader_env_unset)(const char *);

/*
 * bootloader_env_get - get value of a variable
 *
 * @name : variable
 *
 * Return:
 *   string if variable is found
 *   NULL if no variable with name is found
 */
extern char* (*bootloader_env_get)(const char *);

/*
 * bootloader_apply_list - set multiple variables
 *
 * @filename : file in format <variable>=<value>
 *
 * Return:
 *   0 on success
 */
extern int (*bootloader_apply_list)(const char *);