aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-08-10 15:49:20 +0100
committerKeir Fraser <keir.fraser@citrix.com>2010-08-10 15:49:20 +0100
commitd55a8f1a65c111c65296ac34f99b7869d01c489a (patch)
tree75cec24d721f10592a9b3aaaf4e4287c7342681f
parent11ad1ab5e05777fc17ec608b4e16467f44349f52 (diff)
downloadxen-d55a8f1a65c111c65296ac34f99b7869d01c489a.tar.gz
xen-d55a8f1a65c111c65296ac34f99b7869d01c489a.tar.bz2
xen-d55a8f1a65c111c65296ac34f99b7869d01c489a.zip
x86: Correctly cook command lines for GRUB2.
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
-rw-r--r--xen/arch/x86/boot/reloc.c9
-rw-r--r--xen/arch/x86/setup.c30
-rw-r--r--xen/include/xen/multiboot.h34
-rw-r--r--xen/include/xen/multiboot2.h97
4 files changed, 58 insertions, 112 deletions
diff --git a/xen/arch/x86/boot/reloc.c b/xen/arch/x86/boot/reloc.c
index 47b558b29c..b51d472ebe 100644
--- a/xen/arch/x86/boot/reloc.c
+++ b/xen/arch/x86/boot/reloc.c
@@ -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;
}
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index f1557fc68a..33d6d76094 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -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 )
diff --git a/xen/include/xen/multiboot.h b/xen/include/xen/multiboot.h
index 86b59db1fe..53b30f22a6 100644
--- a/xen/include/xen/multiboot.h
+++ b/xen/include/xen/multiboot.h
@@ -31,14 +31,17 @@
/* 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
index 1811750a42..0000000000
--- a/xen/include/xen/multiboot2.h
+++ /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