Skip to contentSkip to conversation

Add an in-memory block device

PATCH New Anthony Liguori 1 participant 2 messages Dec 5, 2007 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add an in-memory block device

This is a generic in-memory block device. It is needed by the next patch.

Regards,

Anthony Liguori

Makefile +1 -1
Index: qemu/Makefile
===================================================================
@@ -40,7 +40,7 @@
 BLOCK_OBJS=cutils.o
 BLOCK_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o
 BLOCK_OBJS+=block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
-BLOCK_OBJS+=block-qcow2.o block-parallels.o
+BLOCK_OBJS+=block-qcow2.o block-parallels.o block-mem.o
 
 ######################################################################
 # libqemu_common.a: Target indepedent part of system emulation. The
block-mem.c new file +99 -0

99 lines not on this page · raw message

block.h +3 -0
Index: qemu/block.h
===================================================================
@@ -16,6 +16,7 @@
 extern BlockDriver bdrv_vvfat;
 extern BlockDriver bdrv_qcow2;
 extern BlockDriver bdrv_parallels;
+extern BlockDriver bdrv_mem;
 
 typedef struct BlockDriverInfo {
     /* in bytes, 0 if irrelevant */
@@ -155,4 +156,6 @@
                   const char *base_path,
                   const char *filename);
 
+int bdrv_mem_open(BlockDriverState *bs, size_t size);
+
 #endif
#1 lore raw

PATCH 2/2 Use extboot to support -kernel

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

hw/pc.c +17 -11
Index: qemu/hw/pc.c
===================================================================
@@ -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);
     }