X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fgrub2%2Fgrub2.c;h=f62ccdd1aa9be4271d1372660a3dd1a5590b8f43;hp=fb3d8668a99bdfa5334ff8f62e6b4e98904e4af3;hb=b6e83bb17299987bdd64a46669c62ea524dd133b;hpb=1513dd5d05f6408a64e19ea18cfaeb0cb8c5fb73 diff --git a/discover/grub2/grub2.c b/discover/grub2/grub2.c index fb3d866..f62ccdd 100644 --- a/discover/grub2/grub2.c +++ b/discover/grub2/grub2.c @@ -1,15 +1,16 @@ #include +#include +#include #include +#include #include #include #include #include "grub2.h" -#include "parser.h" -#include "lexer.h" static const char *const grub2_conf_files[] = { "/grub.cfg", @@ -20,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", @@ -27,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 }; @@ -36,14 +39,20 @@ struct grub2_resource_info { }; /* we use slightly different resources for grub2 */ -struct resource *create_grub2_resource(void *ctx, +struct resource *create_grub2_resource(struct discover_boot_option *opt, struct discover_device *orig_device, const char *root, const char *path) { struct grub2_resource_info *info; struct resource *res; - res = talloc(ctx, struct resource); + if (strstr(path, "://")) { + struct pb_url *url = pb_url_parse(opt, path); + if (url) + return create_url_resource(opt, url); + } + + res = talloc(opt, struct resource); if (root) { info = talloc(res, struct grub2_resource_info); @@ -79,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; - - parser = grub2_parser_create(dc); - - grub2_parser_parse(parser, buf, len); - - talloc_free(parser); - - return 1; + 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; + } + + + 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, };