Skip to contentSkip to conversation

Option ROM for booting from SCSI/PV disks

PATCH In review Anthony Liguori 2 participants 2 messages Dec 5, 2007 – Dec 20, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 Option ROM for booting from SCSI/PV disks

Hi,

The attached patch is an option ROM that allows x86 guests to boot from any block device supported by QEMU (and the guest kernel). It works by hijacking the BIOS int13 function and then uses a very simply protocol to communicate all block requests to QEMU.

This patch also adds a "boot=on|off" parameter to the -drive option. When this option is specified, the extboot option ROM is automatically loaded and this device will be exposes by int13 as '0x80'. What '-boot c' really means is boot from the first disk driver or BIOS drive '0x80' so the -boot option is complimentary to this new boot flag.

I have successfully booted Linux, Win2k, and WinXP from SCSI with this patch. Windows takes a bit of prep work to be able to boot from SCSI. For win2k, you just need to make sure you have the right driver installed. WinXP, however, seems to require that it be installed on SCSI to boot from SCSI. If anyone knows how to modify WinXP after the fact, please let me know.

I can also use this new flag to boot a Linux guest from my previously posted virtio blk driver.

This patch is against my previous virtio patches but does not strictly depend on them. When applying this patch, you'll have to build extboot in extboot/ and then copy extboot/extboot.bin to pc-bios/extboot.bin.

Regards,

Anthony Liguori

extboot/Makefile new file +21 -0
Index: qemu/extboot/Makefile
===================================================================
@@ -0,0 +1,21 @@
+OBJCOPY=objcopy
+
+CFLAGS=-Wall -Wstrict-prototypes -Werror -fomit-frame-pointer -fno-builtin \
+       -fno-stack-protector
+
+all: extboot.bin
+
+%.o: %.S
+	$(CC) $(CFLAGS) -o $@ -c $<
+
+extboot.img: extboot.o
+	$(LD) --oformat binary -Ttext 0 -o $@ $<
+
+extboot.bin: extboot.img signrom
+	./signrom extboot.img extboot.bin
+
+signrom: signrom.c
+	$(CC) -o $@ -g -Wall $^
+
+clean:
+	$(RM) *.o *.img *.bin signrom *~
extboot/extboot.S new file +742 -0

742 lines not on this page · raw message

extboot/signrom.c new file +79 -0

79 lines not on this page · raw message

Makefile.target +1 -1
Index: qemu/Makefile.target
===================================================================
@@ -443,7 +443,7 @@
 VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o
 VL_OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
 VL_OBJS+= cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o
-VL_OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o
+VL_OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o extboot.o
 CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
 endif
 ifeq ($(TARGET_BASE_ARCH), ppc)
hw/extboot.c new file +128 -0

128 lines not on this page · raw message

hw/pc.h +4 -0
Index: qemu/hw/pc.h
===================================================================
@@ -151,4 +151,8 @@
 void *virtio_blk_init(PCIBus *bus, uint16_t vendor, uint16_t device,
 		      BlockDriverState *bs);
 
+/* extboot.c */
+
+void extboot_init(BlockDriverState *bs, int cmd);
+
 #endif
hw/pc.c +46 -27

103 lines not on this page · raw message

sysemu.h +1 -0
Index: qemu/sysemu.h
===================================================================
@@ -133,6 +133,7 @@
 
 int nb_drives;
 DriveInfo drives_table[MAX_DRIVES+1];
+int extboot_drive;
 
 extern int drive_get_index(BlockInterfaceType interface, int bus, int unit);
 extern int drive_get_max_bus(BlockInterfaceType interface);
vl.c +18 -2
Index: qemu/vl.c
===================================================================
@@ -167,6 +167,7 @@
    to store the VM snapshots */
 DriveInfo drives_table[MAX_DRIVES+1];
 int nb_drives;
+int extboot_drive = -1;
 /* point to the block driver where the snapshots are managed */
 BlockDriverState *bs_snapshots;
 int vga_ram_size;
