8 #include "talloc/talloc.h"
9 #include "types/types.h"
10 #include "parser-conf.h"
11 #include "parser-utils.h"
14 static void kboot_process_pair(struct conf_context *conf, const char *name,
17 const char *const *ignored_names = conf->parser_info;
18 struct discover_boot_option *d_opt;
19 struct boot_option *opt;
26 /* ignore bare values */
31 if (conf_param_in_list(ignored_names, name))
34 if (conf_set_global_option(conf, name, value))
37 /* opt must be associated with dc */
39 d_opt = talloc_zero(conf->dc, struct discover_boot_option);
40 d_opt->device = conf->dc->device;
41 opt = talloc_zero(d_opt, struct boot_option);
46 opt->id = talloc_asprintf(opt, "%s#%s", conf->dc->device->device->id,
48 opt->name = talloc_strdup(opt, name);
51 args = talloc_strdup(opt, "");
52 initrd = conf_get_global_option(conf, "initrd");
53 root = conf_get_global_option(conf, "root");
54 dtb = conf_get_global_option(conf, "dtb");
56 pos = strchr(value, ' ');
58 /* if there's no space, it's only a kernel image with no params */
65 char *cl_name, *cl_value;
67 pos = conf_get_pair_equal(conf, pos, &cl_name, &cl_value, ' ');
70 args = talloc_asprintf_append(args, "%s ", cl_value);
74 if (streq(cl_name, "initrd")) {
79 if (streq(cl_name, "root")) {
84 if (streq(cl_name, "dtb")) {
89 args = talloc_asprintf_append(args, "%s=%s ", cl_name,
94 d_opt->boot_image = create_devpath_resource(d_opt,
95 conf->dc->device, value);
98 opt->boot_args = talloc_asprintf(opt, "root=%s %s", root, args);
101 opt->boot_args = args;
103 opt->description = talloc_asprintf(opt, "%s %s", value,
107 d_opt->initrd = create_devpath_resource(d_opt,
108 conf->dc->device, initrd);
109 opt->description = talloc_asprintf_append(opt->description,
110 " initrd=%s", initrd);
114 d_opt->dtb = create_devpath_resource(d_opt,
115 conf->dc->device, dtb);
116 opt->description = talloc_asprintf_append(opt->description,
120 conf_strip_str(opt->boot_args);
121 conf_strip_str(opt->description);
123 discover_context_add_boot_option(conf->dc, d_opt);
126 static struct conf_global_option kboot_global_options[] = {
128 { .name = "initrd" },
134 static const char *const kboot_conf_files[] = {
146 static const char *const kboot_ignored_names[] = {
154 static int kboot_parse(struct discover_context *dc, char *buf, int len)
156 struct conf_context *conf;
158 conf = talloc_zero(dc, struct conf_context);
164 conf->global_options = kboot_global_options,
165 conf_init_global_options(conf);
166 conf->get_pair = conf_get_pair_equal;
167 conf->process_pair = kboot_process_pair;
168 conf->parser_info = (void *)kboot_ignored_names,
170 conf_parse_buf(conf, buf, len);
176 static struct parser kboot_parser = {
178 .method = CONF_METHOD_LOCAL_FILE,
179 .parse = kboot_parse,
180 .filenames = kboot_conf_files,
181 .resolve_resource = resolve_devpath_resource,
184 register_parser(kboot_parser);