]> xenbits.xensource.com Git - xen.git/commitdiff
x86: Correctly cook command lines for GRUB2.
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 10 Aug 2010 14:49:20 +0000 (15:49 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 10 Aug 2010 14:49:20 +0000 (15:49 +0100)
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
xen-unstable changeset:   21883:4207549948a4
xen-unstable date:        Wed Jul 28 08:32:01 2010 +0100

xen/arch/x86/boot/reloc.c
xen/arch/x86/setup.c
xen/include/xen/multiboot.h
xen/include/xen/multiboot2.h [deleted file]

index 47b558b29cd3d468d15c9d6319657c9ec5f0f40a..b51d472ebe38d6fdeadd4e9441aae4d33b7d6a6c 100644 (file)
@@ -106,12 +106,17 @@ multiboot_info_t *reloc(multiboot_info_t *mbi_old)
         mbi->mmap_addr = (u32)reloc_mbi_struct(
             (memory_map_t *)mbi->mmap_addr, mbi->mmap_length);
 
+    if ( mbi->flags & MBI_LOADERNAME )
+        mbi->boot_loader_name = (u32)reloc_mbi_string(
+            (char *)mbi->boot_loader_name);
+
     /* Mask features we don't understand or don't relocate. */
     mbi->flags &= (MBI_MEMLIMITS |
-                   MBI_DRIVES |
+                   MBI_BOOTDEV |
                    MBI_CMDLINE |
                    MBI_MODULES |
-                   MBI_MEMMAP);
+                   MBI_MEMMAP |
+                   MBI_LOADERNAME);
 
     return mbi;
 }
index f1557fc68a31902845c777e3048b2c18417fe1da..33d6d7609410caa205b431761c632ba4f1d0f0b8 100644 (file)
@@ -431,22 +431,38 @@ void init_done(void)
     startup_cpu_idle_loop();
 }
 
