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")) {
88 const char *g_boot = conf_get_global_option(conf, "boot");
89 const char *g_part = conf_get_global_option(conf, "partition");
91 /* First finish any previous image. */
93 if (state->opt->boot_image_file)
96 /* Then start the new image. */
98 if (g_boot && g_part) {
99 char* dev = talloc_asprintf(NULL, "%s%s", g_boot,
102 state->opt->boot_image_file = resolve_path(state->opt,
104 state->desc_image = talloc_asprintf(state->opt,
108 state->opt->boot_image_file = resolve_path(state->opt,
110 state->desc_image = talloc_asprintf(state->opt,
111 "%s%s", g_boot, value);
113 state->opt->boot_image_file = resolve_path(state->opt,
114 value, conf->dc->device_path);
115 state->desc_image = talloc_strdup(state->opt, value);
121 /* Special processing for SUSE install CD. */
123 if (streq(name, "image[32bit]"))
124 suse_fp = &suse_fp32;
125 else if (streq(name, "image[64bit]"))
126 suse_fp = &suse_fp64;
131 /* First finish any previous image. */
133 if (state->opt->boot_image_file)
136 /* Then start the new image. */
139 state->opt->boot_image_file = resolve_path(state->opt,
140 value, conf->dc->device_path);
141 state->desc_image = talloc_strdup(state->opt, value);
143 state->opt->boot_image_file = resolve_path(state->opt,
144 suse_fp->image, conf->dc->device_path);
145 state->desc_image = talloc_strdup(state->opt,
148 state->opt->initrd_file = resolve_path(state->opt,
149 suse_fp->initrd, conf->dc->device_path);
150 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
157 if (!state->opt->boot_image_file) {
158 pb_log("%s: unknown name: %s\n", __func__, name);
164 if (streq(name, "initrd")) {
165 const char *g_boot = conf_get_global_option(conf, "boot");
166 const char *g_part = conf_get_global_option(conf, "partition");
168 if (g_boot && g_part) {
169 char* dev = talloc_asprintf(NULL, "%s%s", g_boot,
172 state->opt->initrd_file = resolve_path(state->opt,
174 state->desc_initrd = talloc_asprintf(state,
175 "initrd=%s%s", dev, value);
178 state->opt->initrd_file = resolve_path(state->opt,
180 state->desc_initrd = talloc_asprintf(state,
181 "initrd=%s%s", g_boot, value);
183 state->opt->initrd_file = resolve_path(state->opt,
184 value, conf->dc->device_path);
185 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
193 if (streq(name, "label")) {
194 state->opt->id = talloc_asprintf(state->opt, "%s#%s",
195 conf->dc->device->id, value);
196 state->opt->name = talloc_strdup(state->opt, value);
202 if (streq(name, "append")) {
203 state->opt->boot_args = talloc_asprintf_append(
204 state->opt->boot_args, "%s ", value);
208 if (streq(name, "initrd-size")) {
209 state->opt->boot_args = talloc_asprintf_append(
210 state->opt->boot_args, "ramdisk_size=%s ", value);
214 if (streq(name, "literal")) {
215 if (*state->opt->boot_args) {
216 pb_log("%s: literal over writes '%s'\n", __func__,
217 state->opt->boot_args);
218 talloc_free(state->opt->boot_args);
220 talloc_asprintf(state->opt, "%s ", value);
224 if (streq(name, "ramdisk")) {
225 state->opt->boot_args = talloc_asprintf_append(
226 state->opt->boot_args, "ramdisk=%s ", value);
230 if (streq(name, "read-only")) {
231 state->opt->boot_args = talloc_asprintf_append(
232 state->opt->boot_args, "ro ");
236 if (streq(name, "read-write")) {
237 state->opt->boot_args = talloc_asprintf_append(
238 state->opt->boot_args, "rw ");
242 if (streq(name, "root")) {
243 state->opt->boot_args = talloc_asprintf_append(
244 state->opt->boot_args, "root=%s ", value);
248 pb_log("%s: unknown name: %s\n", __func__, name);
251 static struct conf_global_option yaboot_global_options[] = {
253 { .name = "initrd" },
254 { .name = "partition" },
259 static const char *const yaboot_conf_files[] = {
264 "/suseboot/yaboot.cnf",
269 "/SUSEBOOT/YABOOT.CNF",
273 static const char *yaboot_known_names[] = {
276 "image[64bit]", /* SUSE extension */
277 "image[32bit]", /* SUSE extension */
289 static int yaboot_parse(struct discover_context *dc)
291 struct conf_context *conf;
292 struct yaboot_state *state;
295 conf = talloc_zero(dc, struct conf_context);
301 conf->global_options = yaboot_global_options,
302 conf_init_global_options(conf);
303 conf->conf_files = yaboot_conf_files,
304 conf->get_pair = conf_get_pair_equal;
305 conf->process_pair = yaboot_process_pair;
306 conf->finish = yaboot_finish;
307 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
309 state->known_names = yaboot_known_names;
311 /* opt is persistent, so must be associated with device */
313 state->opt = talloc_zero(conf->dc->device, struct boot_option);
314 state->opt->boot_args = talloc_strdup(state->opt, "");
316 rc = conf_parse(conf);
322 define_parser(yaboot, yaboot_parse);