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 if (!state->desc_image) {
28 pb_log("%s: %s: no image found\n", __func__,
29 conf->dc->device->id);
34 assert(state->opt->name);
35 assert(state->opt->boot_args);
37 state->opt->description = talloc_asprintf(state->opt, "%s %s %s",
39 (state->desc_initrd ? state->desc_initrd : ""),
40 state->opt->boot_args);
42 talloc_free(state->desc_initrd);
43 state->desc_initrd = NULL;
45 conf_strip_str(state->opt->boot_args);
46 conf_strip_str(state->opt->description);
48 /* opt is persistent, so must be associated with device */
50 device_add_boot_option(conf->dc->device, state->opt);
51 state->opt = talloc_zero(conf->dc->device, struct boot_option);
52 state->opt->boot_args = talloc_strdup(state->opt, "");
55 static void yaboot_process_pair(struct conf_context *conf, const char *name,
58 struct yaboot_state *state = conf->parser_info;
60 /* fixup for bare values */
65 if (!state->globals_done && conf_set_global_option(conf, name, value))
68 if (!conf_param_in_list(state->known_names, name))
71 state->globals_done = 1;
75 if (streq(name, "image")) {
76 if (state->opt->boot_image_file)
79 state->opt->boot_image_file = resolve_path(state->opt, value,
80 conf->dc->device_path);
81 state->desc_image = talloc_strdup(state->opt, value);
85 if (streq(name, "image[32bit]") || streq(name, "image[64bit]")) {
86 state->found_suse = 1;
88 if (state->opt->boot_image_file)
92 state->opt->boot_image_file = resolve_path(state->opt,
93 value, conf->dc->device_path);
94 state->desc_image = talloc_strdup(state->opt, value);
97 asprintf(&s, "/suseboot/%s", value);
98 state->opt->boot_image_file = resolve_path(state->opt,
99 s, conf->dc->device_path);
100 state->desc_image = talloc_strdup(state->opt, s);
107 if (!state->opt->boot_image_file) {
108 pb_log("%s: unknown name: %s\n", __func__, name);
114 if (streq(name, "initrd")) {
115 if (!state->found_suse || (*value == '/')) {
116 state->opt->initrd_file = resolve_path(state->opt,
117 value, conf->dc->device_path);
118 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
122 asprintf(&s, "/suseboot/%s", value);
123 state->opt->initrd_file = resolve_path(state->opt,
124 s, conf->dc->device_path);
125 state->desc_initrd = talloc_asprintf(state, "initrd=%s",
134 if (streq(name, "label")) {
135 state->opt->id = talloc_asprintf(state->opt, "%s#%s",
136 conf->dc->device->id, value);
137 state->opt->name = talloc_strdup(state->opt, value);
143 if (streq(name, "append")) {
144 state->opt->boot_args = talloc_asprintf_append(
145 state->opt->boot_args, "%s ", value);
149 if (streq(name, "initrd-size")) {
150 state->opt->boot_args = talloc_asprintf_append(
151 state->opt->boot_args, "ramdisk_size=%s ", value);
155 if (streq(name, "literal")) {
156 if (*state->opt->boot_args) {
157 pb_log("%s: literal over writes '%s'\n", __func__,
158 state->opt->boot_args);
159 talloc_free(state->opt->boot_args);
161 talloc_asprintf(state->opt, "%s ", value);
165 if (streq(name, "ramdisk")) {
166 state->opt->boot_args = talloc_asprintf_append(
167 state->opt->boot_args, "ramdisk=%s ", value);
171 if (streq(name, "read-only")) {
172 state->opt->boot_args = talloc_asprintf_append(
173 state->opt->boot_args, "ro ");
177 if (streq(name, "read-write")) {
178 state->opt->boot_args = talloc_asprintf_append(
179 state->opt->boot_args, "rw ");
183 if (streq(name, "root")) {
184 state->opt->boot_args = talloc_asprintf_append(
185 state->opt->boot_args, "root=%s ", value);
189 pb_log("%s: unknown name: %s\n", __func__, name);
192 static struct conf_global_option yaboot_global_options[] = {
194 { .name = "initrd" },
195 { .name = "partition" },
200 static const char *const yaboot_conf_files[] = {
205 "/suseboot/yaboot.cnf",
210 "/SUSEBOOT/YABOOT.CNF",
214 static const char *yaboot_known_names[] = {
217 "image[64bit]", /* SUSE extension */
218 "image[32bit]", /* SUSE extension */
230 static int yaboot_parse(struct discover_context *dc)
232 struct conf_context *conf;
233 struct yaboot_state *state;
236 conf = talloc_zero(dc, struct conf_context);
242 conf->global_options = yaboot_global_options,
243 conf->conf_files = yaboot_conf_files,
244 conf->process_pair = yaboot_process_pair;
245 conf->finish = yaboot_finish;
246 conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
248 state->known_names = yaboot_known_names;
250 /* opt is persistent, so must be associated with device */
252 state->opt = talloc_zero(conf->dc->device, struct boot_option);
253 state->opt->boot_args = talloc_strdup(state->opt, "");
255 rc = conf_parse(conf);
261 define_parser(yaboot, 99, yaboot_parse);