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;
20 const char *const *known_names;
23 static void yaboot_finish(struct conf_context *conf)
25 struct yaboot_state *state = conf->parser_info;
27 assert(state->desc_image);
29 assert(state->opt->name);
30 assert(state->opt->boot_args);
32 state->opt->description = talloc_asprintf(state->opt, "%s %s %s",
34 (state->desc_initrd ? state->desc_initrd : ""),
35 state->opt->boot_args);
37 talloc_free(state->desc_initrd);
38 state->desc_initrd = NULL;
40 conf_strip_str(state->opt->boot_args);
41 conf_strip_str(state->opt->description);
43 /* opt is persistent, so must be associated with device */
45 device_add_boot_option(conf->dc->device, state->opt);
46 state->opt = talloc_zero(conf->dc->device, struct boot_option);
47 state->opt->boot_args = talloc_strdup(state->opt, "");
50 static void yaboot_process_pair(struct conf_context *conf, const char *name,
53 struct yaboot_state *state = conf->parser_info;
55 /* fixup for bare values */
60 if (!state->globals_done && conf_set_global_option(conf, name, value))
63 if (!conf_param_in_list(state->known_names, name))
66 state->globals_done = 1;
70 if (streq(name, "image")) {
71 if (state->opt->boot_image_file)
74 state->opt->boot_image_file = resolve_path(state->opt, value,
75 conf->dc->device_path);
76 state->desc_image = talloc_strdup(state->opt, value);
80 if (streq(name, "image[32bit]") || streq(name, "image[64bit]")) {
81 state->found_suse = 1;
83 if (state->opt->boot_image_file)
87 state->opt->boot_image_file = resolve_path(state->opt,
88 value, conf->dc->device_path);
89 state->desc_image = talloc_strdup(state->opt, value);
92 asprintf(&s, "/suseboot/%s", value);
93 state->opt->boot_image_file = resolve_path(state->opt,
94 s, conf->dc->device_path);
95 state->desc_image = talloc_strdup(state->opt, s);
102 if (!state->opt->boot_image_file) {
103 pb_log("%s: unknown name: %s\n", __func__, name);
109 if (streq(name, "initrd")) {
110 if (!state->found_suse || (*value == '/')) {
111 state->opt->initrd_file = resolve_path(state->opt,
112 value, conf->dc->device_path);
113 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
117 asprintf(&s, "/suseboot/%s", value);
118 state->opt->initrd_file = resolve_path(state->opt,
119 s, conf->dc->device_path);
120 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
129 if (streq(name, "label")) {
130 state->opt->id = talloc_asprintf(state->opt, "%s#%s",
131 conf->dc->device->id, value);
132 state->opt->name = talloc_strdup(state->opt, value);
138 if (streq(name, "append")) {
139 state->opt->boot_args = talloc_asprintf_append(
140 state->opt->boot_args, "%s ", value);
144 if (streq(name, "initrd-size")) {
145 state->opt->boot_args = talloc_asprintf_append(
146 state->opt->boot_args, "ramdisk_size=%s ", value);
150 if (streq(name, "literal")) {
151 if (*state->opt->boot_args) {
152 pb_log("%s: literal over writes '%s'\n", __func__,
153 state->opt->boot_args);
154 talloc_free(state->opt->boot_args);
156 talloc_asprintf(state->opt, "%s ", value);
160 if (streq(name, "ramdisk")) {
161 state->opt->boot_args = talloc_asprintf_append(
162 state->opt->boot_args, "ramdisk=%s ", value);
166 if (streq(name, "read-only")) {
167 state->opt->boot_args = talloc_asprintf_append(
168 state->opt->boot_args, "ro ");
172 if (streq(name, "read-write")) {
173 state->opt->boot_args = talloc_asprintf_append(
174 state->opt->boot_args, "rw ");
178 if (streq(name, "root")) {
179 state->opt->boot_args = talloc_asprintf_append(
180 state->opt->boot_args, "root=%s ", value);
184 pb_log("%s: unknown name: %s\n", __func__, name);
187 static struct conf_global_option yaboot_global_options[] = {
189 { .name = "initrd" },
190 { .name = "partition" },
195 static const char *const yaboot_conf_files[] = {
200 "/suseboot/yaboot.cnf",
205 "/SUSEBOOT/YABOOT.CNF",
209 static const char *yaboot_known_names[] = {
212 "image[64bit]", /* SUSE extension */
213 "image[32bit]", /* SUSE extension */
225 static int yaboot_parse(struct discover_context *dc)
227 struct conf_context *conf;
228 struct yaboot_state *state;
231 conf = talloc_zero(dc, struct conf_context);
237 conf->global_options = yaboot_global_options,
238 conf->conf_files = yaboot_conf_files,
239 conf->process_pair = yaboot_process_pair;
240 conf->finish = yaboot_finish;
241 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
243 state->known_names = yaboot_known_names;
245 /* opt is persistent, so must be associated with device */
247 state->opt = talloc_zero(conf->dc->device, struct boot_option);
248 state->opt->boot_args = talloc_strdup(state->opt, "");
250 rc = conf_parse(conf);
256 define_parser(yaboot, 99, yaboot_parse);