summaryrefslogtreecommitdiffstats
path: root/include/blspec.h
blob: 8422e5b5986d58e70216e30914d557b40ee0d2e8 (plain)
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
#ifndef __LOADER_H__
#define __LOADER_H__

#include <linux/list.h>
#include <menu.h>

struct blspec {
	struct list_head entries;
	struct menu *menu;
};

struct blspec_entry {
	struct list_head list;
	struct device_node *node;
	struct cdev *cdev;
	char *rootpath;
	char *configpath;
	bool boot_default;
	bool boot_once;

	struct menu_entry me;

	char *scriptpath;
};

int blspec_entry_var_set(struct blspec_entry *entry, const char *name,
		const char *val);
const char *blspec_entry_var_get(struct blspec_entry *entry, const char *name);

int blspec_entry_save(struct blspec_entry *entry, const char *path);

int blspec_boot(struct blspec_entry *entry, int verbose, int dryrun);

int blspec_boot_hwdevice(const char *devname, int verbose, int dryrun);

void blspec_scan_devices(struct blspec *blspec);

struct blspec_entry *blspec_entry_default(struct blspec *l);
int blspec_scan_hwdevice(struct blspec *blspec, const char *devname);

#define blspec_for_each_entry(blspec, entry) \
	list_for_each_entry(entry, &blspec->entries, list)

static inline struct blspec_entry *blspec_entry_alloc(struct blspec *blspec)
{
	struct blspec_entry *entry;

	entry = xzalloc(sizeof(*entry));

	entry->node = of_new_node(NULL, NULL);

	list_add_tail(&entry->list, &blspec->entries);

	return entry;
}

static inline void blspec_entry_free(struct blspec_entry *entry)
{
	list_del(&entry->list);
	of_delete_node(entry->node);
	free(entry->me.display);
	free(entry->scriptpath);
	free(entry->configpath);
	free(entry->rootpath);
	free(entry);
}

static inline struct blspec *blspec_alloc(void)
{
	struct blspec *blspec;

	blspec = xzalloc(sizeof(*blspec));
	INIT_LIST_HEAD(&blspec->entries);

	if (IS_ENABLED(CONFIG_MENU))
		blspec->menu = menu_alloc();

	return blspec;
}

static inline void blspec_free(struct blspec *blspec)
{
	struct blspec_entry *entry, *tmp;

	list_for_each_entry_safe(entry, tmp, &blspec->entries, list)
		blspec_entry_free(entry);
	free(blspec->menu->display);
	free(blspec->menu);
	free(blspec);
}

#endif /* __LOADER_H__ */