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 conf_context *conf,
56 const char *path, char **desc_str)
58 const char *g_boot = conf_get_global_option(conf, "boot");
59 const char *g_part = conf_get_global_option(conf, "partition");
63 if (g_boot && g_part) {
64 devpath = talloc_asprintf(conf,
65 "%s%s:%s", g_boot, g_part, path);
67 devpath = talloc_asprintf(conf, "%s:%s", g_boot, path);
69 devpath = talloc_strdup(conf, path);
72 res = create_devpath_resource(conf->dc, conf->dc->device, devpath);
83 static void yaboot_process_pair(struct conf_context *conf, const char *name,
86 struct yaboot_state *state = conf->parser_info;
87 struct discover_boot_option *opt = state->opt;
92 static const struct fixed_pair suse_fp32 = {
93 .image = "/suseboot/vmlinux32",
94 .initrd = "/suseboot/initrd32",
96 static const struct fixed_pair suse_fp64 = {
97 .image = "/suseboot/vmlinux64",
98 .initrd = "/suseboot/initrd64",
100 const struct fixed_pair *suse_fp;
102 /* fixup for bare values */
107 if (!state->globals_done && conf_set_global_option(conf, name, value))
110 if (!conf_param_in_list(state->known_names, name))
113 state->globals_done = 1;
117 if (streq(name, "image")) {
119 /* First finish any previous image. */
123 opt = discover_boot_option_create(conf->dc, conf->dc->device);
124 opt->option->boot_args = talloc_strdup(opt->option, "");
126 /* Then start the new image. */
127 opt->boot_image = create_yaboot_devpath_resource(conf,
128 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. */
149 /* Then start the new image. */
151 opt = discover_boot_option_create(conf->dc, conf->dc->device);
152 opt->option->boot_args = talloc_strdup(opt->option, "");
157 opt->boot_image = create_yaboot_devpath_resource(
158 conf, value, &state->desc_image);
162 opt->boot_image = create_yaboot_devpath_resource(
163 conf, suse_fp->image,
166 opt->initrd = create_yaboot_devpath_resource(
167 conf, suse_fp->initrd, &tmp);
169 state->desc_initrd = talloc_asprintf(opt,
177 if (!opt->boot_image) {
178 pb_log("%s: unknown name: %s\n", __func__, name);
184 if (streq(name, "initrd")) {
185 opt->initrd = create_yaboot_devpath_resource(conf,
186 value, &state->desc_image);
193 if (streq(name, "label")) {
194 opt->option->id = talloc_asprintf(opt->option, "%s#%s",
195 conf->dc->device->device->id, value);
196 opt->option->name = talloc_strdup(opt->option, value);
202 if (streq(name, "append")) {
203 opt->option->boot_args = talloc_asprintf_append(
204 opt->option->boot_args, "%s ", value);
208 if (streq(name, "initrd-size")) {
209 opt->option->boot_args = talloc_asprintf_append(
210 opt->option->boot_args, "ramdisk_size=%s ", value);
214 if (streq(name, "literal")) {
215 if (*opt->option->boot_args) {
216 pb_log("%s: literal over writes '%s'\n", __func__,
217 opt->option->boot_args);
218 talloc_free(opt->option->boot_args);
220 talloc_asprintf(opt->option, "%s ", value);
224 if (streq(name, "ramdisk")) {
225 opt->option->boot_args = talloc_asprintf_append(
226 opt->option->boot_args, "ramdisk=%s ", value);
230 if (streq(name, "read-only")) {
231 opt->option->boot_args = talloc_asprintf_append(
232 opt->option->boot_args, "ro ");
236 if (streq(name, "read-write")) {
237 opt->option->boot_args = talloc_asprintf_append(
238 opt->option->boot_args, "rw ");
242 if (streq(name, "root")) {
243 opt->option->boot_args = talloc_asprintf_append(
244 opt->option->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, char *buf, int len)
291 struct conf_context *conf;
292 struct yaboot_state *state;
294 conf = talloc_zero(dc, struct conf_context);
300 conf->global_options = yaboot_global_options,
301 conf_init_global_options(conf);
302 conf->get_pair = conf_get_pair_equal;
303 conf->process_pair = yaboot_process_pair;
304 conf->finish = yaboot_finish;
305 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
307 state->known_names = yaboot_known_names;
311 conf_parse_buf(conf, buf, len);
317 static struct parser yaboot_parser = {
319 .method = CONF_METHOD_LOCAL_FILE,
320 .parse = yaboot_parse,
321 .filenames = yaboot_conf_files,
322 .resolve_resource = resolve_devpath_resource,
325 register_parser(yaboot_parser);