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;
108 opt = state->opt->option;
111 assert(opt->boot_args);
113 /* populate the boot option from state data */
114 state->opt->boot_image = create_yaboot_devpath_resource(state,
115 conf, state->boot_image);
117 state->opt->initrd = create_yaboot_devpath_resource(state,
118 conf, state->initrd);
121 if (state->initrd_size) {
122 opt->boot_args = talloc_asprintf(opt, "ramdisk_size=%s %s",
123 state->initrd_size, opt->boot_args);
126 if (state->ramdisk) {
127 opt->boot_args = talloc_asprintf(opt, "ramdisk=%s %s",
128 state->initrd_size, opt->boot_args);
132 opt->boot_args = talloc_asprintf(opt, "root=%s %s",
133 state->root, opt->boot_args);
136 if (state->read_only && state->read_write) {
137 pb_log("boot option %s specified both 'ro' and 'rw', "
138 "using 'rw'\n", opt->name);
139 state->read_only = false;
142 if (state->read_only || state->read_write) {
143 opt->boot_args = talloc_asprintf(opt, "%s %s",
144 state->read_only ? "ro" : "rw",
148 if (state->literal) {
149 opt->boot_args = talloc_strdup(opt, state->literal);
152 opt->description = talloc_asprintf(opt, "%s %s %s",
154 (state->initrd ? state->initrd : ""),
155 opt->boot_args ? opt->boot_args : "");
157 conf_strip_str(opt->boot_args);
158 conf_strip_str(opt->description);
160 default_label = conf_get_global_option(conf, "default");
162 !strcasecmp(state->opt->option->name, default_label))
163 state->opt->option->is_default = true;
165 discover_context_add_boot_option(conf->dc, state->opt);
168 static void yaboot_process_pair(struct conf_context *conf, const char *name,
171 struct yaboot_state *state = conf->parser_info;
172 struct discover_boot_option *opt = state->opt;
177 static const struct fixed_pair suse_fp32 = {
178 .image = "/suseboot/vmlinux32",
179 .initrd = "/suseboot/initrd32",
181 static const struct fixed_pair suse_fp64 = {
182 .image = "/suseboot/vmlinux64",
183 .initrd = "/suseboot/initrd64",
185 const struct fixed_pair *suse_fp;
187 /* fixup for bare values */
192 if (!state->globals_done && conf_set_global_option(conf, name, value))
195 if (!conf_param_in_list(state->known_names, name))
198 state->globals_done = 1;
202 if (streq(name, "image")) {
204 /* First finish any previous image. */
208 /* Then start the new image. */
209 opt = state_start_new_option(conf, state);
211 state->boot_image = talloc_strdup(state, value);
216 /* Special processing for SUSE install CD. */
218 if (streq(name, "image[32bit]"))
219 suse_fp = &suse_fp32;
220 else if (streq(name, "image[64bit]"))
221 suse_fp = &suse_fp64;
226 /* First finish any previous image. */
230 /* Then start the new image. */
231 opt = state_start_new_option(conf, state);
234 state->boot_image = talloc_strdup(state, value);
236 state->boot_image = talloc_strdup(state,
238 state->initrd = talloc_strdup(state, suse_fp->initrd);
244 /* all other processing requires an image */
246 pb_log("%s: unknown name: %s\n", __func__, name);
251 if (streq(name, "initrd")) {
252 state->initrd = talloc_strdup(state, value);
257 if (streq(name, "label")) {
258 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
259 conf->dc->device->device->id, value);
260 opt->option->name = talloc_strdup(opt->option, value);
265 if (streq(name, "device")) {
266 printf("option device : %s", value);
267 state->device = talloc_strdup(state, value);
271 if (streq(name, "parititon")) {
272 state->partition = talloc_strdup(state, value);
276 if (streq(name, "append")) {
277 opt->option->boot_args = talloc_asprintf_append(
278 opt->option->boot_args, "%s ", value);
282 if (streq(name, "initrd-size")) {
283 state->initrd_size = talloc_strdup(state, value);
287 if (streq(name, "literal")) {
288 state->literal = talloc_strdup(state, value);
292 if (streq(name, "ramdisk")) {
293 state->ramdisk = talloc_strdup(state, value);
297 if (streq(name, "read-only")) {
298 state->read_only = true;
302 if (streq(name, "read-write")) {
303 state->read_write = true;
307 if (streq(name, "root")) {
308 state->root = talloc_strdup(state, value);
312 pb_log("%s: unknown name: %s\n", __func__, name);
315 static struct conf_global_option yaboot_global_options[] = {
317 { .name = "device" },
318 { .name = "partition" },
319 { .name = "initrd" },
320 { .name = "initrd_size" },
322 { .name = "literal" },
323 { .name = "ramdisk" },
324 { .name = "default" },
328 static const char *const yaboot_conf_files[] = {
333 "/suseboot/yaboot.cnf",
338 "/SUSEBOOT/YABOOT.CNF",
342 static const char *yaboot_known_names[] = {
345 "image[64bit]", /* SUSE extension */
346 "image[32bit]", /* SUSE extension */
360 static int yaboot_parse(struct discover_context *dc)
362 const char * const *filename;
363 struct yaboot_state *state;
364 struct conf_context *conf;
368 /* Support block device boot only at present */
372 conf = talloc_zero(dc, struct conf_context);
378 conf->global_options = yaboot_global_options,
379 conf_init_global_options(conf);
380 conf->get_pair = conf_get_pair_equal;
381 conf->process_pair = yaboot_process_pair;
382 conf->finish = yaboot_finish;
383 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
385 state->known_names = yaboot_known_names;
389 for (filename = yaboot_conf_files; *filename; filename++) {
390 rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
394 conf_parse_buf(conf, buf, len);
402 static struct parser yaboot_parser = {
404 .parse = yaboot_parse,
405 .resolve_resource = resolve_devpath_resource,
408 register_parser(yaboot_parser);