[Lguest] [PATCH 5/5] lguest: loading bzImage directly

Chris Malley mail at chrismalley.co.uk
Wed Oct 3 19:37:01 EST 2007


Hi guys

Would it not be clearer to #include <asm/bootparam.h> and use 
the relevant named members of struct setup_header / struct boot_params
rather than the hard-coded values 0x202, 0x1F1, 0x214 ?

--
Chris


On Wed, 2007-10-03 at 09:40 +1000, Rusty Russell wrote:
[snip]
> +	u8 hdr[1024];
> +	int r;
> +	/* Modern bzImages get loaded at 1M. */
> +	void *p = from_guest_phys(0x100000);
> +
> +	/* Go back to the start of the file and read the header.  It should be
> +	 * a Linux boot header (see Documentation/i386/boot.txt) */
> +	lseek(fd, 0, SEEK_SET);
> +	read(fd, hdr, sizeof(hdr));
> +
> +	/* At offset 0x202, we expect the magic "HdrS" */
> +	if (memcmp(hdr + 0x202, "HdrS", 4) != 0)
> +		errx(1, "This doesn't look like a bzImage to me");
> +
> +	/* The byte at 0x1F1 tells us how many extra sectors of
> +	 * header: skip over them all. */
> +	lseek(fd, (unsigned long)(hdr[0x1F1]+1) * 512, SEEK_SET);
> +
> +	/* Now read everything into memory. in nice big chunks. */
> +	while ((r = read(fd, p, 65536)) > 0)
> +		p += r;
> +
> +	/* Finally, 0x214 tells us where to start the kernel. */
> +	return *(unsigned long *)&hdr[0x214];
>  }
>  
>  /*L:140 Loading the kernel is easy when it's a "vmlinux", but most kernels
> 





More information about the Lguest mailing list