9 #include "talloc/talloc.h"
10 #include "types/types.h"
11 #include "parser-conf.h"
12 #include "parser-utils.h"
17 const char *const *known_names;
19 /* current option data */
20 struct discover_boot_option *opt;
22 const char *partition;
23 const char *boot_image;
25 const char *initrd_size;
33 static struct discover_boot_option *state_start_new_option(
34 struct conf_context *conf,
35 struct yaboot_state *state)
37 state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
38 state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
40 /* old allocated values will get freed with the state */
41 state->device = conf_get_global_option(conf, "device");
42 state->partition = conf_get_global_option(conf, "partition");
43 state->initrd_size = conf_get_global_option(conf, "initrd_size");
44 state->literal = conf_get_global_option(conf, "literal");
45 state->ramdisk = conf_get_global_option(conf, "ramdisk");
46 state->root = conf_get_global_option(conf, "root");
51 static struct resource *create_yaboot_devpath_resource(
52 struct yaboot_state *state,
53 struct conf_context *conf,
56 struct discover_boot_option *opt = state->opt;
57 const char *dev, *part, *devpos;
59 char *devpath, *devstr;
62 part = state->partition;
65 dev = conf_get_global_option(conf, "device");
67 part = conf_get_global_option(conf, "partition");
69 if (strchr(path, ':')) {
70 devpath = talloc_strdup(conf, path);
72 } else if (dev && part) {
73 devpos = &dev[strlen(dev) - 1];
74 if (isdigit(*devpos)) {
75 while (isdigit(*devpos))
78 devstr = talloc_strndup(conf, dev, devpos - dev + 1);
79 devpath = talloc_asprintf(conf, "%s%s:%s", devstr,
83 devpath = talloc_asprintf(conf,
84 "%s%s:%s", dev, part, path);
87 devpath = talloc_asprintf(conf, "%s:%s", dev, path);
89 devpath = talloc_strdup(conf, path);
92 res = create_devpath_resource(opt, conf->dc->device, devpath);
99 static void yaboot_finish(struct conf_context *conf)
101 struct yaboot_state *state = conf->parser_info;
102 const char *default_label;
103 struct boot_option *opt;
107 opt = state->opt->option;
110 assert(opt->boot_args);
112 /* populate the boot option from state data */
113 state->opt->boot_image = create_yaboot_devpath_resource(state,
114 conf, state->boot_image);
116 state->opt->initrd = create_yaboot_devpath_resource(state,
117 conf, state->initrd);
120 if (state->initrd_size) {
121 opt->boot_args = talloc_asprintf(opt, "ramdisk_size=%s %s",
122 state->initrd_size, opt->boot_args);
125 if (state->ramdisk) {
126 opt->boot_args = talloc_asprintf(opt, "ramdisk=%s %s",
127 state->initrd_size, opt->boot_args);
131 opt->boot_args = talloc_asprintf(opt, "root=%s %s",
132 state->root, opt->boot_args);
135 if (state->read_only && state->read_write) {
136 pb_log("boot option %s specified both 'ro' and 'rw', "
137 "using 'rw'\n", opt->name);
138 state->read_only = false;
141 if (state->read_only || state->read_write) {
142 opt->boot_args = talloc_asprintf(opt, "%s %s",
143 state->read_only ? "ro" : "rw",
147 if (state->literal) {
148 opt->boot_args = talloc_strdup(opt, state->literal);
151 opt->description = talloc_asprintf(opt, "%s %s %s",
153 (state->initrd ? state->initrd : ""),
154 opt->boot_args ? opt->boot_args : "");
156 conf_strip_str(opt->boot_args);
157 conf_strip_str(opt->description);
159 default_label = conf_get_global_option(conf, "default");
161 !strcasecmp(state->opt->option->name, default_label))
162 state->opt->option->is_default = true;
164 discover_context_add_boot_option(conf->dc, state->opt);
167 static void yaboot_process_pair(struct conf_context *conf, const char *name,
170 struct yaboot_state *state = conf->parser_info;
171 struct discover_boot_option *opt = state->opt;
176 static const struct fixed_pair suse_fp32 = {
177 .image = "/suseboot/vmlinux32",
178 .initrd = "/suseboot/initrd32",
180 static const struct fixed_pair suse_fp64 = {
181 .image = "/suseboot/vmlinux64",
182 .initrd = "/suseboot/initrd64",
184 const struct fixed_pair *suse_fp;
186 /* fixup for bare values */
191 if (!state->globals_done && conf_set_global_option(conf, name, value))
194 if (!conf_param_in_list(state->known_names, name))
197 state->globals_done = 1;
201 if (streq(name, "image")) {
203 /* First finish any previous image. */
207 /* Then start the new image. */
208 opt = state_start_new_option(conf, state);
210 state->boot_image = talloc_strdup(state, value);
215 /* Special processing for SUSE install CD. */
217 if (streq(name, "image[32bit]"))
218 suse_fp = &suse_fp32;
219 else if (streq(name, "image[64bit]"))
220 suse_fp = &suse_fp64;
225 /* First finish any previous image. */
229 /* Then start the new image. */
230 opt = state_start_new_option(conf, state);
233 state->boot_image = talloc_strdup(state, value);
235 state->boot_image = talloc_strdup(state,
237 state->initrd = talloc_strdup(state, suse_fp->initrd);
243 /* all other processing requires an image */
245 pb_log("%s: unknown name: %s\n", __func__, name);
250 if (streq(name, "initrd")) {
251 state->initrd = talloc_strdup(state, value);
256 if (streq(name, "label")) {
257 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
258 conf->dc->device->device->id, value);
259 opt->option->name = talloc_strdup(opt->option, value);
264 if (streq(name, "device")) {
265 printf("option device : %s", value);
266 state->device = talloc_strdup(state, value);
270 if (streq(name, "parititon")) {
271 state->partition = talloc_strdup(state, value);
275 if (streq(name, "append")) {
276 opt->option->boot_args = talloc_asprintf_append(
277 opt->option->boot_args, "%s ", value);
281 if (streq(name, "initrd-size")) {
282 state->initrd_size = talloc_strdup(state, value);
286 if (streq(name, "literal")) {
287 state->literal = talloc_strdup(state, value);
291 if (streq(name, "ramdisk")) {
292 state->ramdisk = talloc_strdup(state, value);
296 if (streq(name, "read-only")) {
297 state->read_only = true;
301 if (streq(name, "read-write")) {
302 state->read_write = true;
306 if (streq(name, "root")) {
307 state->root = talloc_strdup(state, value);
311 pb_log("%s: unknown name: %s\n", __func__, name);
314 static struct conf_global_option yaboot_global_options[] = {
316 { .name = "device" },
317 { .name = "partition" },
318 { .name = "initrd" },
319 { .name = "initrd_size" },
321 { .name = "literal" },
322 { .name = "ramdisk" },
323 { .name = "default" },
327 static const char *const yaboot_conf_files[] = {
332 "/suseboot/yaboot.cnf",
337 "/SUSEBOOT/YABOOT.CNF",
341 static const char *yaboot_known_names[] = {
344 "image[64bit]", /* SUSE extension */
345 "image[32bit]", /* SUSE extension */
359 static int yaboot_parse(struct discover_context *dc)
361 const char * const *filename;
362 struct yaboot_state *state;
363 struct conf_context *conf;
367 /* Support block device boot only at present */
371 conf = talloc_zero(dc, struct conf_context);
377 conf->global_options = yaboot_global_options,
378 conf_init_global_options(conf);
379 conf->get_pair = conf_get_pair_equal;
380 conf->process_pair = yaboot_process_pair;
381 conf->finish = yaboot_finish;
382 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
384 state->known_names = yaboot_known_names;
388 for (filename = yaboot_conf_files; *filename; filename++) {
389 rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
393 conf_parse_buf(conf, buf, len);
401 static struct parser yaboot_parser = {
403 .parse = yaboot_parse,
404 .resolve_resource = resolve_devpath_resource,
407 register_parser(yaboot_parser);