From: Xuesen Guo Subject: Re: [PATCH] readnote: Add bzImage kernel support Date: Mon, 28 May 2012 14:54:53 +0800 Message-ID: <1338188093.3965.6.camel@goosenl-desktop> References: <27a6422ac06df8bef75d.1335430449@localhost6.localdomain6> <4F992DCF0200007800080283@nat28.tlf.novell.com> <1335432002.28015.78.camel@zakaz.uk.xensource.com> <1335433871.4742.18.camel@goosenl-desktop> <1335487527.4742.19.camel@goosenl-desktop> <20397.16795.166767.442835@mariner.uk.xensource.com> <1336754967.23818.142.camel@zakaz.uk.xensource.com> <1338185019.3965.5.camel@goosenl-desktop> Reply-To: Xuesen.Guo@hitachiconsulting.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-nmoUZ8ImmCvgRVsJ9wfH" Return-path: In-Reply-To: <1338185019.3965.5.camel@goosenl-desktop> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: xen-devel , Ian Jackson , Jan Beulich , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org --=-nmoUZ8ImmCvgRVsJ9wfH Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Also the attached is the patch. On Mon, 2012-05-28 at 14:03 +0800, Xuesen Guo wrote: > I used the Evolution(GUI) sending patches manually, this might mangle the= whitespace of a patch making it impossible to apply. > According to Linux's email-clients.txt, I resend this patch. >=20 > # HG changeset patch > # Parent d690c7e896a26c54a5ab85458824059de72d5cba > readnote: Add bzImage kernel support >=20 > Add the check of bzImage kernel and make it work > with RHEL 6 big zImage kernel >=20 > Signed-off-by: Xuesen Guo > Acked-by: Ian Campbell >=20 > --- > Changed since v1: > * add additional checks of the offset and length > * not changing st.st_size, use size instead of st.st_size > =20 > --- > Changed since v2: > * changing decription bzipped kernels to big zImage kernel >=20 > diff -r d690c7e896a2 tools/xcutils/readnotes.c > --- a/tools/xcutils/readnotes.c=09Thu Apr 05 11:06:03 2012 +0100 > +++ b/tools/xcutils/readnotes.c=09Thu Apr 26 16:53:16 2012 +0800 > @@ -18,6 +18,48 @@ > =20 > static xc_interface *xch; > =20 > +/* According to the implemation of xc_dom_probe_bzimage_kernel() functio= n */ > +/* We add support of bzImage kernel */ > +/* Copied from tools/libxc/xc_doom_bzImageloader.c */ > +struct setup_header { > +=09uint8_t _pad0[0x1f1]; /* skip uninteresting stuff */ > +=09uint8_t setup_sects; > +=09uint16_t root_flags; > +=09uint32_t syssize; > +=09uint16_t ram_size; > +=09uint16_t vid_mode; > +=09uint16_t root_dev; > +=09uint16_t boot_flag; > +=09uint16_t jump; > +=09uint32_t header; > +#define HDR_MAGIC "HdrS" > +#define HDR_MAGIC_SZ 4 > +=09uint16_t version; > +#define VERSION(h,l) (((h)<<8) | (l)) > +=09uint32_t realmode_swtch; > +=09uint16_t start_sys; > +=09uint16_t kernel_version; > +=09uint8_t type_of_loader; > +=09uint8_t loadflags; > +=09uint16_t setup_move_size; > +=09uint32_t code32_start; > +=09uint32_t ramdisk_image; > +=09uint32_t ramdisk_size; > +=09uint32_t bootsect_kludge; > +=09uint16_t heap_end_ptr; > +=09uint16_t _pad1; > +=09uint32_t cmd_line_ptr; > +=09uint32_t initrd_addr_max; > +=09uint32_t kernel_alignment; > +=09uint8_t relocatable_kernel; > +=09uint8_t _pad2[3]; > +=09uint32_t cmdline_size; > +=09uint32_t hardware_subarch; > +=09uint64_t hardware_subarch_data; > +=09uint32_t payload_offset; > +=09uint32_t payload_length; > +} __attribute__((packed)); > + > static void print_string_note(const char *prefix, struct elf_binary *elf= , > =09=09=09 const elf_note *note) > { > @@ -131,6 +173,9 @@ int main(int argc, char **argv) > =09const elf_shdr *shdr; > =09int notes_found =3D 0; > =20 > +=09struct setup_header *hdr; > +=09uint64_t payload_offset, payload_length; > + > =09if (argc !=3D 2) > =09{ > =09=09fprintf(stderr, "Usage: readnotes \n"); > @@ -159,13 +204,45 @@ int main(int argc, char **argv) > =09=09fprintf(stderr, "Unable to map %s: %s\n", f, strerror(errno)); > =09=09return 1; > =09} > -=09size =3D st.st_size; > +=09 > +=09/* Check the magic of bzImage kernel */ > +=09hdr =3D (struct setup_header *)image; > +=09if ( memcmp(&hdr->header, HDR_MAGIC, HDR_MAGIC_SZ) =3D=3D 0 ) > +=09{ > +=09=09if ( hdr->version < VERSION(2,8) ) > +=09=09{ > +=09=09=09printf("%s: boot protocol too old (%04x)", __FUNCTION__, hdr->v= ersion); > +=09=09=09return 1; > +=09=09} > =20 > -=09usize =3D xc_dom_check_gzip(xch, image, st.st_size); > +=09=09/* upcast to 64 bits to avoid overflow */ > +=09=09/* setup_sects is u8 and so cannot overflow */ > +=09=09payload_offset =3D (hdr->setup_sects + 1) * 512; > +=09=09payload_offset +=3D hdr->payload_offset; > +=09=09payload_length =3D hdr->payload_length; > +=09=09 > +=09=09if ( payload_offset >=3D st.st_size ) > +=09=09{ > +=09=09=09printf("%s: payload offset overflow", __FUNCTION__); > +=09=09=09return 1; > +=09=09} > +=09=09if ( (payload_offset + payload_length) > st.st_size ) > +=09=09{ > +=09=09=09printf("%s: payload length overflow", __FUNCTION__); > +=09=09=09return 1; > +=09=09} > + > +=09=09image =3D image + payload_offset; > +=09=09size =3D payload_length; > +=09} else { > +=09=09size =3D st.st_size; > +=09} > + > +=09usize =3D xc_dom_check_gzip(xch, image, size); > =09if (usize) > =09{ > =09=09tmp =3D malloc(usize); > -=09=09xc_dom_do_gunzip(xch, image, st.st_size, tmp, usize); > +=09=09xc_dom_do_gunzip(xch, image, size, tmp, usize); > =09=09image =3D tmp; > =09=09size =3D usize; > =09} >=20 >=20 > On Fri, 2012-05-11 at 17:49 +0100, Ian Campbell wrote: > > On Fri, 2012-05-11 at 17:43 +0100, Ian Jackson wrote: > > > Xuesen Guo writes ("Re: [Xen-devel] [PATCH] readnote: Add bzImage ker= nel support"): > > > > readnote: Add bzImage kernel support > > >=20 > > > I tried to apply this but I'm afraid it no longer applies to > > > xen-unstable tip: > > >=20 > > > patching file tools/xcutils/readnotes.c > > > Hunk #1 FAILED at 17 > > > Hunk #3 FAILED at 161 > > > 2 out of 3 hunks FAILED -- saving rejects to file tools/xcutils/readn= otes.c.rej > > > abort: patch failed to apply > > >=20 > > > Ian. > >=20 > > The most recent change to this file was=20 > > changeset: 21483:779c0ef9682c > > user: Keir Fraser > > date: Fri May 28 09:30:19 2010 +0100 > > summary: libxc: eliminate static variables, use xentoollog;= API change > > =20 > > I expect something else is up -- whitespace mangling perhaps? Or maybe > > the patch simply isn't based on xen-unstable.hg? > >=20 > > Ian. > >=20 > >=20 >=20 This e-mail is intended solely for the person or entity to which it is addr= essed and may contain confidential and/or privileged information. Any review, dis= semination, copying, printing or other use of this e-mail by persons or entities other = than the=20 addressee is prohibited. If you have received this e-mail in error, please = contact the sender immediately and delete the material from any computer. To unsubscribe send an email to: Unsubscribe@hitachiconsulting.com=20 Hitachi Consulting (China) Co., Ltd. (HCCD0411) --=-nmoUZ8ImmCvgRVsJ9wfH Content-Type: text/x-patch; name=bzipped-kernels-support.diff; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="bzipped-kernels-support.diff" # HG changeset patch # Parent d690c7e896a26c54a5ab85458824059de72d5cba readnote: Add bzImage kernel support Add the check of bzImage kernel and make it work with RHEL 6 big zImage kernel Signed-off-by: Xuesen Guo Acked-by: Ian Campbell --- Changed since v1: * add additional checks of the offset and length * not changing st.st_size, use size instead of st.st_size =20 --- Changed since v2: * changing decription bzipped kernels to big zImage kernel diff -r d690c7e896a2 tools/xcutils/readnotes.c --- a/tools/xcutils/readnotes.c=09Thu Apr 05 11:06:03 2012 +0100 +++ b/tools/xcutils/readnotes.c=09Thu Apr 26 16:53:16 2012 +0800 @@ -18,6 +18,48 @@ =20 static xc_interface *xch; =20 +/* According to the implemation of xc_dom_probe_bzimage_kernel() function = */ +/* We add support of bzImage kernel */ +/* Copied from tools/libxc/xc_doom_bzImageloader.c */ +struct setup_header { +=09uint8_t _pad0[0x1f1]; /* skip uninteresting stuff */ +=09uint8_t setup_sects; +=09uint16_t root_flags; +=09uint32_t syssize; +=09uint16_t ram_size; +=09uint16_t vid_mode; +=09uint16_t root_dev; +=09uint16_t boot_flag; +=09uint16_t jump; +=09uint32_t header; +#define HDR_MAGIC "HdrS" +#define HDR_MAGIC_SZ 4 +=09uint16_t version; +#define VERSION(h,l) (((h)<<8) | (l)) +=09uint32_t realmode_swtch; +=09uint16_t start_sys; +=09uint16_t kernel_version; +=09uint8_t type_of_loader; +=09uint8_t loadflags; +=09uint16_t setup_move_size; +=09uint32_t code32_start; +=09uint32_t ramdisk_image; +=09uint32_t ramdisk_size; +=09uint32_t bootsect_kludge; +=09uint16_t heap_end_ptr; +=09uint16_t _pad1; +=09uint32_t cmd_line_ptr; +=09uint32_t initrd_addr_max; +=09uint32_t kernel_alignment; +=09uint8_t relocatable_kernel; +=09uint8_t _pad2[3]; +=09uint32_t cmdline_size; +=09uint32_t hardware_subarch; +=09uint64_t hardware_subarch_data; +=09uint32_t payload_offset; +=09uint32_t payload_length; +} __attribute__((packed)); + static void print_string_note(const char *prefix, struct elf_binary *elf, =09=09=09 const elf_note *note) { @@ -131,6 +173,9 @@ int main(int argc, char **argv) =09const elf_shdr *shdr; =09int notes_found =3D 0; =20 +=09struct setup_header *hdr; +=09uint64_t payload_offset, payload_length; + =09if (argc !=3D 2) =09{ =09=09fprintf(stderr, "Usage: readnotes \n"); @@ -159,13 +204,45 @@ int main(int argc, char **argv) =09=09fprintf(stderr, "Unable to map %s: %s\n", f, strerror(errno)); =09=09return 1; =09} -=09size =3D st.st_size; +=09 +=09/* Check the magic of bzImage kernel */ +=09hdr =3D (struct setup_header *)image; +=09if ( memcmp(&hdr->header, HDR_MAGIC, HDR_MAGIC_SZ) =3D=3D 0 ) +=09{ +=09=09if ( hdr->version < VERSION(2,8) ) +=09=09{ +=09=09=09printf("%s: boot protocol too old (%04x)", __FUNCTION__, hdr->ver= sion); +=09=09=09return 1; +=09=09} =20 -=09usize =3D xc_dom_check_gzip(xch, image, st.st_size); +=09=09/* upcast to 64 bits to avoid overflow */ +=09=09/* setup_sects is u8 and so cannot overflow */ +=09=09payload_offset =3D (hdr->setup_sects + 1) * 512; +=09=09payload_offset +=3D hdr->payload_offset; +=09=09payload_length =3D hdr->payload_length; +=09=09 +=09=09if ( payload_offset >=3D st.st_size ) +=09=09{ +=09=09=09printf("%s: payload offset overflow", __FUNCTION__); +=09=09=09return 1; +=09=09} +=09=09if ( (payload_offset + payload_length) > st.st_size ) +=09=09{ +=09=09=09printf("%s: payload length overflow", __FUNCTION__); +=09=09=09return 1; +=09=09} + +=09=09image =3D image + payload_offset; +=09=09size =3D payload_length; +=09} else { +=09=09size =3D st.st_size; +=09} + +=09usize =3D xc_dom_check_gzip(xch, image, size); =09if (usize) =09{ =09=09tmp =3D malloc(usize); -=09=09xc_dom_do_gunzip(xch, image, st.st_size, tmp, usize); +=09=09xc_dom_do_gunzip(xch, image, size, tmp, usize); =09=09image =3D tmp; =09=09size =3D usize; =09} --=-nmoUZ8ImmCvgRVsJ9wfH 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.xen.org http://lists.xen.org/xen-devel --=-nmoUZ8ImmCvgRVsJ9wfH--