summaryrefslogtreecommitdiffstats
path: root/include/blspec.h
blob: aced246e852bc0a809a25447c9084c3fc891dc5c (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
93
94
95
#ifndef __LOADER_H__
#define __LOADER_H__

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

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

struct bootentry {
	struct list_head list;
	struct menu_entry me;
};

struct blspec_entry {
	struct bootentry entry;

	struct device_node *node;
	struct cdev *cdev;
	char *rootpath;
	char *configpath;

	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_boot(struct bootentry *entry, int verbose, int dryrun);

int blspec_scan_devices(struct bootentries *bootentries);

int blspec_scan_device(struct bootentries *bootentries, struct device_d *dev);
int blspec_scan_devicename(struct bootentries *bootentries, const char *devname);
int blspec_scan_directory(struct bootentries *bootentries, const char *root);

#define bootentries_for_each_entry(bootentries, entry) \
	list_for_each_entry(entry, &bootentries->entries, list)

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

	entry = xzalloc(sizeof(*entry));

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

	list_add_tail(&entry->entry.list, &bootentries->entries);

	return entry;
}

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

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

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

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

	return bootentries;
}

static inline void blspec_free(struct bootentries *bootentries)
{
	struct bootentry *be, *tmp;
	struct blspec_entry *entry;

	list_for_each_entry_safe(be, tmp, &bootentries->entries, list) {
		entry = container_of(be, struct blspec_entry, entry);
		blspec_entry_free(entry);
	}
	if (bootentries->menu)
		free(bootentries->menu->display);
	free(bootentries->menu);
	free(bootentries);
}

#endif /* __LOADER_H__ */