8 #include "talloc/talloc.h"
9 #include "types/types.h"
10 #include "parser-conf.h"
11 #include "parser-utils.h"
18 const char *const *known_names;
20 /* current option data */
21 struct discover_boot_option *opt;
22 const char *initrd_size;
30 static struct discover_boot_option *state_start_new_option(
31 struct conf_context *conf,
32 struct yaboot_state *state)
34 state->desc_initrd = NULL;
36 state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
37 state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
39 /* old allocated values will get freed with the state */
40 state->initrd_size = conf_get_global_option(conf, "initrd_size");
41 state->literal = conf_get_global_option(conf, "literal");
42 state->ramdisk = conf_get_global_option(conf, "ramdisk");
43 state->root = conf_get_global_option(conf, "root");
48 static void yaboot_finish(struct conf_context *conf)
50 struct yaboot_state *state = conf->parser_info;
51 struct device *dev = conf->dc->device->device;
52 struct boot_option *opt;
54 if (!state->desc_image) {
55 pb_log("%s: %s: no image found\n", __func__, dev->id);
61 opt = state->opt->option;
64 assert(opt->boot_args);
66 /* populate the boot option from state data */
67 if (state->initrd_size) {
68 opt->boot_args = talloc_asprintf(opt, "ramdisk_size=%s %s",
69 state->initrd_size, opt->boot_args);
73 opt->boot_args = talloc_asprintf(opt, "ramdisk=%s %s",
74 state->initrd_size, opt->boot_args);
78 opt->boot_args = talloc_asprintf(opt, "root=%s %s",
79 state->root, opt->boot_args);
82 if (state->read_only && state->read_write) {
83 pb_log("boot option %s specified both 'ro' and 'rw', "
84 "using 'rw'\n", opt->name);
85 state->read_only = false;
88 if (state->read_only || state->read_write) {
89 opt->boot_args = talloc_asprintf(opt, "%s %s",
90 state->read_only ? "ro" : "rw",
95 opt->boot_args = talloc_strdup(opt, state->literal);
98 opt->description = talloc_asprintf(opt, "%s %s %s",
100 (state->desc_initrd ? state->desc_initrd : ""),
101 opt->boot_args ? opt->boot_args : "");
103 talloc_free(state->desc_initrd);
105 conf_strip_str(opt->boot_args);
106 conf_strip_str(opt->description);
108 discover_context_add_boot_option(conf->dc, state->opt);
111 static struct resource *create_yaboot_devpath_resource(
112 struct discover_boot_option *opt,
113 struct conf_context *conf,
114 const char *path, char **desc_str)
116 const char *g_boot = conf_get_global_option(conf, "boot");
117 const char *g_part = conf_get_global_option(conf, "partition");
118 struct resource *res;
121 if (g_boot && g_part) {
122 devpath = talloc_asprintf(conf,
123 "%s%s:%s", g_boot, g_part, path);
125 devpath = talloc_asprintf(conf, "%s:%s", g_boot, path);
127 devpath = talloc_strdup(conf, path);
130 res = create_devpath_resource(opt, conf->dc->device, devpath);
135 talloc_free(devpath);
141 static void yaboot_process_pair(struct conf_context *conf, const char *name,
144 struct yaboot_state *state = conf->parser_info;
145 struct discover_boot_option *opt = state->opt;
150 static const struct fixed_pair suse_fp32 = {
151 .image = "/suseboot/vmlinux32",
152 .initrd = "/suseboot/initrd32",
154 static const struct fixed_pair suse_fp64 = {
155 .image = "/suseboot/vmlinux64",
156 .initrd = "/suseboot/initrd64",
158 const struct fixed_pair *suse_fp;
160 /* fixup for bare values */
165 if (!state->globals_done && conf_set_global_option(conf, name, value))
168 if (!conf_param_in_list(state->known_names, name))
171 state->globals_done = 1;
175 if (streq(name, "image")) {
177 /* First finish any previous image. */
181 /* Then start the new image. */
182 opt = state_start_new_option(conf, state);
184 opt->boot_image = create_yaboot_devpath_resource(opt,
185 conf, value, &state->desc_image);
190 /* Special processing for SUSE install CD. */
192 if (streq(name, "image[32bit]"))
193 suse_fp = &suse_fp32;
194 else if (streq(name, "image[64bit]"))
195 suse_fp = &suse_fp64;
200 /* First finish any previous image. */
204 /* Then start the new image. */
205 opt = state_start_new_option(conf, state);
208 opt->boot_image = create_yaboot_devpath_resource(opt,
209 conf, value, &state->desc_image);
213 opt->boot_image = create_yaboot_devpath_resource(opt,
214 conf, suse_fp->image,
217 opt->initrd = create_yaboot_devpath_resource(opt,
218 conf, suse_fp->initrd, &tmp);
220 state->desc_initrd = talloc_asprintf(opt,
228 /* all other processing requires an image */
230 pb_log("%s: unknown name: %s\n", __func__, name);
236 if (streq(name, "initrd")) {
237 opt->initrd = create_yaboot_devpath_resource(opt, conf,
238 value, &state->desc_image);
245 if (streq(name, "label")) {
246 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
247 conf->dc->device->device->id, value);
248 opt->option->name = talloc_strdup(opt->option, value);
254 if (streq(name, "append")) {
255 opt->option->boot_args = talloc_asprintf_append(
256 opt->option->boot_args, "%s ", value);
260 if (streq(name, "initrd-size")) {
261 state->initrd_size = talloc_strdup(state, value);
265 if (streq(name, "literal")) {
266 state->literal = talloc_strdup(state, value);
270 if (streq(name, "ramdisk")) {
271 state->ramdisk = talloc_strdup(state, value);
275 if (streq(name, "read-only")) {
276 state->read_only = true;
280 if (streq(name, "read-write")) {
281 state->read_write = true;
285 if (streq(name, "root")) {
286 state->root = talloc_strdup(state, value);
290 pb_log("%s: unknown name: %s\n", __func__, name);
293 static struct conf_global_option yaboot_global_options[] = {
296 { .name = "initrd" },
297 { .name = "initrd_size" },
298 { .name = "partition" },
300 { .name = "literal" },
301 { .name = "ramdisk" },
305 static const char *const yaboot_conf_files[] = {
310 "/suseboot/yaboot.cnf",
315 "/SUSEBOOT/YABOOT.CNF",
319 static const char *yaboot_known_names[] = {
322 "image[64bit]", /* SUSE extension */
323 "image[32bit]", /* SUSE extension */
335 static int yaboot_parse(struct discover_context *dc, char *buf, int len)
337 struct conf_context *conf;
338 struct yaboot_state *state;
340 conf = talloc_zero(dc, struct conf_context);
346 conf->global_options = yaboot_global_options,
347 conf_init_global_options(conf);
348 conf->get_pair = conf_get_pair_equal;
349 conf->process_pair = yaboot_process_pair;
350 conf->finish = yaboot_finish;
351 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
353 state->known_names = yaboot_known_names;
357 conf_parse_buf(conf, buf, len);
363 static struct parser yaboot_parser = {
365 .method = CONF_METHOD_LOCAL_FILE,
366 .parse = yaboot_parse,
367 .filenames = yaboot_conf_files,
368 .resolve_resource = resolve_devpath_resource,
371 register_parser(yaboot_parser);