8 #include "talloc/talloc.h"
9 #include "types/types.h"
10 #include "parser-conf.h"
11 #include "parser-utils.h"
16 const char *const *known_names;
18 /* current option data */
19 struct discover_boot_option *opt;
21 const char *partition;
22 const char *boot_image;
24 const char *initrd_size;
32 static struct discover_boot_option *state_start_new_option(
33 struct conf_context *conf,
34 struct yaboot_state *state)
36 state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
37 state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
39 /* old allocated values will get freed with the state */
40 state->device = conf_get_global_option(conf, "device");
41 state->partition = conf_get_global_option(conf, "partition");
42 state->initrd_size = conf_get_global_option(conf, "initrd_size");
43 state->literal = conf_get_global_option(conf, "literal");
44 state->ramdisk = conf_get_global_option(conf, "ramdisk");
45 state->root = conf_get_global_option(conf, "root");
50 static struct resource *create_yaboot_devpath_resource(
51 struct yaboot_state *state,
52 struct conf_context *conf,
55 struct discover_boot_option *opt = state->opt;
56 const char *dev, *part;
61 part = state->partition;
64 dev = conf_get_global_option(conf, "device");
66 part = conf_get_global_option(conf, "partition");
68 if (strchr(path, ':')) {
69 devpath = talloc_strdup(conf, path);
71 } else if (dev && part) {
72 devpath = talloc_asprintf(conf,
73 "%s%s:%s", dev, part, path);
75 devpath = talloc_asprintf(conf, "%s:%s", dev, path);
77 devpath = talloc_strdup(conf, path);
80 res = create_devpath_resource(opt, conf->dc->device, devpath);
87 static void yaboot_finish(struct conf_context *conf)
89 struct yaboot_state *state = conf->parser_info;
90 struct boot_option *opt;
94 opt = state->opt->option;
97 assert(opt->boot_args);
99 /* populate the boot option from state data */
100 state->opt->boot_image = create_yaboot_devpath_resource(state,
101 conf, state->boot_image);
103 state->opt->initrd = create_yaboot_devpath_resource(state,
104 conf, state->initrd);
107 if (state->initrd_size) {
108 opt->boot_args = talloc_asprintf(opt, "ramdisk_size=%s %s",
109 state->initrd_size, opt->boot_args);
112 if (state->ramdisk) {
113 opt->boot_args = talloc_asprintf(opt, "ramdisk=%s %s",
114 state->initrd_size, opt->boot_args);
118 opt->boot_args = talloc_asprintf(opt, "root=%s %s",
119 state->root, opt->boot_args);
122 if (state->read_only && state->read_write) {
123 pb_log("boot option %s specified both 'ro' and 'rw', "
124 "using 'rw'\n", opt->name);
125 state->read_only = false;
128 if (state->read_only || state->read_write) {
129 opt->boot_args = talloc_asprintf(opt, "%s %s",
130 state->read_only ? "ro" : "rw",
134 if (state->literal) {
135 opt->boot_args = talloc_strdup(opt, state->literal);
138 opt->description = talloc_asprintf(opt, "%s %s %s",
140 (state->initrd ? state->initrd : ""),
141 opt->boot_args ? opt->boot_args : "");
143 conf_strip_str(opt->boot_args);
144 conf_strip_str(opt->description);
146 discover_context_add_boot_option(conf->dc, state->opt);
149 static void yaboot_process_pair(struct conf_context *conf, const char *name,
152 struct yaboot_state *state = conf->parser_info;
153 struct discover_boot_option *opt = state->opt;
158 static const struct fixed_pair suse_fp32 = {
159 .image = "/suseboot/vmlinux32",
160 .initrd = "/suseboot/initrd32",
162 static const struct fixed_pair suse_fp64 = {
163 .image = "/suseboot/vmlinux64",
164 .initrd = "/suseboot/initrd64",
166 const struct fixed_pair *suse_fp;
168 /* fixup for bare values */
173 if (!state->globals_done && conf_set_global_option(conf, name, value))
176 if (!conf_param_in_list(state->known_names, name))
179 state->globals_done = 1;
183 if (streq(name, "image")) {
185 /* First finish any previous image. */
189 /* Then start the new image. */
190 opt = state_start_new_option(conf, state);
192 state->boot_image = talloc_strdup(state, value);
197 /* Special processing for SUSE install CD. */
199 if (streq(name, "image[32bit]"))
200 suse_fp = &suse_fp32;
201 else if (streq(name, "image[64bit]"))
202 suse_fp = &suse_fp64;
207 /* First finish any previous image. */
211 /* Then start the new image. */
212 opt = state_start_new_option(conf, state);
215 state->boot_image = talloc_strdup(state, value);
217 state->boot_image = talloc_strdup(state,
219 state->initrd = talloc_strdup(state, suse_fp->initrd);
225 /* all other processing requires an image */
227 pb_log("%s: unknown name: %s\n", __func__, name);
232 if (streq(name, "initrd")) {
233 state->initrd = talloc_strdup(state, value);
238 if (streq(name, "label")) {
239 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
240 conf->dc->device->device->id, value);
241 opt->option->name = talloc_strdup(opt->option, value);
246 if (streq(name, "device")) {
247 printf("option device : %s", value);
248 state->device = talloc_strdup(state, value);
252 if (streq(name, "parititon")) {
253 state->partition = talloc_strdup(state, value);
257 if (streq(name, "append")) {
258 opt->option->boot_args = talloc_asprintf_append(
259 opt->option->boot_args, "%s ", value);
263 if (streq(name, "initrd-size")) {
264 state->initrd_size = talloc_strdup(state, value);
268 if (streq(name, "literal")) {
269 state->literal = talloc_strdup(state, value);
273 if (streq(name, "ramdisk")) {
274 state->ramdisk = talloc_strdup(state, value);
278 if (streq(name, "read-only")) {
279 state->read_only = true;
283 if (streq(name, "read-write")) {
284 state->read_write = true;
288 if (streq(name, "root")) {
289 state->root = talloc_strdup(state, value);
293 pb_log("%s: unknown name: %s\n", __func__, name);
296 static struct conf_global_option yaboot_global_options[] = {
298 { .name = "device" },
299 { .name = "partition" },
300 { .name = "initrd" },
301 { .name = "initrd_size" },
303 { .name = "literal" },
304 { .name = "ramdisk" },
308 static const char *const yaboot_conf_files[] = {
313 "/suseboot/yaboot.cnf",
318 "/SUSEBOOT/YABOOT.CNF",
322 static const char *yaboot_known_names[] = {
325 "image[64bit]", /* SUSE extension */
326 "image[32bit]", /* SUSE extension */
340 static int yaboot_parse(struct discover_context *dc, char *buf, int len)
342 struct conf_context *conf;
343 struct yaboot_state *state;
345 conf = talloc_zero(dc, struct conf_context);
351 conf->global_options = yaboot_global_options,
352 conf_init_global_options(conf);
353 conf->get_pair = conf_get_pair_equal;
354 conf->process_pair = yaboot_process_pair;
355 conf->finish = yaboot_finish;
356 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
358 state->known_names = yaboot_known_names;
362 conf_parse_buf(conf, buf, len);
368 static struct parser yaboot_parser = {
370 .method = CONF_METHOD_LOCAL_FILE,
371 .parse = yaboot_parse,
372 .filenames = yaboot_conf_files,
373 .resolve_resource = resolve_devpath_resource,
376 register_parser(yaboot_parser);