@@ -4852,7 +4853,8 @@
     int max_devs;
     int index;
     char *params[] = { "bus", "unit", "if", "index", "cyls", "heads",
-                       "secs", "trans", "media", "snapshot", "file", NULL };
+                       "secs", "trans", "media", "snapshot", "file", "boot",
+		       NULL };
 
     if (check_params(buf, sizeof(buf), params, str) < 0) {
          fprintf(stderr, "qemu: unknowm parameter '%s' in '%s'\n",
@@ -5008,6 +5010,19 @@
 	}
     }
 
+    if (get_param_value(buf, sizeof(buf), "boot", str)) {
+	if (!strcmp(buf, "on")) {
+	    if (extboot_drive != -1) {
+		fprintf(stderr, "qemu: two bootable drives specified\n");
+		return -1;
+	    }
+	    extboot_drive = nb_drives;
+	} else if (strcmp(buf, "off")) {
+	    fprintf(stderr, "qemu: '%s' invalid boot option\n", str);
+	    return -1;
+	}
+    }
+
     get_param_value(file, sizeof(file), "file", str);
 
     /* compute bus and unit according index */
@@ -7443,7 +7458,8 @@
            "-hdc/-hdd file  use 'file' as IDE hard disk 2/3 image\n"
            "-cdrom file     use 'file' as IDE cdrom image (cdrom is ide1 master)\n"
 	   "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][index=i]\n"
-           "       [,cyls=c,heads=h,secs=s[,trans=t]][snapshot=on|off]\n"
+           "       [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
+	   "       [,boot=on|off]\n"
 	   "                use 'file' as a drive image\n"
            "-mtdblock file  use 'file' as on-board Flash memory image\n"
            "-sd file        use 'file' as SecureDigital card image\n"
Makefile +2 -1
Index: qemu/Makefile
===================================================================
@@ -171,7 +171,7 @@
 	mkdir -p "$(DESTDIR)$(datadir)"
 	for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
 		video.x openbios-sparc32 pxe-ne2k_pci.bin \
-		pxe-rtl8139.bin pxe-pcnet.bin; do \
+		pxe-rtl8139.bin pxe-pcnet.bin extboot.bin; do \
 		$(INSTALL) -m 644 $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
 	done
 ifndef CONFIG_WIN32
@@ -271,6 +271,7 @@
         $(datadir)/pxe-ne2k_pci.bin \
 	$(datadir)/pxe-rtl8139.bin \
         $(datadir)/pxe-pcnet.bin \
+	$(datadir)/extboot.bin \
 	$(docdir)/qemu-doc.html \
 	$(docdir)/qemu-tech.html \
 	$(mandir)/man1/qemu.1 $(mandir)/man1/qemu-img.1 )

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 20 lines · Anthony Liguori

Hi,

The attached patch is an option ROM that allows x86 guests to boot from any block device supported by QEMU (and the guest kernel). It works by hijacking the BIOS int13 function and then uses a very simply protocol to communicate all block requests to QEMU.

This patch also adds a "boot=on|off" parameter to the -drive option. When this option is specified, the extboot option ROM is automatically loaded and this device will be exposes by int13 as '0x80'. What '-boot c' really means is boot from the first disk driver or BIOS drive '0x80' so the -boot option is complimentary to this new boot flag.

I have successfully booted Linux, Win2k, and WinXP from SCSI with this patch. Windows takes a bit of prep work to be able to boot from
SCSI. For win2k, you just need to make sure you have the right
driver installed. WinXP, however, seems to require that it be installed on SCSI to boot from SCSI. If anyone knows how to modify WinXP after the fact, please let me know.

Quoted 7 lines

I can also use this new flag to boot a Linux guest from my previously posted virtio blk driver.

This patch is against my previous virtio patches but does not strictly depend on them. When applying this patch, you'll have to build extboot in extboot/ and then copy extboot/extboot.bin to pc-bios/extboot.bin.

Now that we have scsi support (with -drive) I would like to apply this to the kvm tree (I already applied the CHS refactoring patch). But as qemu seems to shy away from sources which can only compile on x86, can you rearrange it to build outside the qemu/ dir (i.e. a new toplevel extboot/)?

The qemu changes should be in a separate patch.

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.