This patch uses the extboot option ROM to support -kernel. Instead of
hijacking the first boot sector of the first IDE drive, we use extboot
to read the boot sector from an in-memory block device. This eliminates
the need to have an IDE device (or any device) configured when using
-kernel.
This depends on the extboot series I posted today.
Regards,
Anthony Liguori
Index: qemu/hw/pc.c
===================================================================
--- qemu.orig/hw/pc.c 2007-12-05 15:53:35.000000000 -0600
+++ qemu/hw/pc.c 2007-12-05 15:59:32.000000000 -0600
@@ -383,20 +383,26 @@
static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip)
{
uint8_t bootsect[512], *p;
- int i;
- int hda;
+ BlockDriverState *bs;
+ int i, cyls, heads, secs;
- hda = drive_get_index(IF_IDE, 0, 0);
- if (hda == -1) {
- fprintf(stderr, "A disk image must be given for 'hda' when booting "
- "a Linux kernel\n");
+ /* Create a device with at least one cylinder */
+ bs = bdrv_new("mem");
+ if (bdrv_mem_open(bs, 63 * 512) == -1) {
+ fprintf(stderr, "Error initializing memory block device\n");
exit(1);
}
- memset(bootsect, 0, sizeof(bootsect));
-
/* Copy the MSDOS partition table if possible */
- bdrv_read(drives_table[hda].bdrv, 0, bootsect, 1);
+ bdrv_read(bs, 0, bootsect, 1);
+
+ /* Setup extboot to boot from the memory block device */
+ bdrv_guess_geometry(bs, &cyls, &heads, &secs);
+ bdrv_set_geometry_hint(bs, cyls, heads, secs);
+ extboot_init(bs, 1);
+
+ /* Prevent double initialization */
+ extboot_drive = -1;
/* Make sure we have a partition signature */
bootsect[510] = 0x55;
@@ -433,7 +439,7 @@
*p++ = segs[1]; /* CS */
*p++ = segs[1] >> 8;
- bdrv_set_boot_sector(drives_table[hda].bdrv, bootsect, sizeof(bootsect));
+ bdrv_write(bs, 0, bootsect, 1);
}
static int load_kernel(const char *filename, uint8_t *addr,
@@ -834,7 +840,7 @@
for (i = 0; i < nb_option_roms; i++)
opt_rom_offset += load_option_rom(option_rom[i], opt_rom_offset);
- if (extboot_drive != -1) {
+ if (extboot_drive != -1 || linux_boot) {
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, EXTBOOT_FILENAME);
opt_rom_offset += load_option_rom(buf, opt_rom_offset);
}