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 /* all other processing requires an image */
180 pb_log("%s: unknown name: %s\n", __func__, name);
186 if (streq(name, "initrd")) {
187 opt->initrd = create_yaboot_devpath_resource(opt, conf,
188 value, &state->desc_image);
195 if (streq(name, "label")) {
196 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
197 conf->dc->device->device->id, value);
198 opt->option->name = talloc_strdup(opt->option, value);
204 if (streq(name, "append")) {
205 opt->option->boot_args = talloc_asprintf_append(
206 opt->option->boot_args, "%s ", value);
210 if (streq(name, "initrd-size")) {
211 opt->option->boot_args = talloc_asprintf_append(
212 opt->option->boot_args, "ramdisk_size=%s ", value);
216 if (streq(name, "literal")) {
217 if (*opt->option->boot_args) {
218 pb_log("%s: literal over writes '%s'\n", __func__,
219 opt->option->boot_args);
220 talloc_free(opt->option->boot_args);
222 talloc_asprintf(opt->option, "%s ", value);
226 if (streq(name, "ramdisk")) {
227 opt->option->boot_args = talloc_asprintf_append(
228 opt->option->boot_args, "ramdisk=%s ", value);
232 if (streq(name, "read-only")) {
233 opt->option->boot_args = talloc_asprintf_append(
234 opt->option->boot_args, "ro ");
238 if (streq(name, "read-write")) {
239 opt->option->boot_args = talloc_asprintf_append(
240 opt->option->boot_args, "rw ");
244 if (streq(name, "root")) {
245 opt->option->boot_args = talloc_asprintf_append(
246 opt->option->boot_args, "root=%s ", value);
250 pb_log("%s: unknown name: %s\n", __func__, name);
253 static struct conf_global_option yaboot_global_options[] = {
255 { .name = "initrd" },
256 { .name = "partition" },
261 static const char *const yaboot_conf_files[] = {
266 "/suseboot/yaboot.cnf",
271 "/SUSEBOOT/YABOOT.CNF",
275 static const char *yaboot_known_names[] = {
278 "image[64bit]", /* SUSE extension */
279 "image[32bit]", /* SUSE extension */
291 static int yaboot_parse(struct discover_context *dc, char *buf, int len)
293 struct conf_context *conf;
294 struct yaboot_state *state;
296 conf = talloc_zero(dc, struct conf_context);
302 conf->global_options = yaboot_global_options,
303 conf_init_global_options(conf);
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;
313 conf_parse_buf(conf, buf, len);
319 static struct parser yaboot_parser = {
321 .method = CONF_METHOD_LOCAL_FILE,
322 .parse = yaboot_parse,
323 .filenames = yaboot_conf_files,
324 .resolve_resource = resolve_devpath_resource,
327 register_parser(yaboot_parser);