qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/7] Add -disk interface
@ 2007-10-31 15:51 Laurent Vivier
  2007-10-31 15:51 ` [Qemu-devel] [PATCH 1/7] Add arg -disk to define new disk with more features Laurent Vivier
  0 siblings, 1 reply; 8+ messages in thread
From: Laurent Vivier @ 2007-10-31 15:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent.Vivier


This series of patches add a new interface to qemu to define storages.

The new parameter is "-disk":

    -disk file[,if=type][,index=i][,bus=n][,unit=m][,media=d][,cyls=c,heads=h,secs=s[,trans=t]][snapshot=on|off]

where:

    file is the disk image
    type is the interface type (ide, scsi, floppy, pflash, mtd, sd)
    i is the index of the disk on the interface (0, 1, 2, ...)
    n is the bus number of the given type
    m is the unit number on the the given bus
    d is the type of the media (disk, cdrom)
    c,h,s,t are the parameters usually given by -hdachs
    snapshot allows to enable or not the snapshot for this disk

"-cdrom file" is an alias for "-disk file,index=2,media=cdrom"
"-hda file" is an alias for "-disk file,index=0,media=disk"
"-hdb file" is an alias for "-disk file,index=1,media=disk"
"-hdc file" is an alias for "-disk file,index=2,media=disk"
"-hdd file" is an alias for "-disk file,index=3,media=disk"
"-hda file -hdachs a,b,c" is an alias for
                 "-disk file,index=0,cyls=a,heads=b,secs=c"
"-fda file" is an alias for "-disk file,index=0,if=floppy"
"-fdb file" is an alias for "-disk file,index=1,if=floppy" 
"-pflash file" is an alias for "-disk file,if=pflash"
"-mtdblock file" is an alias for "-disk file,if=mtd"
"-sd file" becomes the alias of "-disk file,if=sd"

You can also define a cdrom on the slave of ide0 with:
"-disk file,if=ide,bus=0,unit=1,media=cdrom"
You can define a cdrom on the scsi bus 0 with unit id 3:
"-disk file,if=scsi,bus=0,unit=3,media=cdrom"

You can define a scsi disk on bus 0 with unit id 6 with:

"-disk file,if=scsi,bus=0,unit=6"

You can define disks with default ordering:

"-disk a.img -disk b.img -disk c.img" is equal to "-hda a.img -hdb b.img -hdc c.img"

[PATCH 1/7] Add arg -disk to define new disk with more features

    Define -disk, support interface type "ide"

[PATCH 2/7] Add scsi support for the target PC

    support interface type "scsi"

[PATCH 3/7] Add floppy support by -disk

    support interface type "floppy"

[PATCH 4/7] remove fd_filename from the machine init interface

    change machine init interface to remove fd_filename

[PATCH 5/7] Add parallel flash support by -disk

    support interface type "pflash"

[PATCH 6/7] Add flash support by -disk

    support interface type "mtd"

[PATCH 7/7] Add SecureDigital support by -disk

    support interface type "sd"

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 1/7] Add arg -disk to define new disk with more features
  2007-10-31 15:51 [Qemu-devel] [PATCH 0/7] Add -disk interface Laurent Vivier
@ 2007-10-31 15:51 ` Laurent Vivier
  2007-10-31 15:51   ` [Qemu-devel] [PATCH 2/7] Add scsi support for the target PC Laurent Vivier
  0 siblings, 1 reply; 8+ messages in thread
From: Laurent Vivier @ 2007-10-31 15:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent.Vivier


This patch introduces a new parameter allowing to define disks.

The new parameter is "-disk":

    -disk file[,if=type][,index=i][,bus=n][,unit=m][,media=d][,cyls=c,heads=h,secs=s[,trans=t]][snapshot=on|off]

where:

    file is the disk image
    type is the interface type (ide)
    i is the index of the disk on the interface (0, 1, 2, ...)
    n is the bus number of the given type
    m is the unit number on the the given bus
    d is the type of the media (disk, cdrom)
    c,h,s,t are the parameters usually given by -hdachs
    snapshot allows to enable or not the snapshot for this disk

"-cdrom file" is an alias for "-disk file,index=2,media=cdrom"
"-hda file" is an alias for "-disk file,index=0,media=disk"
"-hdb file" is an alias for "-disk file,index=1,media=disk"
"-hdc file" is an alias for "-disk file,index=2,media=disk"
"-hdd file" is an alias for "-disk file,index=3,media=disk"
"-hda file -hdachs a,b,c" is an alias for 
                 "-disk file,index=0,cyls=a,heads=b,secs=c"

You can also define a cdrom on the slave of ide0 with:
"-disk file,if=ide,bus=0,unit=1,media=cdrom"

--
 hw/mips_pica61.c |    5
 hw/mips_r4k.c    |    5
 hw/pc.c          |    5
 hw/ppc_prep.c    |    5
 monitor.c        |    2
 vl.c             |  346 ++++++++++++++++++++++++++++++++++++++++++++++--------- vl.h             |    8 -
 7 files changed, 311 insertions(+), 65 deletions(-)

Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/vl.c	2007-10-31 14:18:25.000000000 +0100
@@ -149,9 +149,9 @@
 void *ioport_opaque[MAX_IOPORTS];
 IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
 IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
-/* Note: bs_table[MAX_DISKS] is a dummy block driver if none available
+/* Note: bs_table[MAX_IDE_DISKS] is a dummy block driver if none available
    to store the VM snapshots */
-BlockDriverState *bs_table[MAX_DISKS + 1], *fd_table[MAX_FD];
+BlockDriverState *bs_table[MAX_IDE_DISKS + 1], *fd_table[MAX_FD];
 BlockDriverState *pflash_table[MAX_PFLASH];
 BlockDriverState *sd_bdrv;
 BlockDriverState *mtd_bdrv;
@@ -1748,7 +1748,7 @@
         case 's':
             {
                 int i;
-                for (i = 0; i < MAX_DISKS; i++) {
+                for (i = 0; i < MAX_IDE_DISKS; i++) {
                     if (bs_table[i])
                         bdrv_commit(bs_table[i]);
                 }
@@ -4706,6 +4706,205 @@
     }
 }
 
+#define HD_ALIAS ",index=%d,media=disk"
+
+#ifdef TARGET_PPC
+#define CDROM_ALIAS ",index=1,media=cdrom"
+#else
+#define CDROM_ALIAS ",index=2,media=cdrom"
+#endif
+
+static int disk_init(const char *str, int snapshot)
+{
+    char buf[16];
+    enum { IF_IDE, IF_SCSI } interface;
+    enum { MEDIA_DISK, MEDIA_CDROM } media;
+    int bus_id, unit_id;
+    int cyls, heads, secs, translation;
+    char *p;
+    char *file;
+    int disk_index;
+
+    file = str;
+    p = str;
+    while (*p != '\0' && *p != ',')
+        p++;
+    if (*p == ',') {
+        *p = '\0';
+        p++;
+    }
+
+    cyls = heads = secs = 0;
+    bus_id = -1;
+    unit_id = -1;
+    disk_index = -1;
+    translation = BIOS_ATA_TRANSLATION_AUTO;
+    interface = IF_IDE;
+    media = MEDIA_DISK;
+
+    /* extract parameters */
+
+    if (get_param_value(buf, sizeof(buf), "bus", p)) {
+        bus_id = strtol(buf, NULL, 0);
+	if (bus_id < 0) {
+	    fprintf(stderr, "qemu: invalid bus id\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "unit", p)) {
+        unit_id = strtol(buf, NULL, 0);
+	if (unit_id < 0) {
+	    fprintf(stderr, "qemu: invalid unit id\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "index", p)) {
+        disk_index = strtol(buf, NULL, 0);
+	if (disk_index < 0) {
+	    fprintf(stderr, "qemu: invalid disk index\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "cyls", p)) {
+        cyls = strtol(buf, NULL, 0);
+        if (cyls < 1 || cyls > 16383) {
+            fprintf(stderr, "qemu: invalid physical cyls number\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "heads", p)) {
+        heads = strtol(buf, NULL, 0);
+        if (heads < 1 || heads > 16) {
+            fprintf(stderr, "qemu: invalid physical heads number\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "secs", p)) {
+        secs = strtol(buf, NULL, 0);
+            if (secs < 1 || secs > 63) {
+            fprintf(stderr, "qemu: invalid physical secs number\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "if", p)) {
+        if (!strcmp(buf, "ide"))
+	    interface = IF_IDE;
+	else if (!strcmp(buf, "scsi"))
+	    interface = IF_SCSI;
+	else {
+            fprintf(stderr, "unsupported bus type '%s'\n", buf);
+            return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "trans", p)) {
+        if (!strcmp(buf, "none"))
+            translation = BIOS_ATA_TRANSLATION_NONE;
+        else if (!strcmp(buf, "lba"))
+            translation = BIOS_ATA_TRANSLATION_LBA;
+        else if (!strcmp(buf, "auto"))
+            translation = BIOS_ATA_TRANSLATION_AUTO;
+	else {
+            fprintf(stderr, "qemu: invalid translation type\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "media", p)) {
+        if (!(strcmp(buf, "disk"))) {
+	    media = MEDIA_DISK;
+	} else if (!strcmp(buf, "cdrom")) {
+            if (cyls || secs || heads) {
+                fprintf(stderr, "qemu: invalid physical CHS format\n");
+	        return -1;
+            }
+	    media = MEDIA_CDROM;
+	} else {
+	    fprintf(stderr, "qemu: invalid media\n");
+	    return -1;
+	}
+    }
+
+    if (get_param_value(buf, sizeof(buf), "snapshot", p)) {
+        if (!(strcmp(buf, "on")))
+	    snapshot = 1;
+        else if (!(strcmp(buf, "off")))
+	    snapshot = 0;
+	else {
+	    fprintf(stderr, "qemu: invalid snapshot option\n");
+	    return -1;
+	}
+    }
+
+    switch(interface) {
+    case IF_IDE:
+	if (bus_id >= MAX_IDE_BUS) {
+	    fprintf(stderr, "qemu: bus number too big\n");
+	    return -1;
+	}
+	if (unit_id >= MAX_IDE_DEVS) {
+	    fprintf(stderr, "qemu: unit number too big\n");
+	    return -1;
+	}
+
+        if (disk_index == -1) {
+	    if (bus_id != -1 && unit_id != -1) {
+	        disk_index = bus_id * MAX_IDE_DEVS + unit_id;
+	    } else {
+	        if (bus_id != -1)
+	            disk_index = bus_id * MAX_IDE_DEVS;
+	        else
+	            disk_index = 0;
+	         while (bs_table[disk_index] &&  disk_index < MAX_IDE_DISKS)
+	             disk_index++;
+	    }
+	}
+
+	if (disk_index >= MAX_IDE_DISKS) {
+	    fprintf(stderr, "qemu: too many disks\n");
+	    return -1;
+	}
+
+        if (!bs_table[disk_index]) {
+            switch(media) {
+	    case MEDIA_DISK:
+                snprintf(buf, sizeof(buf), "hd%c", disk_index + 'a');
+                bs_table[disk_index] = bdrv_new(buf);
+	        break;
+	    case MEDIA_CDROM:
+                snprintf(buf, sizeof(buf), "cdrom%c", disk_index + '0');
+                bs_table[disk_index] = bdrv_new(buf);
+                bdrv_set_type_hint(bs_table[disk_index], BDRV_TYPE_CDROM);
+	        break;
+	    }
+
+            if (file[0] && bdrv_open(bs_table[disk_index], file,
+                          snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
+                fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
+                        file);
+                      return -1;
+            }
+
+            if (cyls != 0) {
+                bdrv_set_geometry_hint(bs_table[disk_index],
+	                               cyls, heads, secs);
+                bdrv_set_translation_hint(bs_table[disk_index], translation);
+            }
+	}
+        break;
+    case IF_SCSI:
+        /* TODO */
+	break;
+    }
+   return 0;
+}
+
 /***********************************************************/
 /* USB devices */
 
@@ -5489,7 +5688,7 @@
 
     if (bs_snapshots)
         return bs_snapshots;
-    for(i = 0; i <= MAX_DISKS; i++) {
+    for(i = 0; i <= MAX_IDE_DISKS; i++) {
         bs = bs_table[i];
         if (bdrv_can_snapshot(bs))
             goto ok;
@@ -5598,7 +5797,7 @@
 
     /* create the snapshots */
 
-    for(i = 0; i < MAX_DISKS; i++) {
+    for(i = 0; i < MAX_IDE_DISKS; i++) {
         bs1 = bs_table[i];
         if (bdrv_has_snapshot(bs1)) {
             if (must_delete) {
@@ -5641,7 +5840,7 @@
     saved_vm_running = vm_running;
     vm_stop(0);
 
-    for(i = 0; i <= MAX_DISKS; i++) {
+    for(i = 0; i <= MAX_IDE_DISKS; i++) {
         bs1 = bs_table[i];
         if (bdrv_has_snapshot(bs1)) {
             ret = bdrv_snapshot_goto(bs1, name);
@@ -5702,7 +5901,7 @@
         return;
     }
 
-    for(i = 0; i <= MAX_DISKS; i++) {
+    for(i = 0; i <= MAX_IDE_DISKS; i++) {
         bs1 = bs_table[i];
         if (bdrv_has_snapshot(bs1)) {
             ret = bdrv_snapshot_delete(bs1, name);
@@ -5731,7 +5930,7 @@
         return;
     }
     term_printf("Snapshot devices:");
-    for(i = 0; i <= MAX_DISKS; i++) {
+    for(i = 0; i <= MAX_IDE_DISKS; i++) {
         bs1 = bs_table[i];
         if (bdrv_has_snapshot(bs1)) {
             if (bs == bs1)
@@ -6436,7 +6635,7 @@
             /* find if the memory block is available on a virtual
                block device */
             sector_num = -1;
-            for(j = 0; j < MAX_DISKS; j++) {
+            for(j = 0; j < MAX_IDE_DISKS; j++) {
                 if (bs_table[j]) {
                     sector_num = bdrv_hash_find(bs_table[j],
                                                 phys_ram_base + i, BDRV_HASH_BLOCK_SIZE);
@@ -6444,7 +6643,7 @@
                         break;
                 }
             }
-            if (j == MAX_DISKS)
+            if (j == MAX_IDE_DISKS)
                 goto normal_compress;
             buf[0] = 1;
             buf[1] = j;
@@ -6495,7 +6694,7 @@
             ram_decompress_buf(s, buf + 1, 9);
             bs_index = buf[1];
             sector_num = be64_to_cpupu((const uint64_t *)(buf + 2));
-            if (bs_index >= MAX_DISKS || bs_table[bs_index] == NULL) {
+            if (bs_index >= MAX_IDE_DISKS || bs_table[bs_index] == NULL) {
                 fprintf(stderr, "Invalid block device index %d\n", bs_index);
                 goto error;
             }
@@ -6996,6 +7195,8 @@
            "-hda/-hdb file  use 'file' as IDE hard disk 0/1 image\n"
            "-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"
+	   "-disk file[,if=type][,index=i][,bus=n][,unit=m][,media=d][,cyls=c,heads=h,secs=s[,trans=t]][snapshot=on|off]\n"
+	   "                use 'file' as a disk image\n"
            "-mtdblock file  use 'file' as on-board Flash memory image\n"
            "-sd file        use 'file' as SecureDigital card image\n"
            "-pflash file    use 'file' as a parallel flash image\n"
@@ -7144,6 +7345,7 @@
     QEMU_OPTION_hdb,
     QEMU_OPTION_hdc,
     QEMU_OPTION_hdd,
+    QEMU_OPTION_disk,
     QEMU_OPTION_cdrom,
     QEMU_OPTION_mtdblock,
     QEMU_OPTION_sd,
@@ -7232,6 +7434,7 @@
     { "hdb", HAS_ARG, QEMU_OPTION_hdb },
     { "hdc", HAS_ARG, QEMU_OPTION_hdc },
     { "hdd", HAS_ARG, QEMU_OPTION_hdd },
+    { "disk", HAS_ARG, QEMU_OPTION_disk },
     { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
     { "mtdblock", HAS_ARG, QEMU_OPTION_mtdblock },
     { "sd", HAS_ARG, QEMU_OPTION_sd },
@@ -7354,10 +7557,10 @@
 {
     BlockDriverState *bs;
 
-    if (index < 4) {
+    if (index < MAX_IDE_DISKS) {
         bs = bs_table[index];
-    } else if (index < 6) {
-        bs = fd_table[index - 4];
+    } else if (index < MAX_IDE_DISKS + MAX_FD) {
+        bs = fd_table[index - MAX_IDE_DISKS];
     } else {
         bs = NULL;
     }
@@ -7556,10 +7759,10 @@
     int use_gdbstub;
     const char *gdbstub_port;
 #endif
-    int i, cdrom_index, pflash_index;
+    int i, pflash_index;
     int snapshot, linux_boot;
     const char *initrd_filename;
-    const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
+    const char *fd_filename[MAX_FD];
     const char *pflash_filename[MAX_PFLASH];
     const char *sd_filename;
     const char *mtd_filename;
@@ -7567,7 +7770,10 @@
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
     char net_clients[MAX_NET_CLIENTS][256];
+    char disks[MAX_DISKS][256];
     int nb_net_clients;
+    int nb_disks;
+    int hda_index;
     int optind;
     const char *r, *optarg;
     CharDriverState *monitor_hd;
@@ -7622,8 +7828,6 @@
     initrd_filename = NULL;
     for(i = 0; i < MAX_FD; i++)
         fd_filename[i] = NULL;
-    for(i = 0; i < MAX_DISKS; i++)
-        hd_filename[i] = NULL;
     for(i = 0; i < MAX_PFLASH; i++)
         pflash_filename[i] = NULL;
     pflash_index = 0;
@@ -7639,11 +7843,6 @@
     nographic = 0;
     kernel_filename = NULL;
     kernel_cmdline = "";
-#ifdef TARGET_PPC
-    cdrom_index = 1;
-#else
-    cdrom_index = 2;
-#endif
     cyls = heads = secs = 0;
     translation = BIOS_ATA_TRANSLATION_AUTO;
     pstrcpy(monitor_device, sizeof(monitor_device), "vc");
@@ -7661,6 +7860,8 @@
     usb_devices_index = 0;
 
     nb_net_clients = 0;
+    nb_disks = 0;
+    hda_index = -1;
 
     nb_nics = 0;
     /* default mac address of the first network interface */
@@ -7671,7 +7872,10 @@
             break;
         r = argv[optind];
         if (r[0] != '-') {
-            hd_filename[0] = argv[optind++];
+	    hda_index = nb_disks;
+            snprintf(disks[nb_disks], sizeof(disks[0]),
+                     "%s" HD_ALIAS, argv[optind++], 0);
+            nb_disks++;
         } else {
             const QEMUOption *popt;
 
@@ -7731,17 +7935,51 @@
                 initrd_filename = optarg;
                 break;
             case QEMU_OPTION_hda:
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
+                }
+                hda_index = nb_disks;
+                if (cyls == 0)
+                    snprintf(disks[nb_disks], sizeof(disks[0]),
+                             "%s" HD_ALIAS, optarg, 0);
+                else {
+                    snprintf(disks[nb_disks], sizeof(disks[0]),
+                             "%s" HD_ALIAS
+			     ",cyls=%d,heads=%d,secs=%d%s",
+                             optarg, 0, cyls, heads, secs,
+                             translation == BIOS_ATA_TRANSLATION_LBA ?
+                                 ",trans=lba" :
+                             translation == BIOS_ATA_TRANSLATION_NONE ?
+                                 ",trans=none" : "");
+                }
+            nb_disks++;
+            break;
             case QEMU_OPTION_hdb:
             case QEMU_OPTION_hdc:
             case QEMU_OPTION_hdd:
                 {
                     int hd_index;
+                    if (nb_disks >= MAX_DISKS) {
+                        fprintf(stderr, "qemu: too many disks\n");
+                        exit(1);
+                    }
                     hd_index = popt->index - QEMU_OPTION_hda;
-                    hd_filename[hd_index] = optarg;
-                    if (hd_index == cdrom_index)
-                        cdrom_index = -1;
+		    snprintf(disks[nb_disks], sizeof(disks[0]),
+		             "%s" HD_ALIAS, optarg, hd_index);
+	            nb_disks++;
                 }
                 break;
+            case QEMU_OPTION_disk:
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
+                }
+		pstrcpy(disks[nb_disks],
+                        sizeof(disks[0]),
+			optarg);
+	        nb_disks++;
+	        break;
             case QEMU_OPTION_mtdblock:
                 mtd_filename = optarg;
                 break;
@@ -7792,6 +8030,15 @@
                         fprintf(stderr, "qemu: invalid physical CHS format\n");
                         exit(1);
                     }
+		    if (hda_index != -1)
+		        snprintf(disks[hda_index] + strlen(disks[hda_index]),
+			         sizeof(disks[0]) - strlen(disks[hda_index]),
+		                 ",cyls=%d,heads=%d,secs=%d%s",
+			         cyls, heads, secs,
+			         translation == BIOS_ATA_TRANSLATION_LBA ?
+			     	    ",trans=lba" :
+			         translation == BIOS_ATA_TRANSLATION_NONE ?
+			             ",trans=none" : "");
                 }
                 break;
             case QEMU_OPTION_nographic:
@@ -7810,9 +8057,13 @@
                 kernel_cmdline = optarg;
                 break;
             case QEMU_OPTION_cdrom:
-                if (cdrom_index >= 0) {
-                    hd_filename[cdrom_index] = optarg;
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
                 }
+		snprintf(disks[nb_disks], sizeof(disks[0]),
+		         "%s" CDROM_ALIAS, optarg);
+	        nb_disks++;
                 break;
             case QEMU_OPTION_boot:
                 if (strlen(optarg) > MAX_BOOT_DEVICES) {
@@ -8179,14 +8430,13 @@
 
     if (!linux_boot &&
         (!strchr(boot_device, 'n')) &&
-        hd_filename[0] == '\0' &&
-        (cdrom_index >= 0 && hd_filename[cdrom_index] == '\0') &&
+        nb_disks == 0 &&
         fd_filename[0] == '\0')
         help(1);
 
     /* boot to floppy or the default cd if no hard disk defined yet */
     if (!boot_device[0]) {
-        if (hd_filename[0] != '\0')
+        if (nb_disks)
             boot_device[0] = 'c';
         else if (fd_filename[0] != '\0')
             boot_device[0] = 'a';
@@ -8261,32 +8511,20 @@
         exit(1);
     }
 
-    /* we always create the cdrom drive, even if no disk is there */
     bdrv_init();
-    if (cdrom_index >= 0) {
-        bs_table[cdrom_index] = bdrv_new("cdrom");
-        bdrv_set_type_hint(bs_table[cdrom_index], BDRV_TYPE_CDROM);
+
+    /* we always create the cdrom drive, even if no disk is there */
+
+    if (nb_disks < MAX_DISKS) {
+        pstrcpy(disks[nb_disks], sizeof(disks[0]), CDROM_ALIAS);
+        nb_disks++;
     }
 
     /* open the virtual block devices */
-    for(i = 0; i < MAX_DISKS; i++) {
-        if (hd_filename[i]) {
-            if (!bs_table[i]) {
-                char buf[64];
-                snprintf(buf, sizeof(buf), "hd%c", i + 'a');
-                bs_table[i] = bdrv_new(buf);
-            }
-            if (bdrv_open(bs_table[i], hd_filename[i], snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
-                fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
-                        hd_filename[i]);
-                exit(1);
-            }
-            if (i == 0 && cyls != 0) {
-                bdrv_set_geometry_hint(bs_table[i], cyls, heads, secs);
-                bdrv_set_translation_hint(bs_table[i], translation);
-            }
-        }
-    }
+
+    for(i = 0; i < nb_disks; i++)
+        if (disk_init(disks[i], snapshot) == -1)
+	    exit(1);
 
     /* we always create at least one floppy disk */
     fd_table[0] = bdrv_new("fda");
Index: qemu/vl.h
===================================================================
--- qemu.orig/vl.h	2007-10-31 14:12:40.000000000 +0100
+++ qemu/vl.h	2007-10-31 14:13:20.000000000 +0100
@@ -984,9 +984,13 @@
 extern uint8_t _translate_keycode(const int key);
 
 /* ide.c */
-#define MAX_DISKS 4
+#define MAX_IDE_BUS 2
+#define MAX_IDE_DEVS 2
+#define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS)
 
-extern BlockDriverState *bs_table[MAX_DISKS + 1];
+#define MAX_DISKS (MAX_IDE_DISKS)
+
+extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
 extern BlockDriverState *sd_bdrv;
 extern BlockDriverState *mtd_bdrv;
 
Index: qemu/monitor.c
===================================================================
--- qemu.orig/monitor.c	2007-10-31 14:12:18.000000000 +0100
+++ qemu/monitor.c	2007-10-31 14:13:20.000000000 +0100
@@ -204,7 +204,7 @@
     int i, all_devices;
 
     all_devices = !strcmp(device, "all");
-    for (i = 0; i < MAX_DISKS; i++) {
+    for (i = 0; i < MAX_IDE_DISKS; i++) {
         if (bs_table[i]) {
             if (all_devices ||
                 !strcmp(bdrv_get_device_name(bs_table[i]), device))
Index: qemu/hw/mips_pica61.c
===================================================================
--- qemu.orig/hw/mips_pica61.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/mips_pica61.c	2007-10-31 14:13:20.000000000 +0100
@@ -136,9 +136,10 @@
     i8042_mm_init(i8259[6], i8259[7], 0x80005060, 0);
 
     /* IDE controller */
-    for(i = 0; i < 2; i++)
+    for(i = 0; i < MAX_IDE_BUS; i++)
         isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
-                     bs_table[2 * i], bs_table[2 * i + 1]);
+                     bs_table[MAX_IDE_DEVS * i],
+		     bs_table[MAX_IDE_DEVS * i + 1]);
 
     /* Network controller */
     /* FIXME: missing NS SONIC DP83932 */
Index: qemu/hw/mips_r4k.c
===================================================================
--- qemu.orig/hw/mips_r4k.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/mips_r4k.c	2007-10-31 14:13:20.000000000 +0100
@@ -240,9 +240,10 @@
         }
     }
 
-    for(i = 0; i < 2; i++)
+    for(i = 0; i < MAX_IDE_BUS; i++)
         isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
-                     bs_table[2 * i], bs_table[2 * i + 1]);
+                     bs_table[MAX_IDE_DEVS * i],
+		     bs_table[MAX_IDE_DEVS * i + 1]);
 
     i8042_init(i8259[1], i8259[12], 0x60);
     ds1225y_init(0x9000, "nvram");
Index: qemu/hw/pc.c
===================================================================
--- qemu.orig/hw/pc.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/pc.c	2007-10-31 14:13:20.000000000 +0100
@@ -892,9 +892,10 @@
     if (pci_enabled) {
         pci_piix3_ide_init(pci_bus, bs_table, piix3_devfn + 1, i8259);
     } else {
-        for(i = 0; i < 2; i++) {
+        for(i = 0; i < MAX_IDE_BUS; i++) {
             isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
-                         bs_table[2 * i], bs_table[2 * i + 1]);
+                         bs_table[MAX_IDE_DEVS * i],
+			 bs_table[MAX_IDE_DEVS * i + 1]);
         }
     }
 
Index: qemu/hw/ppc_prep.c
===================================================================
--- qemu.orig/hw/ppc_prep.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/ppc_prep.c	2007-10-31 14:13:20.000000000 +0100
@@ -649,9 +649,10 @@
         }
     }
 
-    for(i = 0; i < 2; i++) {
+    for(i = 0; i < MAX_IDE_BUS; i++) {
         isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
-                     bs_table[2 * i], bs_table[2 * i + 1]);
+                     bs_table[MAX_IDE_DEVS * i],
+		     bs_table[MAX_IDE_DEVS * i + 1]);
     }
     i8042_init(i8259[1], i8259[12], 0x60);
     DMA_init(1);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 2/7] Add scsi support for the target PC
  2007-10-31 15:51 ` [Qemu-devel] [PATCH 1/7] Add arg -disk to define new disk with more features Laurent Vivier
