[1897] 2008-11-07 Robert Millan <[email protected]>

Robert Millan <[email protected]>
Newsgroups gmane.comp.boot-loaders.grub.cvs
Message-ID <[email protected]>
Revision: 1897
          http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=1897
Author:   robertmh
Date:     2008-11-07 19:53:25 +0000 (Fri, 07 Nov 2008)

Log Message:
-----------
2008-11-07  Robert Millan  <[email protected]>

        * 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.

Modified Paths:
--------------
    trunk/grub2/ChangeLog
    trunk/grub2/include/multiboot2.h
    trunk/grub2/loader/multiboot2.c
    trunk/grub2/loader/multiboot_loader.c

Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog	2008-11-07 19:12:11 UTC (rev 1896)
+++ trunk/grub2/ChangeLog	2008-11-07 19:53:25 UTC (rev 1897)
@@ -1,5 +1,16 @@
 2008-11-07  Robert Millan  <[email protected]>
 
+	* 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  <[email protected]>
+
 	Modularize at_keyboard.mod:
 
 	* conf/i386.rmk (pkglib_MODULES): Add `at_keyboard.mod'.

Modified: trunk/grub2/include/multiboot2.h
===================================================================
--- trunk/grub2/include/multiboot2.h	2008-11-07 19:12:11 UTC (rev 1896)
+++ trunk/grub2/include/multiboot2.h	2008-11-07 19:53:25 UTC (rev 1897)
@@ -46,6 +46,7 @@
 struct multiboot_header
 {
   uint32_t magic;
+  uint32_t flags;
 };
 
 struct multiboot_tag_header

Modified: trunk/grub2/loader/multiboot2.c
===================================================================
--- trunk/grub2/loader/multiboot2.c	2008-11-07 19:12:11 UTC (rev 1896)
+++ trunk/grub2/loader/multiboot2.c	2008-11-07 19:53:25 UTC (rev 1897)
@@ -342,8 +342,8 @@
     }
 
   /* 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)

Modified: trunk/grub2/loader/multiboot_loader.c
===================================================================
--- trunk/grub2/loader/multiboot_loader.c	2008-11-07 19:12:11 UTC (rev 1896)
+++ trunk/grub2/loader/multiboot_loader.c	2008-11-07 19:53:25 UTC (rev 1897)
@@ -71,6 +71,34 @@
    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 @@
     }
 
   /* 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 */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.