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;
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 discover_context_add_boot_option(conf->dc, state->opt);
54 static struct resource *create_yaboot_devpath_resource(
55 struct discover_boot_option *opt,
56 struct conf_context *conf,
57 const char *path, char **desc_str)
59 const char *g_boot = conf_get_global_option(conf, "boot");
60 const char *g_part = conf_get_global_option(conf, "partition");
64 if (g_boot && g_part) {
65 devpath = talloc_asprintf(conf,
66 "%s%s:%s", g_boot, g_part, path);
68 devpath = talloc_asprintf(conf, "%s:%s", g_boot, path);
70 devpath = talloc_strdup(conf, path);
73 res = create_devpath_resource(opt, conf->dc->device, devpath);
84 static void yaboot_process_pair(struct conf_context *conf, const char *name,
87 struct yaboot_state *state = conf->parser_info;
88 struct discover_boot_option *opt = state->opt;
93 static const struct fixed_pair suse_fp32 = {
94 .image = "/suseboot/vmlinux32",
95 .initrd = "/suseboot/initrd32",
97 static const struct fixed_pair suse_fp64 = {
98 .image = "/suseboot/vmlinux64",
99 .initrd = "/suseboot/initrd64",
101 const struct fixed_pair *suse_fp;
103 /* fixup for bare values */
108 if (!state->globals_done && conf_set_global_option(conf, name, value))
111 if (!conf_param_in_list(state->known_names, name))
114 state->globals_done = 1;
118 if (streq(name, "image")) {
120 /* First finish any previous image. */
124 opt = discover_boot_option_create(conf->dc, conf->dc->device);
125 opt->option->boot_args = talloc_strdup(opt->option, "");
127 /* Then start the new image. */
128 opt->boot_image = create_yaboot_devpath_resource(opt,
129 conf, value, &state->desc_image);
136 /* Special processing for SUSE install CD. */
138 if (streq(name, "image[32bit]"))
139 suse_fp = &suse_fp32;
140 else if (streq(name, "image[64bit]"))
141 suse_fp = &suse_fp64;
146 /* First finish any previous image. */
150 /* Then start the new image. */
152 opt = discover_boot_option_create(conf->dc, conf->dc->device);
153 opt->option->boot_args = talloc_strdup(opt->option, "");
158 opt->boot_image = create_yaboot_devpath_resource(opt,
159 conf, value, &state->desc_image);
163 opt->boot_image = create_yaboot_devpath_resource(opt,
164 conf, suse_fp->image,
167 opt->initrd = create_yaboot_devpath_resource(opt,
168 conf, suse_fp->initrd, &tmp);
170 state->desc_initrd = talloc_asprintf(opt,
178 if (!opt->boot_image) {
179 pb_log("%s: unknown name: %s\n", __func__, name);
185 if (streq(name, "initrd")) {
186 opt->initrd = create_yaboot_devpath_resource(opt, conf,
187 value, &state->desc_image);
194 if (streq(name, "label")) {
195 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
196 conf->dc->device->device->id, value);
197 opt->option->name = talloc_strdup(opt->option, value);
203 if (streq(name, "append")) {
204 opt->option->boot_args = talloc_asprintf_append(
205 opt->option->boot_args, "%s ", value);
209 if (streq(name, "initrd-size")) {
210 opt->option->boot_args = talloc_asprintf_append(
211 opt->option->boot_args, "ramdisk_size=%s ", value);
215 if (streq(name, "literal")) {
216 if (*opt->option->boot_args) {
217 pb_log("%s: literal over writes '%s'\n", __func__,
218 opt->option->boot_args);
219 talloc_free(opt->option->boot_args);
221 talloc_asprintf(opt->option, "%s ", value);
225 if (streq(name, "ramdisk")) {
226 opt->option->boot_args = talloc_asprintf_append(
227 opt->option->boot_args, "ramdisk=%s ", value);
231 if (streq(name, "read-only")) {
232 opt->option->boot_args = talloc_asprintf_append(
233 opt->option->boot_args, "ro ");
237 if (streq(name, "read-write")) {
238 opt->option->boot_args = talloc_asprintf_append(
239 opt->option->boot_args, "rw ");
243 if (streq(name, "root")) {
244 opt->option->boot_args = talloc_asprintf_append(
245 opt->option->boot_args, "root=%s ", value);
249 pb_log("%s: unknown name: %s\n", __func__, name);
252 static struct conf_global_option yaboot_global_options[] = {
254 { .name = "initrd" },
255 { .name = "partition" },
260 static const char *const yaboot_conf_files[] = {
265 "/suseboot/yaboot.cnf",
270 "/SUSEBOOT/YABOOT.CNF",
274 static const char *yaboot_known_names[] = {
277 "image[64bit]", /* SUSE extension */
278 "image[32bit]", /* SUSE extension */
290 static int yaboot_parse(struct discover_context *dc, char *buf, int len)
292 struct conf_context *conf;
293 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->get_pair = conf_get_pair_equal;
304 conf->process_pair = yaboot_process_pair;
305 conf->finish = yaboot_finish;
306 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
308 state->known_names = yaboot_known_names;
312 conf_parse_buf(conf, buf, len);
318 static struct parser yaboot_parser = {
320 .method = CONF_METHOD_LOCAL_FILE,
321 .parse = yaboot_parse,
322 .filenames = yaboot_conf_files,
323 .resolve_resource = resolve_devpath_resource,
326 register_parser(yaboot_parser);