1 #if defined(HAVE_CONFIG_H)
11 #include "talloc/talloc.h"
12 #include "types/types.h"
13 #include "parser-conf.h"
14 #include "parser-utils.h"
20 /* current option data */
21 struct discover_boot_option *opt;
23 const char *partition;
24 const char *boot_image;
26 const char *initrd_size;
34 static struct discover_boot_option *state_start_new_option(
35 struct conf_context *conf,
36 struct yaboot_state *state)
38 state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
39 state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
41 /* old allocated values will get freed with the state */
42 state->device = conf_get_global_option(conf, "device");
43 state->partition = conf_get_global_option(conf, "partition");
44 state->initrd_size = conf_get_global_option(conf, "initrd_size");
45 state->literal = conf_get_global_option(conf, "literal");
46 state->ramdisk = conf_get_global_option(conf, "ramdisk");
47 state->root = conf_get_global_option(conf, "root");
52 static struct resource *create_yaboot_devpath_resource(
53 struct yaboot_state *state,
54 struct conf_context *conf,
57 struct discover_boot_option *opt = state->opt;
58 const char *dev, *part, *devpos;
60 char *devpath, *devstr;
63 part = state->partition;
66 dev = conf_get_global_option(conf, "device");
68 part = conf_get_global_option(conf, "partition");
70 if (strchr(path, ':')) {
71 devpath = talloc_strdup(conf, path);
73 } else if (dev && part) {
74 devpos = &dev[strlen(dev) - 1];
75 if (isdigit(*devpos)) {
76 while (isdigit(*devpos))
79 devstr = talloc_strndup(conf, dev, devpos - dev + 1);
80 devpath = talloc_asprintf(conf, "%s%s:%s", devstr,
84 devpath = talloc_asprintf(conf,
85 "%s%s:%s", dev, part, path);
88 devpath = talloc_asprintf(conf, "%s:%s", dev, path);
90 devpath = talloc_strdup(conf, path);
93 res = create_devpath_resource(opt, conf->dc->device, devpath);
100 static void yaboot_finish(struct conf_context *conf)
102 struct yaboot_state *state = conf->parser_info;
103 const char *default_label;
104 struct boot_option *opt;
109 opt = state->opt->option;
112 assert(opt->boot_args);
114 /* populate the boot option from state data */
115 state->opt->boot_image = create_yaboot_devpath_resource(state,
116 conf, state->boot_image);
118 state->opt->initrd = create_yaboot_devpath_resource(state,
119 conf, state->initrd);
122 if (state->initrd_size) {
123 opt->boot_args = talloc_asprintf(opt, "ramdisk_size=%s %s",
124 state->initrd_size, opt->boot_args);
127 if (state->ramdisk) {
128 opt->boot_args = talloc_asprintf(opt, "ramdisk=%s %s",
129 state->initrd_size, opt->boot_args);
133 opt->boot_args = talloc_asprintf(opt, "root=%s %s",
134 state->root, opt->boot_args);
137 if (state->read_only && state->read_write) {
138 pb_log("boot option %s specified both 'ro' and 'rw', "
139 "using 'rw'\n", opt->name);
140 state->read_only = false;
143 if (state->read_only || state->read_write) {
144 opt->boot_args = talloc_asprintf(opt, "%s %s",
145 state->read_only ? "ro" : "rw",
149 if (state->literal) {
150 opt->boot_args = talloc_strdup(opt, state->literal);
153 opt->description = talloc_asprintf(opt, "%s %s %s",
155 (state->initrd ? state->initrd : ""),
156 opt->boot_args ? opt->boot_args : "");
158 conf_strip_str(opt->boot_args);
159 conf_strip_str(opt->description);
161 default_label = conf_get_global_option(conf, "default");
163 !strcasecmp(state->opt->option->name, default_label))
164 state->opt->option->is_default = true;
166 discover_context_add_boot_option(conf->dc, state->opt);
169 static void yaboot_process_pair(struct conf_context *conf, const char *name,
172 struct yaboot_state *state = conf->parser_info;
173 struct discover_boot_option *opt = state->opt;
178 static const struct fixed_pair suse_fp32 = {
179 .image = "/suseboot/vmlinux32",
180 .initrd = "/suseboot/initrd32",
182 static const struct fixed_pair suse_fp64 = {
183 .image = "/suseboot/vmlinux64",
184 .initrd = "/suseboot/initrd64",
186 const struct fixed_pair *suse_fp;
188 /* fixup for bare values */
193 if (!state->globals_done && conf_set_global_option(conf, name, value))
197 if (streq(name, "image")) {
198 /* an image section finishes our global defintions */
199 state->globals_done = 1;
201 /* First finish any previous image. */
205 /* Then start the new image. */
206 opt = state_start_new_option(conf, state);
208 state->boot_image = talloc_strdup(state, value);
213 /* Special processing for SUSE install CD. */
215 if (streq(name, "image[32bit]"))
216 suse_fp = &suse_fp32;
217 else if (streq(name, "image[64bit]"))
218 suse_fp = &suse_fp64;
223 /* First finish any previous image. */
227 /* Then start the new image. */
228 opt = state_start_new_option(conf, state);
231 state->boot_image = talloc_strdup(state, value);
233 state->boot_image = talloc_strdup(state,
235 state->initrd = talloc_strdup(state, suse_fp->initrd);
241 /* all other processing requires an image */
243 pb_debug("%s: unknown name: %s\n", __func__, name);
248 if (streq(name, "initrd")) {
249 state->initrd = talloc_strdup(state, value);
254 if (streq(name, "label")) {
255 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
256 conf->dc->device->device->id, value);
257 opt->option->name = talloc_strdup(opt->option, value);
262 if (streq(name, "device")) {
263 printf("option device : %s", value);
264 state->device = talloc_strdup(state, value);
268 if (streq(name, "parititon")) {
269 state->partition = talloc_strdup(state, value);
273 if (streq(name, "append")) {
274 opt->option->boot_args = talloc_asprintf_append(
275 opt->option->boot_args, "%s ", value);
279 if (streq(name, "initrd-size")) {
280 state->initrd_size = talloc_strdup(state, value);
284 if (streq(name, "literal")) {
285 state->literal = talloc_strdup(state, value);
289 if (streq(name, "ramdisk")) {
290 state->ramdisk = talloc_strdup(state, value);
294 if (streq(name, "read-only")) {
295 state->read_only = true;
299 if (streq(name, "read-write")) {
300 state->read_write = true;
304 if (streq(name, "root")) {
305 state->root = talloc_strdup(state, value);
309 pb_debug("%s: unknown name: %s\n", __func__, name);
312 static struct conf_global_option yaboot_global_options[] = {
314 { .name = "device" },
315 { .name = "partition" },
316 { .name = "initrd" },
317 { .name = "initrd_size" },
319 { .name = "literal" },
320 { .name = "ramdisk" },
321 { .name = "default" },
325 static const char *const yaboot_conf_files[] = {
332 "/suseboot/yaboot.cnf",
339 "/SUSEBOOT/YABOOT.CNF",
343 static int yaboot_parse(struct discover_context *dc)
345 const char * const *filename;
346 struct yaboot_state *state;
347 struct conf_context *conf;
351 /* Support block device boot only at present */
355 conf = talloc_zero(dc, struct conf_context);
361 conf->global_options = yaboot_global_options,
362 conf_init_global_options(conf);
363 conf->get_pair = conf_get_pair_equal;
364 conf->process_pair = yaboot_process_pair;
365 conf->finish = yaboot_finish;
366 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
370 for (filename = yaboot_conf_files; *filename; filename++) {
371 rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
375 conf_parse_buf(conf, buf, len);
383 static struct parser yaboot_parser = {
385 .parse = yaboot_parse,
386 .resolve_resource = resolve_devpath_resource,
389 register_parser(yaboot_parser);