This patch adds a -pflash <filename> option to the Qemu command line.
This seems needed to instanciate parallel NOR flashes using the
pflash_cfi02 driver for embedded targets.

Please comment.

-- 
J. Mayer <[EMAIL PROTECTED]>
Never organized
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.279
diff -u -d -d -p -r1.279 vl.c
--- vl.c	6 Apr 2007 16:49:48 -0000	1.279
+++ vl.c	16 Apr 2007 07:42:10 -0000
@@ -138,6 +138,7 @@ IOPortWriteFunc *ioport_write_table[3][M
 /* Note: bs_table[MAX_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 *pflash_table[MAX_PFLASH];
 BlockDriverState *sd_bdrv;
 /* point to the block driver where the snapshots are managed */
 BlockDriverState *bs_snapshots;
@@ -6347,6 +6348,7 @@ void help(void)
            "-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"
            "-sd file        use 'file' as SecureDigital card image\n"
+           "-pflash file    use 'file' as a parallel flash image\n"
            "-boot [a|c|d|n] boot on floppy (a), hard disk (c), CD-ROM (d), or network (n)\n"
            "-snapshot       write to temporary files instead of disk image files\n"
 #ifdef CONFIG_SDL
@@ -6485,6 +6487,7 @@ enum {
     QEMU_OPTION_hdd,
     QEMU_OPTION_cdrom,
     QEMU_OPTION_sd,
+    QEMU_OPTION_pflash,
     QEMU_OPTION_boot,
     QEMU_OPTION_snapshot,
 #ifdef TARGET_I386
@@ -6564,6 +6567,7 @@ const QEMUOption qemu_options[] = {
     { "hdd", HAS_ARG, QEMU_OPTION_hdd },
     { "cdrom", HAS_ARG, QEMU_OPTION_cdrom },
     { "sd", HAS_ARG, QEMU_OPTION_sd },
+    { "pflash", HAS_ARG, QEMU_OPTION_pflash },
     { "boot", HAS_ARG, QEMU_OPTION_boot },
     { "snapshot", 0, QEMU_OPTION_snapshot },
 #ifdef TARGET_I386
@@ -6847,10 +6854,11 @@ int main(int argc, char **argv)
     int use_gdbstub;
     const char *gdbstub_port;
 #endif
-    int i, cdrom_index;
+    int i, cdrom_index, pflash_index;
     int snapshot, linux_boot;
     const char *initrd_filename;
     const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
+    const char *pflash_filename[MAX_PFLASH];
     const char *sd_filename;
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
@@ -6912,6 +6920,9 @@ int main(int argc, char **argv)
         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;
     sd_filename = NULL;
     ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     vga_ram_size = VGA_RAM_SIZE;
@@ -7034,6 +7045,13 @@ int main(int argc, char **argv)
             case QEMU_OPTION_sd:
                 sd_filename = optarg;
                 break;
+            case QEMU_OPTION_pflash:
+                if (pflash_index >= MAX_PFLASH) {
+                    fprintf(stderr, "qemu: too many parallel flash images\n");
+                    exit(1);
+                }
+                pflash_filename[pflash_index++] = optarg;
+                break;
             case QEMU_OPTION_snapshot:
                 snapshot = 1;
                 break;
@@ -7543,6 +7562,23 @@ int main(int argc, char **argv)
         }
     }
 
+    /* Open the virtual parallel flash bloc 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: vl.h
===================================================================
RCS file: /sources/qemu/qemu/vl.h,v
retrieving revision 1.210
diff -u -d -d -p -r1.210 vl.h
--- vl.h	12 Apr 2007 21:11:02 -0000	1.210
+++ vl.h	16 Apr 2007 07:42:10 -0000
@@ -1432,6 +1508,8 @@ int sh7750_register_io_device(struct SH7
 int tc58128_init(struct SH7750State *s, char *zone1, char *zone2);
 
 /* NOR flash devices */
+#define MAX_PFLASH 4
+extern BlockDriverState *pflash_table[MAX_PFLASH];
 typedef struct pflash_t pflash_t;
 
 pflash_t *pflash_register (target_ulong base, ram_addr_t off,

Reply via email to