@ 2007-10-31 15:51   ` Laurent Vivier
  2007-10-31 15:51     ` [Qemu-devel] [PATCH 3/7] Add floppy support by -disk Laurent Vivier
  0 siblings, 1 reply; 8+ messages in thread
From: Laurent Vivier @ 2007-10-31 15:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent.Vivier


This patch adds the SCSI support for the target PC.
It allows to initalize SCSI interface in the PC init machine.

it adds a new interface type "scsi" to "-disk" interface.

"-disk file,if=scsi,bus=0,unit=6" allows to connect the disk image file to the
bus 0 with the unit id 6.

if there is no SCSI disk, the SCSI interface is not created.

It also defines the default interface type to "scsi" for targets 
"realview", "SS-5", "SS-10", "versatilepb", "versatileab"
to keep old behavior, where "-hda" is a SCSI disk.

--
 hw/esp.c         |    4 +-
 hw/pc.c          |   30 ++++++++-------
 hw/realview.c    |    6 +--
 hw/sun4m.c       |    6 +--
 hw/versatilepb.c |    6 +--
 monitor.c        |    7 +++
 vl.c             |  108 +++++++++++++++++++++++++++++++++++++++++++++++++------
 vl.h             |    9 ++++
 8 files changed, 139 insertions(+), 37 deletions(-)

