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 const char *default_label;
91 struct boot_option *opt;
95 opt = state->opt->option;
98 assert(opt->boot_args);
100 /* populate the boot option from state data */
101 state->opt->boot_image = create_yaboot_devpath_resource(state,
102 conf, state->boot_image);
104 state->opt->initrd = create_yaboot_devpath_resource(state,
105 conf, state->initrd);
108 if (state->initrd_size) {
109 opt->boot_args = talloc_asprintf(opt, "ramdisk_size=%s %s",
110 state->initrd_size, opt->boot_args);
113 if (state->ramdisk) {
114 opt->boot_args = talloc_asprintf(opt, "ramdisk=%s %s",
115 state->initrd_size, opt->boot_args);
119 opt->boot_args = talloc_asprintf(opt, "root=%s %s",
120 state->root, opt->boot_args);
123 if (state->read_only && state->read_write) {
124 pb_log("boot option %s specified both 'ro' and 'rw', "
125 "using 'rw'\n", opt->name);
126 state->read_only = false;
129 if (state->read_only || state->read_write) {
130 opt->boot_args = talloc_asprintf(opt, "%s %s",
131 state->read_only ? "ro" : "rw",
135 if (state->literal) {
136 opt->boot_args = talloc_strdup(opt, state->literal);
139 opt->description = talloc_asprintf(opt, "%s %s %s",
141 (state->initrd ? state->initrd : ""),
142 opt->boot_args ? opt->boot_args : "");
144 conf_strip_str(opt->boot_args);
145 conf_strip_str(opt->description);
147 default_label = conf_get_global_option(conf, "default");
149 !strcasecmp(state->opt->option->name, default_label))
150 state->opt->option->is_default = true;
152 discover_context_add_boot_option(conf->dc, state->opt);
155 static void yaboot_process_pair(struct conf_context *conf, const char *name,
158 struct yaboot_state *state = conf->parser_info;
159 struct discover_boot_option *opt = state->opt;
164 static const struct fixed_pair suse_fp32 = {
165 .image = "/suseboot/vmlinux32",
166 .initrd = "/suseboot/initrd32",
168 static const struct fixed_pair suse_fp64 = {
169 .image = "/suseboot/vmlinux64",
170 .initrd = "/suseboot/initrd64",
172 const struct fixed_pair *suse_fp;
174 /* fixup for bare values */
179 if (!state->globals_done && conf_set_global_option(conf, name, value))
182 if (!conf_param_in_list(state->known_names, name))
185 state->globals_done = 1;
189 if (streq(name, "image")) {
191 /* First finish any previous image. */
195 /* Then start the new image. */
196 opt = state_start_new_option(conf, state);
198 state->boot_image = talloc_strdup(state, value);
203 /* Special processing for SUSE install CD. */
205 if (streq(name, "image[32bit]"))
206 suse_fp = &suse_fp32;
207 else if (streq(name, "image[64bit]"))
208 suse_fp = &suse_fp64;
213 /* First finish any previous image. */
217 /* Then start the new image. */
218 opt = state_start_new_option(conf, state);
221 state->boot_image = talloc_strdup(state, value);
223 state->boot_image = talloc_strdup(state,
225 state->initrd = talloc_strdup(state, suse_fp->initrd);
231 /* all other processing requires an image */
233 pb_log("%s: unknown name: %s\n", __func__, name);
238 if (streq(name, "initrd")) {
239 state->initrd = talloc_strdup(state, value);
244 if (streq(name, "label")) {
245 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
246 conf->dc->device->device->id, value);
247 opt->option->name = talloc_strdup(opt->option, value);
252 if (streq(name, "device")) {
253 printf("option device : %s", value);
254 state->device = talloc_strdup(state, value);
258 if (streq(name, "parititon")) {
259 state->partition = talloc_strdup(state, value);
263 if (streq(name, "append")) {
264 opt->option->boot_args = talloc_asprintf_append(
265 opt->option->boot_args, "%s ", value);
269 if (streq(name, "initrd-size")) {
270 state->initrd_size = talloc_strdup(state, value);
274 if (streq(name, "literal")) {
275 state->literal = talloc_strdup(state, value);
279 if (streq(name, "ramdisk")) {
280 state->ramdisk = talloc_strdup(state, value);
284 if (streq(name, "read-only")) {
285 state->read_only = true;
289 if (streq(name, "read-write")) {
290 state->read_write = true;
294 if (streq(name, "root")) {
295 state->root = talloc_strdup(state, value);
299 pb_log("%s: unknown name: %s\n", __func__, name);
302 static struct conf_global_option yaboot_global_options[] = {
304 { .name = "device" },
305 { .name = "partition" },
306 { .name = "initrd" },
307 { .name = "initrd_size" },
309 { .name = "literal" },
310 { .name = "ramdisk" },
311 { .name = "default" },
315 static const char *const yaboot_conf_files[] = {
320 "/suseboot/yaboot.cnf",
325 "/SUSEBOOT/YABOOT.CNF",
329 static const char *yaboot_known_names[] = {
332 "image[64bit]", /* SUSE extension */
333 "image[32bit]", /* SUSE extension */
347 static int yaboot_parse(struct discover_context *dc, char *buf, int len)
349 struct conf_context *conf;
350 struct yaboot_state *state;
352 conf = talloc_zero(dc, struct conf_context);
358 conf->global_options = yaboot_global_options,
359 conf_init_global_options(conf);
360 conf->get_pair = conf_get_pair_equal;
361 conf->process_pair = yaboot_process_pair;
362 conf->finish = yaboot_finish;
363 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
365 state->known_names = yaboot_known_names;
369 conf_parse_buf(conf, buf, len);
375 static struct parser yaboot_parser = {
377 .method = CONF_METHOD_LOCAL_FILE,
378 .parse = yaboot_parse,
379 .filenames = yaboot_conf_files,
380 .resolve_resource = resolve_devpath_resource,
383 register_parser(yaboot_parser);