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];