]> git.ozlabs.org Git - petitboot/blobdiff - discover/grub2-parser.c
discover/grub2: Add grub2/grub.cfg config file
[petitboot] / discover / grub2-parser.c
index 8a0868a7a72bdba905cf0d379c1c0e08ac3c65b7..cb9635e64122d766a4fc086e89b52fd13f25fac1 100644 (file)
@@ -30,7 +30,7 @@
 #include "types/types.h"
 #include "parser-conf.h"
 #include "parser-utils.h"
 #include "types/types.h"
 #include "parser-conf.h"
 #include "parser-utils.h"
-#include "paths.h"
+#include "resource.h"
 
 struct grub2_state {
        struct discover_boot_option *opt;
 
 struct grub2_state {
        struct discover_boot_option *opt;
@@ -72,12 +72,7 @@ static void grub2_finish(struct conf_context *conf)
 
        discover_context_add_boot_option(conf->dc, state->opt);
 
 
        discover_context_add_boot_option(conf->dc, state->opt);
 
-       state->opt = discover_boot_option_create(conf->dc, conf->dc->device);
-       opt = state->opt->option;
-       opt->boot_args = talloc_strdup(opt, "");
-
-       talloc_free(state->desc_image);
-       state->desc_image = NULL;
+       state->opt = NULL;
 }
 
 static void grub2_process_pair(struct conf_context *conf, const char *name,
 }
 
 static void grub2_process_pair(struct conf_context *conf, const char *name,
@@ -85,7 +80,7 @@ static void grub2_process_pair(struct conf_context *conf, const char *name,
 {
        struct device *dev = conf->dc->device->device;
        struct grub2_state *state = conf->parser_info;
 {
        struct device *dev = conf->dc->device->device;
        struct grub2_state *state = conf->parser_info;
-       struct boot_option *opt = state->opt->option;
+       struct discover_boot_option *opt = state->opt;
 
        if (!name || !conf_param_in_list(state->known_names, name))
                return;
 
        if (!name || !conf_param_in_list(state->known_names, name))
                return;
@@ -93,17 +88,25 @@ static void grub2_process_pair(struct conf_context *conf, const char *name,
        if (streq(name, "menuentry")) {
                char *sep;
 
        if (streq(name, "menuentry")) {
                char *sep;
 
-               grub2_finish(conf);
+               /* complete any existing option... */
+               if (state->opt)
+                       grub2_finish(conf);
 
 
-               /* Then start the new image. */
+               /* ... then start the new one */
+               opt = discover_boot_option_create(conf->dc, conf->dc->device);
+               opt->option->boot_args = talloc_strdup(opt->option, "");
 
                sep = strchr(value, '\'');
 
                if (sep)
                        *sep = 0;
 
 
                sep = strchr(value, '\'');
 
                if (sep)
                        *sep = 0;
 
-               opt->id = talloc_asprintf(opt, "%s#%s", dev->id, value);
-               opt->name = talloc_strdup(opt, value);
+               opt->option->id = talloc_asprintf(opt->option,
+                                       "%s#%s", dev->id, value);
+               opt->option->name = talloc_strdup(opt->option, value);
+               opt->option->boot_args = talloc_strdup(opt, "");
+
+               state->opt = opt;
 
                return;
        }
 
                return;
        }
@@ -116,20 +119,19 @@ static void grub2_process_pair(struct conf_context *conf, const char *name,
                if (sep)
                        *sep = 0;
 
                if (sep)
                        *sep = 0;
 
-               opt->boot_image_file = resolve_path(opt, value,
-                                       conf->dc->device->device_path);
+               opt->boot_image = create_devpath_resource(opt,
+                                       conf->dc->device, value);
                state->desc_image = talloc_strdup(opt, value);
 
                if (sep)
                state->desc_image = talloc_strdup(opt, value);
 
                if (sep)
-                       opt->boot_args = talloc_strdup(opt,
-                               sep + 1);
+                       opt->option->boot_args = talloc_strdup(opt, sep + 1);
 
                return;
        }
 
        if (streq(name, "initrd")) {
 
                return;
        }
 
        if (streq(name, "initrd")) {
-               opt->initrd_file = resolve_path(opt,
-                       value, conf->dc->device->device_path);
+               opt->initrd = create_devpath_resource(opt,
+                                       conf->dc->device, value);
                state->desc_initrd = talloc_asprintf(state, "initrd=%s",
                        value);
                return;
                state->desc_initrd = talloc_asprintf(state, "initrd=%s",
                        value);
                return;
@@ -142,12 +144,14 @@ static const char *const grub2_conf_files[] = {
        "/grub.cfg",
        "/menu.lst",
        "/grub/grub.cfg",
        "/grub.cfg",
        "/menu.lst",
        "/grub/grub.cfg",
+       "/grub2/grub.cfg",
        "/grub/menu.lst",
        "/boot/grub/grub.cfg",
        "/boot/grub/menu.lst",
        "/GRUB.CFG",
        "/MENU.LST",
        "/GRUB/GRUB.CFG",
        "/grub/menu.lst",
        "/boot/grub/grub.cfg",
        "/boot/grub/menu.lst",
        "/GRUB.CFG",
        "/MENU.LST",
        "/GRUB/GRUB.CFG",
+       "/GRUB2/GRUB.CFG",
        "/GRUB/MENU.LST",
        "/BOOT/GRUB/GRUB.CFG",
        "/BOOT/GRUB/MENU.LST",
        "/GRUB/MENU.LST",
        "/BOOT/GRUB/GRUB.CFG",
        "/BOOT/GRUB/MENU.LST",
@@ -180,19 +184,18 @@ static int grub2_parse(struct discover_context *dc, char *buf, int len)
 
        state->known_names = grub2_known_names;
 
 
        state->known_names = grub2_known_names;
 
-       /* opt is persistent, so must be associated with device */
-
-       state->opt = discover_boot_option_create(dc, dc->device);
-       state->opt->option->boot_args = talloc_strdup(state->opt->option, "");
-
        conf_parse_buf(conf, buf, len);
 
        talloc_free(conf);
        return 1;
 }
 
        conf_parse_buf(conf, buf, len);
 
        talloc_free(conf);
        return 1;
 }
 
-struct parser __grub2_parser = {
-       .name           = "grub2",
-       .parse          = grub2_parse,
-       .filenames      = grub2_conf_files,
+static struct parser grub2_parser = {
+       .name                   = "grub2",
+       .method                 = CONF_METHOD_LOCAL_FILE,
+       .parse                  = grub2_parse,
+       .filenames              = grub2_conf_files,
+       .resolve_resource       = resolve_devpath_resource,
 };
 };
+
+register_parser(grub2_parser);