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 /* 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 struct resource *create_yaboot_devpath_resource(
60 struct conf_context *conf,
61 const char *path, char **desc_str)
63 const char *g_boot = conf_get_global_option(conf, "boot");
64 const char *g_part = conf_get_global_option(conf, "partition");
68 if (g_boot && g_part) {
69 devpath = talloc_asprintf(conf,
70 "%s%s:%s", g_boot, g_part, path);
72 devpath = talloc_asprintf(conf, "%s:%s", g_boot, path);
74 devpath = talloc_strdup(conf, path);
77 res = create_devpath_resource(conf->dc, conf->dc->device, devpath);
88 static void yaboot_process_pair(struct conf_context *conf, const char *name,
91 struct yaboot_state *state = conf->parser_info;
92 struct discover_boot_option *opt = state->opt;
97 static const struct fixed_pair suse_fp32 = {
98 .image = "/suseboot/vmlinux32",
99 .initrd = "/suseboot/initrd32",
101 static const struct fixed_pair suse_fp64 = {
102 .image = "/suseboot/vmlinux64",
103 .initrd = "/suseboot/initrd64",
105 const struct fixed_pair *suse_fp;
107 /* fixup for bare values */
112 if (!state->globals_done && conf_set_global_option(conf, name, value))
115 if (!conf_param_in_list(state->known_names, name))
118 state->globals_done = 1;
122 if (streq(name, "image")) {
124 /* First finish any previous image. */
128 /* Then start the new image. */
129 opt->boot_image = create_yaboot_devpath_resource(conf,
130 value, &state->desc_image);
135 /* Special processing for SUSE install CD. */
137 if (streq(name, "image[32bit]"))
138 suse_fp = &suse_fp32;
139 else if (streq(name, "image[64bit]"))
140 suse_fp = &suse_fp64;
145 /* First finish any previous image. */
150 /* Then start the new image. */
153 opt->boot_image = create_yaboot_devpath_resource(
154 conf, value, &state->desc_image);
158 opt->boot_image = create_yaboot_devpath_resource(
159 conf, suse_fp->image,
162 opt->initrd = create_yaboot_devpath_resource(
163 conf, suse_fp->initrd, &tmp);
165 state->desc_initrd = talloc_asprintf(opt,
173 if (!opt->boot_image) {
174 pb_log("%s: unknown name: %s\n", __func__, name);
180 if (streq(name, "initrd")) {
181 opt->initrd = create_yaboot_devpath_resource(conf,
182 value, &state->desc_image);
189 if (streq(name, "label")) {
190 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
191 conf->dc->device->device->id, value);
192 opt->option->name = talloc_strdup(opt->option, value);
198 if (streq(name, "append")) {
199 opt->option->boot_args = talloc_asprintf_append(
200 opt->option->boot_args, "%s ", value);
204 if (streq(name, "initrd-size")) {
205 opt->option->boot_args = talloc_asprintf_append(
206 opt->option->boot_args, "ramdisk_size=%s ", value);
210 if (streq(name, "literal")) {
211 if (*opt->option->boot_args) {
212 pb_log("%s: literal over writes '%s'\n", __func__,
213 opt->option->boot_args);
214 talloc_free(opt->option->boot_args);
216 talloc_asprintf(opt->option, "%s ", value);
220 if (streq(name, "ramdisk")) {
221 opt->option->boot_args = talloc_asprintf_append(
222 opt->option->boot_args, "ramdisk=%s ", value);
226 if (streq(name, "read-only")) {
227 opt->option->boot_args = talloc_asprintf_append(
228 opt->option->boot_args, "ro ");
232 if (streq(name, "read-write")) {
233 opt->option->boot_args = talloc_asprintf_append(
234 opt->option->boot_args, "rw ");
238 if (streq(name, "root")) {
239 opt->option->boot_args = talloc_asprintf_append(
240 opt->option->boot_args, "root=%s ", value);
244 pb_log("%s: unknown name: %s\n", __func__, name);
247 static struct conf_global_option yaboot_global_options[] = {
249 { .name = "initrd" },
250 { .name = "partition" },
255 static const char *const yaboot_conf_files[] = {
260 "/suseboot/yaboot.cnf",
265 "/SUSEBOOT/YABOOT.CNF",
269 static const char *yaboot_known_names[] = {
272 "image[64bit]", /* SUSE extension */
273 "image[32bit]", /* SUSE extension */
285 static int yaboot_parse(struct discover_context *dc, char *buf, int len)
287 struct conf_context *conf;
288 struct yaboot_state *state;
290 conf = talloc_zero(dc, struct conf_context);
296 conf->global_options = yaboot_global_options,
297 conf_init_global_options(conf);
298 conf->get_pair = conf_get_pair_equal;
299 conf->process_pair = yaboot_process_pair;
300 conf->finish = yaboot_finish;
301 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
303 state->known_names = yaboot_known_names;
305 /* opt is persistent, so must be associated with device */
307 state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
308 state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
310 conf_parse_buf(conf, buf, len);
316 static struct parser yaboot_parser = {
318 .method = CONF_METHOD_LOCAL_FILE,
319 .parse = yaboot_parse,
320 .filenames = yaboot_conf_files,
323 register_parser(yaboot_parser);