8 #include "talloc/talloc.h"
9 #include "pb-protocol/pb-protocol.h"
10 #include "parser-conf.h"
11 #include "parser-utils.h"
15 struct 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;
26 if (!state->desc_image) {
27 pb_log("%s: %s: no image found\n", __func__,
28 conf->dc->device->id);
33 assert(state->opt->name);
34 assert(state->opt->boot_args);
36 state->opt->description = talloc_asprintf(state->opt, "%s %s %s",
38 (state->desc_initrd ? state->desc_initrd : ""),
39 state->opt->boot_args);
41 talloc_free(state->desc_initrd);
42 state->desc_initrd = NULL;
44 conf_strip_str(state->opt->boot_args);
45 conf_strip_str(state->opt->description);
47 /* opt is persistent, so must be associated with device */
49 device_add_boot_option(conf->dc->device, state->opt);
50 state->opt = talloc_zero(conf->dc->device, struct boot_option);
51 state->opt->boot_args = talloc_strdup(state->opt, "");
54 static void yaboot_process_pair(struct conf_context *conf, const char *name,
57 struct yaboot_state *state = conf->parser_info;
62 static const struct fixed_pair suse_fp32 = {
63 .image = "/suseboot/vmlinux32",
64 .initrd = "/suseboot/initrd32",
66 static const struct fixed_pair suse_fp64 = {
67 .image = "/suseboot/vmlinux64",
68 .initrd = "/suseboot/initrd64",
70 const struct fixed_pair *suse_fp;
72 /* fixup for bare values */
77 if (!state->globals_done && conf_set_global_option(conf, name, value))
80 if (!conf_param_in_list(state->known_names, name))
83 state->globals_done = 1;
87 if (streq(name, "image")) {
89 /* First finish any previous image. */
91 if (state->opt->boot_image_file)
94 /* Then start the new image. */
96 state->opt->boot_image_file = resolve_path(state->opt, value,
97 conf->dc->device_path);
98 state->desc_image = talloc_strdup(state->opt, value);
103 /* Special processing for SUSE install CD. */
105 if (streq(name, "image[32bit]"))
106 suse_fp = &suse_fp32;
107 else if (streq(name, "image[64bit]"))
108 suse_fp = &suse_fp64;
113 /* First finish any previous image. */
115 if (state->opt->boot_image_file)
118 /* Then start the new image. */
121 state->opt->boot_image_file = resolve_path(state->opt,
122 value, conf->dc->device_path);
123 state->desc_image = talloc_strdup(state->opt, value);
125 state->opt->boot_image_file = resolve_path(state->opt,
126 suse_fp->image, conf->dc->device_path);
127 state->desc_image = talloc_strdup(state->opt,
130 state->opt->initrd_file = resolve_path(state->opt,
131 suse_fp->initrd, conf->dc->device_path);
132 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
139 if (!state->opt->boot_image_file) {
140 pb_log("%s: unknown name: %s\n", __func__, name);
146 if (streq(name, "initrd")) {
147 state->opt->initrd_file = resolve_path(state->opt,
148 value, conf->dc->device_path);
149 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
156 if (streq(name, "label")) {
157 state->opt->id = talloc_asprintf(state->opt, "%s#%s",
158 conf->dc->device->id, value);
159 state->opt->name = talloc_strdup(state->opt, value);
165 if (streq(name, "append")) {
166 state->opt->boot_args = talloc_asprintf_append(
167 state->opt->boot_args, "%s ", value);
171 if (streq(name, "initrd-size")) {
172 state->opt->boot_args = talloc_asprintf_append(
173 state->opt->boot_args, "ramdisk_size=%s ", value);
177 if (streq(name, "literal")) {
178 if (*state->opt->boot_args) {
179 pb_log("%s: literal over writes '%s'\n", __func__,
180 state->opt->boot_args);
181 talloc_free(state->opt->boot_args);
183 talloc_asprintf(state->opt, "%s ", value);
187 if (streq(name, "ramdisk")) {
188 state->opt->boot_args = talloc_asprintf_append(
189 state->opt->boot_args, "ramdisk=%s ", value);
193 if (streq(name, "read-only")) {
194 state->opt->boot_args = talloc_asprintf_append(
195 state->opt->boot_args, "ro ");
199 if (streq(name, "read-write")) {
200 state->opt->boot_args = talloc_asprintf_append(
201 state->opt->boot_args, "rw ");
205 if (streq(name, "root")) {
206 state->opt->boot_args = talloc_asprintf_append(
207 state->opt->boot_args, "root=%s ", value);
211 pb_log("%s: unknown name: %s\n", __func__, name);
214 static struct conf_global_option yaboot_global_options[] = {
216 { .name = "initrd" },
217 { .name = "partition" },
222 static const char *const yaboot_conf_files[] = {
227 "/suseboot/yaboot.cnf",
232 "/SUSEBOOT/YABOOT.CNF",
236 static const char *yaboot_known_names[] = {
239 "image[64bit]", /* SUSE extension */
240 "image[32bit]", /* SUSE extension */
252 static int yaboot_parse(struct discover_context *dc)
254 struct conf_context *conf;
255 struct yaboot_state *state;
258 conf = talloc_zero(dc, struct conf_context);
264 conf->global_options = yaboot_global_options,
265 conf_init_global_options(conf);
266 conf->conf_files = yaboot_conf_files,
267 conf->process_pair = yaboot_process_pair;
268 conf->finish = yaboot_finish;
269 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
271 state->known_names = yaboot_known_names;
273 /* opt is persistent, so must be associated with device */
275 state->opt = talloc_zero(conf->dc->device, struct boot_option);
276 state->opt->boot_args = talloc_strdup(state->opt, "");
278 rc = conf_parse(conf);
284 define_parser(yaboot, 99, yaboot_parse);