5 #include "yaboot-cfg.h"
10 #include <sys/types.h>
15 #include <sys/param.h>
17 static struct device *dev;
19 static char *defimage;
22 make_params(char *label, char *params)
25 static char buffer[2048];
30 p = cfg_get_strg(label, "literal");
42 p = cfg_get_strg(label, "root");
49 if (cfg_get_flag(label, "read-only")) {
53 if (cfg_get_flag(label, "read-write")) {
57 p = cfg_get_strg(label, "ramdisk");
59 strcpy (q, "ramdisk=");
64 p = cfg_get_strg(label, "initrd-size");
66 strcpy (q, "ramdisk_size=");
71 if (cfg_get_flag(label, "novideo")) {
72 strcpy (q, "video=ofonly");
76 p = cfg_get_strg (label, "append");
89 static int check_and_add_device(struct device *dev)
92 dev->icon_file = strdup(generic_icon_file(guess_device_type()));
94 return !add_device(dev);
97 void process_image(char *label)
99 struct boot_option opt;
102 memset(&opt, 0, sizeof(opt));
105 cfgopt = cfg_get_strg(label, "image");
106 opt.boot_image_file = resolve_path(cfgopt, devpath);
107 if (cfgopt == defimage)
108 pb_log("This one is default. What do we do about it?\n");
110 cfgopt = cfg_get_strg(label, "initrd");
112 opt.initrd_file = resolve_path(cfgopt, devpath);
114 opt.boot_args = make_params(label, NULL);
116 add_boot_option(&opt);
119 free(opt.initrd_file);
122 static int yaboot_parse(const char *device)
132 devpath = strdup(device);
134 filepath = resolve_path("/etc/yaboot.conf", devpath);
136 fd = open(filepath, O_RDONLY);
139 filepath = resolve_path("/yaboot.conf", devpath);
140 fd = open(filepath, O_RDONLY);
146 if (fstat(fd, &st)) {
151 conf_file = malloc(st.st_size+1);
157 conf_len = read(fd, conf_file, st.st_size);
162 conf_file[conf_len] = 0;
166 if (cfg_parse(filepath, conf_file, conf_len)) {
167 pb_log("Error parsing yaboot.conf\n");
173 dev = malloc(sizeof(*dev));
174 memset(dev, 0, sizeof(*dev));
175 dev->id = strdup(devpath);
176 if (cfg_get_strg(0, "init-message")) {
178 dev->description = strdup(cfg_get_strg(0, "init-message"));
179 newline = strchr(dev->description, '\n');
183 dev->icon_file = strdup(generic_icon_file(guess_device_type()));
185 /* If we have a 'partiton=' directive, update the default devpath
186 * to use that instead of the current device */
187 tmpstr = cfg_get_strg(0, "partition");
190 int partnr = strtol(tmpstr, &endp, 10);
191 if (endp != tmpstr && !*endp) {
194 new_dev = malloc(strlen(devpath) + strlen(tmpstr) + 1);
198 strcpy(new_dev, devpath);
200 /* Strip digits (partition number) from string */
201 endp = new_dev + strlen(devpath) - 1;
202 while (isdigit(*endp))
205 /* and add our own... */
206 sprintf(endp + 1, "%d", partnr);
209 devpath = parse_device_path(new_dev, devpath);
215 defimage = cfg_get_default();
218 defimage = cfg_get_strg(defimage, "image");
220 label = cfg_next_image(NULL);
221 if (!label || !check_and_add_device(dev))
225 process_image(label);
226 } while ((label = cfg_next_image(label)));
231 struct parser yaboot_parser = {
232 .name = "yaboot.conf parser",
234 .parse = yaboot_parse