grub2/grub2: add Yocto paths to default grub2 conf search paths
[petitboot] / discover / grub2 / grub2.c
index 22d42dfc432a093d776a03b4109847413a66077b..f62ccdd1aa9be4271d1372660a3dd1a5590b8f43 100644 (file)
@@ -1,5 +1,7 @@
 
 #include <assert.h>
+#include <string.h>
+#include <i18n/i18n.h>
 
 #include <talloc/talloc.h>
 #include <url/url.h>
@@ -9,8 +11,6 @@
 #include <discover/parser-utils.h>
 
 #include "grub2.h"
-#include "parser.h"
-#include "lexer.h"
 
 static const char *const grub2_conf_files[] = {
        "/grub.cfg",
@@ -21,6 +21,7 @@ static const char *const grub2_conf_files[] = {
        "/boot/grub/grub.cfg",
        "/boot/grub2/grub.cfg",
        "/boot/grub/menu.lst",
+       "/efi/boot/grub.cfg",
        "/GRUB.CFG",
        "/MENU.LST",
        "/GRUB/GRUB.CFG",
@@ -28,6 +29,7 @@ static const char *const grub2_conf_files[] = {
        "/GRUB/MENU.LST",
        "/BOOT/GRUB/GRUB.CFG",
        "/BOOT/GRUB/MENU.LST",
+       "/EFI/BOOT/GRUB.CFG",
        NULL
 };
 
@@ -86,24 +88,39 @@ bool resolve_grub2_resource(struct device_handler *handler,
        return true;
 }
 
-static int grub2_parse(struct discover_context *dc, char *buf, int len)
+static int grub2_parse(struct discover_context *dc)
 {
+       const char * const *filename;
        struct grub2_parser *parser;
+       int len, rc;
+       char *buf;
+
+       /* Support block device boot only at present */
+       if (dc->event)
+               return -1;
+
+       for (filename = grub2_conf_files; *filename; filename++) {
+               rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
+               if (rc)
+                       continue;
+
+               parser = grub2_parser_create(dc);
+               grub2_parser_parse(parser, *filename, buf, len);
+               device_handler_status_dev_info(dc->handler, dc->device,
+                               _("Parsed GRUB configuration from %s"),
+                               *filename);
+               talloc_free(buf);
+               talloc_free(parser);
+               break;
+       }
 
-       parser = grub2_parser_create(dc);
-
-       grub2_parser_parse(parser, buf, len);
-
-       talloc_free(parser);
 
-       return 1;
+       return 0;
 }
 
 static struct parser grub2_parser = {
        .name                   = "grub2",
-       .method                 = CONF_METHOD_LOCAL_FILE,
        .parse                  = grub2_parse,
-       .filenames              = grub2_conf_files,
        .resolve_resource       = resolve_grub2_resource,
 };