From: robertmh Date: Fri, 7 Nov 2008 19:53:25 +0000 (+0000) Subject: 2008-11-07 Robert Millan X-Git-Tag: 1.98~1222 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c32ee8c9a88e94168bcb9d8dc3f6b1a7d5277ab2;p=thirdparty%2Fgrub.git 2008-11-07 Robert Millan * include/multiboot2.h (struct multiboot_header): Add `flags' member as per specification. * loader/multiboot2.c (grub_multiboot2): Fix Multiboot2 header check. * loader/multiboot_loader.c (find_multi_boot2_header): New function (based on find_multi_boot1_header). (grub_rescue_cmd_multiboot_loader): Check for Multiboot2 header, using find_multi_boot2_header(), and abort if neither Multiboot or Multiboot headers were found. --- diff --git a/ChangeLog b/ChangeLog index 481446c45..c00a0026e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-11-07 Robert Millan + + * include/multiboot2.h (struct multiboot_header): Add `flags' member as + per specification. + * loader/multiboot2.c (grub_multiboot2): Fix Multiboot2 header check. + * loader/multiboot_loader.c (find_multi_boot2_header): New function + (based on find_multi_boot1_header). + (grub_rescue_cmd_multiboot_loader): Check for Multiboot2 header, + using find_multi_boot2_header(), and abort if neither Multiboot or + Multiboot headers were found. + 2008-11-07 Robert Millan Modularize at_keyboard.mod: diff --git a/include/multiboot2.h b/include/multiboot2.h index f720dc3ea..0f2b0cf2d 100644 --- a/include/multiboot2.h +++ b/include/multiboot2.h @@ -46,6 +46,7 @@ typedef uint32_t multiboot_word; struct multiboot_header { uint32_t magic; + uint32_t flags; }; struct multiboot_tag_header diff --git a/loader/multiboot2.c b/loader/multiboot2.c index 42c6fadfe..2fb56bfdf 100644 --- a/loader/multiboot2.c +++ b/loader/multiboot2.c @@ -342,8 +342,8 @@ grub_multiboot2 (int argc, char *argv[]) } /* Look for the multiboot header in the buffer. The header should - be at least 12 bytes and aligned on a 4-byte boundary. */ - for (p = buffer; p <= buffer + len - 12; p += 4) + be at least 8 bytes and aligned on a 8-byte boundary. */ + for (p = buffer; p <= buffer + len - 8; p += 8) { header = (struct multiboot_header *) p; if (header->magic == MULTIBOOT2_HEADER_MAGIC) diff --git a/loader/multiboot_loader.c b/loader/multiboot_loader.c index d56b42c20..53971dfea 100644 --- a/loader/multiboot_loader.c +++ b/loader/multiboot_loader.c @@ -71,6 +71,34 @@ find_multi_boot1_header (grub_file_t file) return found_status; } +static int +find_multi_boot2_header (grub_file_t file) +{ + struct multiboot_header *header; + char buffer[MULTIBOOT_SEARCH]; + int found_status = 0; + grub_ssize_t len; + + len = grub_file_read (file, buffer, MULTIBOOT_SEARCH); + if (len < 32) + return found_status; + + /* Look for the multiboot header in the buffer. The header should + be at least 8 bytes and aligned on a 8-byte boundary. */ + for (header = (struct multiboot_header *) buffer; + ((char *) header <= buffer + len - 8) || (header = 0); + header = (struct multiboot_header *) ((char *) header + 8)) + { + if (header->magic == MULTIBOOT2_HEADER_MAGIC) + { + found_status = 1; + break; + } + } + + return found_status; +} + void grub_rescue_cmd_multiboot_loader (int argc, char *argv[]) { @@ -94,16 +122,14 @@ grub_rescue_cmd_multiboot_loader (int argc, char *argv[]) } /* find which header is in the file */ - if (find_multi_boot1_header(file)) + if (find_multi_boot1_header (file)) header_multi_ver_found = 1; + else if (find_multi_boot2_header (file)) + header_multi_ver_found = 2; else { - /* The behavior is that if you don't find a multiboot 1 header - use multiboot 2 loader (as you do not have to have a header - to use multiboot 2 */ - grub_dprintf ("multiboot_loader", "No multiboot 1 header found. \n \ - Using multiboot 2 loader\n"); - header_multi_ver_found = 0; + grub_error (GRUB_ERR_BAD_OS, "Multiboot header not found"); + goto fail; } /* close file before calling functions */