-static char * __init cmdline_cook(char *p)
+static bool_t __init loader_is_grub2(const char *loader_name)
+{
+    /* GRUB1="GNU GRUB 0.xx"; GRUB2="GRUB 1.xx" */
+    const char *p = strstr(loader_name, "GRUB ");
+    return (p != NULL) && (p[5] != '0');
+}
+
+static char * __init cmdline_cook(char *p, char *loader_name)
 {
     p = p ? : "";
+
+    /* Strip leading whitespace. */
     while ( *p == ' ' )
         p++;
+
+    /* GRUB2 does not include image name as first item on command line. */
+    if ( loader_is_grub2(loader_name) )
+        return p;
+
+    /* Strip image name plus whitespace. */
     while ( (*p != ' ') && (*p != '\0') )
         p++;
     while ( *p == ' ' )
         p++;
+
     return p;
 }
 
 void __init __start_xen(unsigned long mbi_p)
 {
     char *memmap_type = NULL;
-    char *cmdline, *kextra;
+    char *cmdline, *kextra, *loader;
     unsigned long _initrd_start = 0, _initrd_len = 0;
     unsigned int initrdidx = 1;
     multiboot_info_t *mbi = __va(mbi_p);
@@ -464,9 +480,13 @@ void __init __start_xen(unsigned long mbi_p)
 
     set_intr_gate(TRAP_page_fault, &early_page_fault);
 
+    loader = (mbi->flags & MBI_LOADERNAME)
+        ? (char *)__va(mbi->boot_loader_name) : "unknown";
+
     /* Parse the command-line options. */
     cmdline = cmdline_cook((mbi->flags & MBI_CMDLINE) ?
-                           __va(mbi->cmdline) : NULL);
+                           __va(mbi->cmdline) : NULL,
+                           loader);
     if ( (kextra = strstr(cmdline, " -- ")) != NULL )
     {
         /*
@@ -508,6 +528,8 @@ void __init __start_xen(unsigned long mbi_p)
     ns16550_init(1, &ns16550);
     console_init_preirq();
 
+    printk("Bootloader: %s\n", loader);
+
     printk("Command line: %s\n", cmdline);
 
     printk("Video information:\n");
@@ -1109,7 +1131,7 @@ void __init __start_xen(unsigned long mbi_p)
     {
         static char dom0_cmdline[MAX_GUEST_CMDLINE];
 
-        cmdline = cmdline_cook(cmdline);
+        cmdline = cmdline_cook(cmdline, loader);
         safe_strcpy(dom0_cmdline, cmdline);
 
         if ( kextra != NULL )
index 86b59db1fe81d530140eb93e64f3c203f94ce345..53b30f22a6ddcf42b6c6c40ca3bc79db45981bb3 100644 (file)
 /* The magic number passed by a Multiboot-compliant boot loader. */
 #define MULTIBOOT_BOOTLOADER_MAGIC     0x2BADB002
 
-#define MBI_MEMLIMITS  (1<<0)
-#define MBI_DRIVES     (1<<1)
-#define MBI_CMDLINE    (1<<2)
-#define MBI_MODULES    (1<<3)
-#define MBI_AOUT_SYMS  (1<<4)
-#define MBI_ELF_SYMS   (1<<5)
-#define MBI_MEMMAP     (1<<6)
-#define MBI_LOADERNAME (1<<9)
+#define MBI_MEMLIMITS  (1u<< 0)
+#define MBI_BOOTDEV    (1u<< 1)
+#define MBI_CMDLINE    (1u<< 2)
+#define MBI_MODULES    (1u<< 3)
+#define MBI_AOUT_SYMS  (1u<< 4)
+#define MBI_ELF_SYMS   (1u<< 5)
+#define MBI_MEMMAP     (1u<< 6)
+#define MBI_DRIVES     (1u<< 7)
+#define MBI_BIOSCONFIG (1u<< 8)
+#define MBI_LOADERNAME (1u<< 9)
+#define MBI_APM        (1u<<10)
 
 #ifndef __ASSEMBLY__
 
@@ -66,7 +69,7 @@ typedef struct {
     u32 mem_lower;
     u32 mem_upper;
 
-    /* Valid if flags sets MBI_DRIVES */
+    /* Valid if flags sets MBI_BOOTDEV */
     u32 boot_device;
 
     /* Valid if flags sets MBI_CMDLINE */
@@ -85,6 +88,19 @@ typedef struct {
     /* Valid if flags sets MBI_MEMMAP */
     u32 mmap_length;
     u32 mmap_addr;
+
+    /* Valid if flags sets MBI_DRIVES */
+    u32 drives_length;
+    u32 drives_addr;
+
+    /* Valid if flags sets MBI_BIOSCONFIG */
+    u32 config_table;
+
+    /* Valid if flags sets MBI_LOADERNAME */
+    u32 boot_loader_name;
+
+    /* Valid if flags sets MBI_APM */
+    u32 apm_table;
 } multiboot_info_t;
 
 /* The module structure.  */
diff --git a/xen/include/xen/multiboot2.h b/xen/include/xen/multiboot2.h
deleted file mode 100644 (file)
index 1811750..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- *
- * Copyright IBM Corp. 2006, 2007
- *
- * Authors: Hollis Blanchard <hollisb@us.ibm.com>
- *          
- */
-
-#ifndef _MULTIBOOT2_H_
-#define _MULTIBOOT2_H_
-
-/* How many bytes from the start of the file we search for the header.  */
-#define MB2_HEADER_SEARCH           8192
-
-/* The magic field should contain this.  */
-#define MB2_HEADER_MAGIC            0xe85250d6
-
-/* Passed from the bootloader to the kernel.  */
-#define MB2_BOOTLOADER_MAGIC        0x36d76289
-
-#define for_each_tag(_tag, _tags) \
-    for ((_tag) = (_tags); \
-            ((_tag)->key != MB2_TAG_END && (_tag)->key != 0); \
-            (_tag) = (void *)(_tag) + (_tag)->len)
-
-typedef uint32_t mb2_word;
-
-struct mb2_header
-{
-  uint32_t magic;
-};
-
-struct mb2_tag_header
-{
-  uint32_t key;
-  uint32_t len;
-};
-
-#define MB2_TAG_START     1
-struct mb2_tag_start
-{
-  struct mb2_tag_header header;
-  mb2_word size; /* Total size of all mb2 tags. */
-};
-
-#define MB2_TAG_NAME      2
-struct mb2_tag_name
-{
-  struct mb2_tag_header header;
-  char name[1];
-};
-
-#define MB2_TAG_MODULE    3
-struct mb2_tag_module
-{
-  struct mb2_tag_header header;
-  mb2_word addr;
-  mb2_word size;
-  unsigned char type[36];
-  unsigned char cmdline[1];
-};
-
-#define MB2_TAG_MEMORY    4
-struct mb2_tag_memory
-{
-  struct mb2_tag_header header;
-  mb2_word addr;
-  mb2_word size;
-  mb2_word type;
-};
-
-#define MB2_TAG_UNUSED    5
-struct mb2_tag_unused
-{
-  struct mb2_tag_header header;
-};
-
-#define MB2_TAG_END       0xffff
-struct mb2_tag_end
-{
-  struct mb2_tag_header header;
-};
-
-#endif