From: "Jan Beulich" Subject: [PATCH] x86: allow Dom0 image to be compressed ELF Date: Tue, 21 Jun 2011 08:59:27 +0100 Message-ID: <4E006B7F02000078000486E9@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part2609654F.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part2609654F.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Rather than being able to decompress only the payloads of bzImage containers, extend the logic to also decompress simple compressed ELF images. At once, allow uncompressed bzImage payloads. This is a prerequisite for native EFI booting support (where, in the absence of a capable secondary boot loader, the image will always be in compressed form). Signed-off-by: Jan Beulich --- a/xen/arch/x86/bzimage.c +++ b/xen/arch/x86/bzimage.c @@ -5,6 +5,7 @@ #include #include #include +#include #include =20 #define HEAPORDER 3 @@ -200,25 +201,36 @@ static __init int bzimage_check(struct s return 1; } =20 -int __init bzimage_headroom(char *image_start, unsigned long image_length)= +static unsigned long __initdata orig_image_len; + +unsigned long __init bzimage_headroom(char *image_start, + unsigned long image_length) { struct setup_header *hdr =3D (struct setup_header *)image_start; - char *img; - int err, headroom; + int err; + unsigned long headroom; =20 err =3D bzimage_check(hdr, image_length); - if (err < 1) + if ( err < 0 ) return 0; =20 - img =3D image_start + (hdr->setup_sects+1) * 512; - img +=3D hdr->payload_offset; + if ( err > 0 ) + { + image_start +=3D (hdr->setup_sects + 1) * 512 + hdr->payload_offse= t; + image_length =3D hdr->payload_length; + } + + if ( elf_is_elfbinary(image_start) ) + return 0; =20 - headroom =3D output_length(img, hdr->payload_length); - if (gzip_check(img, hdr->payload_length)) { + orig_image_len =3D image_length; + headroom =3D output_length(image_start, image_length); + if (gzip_check(image_start, image_length)) + { headroom +=3D headroom >> 12; /* Add 8 bytes for every 32K input = block */ headroom +=3D (32768 + 18); /* Add 32K + 18 bytes of extra = headroom */ } else - headroom +=3D hdr->payload_length; + headroom +=3D image_length; headroom =3D (headroom + 4095) & ~4095; =20 return headroom; @@ -230,18 +242,24 @@ int __init bzimage_parse(char *image_bas int err =3D bzimage_check(hdr, *image_len); unsigned long output_len; =20 - if (err < 1) + if ( err < 0 ) return err; =20 + if ( err > 0 ) + { + *image_start +=3D (hdr->setup_sects + 1) * 512 + hdr->payload_offs= et; + *image_len =3D hdr->payload_length; + } + + if ( elf_is_elfbinary(*image_start) ) + return 0; + BUG_ON(!(image_base < *image_start)); =20 - *image_start +=3D (hdr->setup_sects+1) * 512; - *image_start +=3D hdr->payload_offset; - *image_len =3D hdr->payload_length; - output_len =3D output_length(*image_start, *image_len); + output_len =3D output_length(*image_start, orig_image_len); =20 - if ( (err =3D perform_gunzip(image_base, *image_start, *image_len)) > = 0 ) - err =3D decompress(*image_start, *image_len, image_base); + if ( (err =3D perform_gunzip(image_base, *image_start, orig_image_len)= ) > 0 ) + err =3D decompress(*image_start, orig_image_len, image_base); =20 if ( !err ) { --- a/xen/include/asm-x86/bzimage.h +++ b/xen/include/asm-x86/bzimage.h @@ -4,7 +4,7 @@ #include #include =20 -int bzimage_headroom(char *image_start, unsigned long image_length); +unsigned long bzimage_headroom(char *image_start, unsigned long image_leng= th); =20 int bzimage_parse(char *image_base, char **image_start, unsigned long *image_len); --=__Part2609654F.0__= Content-Type: text/plain; name="x86-dom0-compressed-ELF.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-dom0-compressed-ELF.patch" Rather than being able to decompress only the payloads of bzImage=0Acontain= ers, extend the logic to also decompress simple compressed ELF=0Aimages. = At once, allow uncompressed bzImage payloads.=0A=0AThis is a prerequisite = for native EFI booting support (where, in the=0Aabsence of a capable = secondary boot loader, the image will always be=0Ain compressed = form).=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/bzimage.c=0A+++ b/xen/arch/x86/bzimage.c=0A@@ -5,6 +5,7 = @@=0A #include =0A #include =0A #include = =0A+#include =0A #include = =0A =0A #define HEAPORDER 3=0A@@ -200,25 +201,36 @@ static __init int = bzimage_check(struct s=0A return 1;=0A }=0A =0A-int __init bzimage_head= room(char *image_start, unsigned long image_length)=0A+static unsigned = long __initdata orig_image_len;=0A+=0A+unsigned long __init bzimage_headroo= m(char *image_start,=0A+ unsigned = long image_length)=0A {=0A struct setup_header *hdr =3D (struct = setup_header *)image_start;=0A- char *img;=0A- int err, headroom;=0A+= int err;=0A+ unsigned long headroom;=0A =0A err =3D bzimage_chec= k(hdr, image_length);=0A- if (err < 1)=0A+ if ( err < 0 )=0A = return 0;=0A =0A- img =3D image_start + (hdr->setup_sects+1) * 512;=0A- = img +=3D hdr->payload_offset;=0A+ if ( err > 0 )=0A+ {=0A+ = image_start +=3D (hdr->setup_sects + 1) * 512 + hdr->payload_offset;=0A+ = image_length =3D hdr->payload_length;=0A+ }=0A+=0A+ if ( = elf_is_elfbinary(image_start) )=0A+ return 0;=0A =0A- headroom = =3D output_length(img, hdr->payload_length);=0A- if (gzip_check(img, = hdr->payload_length)) {=0A+ orig_image_len =3D image_length;=0A+ = headroom =3D output_length(image_start, image_length);=0A+ if (gzip_chec= k(image_start, image_length))=0A+ {=0A headroom +=3D headroom = >> 12; /* Add 8 bytes for every 32K input block */=0A headroom = +=3D (32768 + 18); /* Add 32K + 18 bytes of extra headroom */=0A } = else=0A- headroom +=3D hdr->payload_length;=0A+ headroom = +=3D image_length;=0A headroom =3D (headroom + 4095) & ~4095;=0A =0A = return headroom;=0A@@ -230,18 +242,24 @@ int __init bzimage_parse(char = *image_bas=0A int err =3D bzimage_check(hdr, *image_len);=0A = unsigned long output_len;=0A =0A- if (err < 1)=0A+ if ( err < 0 )=0A = return err;=0A =0A+ if ( err > 0 )=0A+ {=0A+ = *image_start +=3D (hdr->setup_sects + 1) * 512 + hdr->payload_offset;=0A+ = *image_len =3D hdr->payload_length;=0A+ }=0A+=0A+ if ( = elf_is_elfbinary(*image_start) )=0A+ return 0;=0A+=0A BUG_ON(!(i= mage_base < *image_start));=0A =0A- *image_start +=3D (hdr->setup_sects+= 1) * 512;=0A- *image_start +=3D hdr->payload_offset;=0A- *image_len = =3D hdr->payload_length;=0A- output_len =3D output_length(*image_start, = *image_len);=0A+ output_len =3D output_length(*image_start, orig_image_l= en);=0A =0A- if ( (err =3D perform_gunzip(image_base, *image_start, = *image_len)) > 0 )=0A- err =3D decompress(*image_start, *image_len, = image_base);=0A+ if ( (err =3D perform_gunzip(image_base, *image_start, = orig_image_len)) > 0 )=0A+ err =3D decompress(*image_start, = orig_image_len, image_base);=0A =0A if ( !err )=0A {=0A--- = a/xen/include/asm-x86/bzimage.h=0A+++ b/xen/include/asm-x86/bzimage.h=0A@@ = -4,7 +4,7 @@=0A #include =0A #include =0A = =0A-int bzimage_headroom(char *image_start, unsigned long image_length);=0A= +unsigned long bzimage_headroom(char *image_start, unsigned long image_leng= th);=0A =0A int bzimage_parse(char *image_base, char **image_start,=0A = unsigned long *image_len);=0A --=__Part2609654F.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part2609654F.0__=--