diff options
author | Juha Riihimäki <juha.riihimaki@nokia.com> | 2011-10-20 14:53:34 +0200 |
---|---|---|
committer | Andrzej Zaborowski <andrew.zaborowski@intel.com> | 2011-11-14 03:19:18 +0100 |
commit | 3fc3abf7ecc5b27fa4f6014b44101072134ea0e4 (patch) | |
tree | 3c413f3a014d74c5fdfdf0b4e2f1158bc3a04867 | |
parent | b2887c43eeec4b8e7697e18dfac071fd9cb4f0c0 (diff) |
hw/nand: reject read-only drives
also gracefully fail on nand_device_init() for unsupported block
size instead of aborting.
Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Andrzej Zaborowski <andrew.zaborowski@intel.com>
-rw-r--r-- | hw/nand.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -19,6 +19,7 @@ # include "flash.h" # include "blockdev.h" # include "sysbus.h" +#include "qemu-error.h" # define NAND_CMD_READ0 0x00 # define NAND_CMD_READ1 0x01 @@ -384,18 +385,23 @@ static int nand_device_init(SysBusDevice *dev) nand_init_2048(s); break; default: - hw_error("%s: Unsupported NAND block size.\n", __func__); + error_report("Unsupported NAND block size"); + return -1; } pagesize = 1 << s->oob_shift; s->mem_oob = 1; - if (s->bdrv && bdrv_getlength(s->bdrv) >= - (s->pages << s->page_shift) + (s->pages << s->oob_shift)) { - pagesize = 0; - s->mem_oob = 0; - } - - if (!s->bdrv) { + if (s->bdrv) { + if (bdrv_is_read_only(s->bdrv)) { + error_report("Can't use a read-only drive"); + return -1; + } + if (bdrv_getlength(s->bdrv) >= + (s->pages << s->page_shift) + (s->pages << s->oob_shift)) { + pagesize = 0; + s->mem_oob = 0; + } + } else { pagesize += 1 << s->page_shift; } if (pagesize) { |