Index: qemu/hw/pc.c
===================================================================
--- qemu.orig/hw/pc.c	2007-10-31 14:13:20.000000000 +0100
+++ qemu/hw/pc.c	2007-10-31 14:23:52.000000000 +0100
@@ -927,23 +927,25 @@
     if (i440fx_state) {
         i440fx_init_memory_mappings(i440fx_state);
     }
-#if 0
-    /* ??? Need to figure out some way for the user to
-       specify SCSI devices.  */
+
     if (pci_enabled) {
-        void *scsi;
-        BlockDriverState *bdrv;
+        void *scsi[SCSI_MAX_BUS];
+	int max_bus = -1;
+
+	for (i = 0; i < MAX_SCSI_DISKS; i++)
+	    if (sd_table[i])
+	        max_bus = i / SCSI_MAX_DEVS + 1;
+
+	for (i = 0; i < max_bus; i++)
+            scsi[i] = lsi_scsi_init(pci_bus, -1);
 
-        scsi = lsi_scsi_init(pci_bus, -1);
-        bdrv = bdrv_new("scsidisk");
-        bdrv_open(bdrv, "scsi_disk.img", 0);
-        lsi_scsi_attach(scsi, bdrv, -1);
-        bdrv = bdrv_new("scsicd");
-        bdrv_open(bdrv, "scsi_cd.iso", 0);
-        bdrv_set_type_hint(bdrv, BDRV_TYPE_CDROM);
-        lsi_scsi_attach(scsi, bdrv, -1);
+	for (i = 0; i < MAX_SCSI_DISKS; i++) {
+	    if (sd_table[i]) {
+                lsi_scsi_attach(scsi[i / SCSI_MAX_DEVS],
+		                sd_table[i], i % SCSI_MAX_DEVS);
+	    }
+        }
     }
