8 #include "talloc/talloc.h"
9 #include "types/types.h"
10 #include "parser-conf.h"
11 #include "parser-utils.h"
15 struct discover_boot_option *opt;
16 const char *desc_image;
19 const char *const *known_names;
22 static void yaboot_finish(struct conf_context *conf)
24 struct yaboot_state *state = conf->parser_info;
25 struct device *dev = conf->dc->device->device;
26 struct boot_option *opt;
28 if (!state->desc_image) {
29 pb_log("%s: %s: no image found\n", __func__, dev->id);
35 opt = state->opt->option;
38 assert(opt->boot_args);
40 opt->description = talloc_asprintf(opt, "%s %s %s",
42 (state->desc_initrd ? state->desc_initrd : ""),
45 talloc_free(state->desc_initrd);
46 state->desc_initrd = NULL;
48 conf_strip_str(opt->boot_args);
49 conf_strip_str(opt->description);
51 /* opt is persistent, so must be associated with device */
53 discover_context_add_boot_option(conf->dc, state->opt);
55 state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
56 state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
59 static void yaboot_process_pair(struct conf_context *conf, const char *name,
62 struct yaboot_state *state = conf->parser_info;
63 struct boot_option *opt = state->opt->option;
68 static const struct fixed_pair suse_fp32 = {
69 .image = "/suseboot/vmlinux32",
70 .initrd = "/suseboot/initrd32",
72 static const struct fixed_pair suse_fp64 = {
73 .image = "/suseboot/vmlinux64",
74 .initrd = "/suseboot/initrd64",
76 const struct fixed_pair *suse_fp;
78 /* fixup for bare values */
83 if (!state->globals_done && conf_set_global_option(conf, name, value))
86 if (!conf_param_in_list(state->known_names, name))
89 state->globals_done = 1;
93 if (streq(name, "image")) {
94 const char *g_boot = conf_get_global_option(conf, "boot");
95 const char *g_part = conf_get_global_option(conf, "partition");
97 /* First finish any previous image. */
99 if (opt->boot_image_file)
102 /* Then start the new image. */
104 if (g_boot && g_part) {
105 char* dev = talloc_asprintf(NULL, "%s%s", g_boot,
108 opt->boot_image_file = resolve_path(opt,
110 state->desc_image = talloc_asprintf(opt,
114 opt->boot_image_file = resolve_path(opt,
116 state->desc_image = talloc_asprintf(opt,
117 "%s%s", g_boot, value);
119 opt->boot_image_file = resolve_path(opt,
120 value, conf->dc->device->device_path);
121 state->desc_image = talloc_strdup(opt, value);
127 /* Special processing for SUSE install CD. */
129 if (streq(name, "image[32bit]"))
130 suse_fp = &suse_fp32;
131 else if (streq(name, "image[64bit]"))
132 suse_fp = &suse_fp64;
137 /* First finish any previous image. */
139 if (opt->boot_image_file)
142 /* Then start the new image. */
145 opt->boot_image_file = resolve_path(opt,
146 value, conf->dc->device->device_path);
147 state->desc_image = talloc_strdup(opt, value);
149 opt->boot_image_file = resolve_path(opt,
150 suse_fp->image, conf->dc->device->device_path);
151 state->desc_image = talloc_strdup(opt,
154 opt->initrd_file = resolve_path(opt,
155 suse_fp->initrd, conf->dc->device->device_path);
156 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
163 if (!opt->boot_image_file) {
164 pb_log("%s: unknown name: %s\n", __func__, name);
170 if (streq(name, "initrd")) {
171 const char *g_boot = conf_get_global_option(conf, "boot");
172 const char *g_part = conf_get_global_option(conf, "partition");
174 if (g_boot && g_part) {
175 char* dev = talloc_asprintf(NULL, "%s%s", g_boot,
178 opt->initrd_file = resolve_path(opt,
180 state->desc_initrd = talloc_asprintf(state,
181 "initrd=%s%s", dev, value);
184 opt->initrd_file = resolve_path(opt,
186 state->desc_initrd = talloc_asprintf(state,
187 "initrd=%s%s", g_boot, value);
189 opt->initrd_file = resolve_path(opt,
190 value, conf->dc->device->device_path);
191 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
199 if (streq(name, "label")) {
200 opt->id = talloc_asprintf(opt, "%s#%s",
201 conf->dc->device->device->id, value);
202 opt->name = talloc_strdup(opt, value);
208 if (streq(name, "append")) {
209 opt->boot_args = talloc_asprintf_append(
210 opt->boot_args, "%s ", value);
214 if (streq(name, "initrd-size")) {
215 opt->boot_args = talloc_asprintf_append(
216 opt->boot_args, "ramdisk_size=%s ", value);
220 if (streq(name, "literal")) {
221 if (*opt->boot_args) {
222 pb_log("%s: literal over writes '%s'\n", __func__,
224 talloc_free(opt->boot_args);
226 talloc_asprintf(opt, "%s ", value);
230 if (streq(name, "ramdisk")) {
231 opt->boot_args = talloc_asprintf_append(
232 opt->boot_args, "ramdisk=%s ", value);
236 if (streq(name, "read-only")) {
237 opt->boot_args = talloc_asprintf_append(
238 opt->boot_args, "ro ");
242 if (streq(name, "read-write")) {
243 opt->boot_args = talloc_asprintf_append(
244 opt->boot_args, "rw ");
248 if (streq(name, "root")) {
249 opt->boot_args = talloc_asprintf_append(
250 opt->boot_args, "root=%s ", value);
254 pb_log("%s: unknown name: %s\n", __func__, name);
257 static struct conf_global_option yaboot_global_options[] = {
259 { .name = "initrd" },
260 { .name = "partition" },
265 static const char *const yaboot_conf_files[] = {
270 "/suseboot/yaboot.cnf",
275 "/SUSEBOOT/YABOOT.CNF",
279 static const char *yaboot_known_names[] = {
282 "image[64bit]", /* SUSE extension */
283 "image[32bit]", /* SUSE extension */
295 static int yaboot_parse(struct discover_context *dc, char *buf, int len)
297 struct conf_context *conf;
298 struct yaboot_state *state;
300 conf = talloc_zero(dc, struct conf_context);
306 conf->global_options = yaboot_global_options,
307 conf_init_global_options(conf);
308 conf->get_pair = conf_get_pair_equal;
309 conf->process_pair = yaboot_process_pair;
310 conf->finish = yaboot_finish;
311 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
313 state->known_names = yaboot_known_names;
315 /* opt is persistent, so must be associated with device */
317 state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
318 state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
320 conf_parse_buf(conf, buf, len);
326 struct parser __yaboot_parser = {
328 .parse = yaboot_parse,
329 .filenames = yaboot_conf_files,