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 char* args_sigfile_default = talloc_asprintf(opt,
119 "%s.cmdline.sig", state->boot_image);
120 state->opt->args_sig_file = create_yaboot_devpath_resource(state,
121 conf, args_sigfile_default);
122 talloc_free(args_sigfile_default);
125 state->opt->initrd = create_yaboot_devpath_resource(state,
126 conf, state->initrd);
129 if (state->initrd_size) {
130 opt->boot_args = talloc_asprintf(opt, "ramdisk_size=%s %s",
131 state->initrd_size, opt->boot_args);
134 if (state->ramdisk) {
135 opt->boot_args = talloc_asprintf(opt, "ramdisk=%s %s",
136 state->initrd_size, opt->boot_args);
140 opt->boot_args = talloc_asprintf(opt, "root=%s %s",
141 state->root, opt->boot_args);
144 if (state->read_only && state->read_write) {
145 pb_log("boot option %s specified both 'ro' and 'rw', "
146 "using 'rw'\n", opt->name);
147 state->read_only = false;
150 if (state->read_only || state->read_write) {
151 opt->boot_args = talloc_asprintf(opt, "%s %s",
152 state->read_only ? "ro" : "rw",
156 if (state->literal) {
157 opt->boot_args = talloc_strdup(opt, state->literal);
160 opt->description = talloc_asprintf(opt, "%s %s %s",
162 (state->initrd ? state->initrd : ""),
163 opt->boot_args ? opt->boot_args : "");
165 conf_strip_str(opt->boot_args);
166 conf_strip_str(opt->description);
168 default_label = conf_get_global_option(conf, "default");
170 !strcasecmp(state->opt->option->name, default_label))
171 state->opt->option->is_default = true;
173 discover_context_add_boot_option(conf->dc, state->opt);
176 static void yaboot_process_pair(struct conf_context *conf, const char *name,
179 struct yaboot_state *state = conf->parser_info;
180 struct discover_boot_option *opt = state->opt;
185 static const struct fixed_pair suse_fp32 = {
186 .image = "/suseboot/vmlinux32",
187 .initrd = "/suseboot/initrd32",
189 static const struct fixed_pair suse_fp64 = {
190 .image = "/suseboot/vmlinux64",
191 .initrd = "/suseboot/initrd64",
193 const struct fixed_pair *suse_fp;
195 /* fixup for bare values */
200 if (!state->globals_done && conf_set_global_option(conf, name, value))
204 if (streq(name, "image")) {
205 /* an image section finishes our global defintions */
206 state->globals_done = 1;
208 /* First finish any previous image. */
212 /* Then start the new image. */
213 opt = state_start_new_option(conf, state);
215 state->boot_image = talloc_strdup(state, value);
220 /* Special processing for SUSE install CD. */
222 if (streq(name, "image[32bit]"))
223 suse_fp = &suse_fp32;
224 else if (streq(name, "image[64bit]"))
225 suse_fp = &suse_fp64;
230 /* First finish any previous image. */
234 /* Then start the new image. */
235 opt = state_start_new_option(conf, state);
238 state->boot_image = talloc_strdup(state, value);
240 state->boot_image = talloc_strdup(state,
242 state->initrd = talloc_strdup(state, suse_fp->initrd);
248 /* all other processing requires an image */
250 pb_debug("%s: unknown name: %s\n", __func__, name);
255 if (streq(name, "initrd")) {
256 state->initrd = talloc_strdup(state, value);
261 if (streq(name, "label")) {
262 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
263 conf->dc->device->device->id, value);
264 opt->option->name = talloc_strdup(opt->option, value);
269 if (streq(name, "device")) {
270 printf("option device : %s", value);
271 state->device = talloc_strdup(state, value);
275 if (streq(name, "parititon")) {
276 state->partition = talloc_strdup(state, value);
280 if (streq(name, "append")) {
281 opt->option->boot_args = talloc_asprintf_append(
282 opt->option->boot_args, "%s ", value);
286 if (streq(name, "initrd-size")) {
287 state->initrd_size = talloc_strdup(state, value);
291 if (streq(name, "literal")) {
292 state->literal = talloc_strdup(state, value);
296 if (streq(name, "ramdisk")) {
297 state->ramdisk = talloc_strdup(state, value);
301 if (streq(name, "read-only")) {
302 state->read_only = true;
306 if (streq(name, "read-write")) {
307 state->read_write = true;
311 if (streq(name, "root")) {
312 state->root = talloc_strdup(state, value);
316 pb_debug("%s: unknown name: %s\n", __func__, name);
319 static struct conf_global_option yaboot_global_options[] = {
321 { .name = "device" },
322 { .name = "partition" },
323 { .name = "initrd" },
324 { .name = "initrd_size" },
326 { .name = "literal" },
327 { .name = "ramdisk" },
328 { .name = "default" },
332 static const char *const yaboot_conf_files[] = {
339 "/suseboot/yaboot.cnf",
346 "/SUSEBOOT/YABOOT.CNF",
350 static int yaboot_parse(struct discover_context *dc)
352 const char * const *filename;
353 struct yaboot_state *state;
354 struct conf_context *conf;
358 /* Support block device boot only at present */
362 conf = talloc_zero(dc, struct conf_context);
368 conf->global_options = yaboot_global_options,
369 conf_init_global_options(conf);
370 conf->get_pair = conf_get_pair_equal;
371 conf->process_pair = yaboot_process_pair;
372 conf->finish = yaboot_finish;
373 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
377 for (filename = yaboot_conf_files; *filename; filename++) {
378 rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
382 conf_parse_buf(conf, buf, len);
390 static struct parser yaboot_parser = {
392 .parse = yaboot_parse,
393 .resolve_resource = resolve_devpath_resource,
396 register_parser(yaboot_parser);