-#endif
 }
 
 static void pc_init_pci(int ram_size, int vga_ram_size, const char *boot_device,
Index: qemu/hw/realview.c
===================================================================
--- qemu.orig/hw/realview.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/realview.c	2007-10-31 14:23:52.000000000 +0100
@@ -65,9 +65,9 @@
         usb_ohci_init_pci(pci_bus, 3, -1);
     }
     scsi_hba = lsi_scsi_init(pci_bus, -1);
-    for (n = 0; n < MAX_DISKS; n++) {
-        if (bs_table[n]) {
-            lsi_scsi_attach(scsi_hba, bs_table[n], n);
+    for (n = 0; n < SCSI_MAX_DEVS; n++) {
+        if (sd_table[n]) {
+            lsi_scsi_attach(scsi_hba, sd_table[n], n);
         }
     }
     for(n = 0; n < nb_nics; n++) {
Index: qemu/hw/versatilepb.c
===================================================================
--- qemu.orig/hw/versatilepb.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/versatilepb.c	2007-10-31 14:23:52.000000000 +0100
@@ -199,9 +199,9 @@
         usb_ohci_init_pci(pci_bus, 3, -1);
     }
     scsi_hba = lsi_scsi_init(pci_bus, -1);
-    for (n = 0; n < MAX_DISKS; n++) {
-        if (bs_table[n]) {
-            lsi_scsi_attach(scsi_hba, bs_table[n], n);
+    for (n = 0; n < SCSI_MAX_DEVS; n++) {
+        if (sd_table[n]) {
+            lsi_scsi_attach(scsi_hba, sd_table[n], n);
         }
     }
 
Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c	2007-10-31 14:18:25.000000000 +0100
+++ qemu/vl.c	2007-10-31 14:23:52.000000000 +0100
@@ -152,6 +152,7 @@
 /* Note: bs_table[MAX_IDE_DISKS] is a dummy block driver if none available
    to store the VM snapshots */
 BlockDriverState *bs_table[MAX_IDE_DISKS + 1], *fd_table[MAX_FD];
+BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];
 BlockDriverState *pflash_table[MAX_PFLASH];
 BlockDriverState *sd_bdrv;
 BlockDriverState *mtd_bdrv;
@@ -1752,6 +1753,10 @@
                     if (bs_table[i])
                         bdrv_commit(bs_table[i]);
                 }
+                for (i = 0; i < MAX_SCSI_DISKS; i++) {
+                    if (sd_table[i])
+                        bdrv_commit(sd_table[i]);
+                }
                 if (mtd_bdrv)
                     bdrv_commit(mtd_bdrv);
             }
@@ -4714,7 +4719,7 @@
 #define CDROM_ALIAS ",index=2,media=cdrom"
 #endif
 
-static int disk_init(const char *str, int snapshot)
+static int disk_init(const char *str, int snapshot, QEMUMachine *machine)
 {
     char buf[16];
     enum { IF_IDE, IF_SCSI } interface;
@@ -4739,7 +4744,16 @@
     unit_id = -1;
     disk_index = -1;
     translation = BIOS_ATA_TRANSLATION_AUTO;
-    interface = IF_IDE;
+
+    if (!strcmp(machine->name, "realview") ||
+        !strcmp(machine->name, "SS-5") ||
+        !strcmp(machine->name, "SS-10") ||
+        !strcmp(machine->name, "versatilepb") ||
+        !strcmp(machine->name, "versatileab")) {
+        interface = IF_SCSI;
+    } else {
+        interface = IF_IDE;
+    }
     media = MEDIA_DISK;
 
     /* extract parameters */
@@ -4899,8 +4913,59 @@
 	}
         break;
     case IF_SCSI:
-        /* TODO */
-	break;
+
+	if (bus_id >= SCSI_MAX_BUS) {
+            fprintf(stderr, "qemu: bus id too big\n");
+	    return -1;
+        }
+
+	if (unit_id >= SCSI_MAX_DEVS) {
+            fprintf(stderr, "qemu: unit id too big\n");
+	    return -1;
+        }
+
+	if (bus_id != -1 && unit_id != -1)
+	    disk_index = bus_id * SCSI_MAX_DEVS + unit_id;
+	else {
+	    if (bus_id != -1)
+	        disk_index = bus_id * SCSI_MAX_DEVS;
+	    else
+	        disk_index = 0;
+	     while (sd_table[disk_index] && disk_index < SCSI_MAX_DEVS)
+	         disk_index++;
+	}
+	if (disk_index >= MAX_SCSI_DISKS) {
+	    fprintf(stderr, "qemu: too many disks\n");
+	    return -1;
+	}
+
+        if (!sd_table[disk_index]) {
+            switch(media) {
+	    case MEDIA_DISK:
+                snprintf(buf, sizeof(buf), "sd%c", disk_index + 'a');
+                sd_table[disk_index] = bdrv_new(buf);
+	        break;
+	    case MEDIA_CDROM:
+                snprintf(buf, sizeof(buf), "sr%c", disk_index + '0');
+                sd_table[disk_index] = bdrv_new(buf);
+                bdrv_set_type_hint(sd_table[disk_index], BDRV_TYPE_CDROM);
+	        break;
+	    }
+
+            if (file[0] && bdrv_open(sd_table[disk_index], file,
+                          snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
+                fprintf(stderr, "qemu: could not open hard disk image '%s'\n",
+                        file);
+                      return -1;
+            }
+
+            if (cyls != 0) {
+                bdrv_set_geometry_hint(sd_table[disk_index],
+	                               cyls, heads, secs);
+                bdrv_set_translation_hint(sd_table[disk_index], translation);
+            }
+	}
+        break;
     }
    return 0;
 }
@@ -5693,6 +5758,11 @@
         if (bdrv_can_snapshot(bs))
             goto ok;
     }
+    for(i = 0; i <= MAX_SCSI_DISKS; i++) {
+        bs = sd_table[i];
+        if (bdrv_can_snapshot(bs))
+            goto ok;
+    }
     return NULL;
  ok:
     bs_snapshots = bs;
@@ -5797,8 +5867,11 @@
 
     /* create the snapshots */
 
