ia64/xen-unstable

changeset 17362:db943e8d1051

x86: Support loading Linux bzImage v2.08 and up.

The latest -mm kernel (2.6.25-rc3-mm1) contains v2.08 of the Linux
bzImage format which embeds an ELF file in place of the raw payload
allowing it to be extracted and used by the Xen domain builder.

It is expected that this functionality will be put forward for 2.6.26.

Signed-off-by : Ian Campbell <ijc@hellion.org.uk>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Apr 01 10:09:33 2008 +0100 (2008-04-01)
parents ff32e4cd61af
children 69c951243105
files tools/libxc/Makefile tools/libxc/xc_dom_bzimageloader.c tools/libxc/xc_dom_elfloader.c
line diff
     1.1 --- a/tools/libxc/Makefile	Tue Apr 01 10:08:03 2008 +0100
     1.2 +++ b/tools/libxc/Makefile	Tue Apr 01 10:09:33 2008 +0100
     1.3 @@ -46,10 +46,11 @@ GUEST_SRCS-y += libelf-tools.c libelf-lo
     1.4  GUEST_SRCS-y += libelf-dominfo.c libelf-relocate.c
     1.5  
     1.6  # new domain builder
     1.7 -GUEST_SRCS-y += xc_dom_core.c xc_dom_boot.c
     1.8 -GUEST_SRCS-y += xc_dom_elfloader.c
     1.9 -GUEST_SRCS-y += xc_dom_binloader.c
    1.10 -GUEST_SRCS-y += xc_dom_compat_linux.c
    1.11 +GUEST_SRCS-y                 += xc_dom_core.c xc_dom_boot.c
    1.12 +GUEST_SRCS-y                 += xc_dom_elfloader.c
    1.13 +GUEST_SRCS-$(CONFIG_X86)     += xc_dom_bzimageloader.c
    1.14 +GUEST_SRCS-y                 += xc_dom_binloader.c
    1.15 +GUEST_SRCS-y                 += xc_dom_compat_linux.c
    1.16  
    1.17  GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c
    1.18  GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_ia64.c
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/libxc/xc_dom_bzimageloader.c	Tue Apr 01 10:09:33 2008 +0100
     2.3 @@ -0,0 +1,159 @@
     2.4 +/*
     2.5 + * Xen domain builder -- bzImage bits
     2.6 + *
     2.7 + * Parse and load bzImage kernel images.
     2.8 + *
     2.9 + * This relies on version 2.08 of the boot protocol, which contains an
    2.10 + * ELF file embedded in the bzImage.  The loader extracts this ELF
    2.11 + * image and passes it off to the standard ELF loader.
    2.12 + *
    2.13 + * This code is licenced under the GPL.
    2.14 + * written 2006 by Gerd Hoffmann <kraxel@suse.de>.
    2.15 + * written 2007 by Jeremy Fitzhardinge <jeremy@xensource.com>
    2.16 + * written 2008 by Ian Campbell <ijc@hellion.org.uk>
    2.17 + *
    2.18 + */
    2.19 +#include <stdio.h>
    2.20 +#include <stdlib.h>
    2.21 +#include <inttypes.h>
    2.22 +
    2.23 +#include "xg_private.h"
    2.24 +#include "xc_dom.h"
    2.25 +
    2.26 +struct setup_header {
    2.27 +	uint8_t		_pad0[0x1f1];		/* skip uninteresting stuff */
    2.28 +	uint8_t		setup_sects;
    2.29 +	uint16_t	root_flags;
    2.30 +	uint32_t	syssize;
    2.31 +	uint16_t	ram_size;
    2.32 +	uint16_t	vid_mode;
    2.33 +	uint16_t	root_dev;
    2.34 +	uint16_t	boot_flag;
    2.35 +	uint16_t	jump;
    2.36 +	uint32_t	header;
    2.37 +#define HDR_MAGIC		"HdrS"
    2.38 +#define HDR_MAGIC_SZ	4
    2.39 +	uint16_t	version;
    2.40 +#define VERSION(h,l)	(((h)<<8) | (l))
    2.41 +	uint32_t	realmode_swtch;
    2.42 +	uint16_t	start_sys;
    2.43 +	uint16_t	kernel_version;
    2.44 +	uint8_t		type_of_loader;
    2.45 +	uint8_t		loadflags;
    2.46 +	uint16_t	setup_move_size;
    2.47 +	uint32_t	code32_start;
    2.48 +	uint32_t	ramdisk_image;
    2.49 +	uint32_t	ramdisk_size;
    2.50 +	uint32_t	bootsect_kludge;
    2.51 +	uint16_t	heap_end_ptr;
    2.52 +	uint16_t	_pad1;
    2.53 +	uint32_t	cmd_line_ptr;
    2.54 +	uint32_t	initrd_addr_max;
    2.55 +	uint32_t	kernel_alignment;
    2.56 +	uint8_t		relocatable_kernel;
    2.57 +	uint8_t		_pad2[3];
    2.58 +	uint32_t	cmdline_size;
    2.59 +	uint32_t	hardware_subarch;
    2.60 +	uint64_t	hardware_subarch_data;
    2.61 +	uint32_t	payload_offset;
    2.62 +	uint32_t	payload_length;
    2.63 +} __attribute__((packed));
    2.64 +
    2.65 +extern struct xc_dom_loader elf_loader;
    2.66 +
    2.67 +static unsigned int payload_offset(struct setup_header *hdr)
    2.68 +{
    2.69 +    unsigned int off;
    2.70 +
    2.71 +    off = (hdr->setup_sects + 1) * 512;
    2.72 +    off += hdr->payload_offset;
    2.73 +    return off;
    2.74 +}
    2.75 +
    2.76 +static int check_bzimage_kernel(struct xc_dom_image *dom, int verbose)
    2.77 +{
    2.78 +    struct setup_header *hdr;
    2.79 +
    2.80 +    if ( dom->kernel_blob == NULL )
    2.81 +    {
    2.82 +        if ( verbose )
    2.83 +            xc_dom_panic(XC_INTERNAL_ERROR, "%s: no kernel image loaded\n",
    2.84 +                         __FUNCTION__);
    2.85 +        return -EINVAL;
    2.86 +    }
    2.87 +    if ( dom->kernel_size < sizeof(struct setup_header) )
    2.88 +    {
    2.89 +        if ( verbose )
    2.90 +            xc_dom_panic(XC_INTERNAL_ERROR, "%s: kernel image too small\n",
    2.91 +                         __FUNCTION__);
    2.92 +        return -EINVAL;
    2.93 +    }
    2.94 +
    2.95 +    hdr = dom->kernel_blob;
    2.96 +
    2.97 +    if ( memcmp(&hdr->header, HDR_MAGIC, HDR_MAGIC_SZ) != 0 )
    2.98 +    {
    2.99 +        if ( verbose )
   2.100 +            xc_dom_panic(XC_INVALID_KERNEL, "%s: kernel is not a bzImage\n",
   2.101 +                         __FUNCTION__);
   2.102 +        return -EINVAL;
   2.103 +    }
   2.104 +
   2.105 +    if ( hdr->version < VERSION(2,8) )
   2.106 +    {
   2.107 +        if ( verbose )
   2.108 +            xc_dom_panic(XC_INVALID_KERNEL, "%s: boot protocol too old (%04x)\n",
   2.109 +                         __FUNCTION__, hdr->version);
   2.110 +        return -EINVAL;
   2.111 +    }
   2.112 +
   2.113 +    dom->kernel_blob = dom->kernel_blob + payload_offset(hdr);
   2.114 +    dom->kernel_size = hdr->payload_length;
   2.115 +
   2.116 +    if ( xc_dom_try_gunzip(dom, &dom->kernel_blob, &dom->kernel_size) == -1 )
   2.117 +    {
   2.118 +        if ( verbose )
   2.119 +            xc_dom_panic(XC_INVALID_KERNEL, "%s: unable to decompress kernel\n",
   2.120 +                         __FUNCTION__);
   2.121 +        return -EINVAL;
   2.122 +    }
   2.123 +
   2.124 +    return elf_loader.probe(dom);
   2.125 +}
   2.126 +
   2.127 +static int xc_dom_probe_bzimage_kernel(struct xc_dom_image *dom)
   2.128 +{
   2.129 +    return check_bzimage_kernel(dom, 0);
   2.130 +}
   2.131 +
   2.132 +static int xc_dom_parse_bzimage_kernel(struct xc_dom_image *dom)
   2.133 +{
   2.134 +    return elf_loader.parser(dom);
   2.135 +}
   2.136 +
   2.137 +static int xc_dom_load_bzimage_kernel(struct xc_dom_image *dom)
   2.138 +{
   2.139 +    return elf_loader.loader(dom);
   2.140 +}
   2.141 +
   2.142 +static struct xc_dom_loader bzimage_loader = {
   2.143 +    .name = "Linux bzImage",
   2.144 +    .probe = xc_dom_probe_bzimage_kernel,
   2.145 +    .parser = xc_dom_parse_bzimage_kernel,
   2.146 +    .loader = xc_dom_load_bzimage_kernel,
   2.147 +};
   2.148 +
   2.149 +static void __init register_loader(void)
   2.150 +{
   2.151 +    xc_dom_register_loader(&bzimage_loader);
   2.152 +}
   2.153 +
   2.154 +/*
   2.155 + * Local variables:
   2.156 + * mode: C
   2.157 + * c-set-style: "BSD"
   2.158 + * c-basic-offset: 4
   2.159 + * tab-width: 4
   2.160 + * indent-tabs-mode: nil
   2.161 + * End:
   2.162 + */
     3.1 --- a/tools/libxc/xc_dom_elfloader.c	Tue Apr 01 10:08:03 2008 +0100
     3.2 +++ b/tools/libxc/xc_dom_elfloader.c	Tue Apr 01 10:09:33 2008 +0100
     3.3 @@ -281,7 +281,7 @@ static int xc_dom_load_elf_kernel(struct
     3.4  
     3.5  /* ------------------------------------------------------------------------ */
     3.6  
     3.7 -static struct xc_dom_loader elf_loader = {
     3.8 +struct xc_dom_loader elf_loader = {
     3.9      .name = "ELF-generic",
    3.10      .probe = xc_dom_probe_elf_kernel,
    3.11      .parser = xc_dom_parse_elf_kernel,