1 #if defined(HAVE_CONFIG_H)
12 #include "talloc/talloc.h"
13 #include "types/types.h"
14 #include "parser-conf.h"
15 #include "parser-utils.h"
21 /* current option data */
22 struct discover_boot_option *opt;
24 const char *partition;
25 const char *boot_image;
27 const char *initrd_size;
35 static struct discover_boot_option *state_start_new_option(
36 struct conf_context *conf,
37 struct yaboot_state *state)
39 state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
40 state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
42 /* old allocated values will get freed with the state */
43 state->device = conf_get_global_option(conf, "device");
44 state->partition = conf_get_global_option(conf, "partition");
45 state->initrd_size = conf_get_global_option(conf, "initrd_size");
46 state->literal = conf_get_global_option(conf, "literal");
47 state->ramdisk = conf_get_global_option(conf, "ramdisk");
48 state->root = conf_get_global_option(conf, "root");
53 static struct resource *create_yaboot_devpath_resource(
54 struct yaboot_state *state,
55 struct conf_context *conf,
58 struct discover_boot_option *opt = state->opt;
59 const char *dev, *part, *devpos;
61 char *devpath, *devstr;
64 part = state->partition;
67 dev = conf_get_global_option(conf, "device");
69 part = conf_get_global_option(conf, "partition");
71 if (strchr(path, ':')) {
72 devpath = talloc_strdup(conf, path);
74 } else if (dev && part) {
75 devpos = &dev[strlen(dev) - 1];
76 if (isdigit(*devpos)) {
77 while (isdigit(*devpos))
80 devstr = talloc_strndup(conf, dev, devpos - dev + 1);
81 devpath = talloc_asprintf(conf, "%s%s:%s", devstr,
85 devpath = talloc_asprintf(conf,
86 "%s%s:%s", dev, part, path);
89 devpath = talloc_asprintf(conf, "%s:%s", dev, path);
91 devpath = talloc_strdup(conf, path);
94 res = create_devpath_resource(opt, conf->dc->device, devpath);
101 static void yaboot_finish(struct conf_context *conf)
103 struct yaboot_state *state = conf->parser_info;
104 const char *default_label;
105 struct boot_option *opt;
110 opt = state->opt->option;
113 assert(opt->boot_args);
115 /* populate the boot option from state data */
116 state->opt->boot_image = create_yaboot_devpath_resource(state,
117 conf, state->boot_image);
119 char* args_sigfile_default = talloc_asprintf(opt,
120 "%s.cmdline.sig", state->boot_image);
121 state->opt->args_sig_file = create_yaboot_devpath_resource(state,
122 conf, args_sigfile_default);
123 talloc_free(args_sigfile_default);
126 state->opt->initrd = create_yaboot_devpath_resource(state,
127 conf, state->initrd);
130 if (state->initrd_size) {
131 opt->boot_args = talloc_asprintf(opt, "ramdisk_size=%s %s",
132 state->initrd_size, opt->boot_args);
135 if (state->ramdisk) {
136 opt->boot_args = talloc_asprintf(opt, "ramdisk=%s %s",
137 state->initrd_size, opt->boot_args);
141 opt->boot_args = talloc_asprintf(opt, "root=%s %s",
142 state->root, opt->boot_args);
145 if (state->read_only && state->read_write) {
146 pb_log("boot option %s specified both 'ro' and 'rw', "
147 "using 'rw'\n", opt->name);
148 state->read_only = false;
151 if (state->read_only || state->read_write) {
152 opt->boot_args = talloc_asprintf(opt, "%s %s",
153 state->read_only ? "ro" : "rw",
157 if (state->literal) {
158 opt->boot_args = talloc_strdup(opt, state->literal);
161 opt->description = talloc_asprintf(opt, "%s %s %s",
163 (state->initrd ? state->initrd : ""),
164 opt->boot_args ? opt->boot_args : "");
166 conf_strip_str(opt->boot_args);
167 conf_strip_str(opt->description);
169 default_label = conf_get_global_option(conf, "default");
171 !strcasecmp(state->opt->option->name, default_label))
172 state->opt->option->is_default = true;
174 discover_context_add_boot_option(conf->dc, state->opt);
178 static void yaboot_process_pair(struct conf_context *conf, const char *name,
181 struct yaboot_state *state = conf->parser_info;
182 struct discover_boot_option *opt = state->opt;
187 static const struct fixed_pair suse_fp32 = {
188 .image = "/suseboot/vmlinux32",
189 .initrd = "/suseboot/initrd32",
191 static const struct fixed_pair suse_fp64 = {
192 .image = "/suseboot/vmlinux64",
193 .initrd = "/suseboot/initrd64",
195 const struct fixed_pair *suse_fp;
197 /* fixup for bare values */
202 if (!state->globals_done && conf_set_global_option(conf, name, value))
206 if (streq(name, "image")) {
207 /* an image section finishes our global defintions */
208 state->globals_done = 1;
210 /* First finish any previous image. */
214 /* Then start the new image. */
215 opt = state_start_new_option(conf, state);
217 pb_debug_fn("new opt is NULL\n");
219 state->boot_image = talloc_strdup(state, value);
224 /* Special processing for SUSE install CD. */
226 if (streq(name, "image[32bit]"))
227 suse_fp = &suse_fp32;
228 else if (streq(name, "image[64bit]"))
229 suse_fp = &suse_fp64;
234 /* First finish any previous image. */
238 /* Then start the new image. */
239 opt = state_start_new_option(conf, state);
241 pb_debug_fn("new opt is NULL\n");
244 state->boot_image = talloc_strdup(state, value);
246 state->boot_image = talloc_strdup(state,
248 state->initrd = talloc_strdup(state, suse_fp->initrd);
254 /* all other processing requires an image */
256 pb_debug("%s: unknown name: %s\n", __func__, name);
261 if (streq(name, "initrd")) {
262 state->initrd = talloc_strdup(state, value);
267 if (streq(name, "label")) {
268 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
269 conf->dc->device->device->id, value);
270 opt->option->name = talloc_strdup(opt->option, value);
275 if (streq(name, "device")) {
276 printf("option device : %s", value);
277 state->device = talloc_strdup(state, value);
281 if (streq(name, "parititon")) {
282 state->partition = talloc_strdup(state, value);
286 if (streq(name, "append")) {
287 opt->option->boot_args = talloc_asprintf_append(
288 opt->option->boot_args, "%s ", value);
292 if (streq(name, "initrd-size")) {
293 state->initrd_size = talloc_strdup(state, value);
297 if (streq(name, "literal")) {
298 state->literal = talloc_strdup(state, value);
302 if (streq(name, "ramdisk")) {
303 state->ramdisk = talloc_strdup(state, value);
307 if (streq(name, "read-only")) {
308 state->read_only = true;
312 if (streq(name, "read-write")) {
313 state->read_write = true;
317 if (streq(name, "root")) {
318 state->root = talloc_strdup(state, value);
322 pb_debug("%s: unknown name: %s\n", __func__, name);
325 static struct conf_global_option yaboot_global_options[] = {
327 { .name = "device" },
328 { .name = "partition" },
329 { .name = "initrd" },
330 { .name = "initrd_size" },
332 { .name = "literal" },
333 { .name = "ramdisk" },
334 { .name = "default" },
338 static const char *const yaboot_conf_files[] = {
345 "/suseboot/yaboot.cnf",
352 "/SUSEBOOT/YABOOT.CNF",
356 static int yaboot_parse(struct discover_context *dc)
358 const char * const *filename;
359 struct yaboot_state *state;
360 struct conf_context *conf;
364 /* Support block device boot only at present */
368 conf = talloc_zero(dc, struct conf_context);
374 conf->global_options = yaboot_global_options,
375 conf_init_global_options(conf);
376 conf->get_pair = conf_get_pair_equal;
377 conf->process_pair = yaboot_process_pair;
378 conf->finish = yaboot_finish;
379 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
383 for (filename = yaboot_conf_files; *filename; filename++) {
384 rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
388 conf_parse_buf(conf, buf, len);
389 device_handler_status_dev_info(dc->handler, dc->device,
390 _("Parsed yaboot configuration from %s"),
399 static struct parser yaboot_parser = {
401 .parse = yaboot_parse,
402 .resolve_resource = resolve_devpath_resource,
405 register_parser(yaboot_parser);