-    for(i = 0; i < MAX_IDE_DISKS; i++) {
-        bs1 = bs_table[i];
+    for(i = 0; i < MAX_IDE_DISKS + MAX_SCSI_DISKS; i++) {
+	if (i < MAX_IDE_DISKS)
+            bs1 = bs_table[i];
+	else
+            bs1 = sd_table[i - MAX_IDE_DISKS];
         if (bdrv_has_snapshot(bs1)) {
             if (must_delete) {
                 ret = bdrv_snapshot_delete(bs1, old_sn->id_str);
@@ -5840,8 +5913,11 @@
     saved_vm_running = vm_running;
     vm_stop(0);
 
-    for(i = 0; i <= MAX_IDE_DISKS; i++) {
-        bs1 = bs_table[i];
+    for(i = 0; i <= MAX_IDE_DISKS + MAX_SCSI_DISKS; i++) {
+	if (i < MAX_IDE_DISKS)
+            bs1 = bs_table[i];
+	else
+            bs1 = sd_table[i - MAX_IDE_DISKS];
         if (bdrv_has_snapshot(bs1)) {
             ret = bdrv_snapshot_goto(bs1, name);
             if (ret < 0) {
@@ -5901,8 +5977,11 @@
         return;
     }
 
-    for(i = 0; i <= MAX_IDE_DISKS; i++) {
-        bs1 = bs_table[i];
+    for(i = 0; i <= MAX_IDE_DISKS + MAX_SCSI_DISKS; i++) {
+	if (i < MAX_IDE_DISKS)
+            bs1 = bs_table[i];
+	else
+            bs1 = sd_table[i - MAX_IDE_DISKS];
         if (bdrv_has_snapshot(bs1)) {
             ret = bdrv_snapshot_delete(bs1, name);
             if (ret < 0) {
@@ -5937,6 +6016,13 @@
                 term_printf(" %s", bdrv_get_device_name(bs1));
         }
     }
+    for(i = 0; i <= MAX_SCSI_DISKS; i++) {
+        bs1 = sd_table[i];
+        if (bdrv_has_snapshot(bs1)) {
+            if (bs == bs1)
+                term_printf(" %s", bdrv_get_device_name(bs1));
+        }
+    }
     term_printf("\n");
 
     nb_sns = bdrv_snapshot_list(bs, &sn_tab);
@@ -8523,7 +8609,7 @@
     /* open the virtual block devices */
 
     for(i = 0; i < nb_disks; i++)
-        if (disk_init(disks[i], snapshot) == -1)
+        if (disk_init(disks[i], snapshot, machine) == -1)
 	    exit(1);
 
     /* we always create at least one floppy disk */
Index: qemu/vl.h
===================================================================
--- qemu.orig/vl.h	2007-10-31 14:13:20.000000000 +0100
+++ qemu/vl.h	2007-10-31 14:23:52.000000000 +0100
@@ -983,14 +983,21 @@
 /* x_keymap.c */
 extern uint8_t _translate_keycode(const int key);
 
+/* lsi53c895a.c */
+
+#define SCSI_MAX_DEVS 7
+#define SCSI_MAX_BUS 4
+#define MAX_SCSI_DISKS (SCSI_MAX_BUS * SCSI_MAX_DEVS)
+
 /* ide.c */
 #define MAX_IDE_BUS 2
 #define MAX_IDE_DEVS 2
 #define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS)
 
-#define MAX_DISKS (MAX_IDE_DISKS)
+#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS)
 
 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
+extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];
 extern BlockDriverState *sd_bdrv;
 extern BlockDriverState *mtd_bdrv;
 
Index: qemu/hw/sun4m.c
===================================================================
--- qemu.orig/hw/sun4m.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/sun4m.c	2007-10-31 14:23:52.000000000 +0100
@@ -394,9 +394,9 @@
     main_esp = esp_init(bs_table, hwdef->esp_base, espdma, *espdma_irq,
                         esp_reset);
 
-    for (i = 0; i < MAX_DISKS; i++) {
-        if (bs_table[i]) {
-            esp_scsi_attach(main_esp, bs_table[i], i);
+    for (i = 0; i < MAX_SCSI_DISKS; i++) {
+        if (sd_table[i]) {
+            esp_scsi_attach(main_esp, sd_table[i], i);
         }
     }
 
Index: qemu/monitor.c
===================================================================
--- qemu.orig/monitor.c	2007-10-31 14:13:20.000000000 +0100
+++ qemu/monitor.c	2007-10-31 14:23:52.000000000 +0100
@@ -211,6 +211,13 @@
                 bdrv_commit(bs_table[i]);
         }
     }
+    for (i = 0; i < MAX_SCSI_DISKS; i++) {
+        if (sd_table[i]) {
+            if (all_devices ||
+                !strcmp(bdrv_get_device_name(sd_table[i]), device))
+                bdrv_commit(sd_table[i]);
+        }
+    }
     if (mtd_bdrv)
         if (all_devices || !strcmp(bdrv_get_device_name(mtd_bdrv), device))
             bdrv_commit(mtd_bdrv);
Index: qemu/hw/esp.c
===================================================================
--- qemu.orig/hw/esp.c	2007-10-31 14:12:18.000000000 +0100
+++ qemu/hw/esp.c	2007-10-31 14:23:52.000000000 +0100
@@ -60,7 +60,7 @@
     uint8_t ti_buf[TI_BUFSZ];
     int sense;
     int dma;
-    SCSIDevice *scsi_dev[MAX_DISKS];
+    SCSIDevice *scsi_dev[SCSI_MAX_DEVS];
     SCSIDevice *current_dev;
     uint8_t cmdbuf[TI_BUFSZ];
     int cmdlen;
@@ -122,7 +122,7 @@
         s->async_len = 0;
     }
 
-    if (target >= MAX_DISKS || !s->scsi_dev[target]) {
+    if (target >= SCSI_MAX_DEVS || !s->scsi_dev[target]) {
         // No such drive
         s->rregs[4] = STAT_IN;
         s->rregs[5] = INTR_DC;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 3/7] Add floppy support by -disk
  2007-10-31 15:51   ` [Qemu-devel] [PATCH 2/7] Add scsi support for the target PC Laurent Vivier
@ 2007-10-31 15:51     ` Laurent Vivier
  2007-10-31 15:51       ` [Qemu-devel] [PATCH 4/7] remove fd_filename from the machine init interface Laurent Vivier
  0 siblings, 1 reply; 8+ messages in thread
From: Laurent Vivier @ 2007-10-31 15:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent.Vivier


This patch allows to define floppy using the "-disk" syntax.
It adds an interface type "floppy".

"-fda file" is an alias for "-disk file,index=0,if=floppy"
"-fdb file" is an alias for "-disk file,index=1,if=floppy"

--
 vl.c |   86 +++++++++++++++++++++++++++++++++++--------------------------------
 vl.h |    2 -
 2 files changed, 46 insertions(+), 42 deletions(-)

Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c	2007-10-31 15:48:54.000000000 +0100
+++ qemu/vl.c	2007-10-31 15:49:17.000000000 +0100
@@ -4711,6 +4711,7 @@
     }
 }
 
+#define FD_ALIAS ",index=%d,if=floppy"
 #define HD_ALIAS ",index=%d,media=disk"
 
 #ifdef TARGET_PPC
@@ -4722,7 +4723,7 @@
 static int disk_init(const char *str, int snapshot, QEMUMachine *machine)
 {
     char buf[16];
-    enum { IF_IDE, IF_SCSI } interface;
+    enum { IF_IDE, IF_SCSI, IF_FLOPPY } interface;
     enum { MEDIA_DISK, MEDIA_CDROM } media;
     int bus_id, unit_id;
     int cyls, heads, secs, translation;
@@ -4811,6 +4812,8 @@
 	    interface = IF_IDE;
 	else if (!strcmp(buf, "scsi"))
 	    interface = IF_SCSI;
+	else if (!strcmp(buf, "floppy"))
+	    interface = IF_FLOPPY;
 	else {
             fprintf(stderr, "unsupported bus type '%s'\n", buf);
             return -1;
@@ -4966,6 +4969,30 @@
             }
 	}
         break;
+    case IF_FLOPPY:
+	if (disk_index == -1) {
+	    disk_index = 0;
+	    while (fd_table[disk_index] && disk_index < MAX_FD)
+	        disk_index++;
+	}
+	if (disk_index >= MAX_FD) {
+	    fprintf(stderr, "qemu: too many floppy\n");
+	    return -1;
+	}
+
+        if (!fd_table[disk_index]) {
+            snprintf(buf, sizeof(buf), "fd%c", disk_index + 'a');
+            fd_table[disk_index] = bdrv_new(buf);
+            bdrv_set_type_hint(fd_table[disk_index], BDRV_TYPE_FLOPPY);
+
+            if ( file[0] && (bdrv_open(fd_table[disk_index], file,
+                                       snapshot ? BDRV_O_SNAPSHOT : 0) < 0)) {
+                fprintf(stderr, "qemu: could not open floppy disk image '%s'\n",
+                                file);
+                return -1;
+            }
+	}
+        break;
     }
    return 0;
 }
@@ -7848,7 +7875,6 @@
     int i, pflash_index;
     int snapshot, linux_boot;
     const char *initrd_filename;
-    const char *fd_filename[MAX_FD];
     const char *pflash_filename[MAX_PFLASH];
     const char *sd_filename;
     const char *mtd_filename;
@@ -7912,8 +7938,6 @@
     machine = first_machine;
     cpu_model = NULL;
     initrd_filename = NULL;
-    for(i = 0; i < MAX_FD; i++)
-        fd_filename[i] = NULL;
     for(i = 0; i < MAX_PFLASH; i++)
         pflash_filename[i] = NULL;
     pflash_index = 0;
@@ -8169,10 +8193,14 @@
                 }
                 break;
             case QEMU_OPTION_fda:
-                fd_filename[0] = optarg;
-                break;
             case QEMU_OPTION_fdb:
-                fd_filename[1] = optarg;
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
+                }
+		snprintf(disks[nb_disks], sizeof(disks[0]),
+		         "%s" FD_ALIAS, optarg, popt->index - QEMU_OPTION_fda);
+	        nb_disks++;
                 break;
 #ifdef TARGET_I386
             case QEMU_OPTION_no_fd_bootchk:
@@ -8516,19 +8544,11 @@
 
     if (!linux_boot &&
         (!strchr(boot_device, 'n')) &&
-        nb_disks == 0 &&
-        fd_filename[0] == '\0')
+        nb_disks == 0)
         help(1);
 
-    /* boot to floppy or the default cd if no hard disk defined yet */
     if (!boot_device[0]) {
-        if (nb_disks)
-            boot_device[0] = 'c';
-        else if (fd_filename[0] != '\0')
-            boot_device[0] = 'a';
-        else
-            boot_device[0] = 'd';
-        boot_device[1] = 0;
+        pstrcpy(boot_device, sizeof(boot_device), BOOTCHARS);
     }
     setvbuf(stdout, NULL, _IOLBF, 0);
 
@@ -8606,35 +8626,19 @@
         nb_disks++;
     }
 
+    /* we always create at least on floppy */
+
+    if (nb_disks < MAX_DISKS) {
+        snprintf(disks[nb_disks], sizeof(disks[0]), FD_ALIAS, 0);
+        nb_disks++;
+    }
+
     /* open the virtual block devices */
 
     for(i = 0; i < nb_disks; i++)
         if (disk_init(disks[i], snapshot, machine) == -1)
 	    exit(1);
 
-    /* we always create at least one floppy disk */
-    fd_table[0] = bdrv_new("fda");
-    bdrv_set_type_hint(fd_table[0], BDRV_TYPE_FLOPPY);
-
-    for(i = 0; i < MAX_FD; i++) {
-        if (fd_filename[i]) {
-            if (!fd_table[i]) {
-                char buf[64];
-                snprintf(buf, sizeof(buf), "fd%c", i + 'a');
-                fd_table[i] = bdrv_new(buf);
-                bdrv_set_type_hint(fd_table[i], BDRV_TYPE_FLOPPY);
-            }
-            if (fd_filename[i][0] != '\0') {
-                if (bdrv_open(fd_table[i], fd_filename[i],
-                              snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
-                    fprintf(stderr, "qemu: could not open floppy disk image '%s'\n",
-                            fd_filename[i]);
-                    exit(1);
-                }
-            }
-        }
-    }
-
     /* Open the virtual parallel flash block devices */
     for(i = 0; i < MAX_PFLASH; i++) {
         if (pflash_filename[i]) {
@@ -8750,7 +8754,7 @@
     }
 
     machine->init(ram_size, vga_ram_size, boot_device,
-                  ds, fd_filename, snapshot,
+                  ds, NULL, snapshot,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
     /* init USB devices */
Index: qemu/vl.h
===================================================================
--- qemu.orig/vl.h	2007-10-31 15:49:23.000000000 +0100
+++ qemu/vl.h	2007-10-31 15:49:40.000000000 +0100
@@ -994,7 +994,7 @@
 #define MAX_IDE_DEVS 2
 #define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS)
 
-#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS)
+#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD)
 
 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
 extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 4/7] remove fd_filename from the machine init interface
  2007-10-31 15:51     ` [Qemu-devel] [PATCH 3/7] Add floppy support by -disk Laurent Vivier
@ 2007-10-31 15:51       ` Laurent Vivier
  2007-10-31 15:51         ` [Qemu-devel] [PATCH 5/7] Add parallel flash support by -disk Laurent Vivier
  0 siblings, 1 reply; 8+ messages in thread
From: Laurent Vivier @ 2007-10-31 15:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent.Vivier


As the parameter fd_filename seems unused and as we can't provide it anymore
using the "-disk" interface, this patch removes it.

--
 hw/an5206.c        |    2 +-
 hw/etraxfs.c       |    2 +-
 hw/integratorcp.c  |    2 +-
 hw/mcf5208.c       |    2 +-
 hw/mips_malta.c    |    2 +-
 hw/mips_mipssim.c  |    2 +-
 hw/mips_pica61.c   |    2 +-
 hw/mips_r4k.c      |    2 +-
 hw/palm.c          |    2 +-
 hw/pc.c            |   12 +++++-------
 hw/ppc405_boards.c |    4 ++--
 hw/ppc_chrp.c      |    2 +-
 hw/ppc_oldworld.c  |    2 +-
 hw/ppc_prep.c      |    2 +-
 hw/r2d.c           |    2 +-
 hw/realview.c      |    2 +-
 hw/shix.c          |    2 +-
 hw/spitz.c         |    8 ++++----
 hw/sun4m.c         |    4 ++--
 hw/sun4u.c         |    2 +-
 hw/versatilepb.c   |   10 +++++-----
 vl.c               |    2 +-
 vl.h               |    2 +-
 23 files changed, 36 insertions(+), 38 deletions(-)

Index: qemu/vl.h
===================================================================
--- qemu.orig/vl.h	2007-10-31 14:23:52.000000000 +0100
+++ qemu/vl.h	2007-10-31 14:51:08.000000000 +0100
@@ -732,7 +732,7 @@
 
 typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size,
                                  const char *boot_device,
-             DisplayState *ds, const char **fd_filename, int snapshot,
+             DisplayState *ds, int snapshot,
              const char *kernel_filename, const char *kernel_cmdline,
              const char *initrd_filename, const char *cpu_model);
 
Index: qemu/hw/an5206.c
===================================================================
--- qemu.orig/hw/an5206.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/an5206.c	2007-10-31 14:51:40.000000000 +0100
@@ -28,7 +28,7 @@
 /* Board init.  */
 
 static void an5206_init(int ram_size, int vga_ram_size, const char *boot_device,
-                     DisplayState *ds, const char **fd_filename, int snapshot,
+                     DisplayState *ds, int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/etraxfs.c
===================================================================
--- qemu.orig/hw/etraxfs.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/etraxfs.c	2007-10-31 14:51:50.000000000 +0100
@@ -108,7 +108,7 @@
 
 static
 void bareetraxfs_init (int ram_size, int vga_ram_size, const char *boot_device,
-                       DisplayState *ds, const char **fd_filename, int snapshot,
+                       DisplayState *ds, int snapshot,
                        const char *kernel_filename, const char *kernel_cmdline,
                        const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/integratorcp.c
===================================================================
--- qemu.orig/hw/integratorcp.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/integratorcp.c	2007-10-31 14:52:07.000000000 +0100
@@ -464,7 +464,7 @@
 
 static void integratorcp_init(int ram_size, int vga_ram_size,
                      const char *boot_device, DisplayState *ds,
-                     const char **fd_filename, int snapshot,
+                     int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/mcf5208.c
===================================================================
--- qemu.orig/hw/mcf5208.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/mcf5208.c	2007-10-31 14:52:14.000000000 +0100
@@ -199,7 +199,7 @@
 
 static void mcf5208evb_init(int ram_size, int vga_ram_size,
                      const char *boot_device, DisplayState *ds,
-                     const char **fd_filename, int snapshot,
+                     int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/mips_malta.c
===================================================================
--- qemu.orig/hw/mips_malta.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/mips_malta.c	2007-10-31 14:52:27.000000000 +0100
@@ -741,7 +741,7 @@
 
 static
 void mips_malta_init (int ram_size, int vga_ram_size, const char *boot_device,
-                      DisplayState *ds, const char **fd_filename, int snapshot,
+                      DisplayState *ds, int snapshot,
                       const char *kernel_filename, const char *kernel_cmdline,
                       const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/mips_mipssim.c
===================================================================
--- qemu.orig/hw/mips_mipssim.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/mips_mipssim.c	2007-10-31 14:52:35.000000000 +0100
@@ -75,7 +75,7 @@
 
 static void
 mips_mipssim_init (int ram_size, int vga_ram_size, const char *boot_device,
-                   DisplayState *ds, const char **fd_filename, int snapshot,
+                   DisplayState *ds, int snapshot,
                    const char *kernel_filename, const char *kernel_cmdline,
                    const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/palm.c
===================================================================
--- qemu.orig/hw/palm.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/palm.c	2007-10-31 14:53:01.000000000 +0100
@@ -117,7 +117,7 @@
 
 static void palmte_init(int ram_size, int vga_ram_size,
                 const char *boot_device, DisplayState *ds,
-                const char **fd_filename, int snapshot,
+                int snapshot,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/ppc405_boards.c
===================================================================
--- qemu.orig/hw/ppc405_boards.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/ppc405_boards.c	2007-10-31 14:53:42.000000000 +0100
@@ -173,7 +173,7 @@
 
 static void ref405ep_init (int ram_size, int vga_ram_size,
                            const char *boot_device, DisplayState *ds,
-                           const char **fd_filename, int snapshot,
+                           int snapshot,
                            const char *kernel_filename,
                            const char *kernel_cmdline,
                            const char *initrd_filename,
@@ -499,7 +499,7 @@
 
 static void taihu_405ep_init(int ram_size, int vga_ram_size,
                              const char *boot_device, DisplayState *ds,
-                             const char **fd_filename, int snapshot,
+                             int snapshot,
                              const char *kernel_filename,
                              const char *kernel_cmdline,
                              const char *initrd_filename,
Index: qemu/hw/ppc_chrp.c
===================================================================
--- qemu.orig/hw/ppc_chrp.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/ppc_chrp.c	2007-10-31 14:53:49.000000000 +0100
@@ -50,7 +50,7 @@
 /* PowerPC Mac99 hardware initialisation */
 static void ppc_core99_init (int ram_size, int vga_ram_size,
                              const char *boot_device, DisplayState *ds,
-                             const char **fd_filename, int snapshot,
+                             int snapshot,
                              const char *kernel_filename,
                              const char *kernel_cmdline,
                              const char *initrd_filename,
Index: qemu/hw/ppc_oldworld.c
===================================================================
--- qemu.orig/hw/ppc_oldworld.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/ppc_oldworld.c	2007-10-31 14:53:57.000000000 +0100
@@ -94,7 +94,7 @@
 
 static void ppc_heathrow_init (int ram_size, int vga_ram_size,
                                const char *boot_device, DisplayState *ds,
-                               const char **fd_filename, int snapshot,
+                               int snapshot,
                                const char *kernel_filename,
                                const char *kernel_cmdline,
                                const char *initrd_filename,
Index: qemu/hw/r2d.c
===================================================================
--- qemu.orig/hw/r2d.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/r2d.c	2007-10-31 14:54:11.000000000 +0100
@@ -28,7 +28,7 @@
 #define SDRAM_SIZE 0x04000000
 
 static void r2d_init(int ram_size, int vga_ram_size, const char *boot_device,
-	      DisplayState * ds, const char **fd_filename, int snapshot,
+	      DisplayState * ds, int snapshot,
 	      const char *kernel_filename, const char *kernel_cmdline,
 	      const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/shix.c
===================================================================
--- qemu.orig/hw/shix.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/shix.c	2007-10-31 14:54:27.000000000 +0100
@@ -63,7 +63,7 @@
 }
 
 static void shix_init(int ram_size, int vga_ram_size, const char *boot_device,
-	       DisplayState * ds, const char **fd_filename, int snapshot,
+	       DisplayState * ds, int snapshot,
 	       const char *kernel_filename, const char *kernel_cmdline,
 	       const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/spitz.c
===================================================================
--- qemu.orig/hw/spitz.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/spitz.c	2007-10-31 14:54:50.000000000 +0100
@@ -1230,7 +1230,7 @@
 
 static void spitz_init(int ram_size, int vga_ram_size,
                 const char *boot_device, DisplayState *ds,
-                const char **fd_filename, int snapshot,
+                int snapshot,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
@@ -1240,7 +1240,7 @@
 
 static void borzoi_init(int ram_size, int vga_ram_size,
                 const char *boot_device, DisplayState *ds,
-                const char **fd_filename, int snapshot,
+                int snapshot,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
@@ -1250,7 +1250,7 @@
 
 static void akita_init(int ram_size, int vga_ram_size,
                 const char *boot_device, DisplayState *ds,
-                const char **fd_filename, int snapshot,
+                int snapshot,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
@@ -1260,7 +1260,7 @@
 
 static void terrier_init(int ram_size, int vga_ram_size,
                 const char *boot_device, DisplayState *ds,
-                const char **fd_filename, int snapshot,
+                int snapshot,
                 const char *kernel_filename, const char *kernel_cmdline,
                 const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/sun4u.c
===================================================================
--- qemu.orig/hw/sun4u.c	2007-10-31 14:12:40.000000000 +0100
+++ qemu/hw/sun4u.c	2007-10-31 14:55:12.000000000 +0100
@@ -332,7 +332,7 @@
 
 /* Sun4u hardware initialisation */
 static void sun4u_init(int ram_size, int vga_ram_size, const char *boot_device,
-             DisplayState *ds, const char **fd_filename, int snapshot,
+             DisplayState *ds, int snapshot,
              const char *kernel_filename, const char *kernel_cmdline,
              const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/mips_pica61.c
===================================================================
--- qemu.orig/hw/mips_pica61.c	2007-10-31 14:13:20.000000000 +0100
+++ qemu/hw/mips_pica61.c	2007-10-31 14:52:42.000000000 +0100
@@ -56,7 +56,7 @@
 
 static
 void mips_pica61_init (int ram_size, int vga_ram_size, const char *boot_device,
-                    DisplayState *ds, const char **fd_filename, int snapshot,
+                    DisplayState *ds, int snapshot,
                     const char *kernel_filename, const char *kernel_cmdline,
                     const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/mips_r4k.c
===================================================================
--- qemu.orig/hw/mips_r4k.c	2007-10-31 14:13:20.000000000 +0100
+++ qemu/hw/mips_r4k.c	2007-10-31 14:52:53.000000000 +0100
@@ -138,7 +138,7 @@
 
 static
 void mips_r4k_init (int ram_size, int vga_ram_size, const char *boot_device,
-                    DisplayState *ds, const char **fd_filename, int snapshot,
+                    DisplayState *ds, int snapshot,
                     const char *kernel_filename, const char *kernel_cmdline,
                     const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/pc.c
===================================================================
--- qemu.orig/hw/pc.c	2007-10-31 14:23:52.000000000 +0100
+++ qemu/hw/pc.c	2007-10-31 14:53:25.000000000 +0100
@@ -669,7 +669,7 @@
 
 /* PC hardware initialisation */
 static void pc_init1(int ram_size, int vga_ram_size, const char *boot_device,
-                     DisplayState *ds, const char **fd_filename, int snapshot,
+                     DisplayState *ds, int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename,
                      int pci_enabled)
@@ -949,29 +949,27 @@
 }
 
 static void pc_init_pci(int ram_size, int vga_ram_size, const char *boot_device,
-                        DisplayState *ds, const char **fd_filename,
-                        int snapshot,
+                        DisplayState *ds, int snapshot,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
                         const char *initrd_filename,
                         const char *cpu_model)
 {
     pc_init1(ram_size, vga_ram_size, boot_device,
-             ds, fd_filename, snapshot,
+             ds, snapshot,
              kernel_filename, kernel_cmdline,
              initrd_filename, 1);
 }
 
 static void pc_init_isa(int ram_size, int vga_ram_size, const char *boot_device,
-                        DisplayState *ds, const char **fd_filename,
-                        int snapshot,
+                        DisplayState *ds, int snapshot,
                         const char *kernel_filename,
                         const char *kernel_cmdline,
                         const char *initrd_filename,
                         const char *cpu_model)
 {
     pc_init1(ram_size, vga_ram_size, boot_device,
-             ds, fd_filename, snapshot,
+             ds, snapshot,
              kernel_filename, kernel_cmdline,
              initrd_filename, 0);
 }
Index: qemu/hw/ppc_prep.c
===================================================================
--- qemu.orig/hw/ppc_prep.c	2007-10-31 14:13:20.000000000 +0100
+++ qemu/hw/ppc_prep.c	2007-10-31 14:54:03.000000000 +0100
@@ -522,7 +522,7 @@
 
 /* PowerPC PREP hardware initialisation */
 static void ppc_prep_init (int ram_size, int vga_ram_size, const char *boot_device,
-                           DisplayState *ds, const char **fd_filename,
+                           DisplayState *ds,
                            int snapshot, const char *kernel_filename,
                            const char *kernel_cmdline,
                            const char *initrd_filename,
Index: qemu/hw/realview.c
===================================================================
--- qemu.orig/hw/realview.c	2007-10-31 14:23:52.000000000 +0100
+++ qemu/hw/realview.c	2007-10-31 14:54:19.000000000 +0100
@@ -14,7 +14,7 @@
 
 static void realview_init(int ram_size, int vga_ram_size,
                      const char *boot_device, DisplayState *ds,
-                     const char **fd_filename, int snapshot,
+                     int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/sun4m.c
===================================================================
--- qemu.orig/hw/sun4m.c	2007-10-31 14:23:52.000000000 +0100
+++ qemu/hw/sun4m.c	2007-10-31 14:55:03.000000000 +0100
@@ -571,7 +571,7 @@
 
 /* SPARCstation 5 hardware initialisation */
 static void ss5_init(int RAM_size, int vga_ram_size, const char *boot_device,
-                       DisplayState *ds, const char **fd_filename, int snapshot,
+                       DisplayState *ds, int snapshot,
                        const char *kernel_filename, const char *kernel_cmdline,
                        const char *initrd_filename, const char *cpu_model)
 {
@@ -584,7 +584,7 @@
 
 /* SPARCstation 10 hardware initialisation */
 static void ss10_init(int RAM_size, int vga_ram_size, const char *boot_device,
-                            DisplayState *ds, const char **fd_filename, int snapshot,
+                            DisplayState *ds, int snapshot,
                             const char *kernel_filename, const char *kernel_cmdline,
                             const char *initrd_filename, const char *cpu_model)
 {
Index: qemu/hw/versatilepb.c
===================================================================
--- qemu.orig/hw/versatilepb.c	2007-10-31 14:23:52.000000000 +0100
+++ qemu/hw/versatilepb.c	2007-10-31 14:55:34.000000000 +0100
@@ -153,7 +153,7 @@
 
 static void versatile_init(int ram_size, int vga_ram_size,
                      const char *boot_device, DisplayState *ds,
-                     const char **fd_filename, int snapshot,
+                     int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model,
                      int board_id)
@@ -268,23 +268,23 @@
 }
 
 static void vpb_init(int ram_size, int vga_ram_size, const char *boot_device,
-                     DisplayState *ds, const char **fd_filename, int snapshot,
+                     DisplayState *ds, int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
     versatile_init(ram_size, vga_ram_size, boot_device,
-                   ds, fd_filename, snapshot,
+                   ds, snapshot,
                    kernel_filename, kernel_cmdline,
                    initrd_filename, cpu_model, 0x183);
 }
 
 static void vab_init(int ram_size, int vga_ram_size, const char *boot_device,
-                     DisplayState *ds, const char **fd_filename, int snapshot,
+                     DisplayState *ds, int snapshot,
                      const char *kernel_filename, const char *kernel_cmdline,
                      const char *initrd_filename, const char *cpu_model)
 {
     versatile_init(ram_size, vga_ram_size, boot_device,
-                   ds, fd_filename, snapshot,
+                   ds, snapshot,
                    kernel_filename, kernel_cmdline,
                    initrd_filename, cpu_model, 0x25e);
 }
Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c	2007-10-31 14:46:45.000000000 +0100
+++ qemu/vl.c	2007-10-31 14:49:59.000000000 +0100
@@ -8754,7 +8754,7 @@
     }
 
     machine->init(ram_size, vga_ram_size, boot_device,
-                  ds, NULL, snapshot,
+                  ds, snapshot,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
     /* init USB devices */

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 5/7] Add parallel flash support by -disk
  2007-10-31 15:51       ` [Qemu-devel] [PATCH 4/7] remove fd_filename from the machine init interface Laurent Vivier
@ 2007-10-31 15:51         ` Laurent Vivier
  2007-10-31 15:51           ` [Qemu-devel] [PATCH 6/7] Add " Laurent Vivier
  0 siblings, 1 reply; 8+ messages in thread
From: Laurent Vivier @ 2007-10-31 15:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent.Vivier


This patch allows to define a parallel flash using -disk syntax.
It adds an interface type "pflash".

"-pflash file" is an alias for "-disk file,if=pflash"

--
 vl.c |   59 +++++++++++++++++++++++++++++++++--------------------------
 vl.h |    2 +-
 2 files changed, 34 insertions(+), 27 deletions(-)

Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c	2007-10-31 14:49:59.000000000 +0100
+++ qemu/vl.c	2007-10-31 15:01:05.000000000 +0100
@@ -4712,6 +4712,7 @@
 }
 
 #define FD_ALIAS ",index=%d,if=floppy"
+#define PFLASH_ALIAS ",if=pflash"
 #define HD_ALIAS ",index=%d,media=disk"
 
 #ifdef TARGET_PPC
@@ -4723,7 +4724,7 @@
 static int disk_init(const char *str, int snapshot, QEMUMachine *machine)
 {
     char buf[16];
-    enum { IF_IDE, IF_SCSI, IF_FLOPPY } interface;
+    enum { IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH } interface;
     enum { MEDIA_DISK, MEDIA_CDROM } media;
     int bus_id, unit_id;
     int cyls, heads, secs, translation;
@@ -4814,6 +4815,8 @@
 	    interface = IF_SCSI;
 	else if (!strcmp(buf, "floppy"))
 	    interface = IF_FLOPPY;
+	else if (!strcmp(buf, "pflash"))
+	    interface = IF_PFLASH;
 	else {
             fprintf(stderr, "unsupported bus type '%s'\n", buf);
             return -1;
@@ -4993,6 +4996,29 @@
             }
 	}
         break;
+    case IF_PFLASH:
+        if (disk_index == -1) {
+	    disk_index = 0;
+	    while (pflash_table[disk_index] && disk_index < MAX_PFLASH)
+	        disk_index++;
+	}
+	if (disk_index >= MAX_PFLASH) {
+	    fprintf(stderr, "qemu: too many parallel flash images\n");
+	    return -1;
+	}
+
+        if (!pflash_table[disk_index]) {
+            snprintf(buf, sizeof(buf), "fl%c", disk_index + 'a');
+            pflash_table[disk_index] = bdrv_new(buf);
+
+            if (file[0] && bdrv_open(pflash_table[disk_index], file,
+                          snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
+                fprintf(stderr, "qemu: could not open flash image '%s'\n",
+                        file);
+                return -1;
+            }
+        }
+	break;
     }
    return 0;
 }
@@ -7872,10 +7898,9 @@
     int use_gdbstub;
     const char *gdbstub_port;
 #endif
-    int i, pflash_index;
+    int i;
     int snapshot, linux_boot;
     const char *initrd_filename;
-    const char *pflash_filename[MAX_PFLASH];
     const char *sd_filename;
     const char *mtd_filename;
     const char *kernel_filename, *kernel_cmdline;
@@ -7938,9 +7963,6 @@
     machine = first_machine;
     cpu_model = NULL;
     initrd_filename = NULL;
-    for(i = 0; i < MAX_PFLASH; i++)
-        pflash_filename[i] = NULL;
-    pflash_index = 0;
     sd_filename = NULL;
     mtd_filename = NULL;
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
@@ -8097,11 +8119,13 @@
                 sd_filename = optarg;
                 break;
             case QEMU_OPTION_pflash:
-                if (pflash_index >= MAX_PFLASH) {
-                    fprintf(stderr, "qemu: too many parallel flash images\n");
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
                     exit(1);
                 }
-                pflash_filename[pflash_index++] = optarg;
+		snprintf(disks[nb_disks], sizeof(disks[0]),
+		         "%s" PFLASH_ALIAS, optarg);
+	        nb_disks++;
                 break;
             case QEMU_OPTION_snapshot:
                 snapshot = 1;
@@ -8639,23 +8663,6 @@
         if (disk_init(disks[i], snapshot, machine) == -1)
 	    exit(1);
 
-    /* Open the virtual parallel flash block devices */
-    for(i = 0; i < MAX_PFLASH; i++) {
-        if (pflash_filename[i]) {
-            if (!pflash_table[i]) {
-                char buf[64];
-                snprintf(buf, sizeof(buf), "fl%c", i + 'a');
-                pflash_table[i] = bdrv_new(buf);
-            }
-            if (bdrv_open(pflash_table[i], pflash_filename[i],
-                          snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
-                fprintf(stderr, "qemu: could not open flash image '%s'\n",
-                        pflash_filename[i]);
-                exit(1);
-            }
-        }
-    }
-
     sd_bdrv = bdrv_new ("sd");
     /* FIXME: This isn't really a floppy, but it's a reasonable
        approximation.  */
Index: qemu/vl.h
===================================================================
--- qemu.orig/vl.h	2007-10-31 14:51:08.000000000 +0100
+++ qemu/vl.h	2007-10-31 15:01:05.000000000 +0100
@@ -994,7 +994,7 @@
 #define MAX_IDE_DEVS 2
 #define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS)
 
-#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD)
+#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD + MAX_PFLASH)
 
 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
 extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 6/7] Add flash support by -disk
  2007-10-31 15:51         ` [Qemu-devel] [PATCH 5/7] Add parallel flash support by -disk Laurent Vivier
@ 2007-10-31 15:51           ` Laurent Vivier
  2007-10-31 15:51             ` [Qemu-devel] [PATCH 7/7] Add SecureDigital " Laurent Vivier
  0 siblings, 1 reply; 8+ messages in thread
From: Laurent Vivier @ 2007-10-31 15:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent.Vivier


This patch allows to define a flash (mtd) using the "-disk" syntax.
It adds an interface type "mtd"

"-mtdblock file" is an alias for "-disk file,if=mtd"

--
 vl.c |   39 +++++++++++++++++++++++----------------
 vl.h |    5 ++++-
 2 files changed, 27 insertions(+), 17 deletions(-)

Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c	2007-10-31 15:01:05.000000000 +0100
+++ qemu/vl.c	2007-10-31 15:05:27.000000000 +0100
@@ -4713,6 +4713,7 @@
 
 #define FD_ALIAS ",index=%d,if=floppy"
 #define PFLASH_ALIAS ",if=pflash"
+#define MTD_ALIAS ",if=mtd"
 #define HD_ALIAS ",index=%d,media=disk"
 
 #ifdef TARGET_PPC
@@ -4724,7 +4725,7 @@
 static int disk_init(const char *str, int snapshot, QEMUMachine *machine)
 {
     char buf[16];
-    enum { IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH } interface;
+    enum { IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD } interface;
     enum { MEDIA_DISK, MEDIA_CDROM } media;
     int bus_id, unit_id;
     int cyls, heads, secs, translation;
@@ -4817,6 +4818,8 @@
 	    interface = IF_FLOPPY;
 	else if (!strcmp(buf, "pflash"))
 	    interface = IF_PFLASH;
+	else if (!strcmp(buf, "mtd"))
+	    interface = IF_MTD;
 	else {
             fprintf(stderr, "unsupported bus type '%s'\n", buf);
             return -1;
@@ -5019,6 +5022,18 @@
             }
         }
 	break;
+    case IF_MTD:
+	if (!mtd_bdrv) {
+            mtd_bdrv = bdrv_new ("mtd");
+            if (file[0] && bdrv_open(mtd_bdrv, file,
+                                     snapshot ? BDRV_O_SNAPSHOT : 0) < 0
+                        || qemu_key_check(mtd_bdrv, file)) {
+                fprintf(stderr, "qemu: could not open Flash image %s\n",
+                                file);
+		return -1;
+            }
+	}
+        break;
     }
    return 0;
 }
@@ -7902,7 +7917,6 @@
     int snapshot, linux_boot;
     const char *initrd_filename;
     const char *sd_filename;
-    const char *mtd_filename;
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
@@ -7964,7 +7978,6 @@
     cpu_model = NULL;
     initrd_filename = NULL;
     sd_filename = NULL;
-    mtd_filename = NULL;
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     vga_ram_size = VGA_RAM_SIZE;
 #ifdef CONFIG_GDBSTUB
@@ -8113,7 +8126,13 @@
 	        nb_disks++;
 	        break;
             case QEMU_OPTION_mtdblock:
-                mtd_filename = optarg;
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
+                }
+		snprintf(disks[nb_disks], sizeof(disks[0]),
+		         "%s" MTD_ALIAS, optarg);
+	        nb_disks++;
                 break;
             case QEMU_OPTION_sd:
                 sd_filename = optarg;
@@ -8676,18 +8695,6 @@
             qemu_key_check(sd_bdrv, sd_filename);
     }
 
-    if (mtd_filename) {
-        mtd_bdrv = bdrv_new ("mtd");
-        if (bdrv_open(mtd_bdrv, mtd_filename,
-                      snapshot ? BDRV_O_SNAPSHOT : 0) < 0 ||
-            qemu_key_check(mtd_bdrv, mtd_filename)) {
-            fprintf(stderr, "qemu: could not open Flash image %s\n",
-                    mtd_filename);
-            bdrv_delete(mtd_bdrv);
-            mtd_bdrv = 0;
-        }
-    }
-
     register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
     register_savevm("ram", 0, 2, ram_save, ram_load, NULL);
 
Index: qemu/vl.h
===================================================================
--- qemu.orig/vl.h	2007-10-31 15:01:05.000000000 +0100
+++ qemu/vl.h	2007-10-31 15:05:27.000000000 +0100
@@ -994,7 +994,10 @@
 #define MAX_IDE_DEVS 2
 #define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS)
 
-#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD + MAX_PFLASH)
+#define MAX_MTD 1
+
+#define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD + MAX_PFLASH + \
+                   MAX_MTD)
 
 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
 extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 7/7] Add SecureDigital support by -disk
  2007-10-31 15:51           ` [Qemu-devel] [PATCH 6/7] Add " Laurent Vivier
@ 2007-10-31 15:51             ` Laurent Vivier
  0 siblings, 0 replies; 8+ messages in thread
From: Laurent Vivier @ 2007-10-31 15:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent.Vivier


This patch allows to define SecureDigital disk using "-disk" syntax"
It adds an interface type "sd"

"-sd file" becomes the alias of "-disk file,if=sd"

--
 vl.c |   43 ++++++++++++++++++++++++++-----------------
 vl.h |    3 ++-
 2 files changed, 28 insertions(+), 18 deletions(-)

Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c	2007-10-31 15:05:44.000000000 +0100
+++ qemu/vl.c	2007-10-31 15:10:48.000000000 +0100
@@ -4714,6 +4714,7 @@
 #define FD_ALIAS ",index=%d,if=floppy"
 #define PFLASH_ALIAS ",if=pflash"
 #define MTD_ALIAS ",if=mtd"
+#define SD_ALIAS ",if=sd"
 #define HD_ALIAS ",index=%d,media=disk"
 
 #ifdef TARGET_PPC
@@ -4725,7 +4726,7 @@
 static int disk_init(const char *str, int snapshot, QEMUMachine *machine)
 {
     char buf[16];
-    enum { IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD } interface;
+    enum { IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD } interface;
     enum { MEDIA_DISK, MEDIA_CDROM } media;
     int bus_id, unit_id;
     int cyls, heads, secs, translation;
@@ -4820,6 +4821,8 @@
 	    interface = IF_PFLASH;
 	else if (!strcmp(buf, "mtd"))
 	    interface = IF_MTD;
+	else if (!strcmp(buf, "sd"))
+	    interface = IF_SD;
 	else {
             fprintf(stderr, "unsupported bus type '%s'\n", buf);
             return -1;
@@ -5034,6 +5037,21 @@
             }
 	}
         break;
+    case IF_SD:
+	if (!sd_bdrv) {
+            sd_bdrv = bdrv_new ("sd");
+            /* FIXME: This isn't really a floppy, but it's a reasonable
+               approximation.  */
+            bdrv_set_type_hint(sd_bdrv, BDRV_TYPE_FLOPPY);
+            if (file[0] && bdrv_open(sd_bdrv, file,
+                                     snapshot ? BDRV_O_SNAPSHOT : 0) < 0
+                        || qemu_key_check(sd_bdrv, file)) {
+                fprintf(stderr, "qemu: could not open SD card image %s\n",
+                        file);
+                return -1;
+	    }
+	}
+        break;
     }
    return 0;
 }
@@ -7916,7 +7934,6 @@
     int i;
     int snapshot, linux_boot;
     const char *initrd_filename;
-    const char *sd_filename;
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
     int cyls, heads, secs, translation;
@@ -7977,7 +7994,6 @@
     machine = first_machine;
     cpu_model = NULL;
     initrd_filename = NULL;
-    sd_filename = NULL;
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     vga_ram_size = VGA_RAM_SIZE;
 #ifdef CONFIG_GDBSTUB
@@ -8135,7 +8151,13 @@
 	        nb_disks++;
                 break;
             case QEMU_OPTION_sd:
-                sd_filename = optarg;
+                if (nb_disks >= MAX_DISKS) {
+                    fprintf(stderr, "qemu: too many disks\n");
+                    exit(1);
+                }
+		snprintf(disks[nb_disks], sizeof(disks[0]),
+		         "%s" SD_ALIAS, optarg);
+	        nb_disks++;
                 break;
             case QEMU_OPTION_pflash:
                 if (nb_disks >= MAX_DISKS) {
@@ -8682,19 +8704,6 @@
         if (disk_init(disks[i], snapshot, machine) == -1)
 	    exit(1);
 
-    sd_bdrv = bdrv_new ("sd");
-    /* FIXME: This isn't really a floppy, but it's a reasonable
-       approximation.  */
-    bdrv_set_type_hint(sd_bdrv, BDRV_TYPE_FLOPPY);
-    if (sd_filename) {
-        if (bdrv_open(sd_bdrv, sd_filename,
-                      snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
-            fprintf(stderr, "qemu: could not open SD card image %s\n",
-                    sd_filename);
-        } else
-            qemu_key_check(sd_bdrv, sd_filename);
-    }
-
     register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
     register_savevm("ram", 0, 2, ram_save, ram_load, NULL);
 
Index: qemu/vl.h
===================================================================
--- qemu.orig/vl.h	2007-10-31 15:05:44.000000000 +0100
+++ qemu/vl.h	2007-10-31 15:10:48.000000000 +0100
@@ -995,9 +995,10 @@
 #define MAX_IDE_DISKS (MAX_IDE_BUS * MAX_IDE_DEVS)
 
 #define MAX_MTD 1
+#define MAX_SD 1
 
 #define MAX_DISKS (MAX_IDE_DISKS + MAX_SCSI_DISKS + MAX_FD + MAX_PFLASH + \
-                   MAX_MTD)
+                   MAX_MTD + MAX_SD)
 
 extern BlockDriverState *bs_table[MAX_IDE_DISKS + 1];
 extern BlockDriverState *sd_table[MAX_SCSI_DISKS + 1];

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-10-31 16:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-31 15:51 [Qemu-devel] [PATCH 0/7] Add -disk interface Laurent Vivier
2007-10-31 15:51 ` [Qemu-devel] [PATCH 1/7] Add arg -disk to define new disk with more features Laurent Vivier
2007-10-31 15:51   ` [Qemu-devel] [PATCH 2/7] Add scsi support for the target PC Laurent Vivier
2007-10-31 15:51     ` [Qemu-devel] [PATCH 3/7] Add floppy support by -disk Laurent Vivier
2007-10-31 15:51       ` [Qemu-devel] [PATCH 4/7] remove fd_filename from the machine init interface Laurent Vivier
2007-10-31 15:51         ` [Qemu-devel] [PATCH 5/7] Add parallel flash support by -disk Laurent Vivier
2007-10-31 15:51           ` [Qemu-devel] [PATCH 6/7] Add " Laurent Vivier
2007-10-31 15:51             ` [Qemu-devel] [PATCH 7/7] Add SecureDigital " Laurent Vivier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).