Check block driver read error in pflash_cfi0x
PATCH 1/1 Check block driver read error in pflash_cfi0x
If a flash file of size smaller than the flash size is specified in the -pflash option, the block driver returns error. But the pflash_cfi0x ignores the error. This results in a flash content of all zeroes. And the simulation aborts while executing code.
This patch adds the checks for errors from bdrv_read and escalates it to the calling code.
hw/pflash_cfi01.c +7 -1
@@ -507,6 +507,7 @@ {pflash_t *pfl;target_phys_addr_t total_len; +int ret; total_len = sector_len * nb_blocs;
@@ -530,7 +531,12 @@ pfl->bs = bs;if (pfl->bs) {/* read the initial flash content */ -bdrv_read (pfl->bs,0 , pfl->storage, total_len >>9 ); + ret =bdrv_read (pfl->bs,0 , pfl->storage, total_len >>9 ); +if (ret <0 ) { +cpu_unregister_io_memory (pfl->fl_mem); +qemu_free (pfl); +return NULL ; + } }#if 0 /* XXX: there should be a bit to set up read-only, * the same way the hardware does (with WP pin).
hw/pflash_cfi02.c +7 -1
@@ -547,6 +547,7 @@ {pflash_t *pfl;int32_t chip_len; +int ret; chip_len = sector_len * nb_blocs;/* XXX: to be fixed */
@@ -568,7 +569,12 @@ pfl->bs = bs;if (pfl->bs) {/* read the initial flash content */ -bdrv_read (pfl->bs,0 , pfl->storage, chip_len >>9 ); + ret =bdrv_read (pfl->bs,0 , pfl->storage, chip_len >>9 ); +if (ret <0 ) { +cpu_unregister_io_memory (pfl->fl_mem); +qemu_free (pfl); +return NULL ; + } }#if 0 /* XXX: there should be a bit to set up read-only, * the same way the hardware does (with WP pin).
2009/8/21 Vijay Kumar <[email protected]>:
Quoted 7 lines
If a flash file of size smaller than the flash size is specified in the -pflash option, the block driver returns error. But the
pflash_cfi0xignores the error. This results in a flash content of all zeroes. And the simulation aborts while executing code.This patch adds the checks for errors from
bdrv_readand escalates it to the calling code.
Maybe it should print a message indicating the expected size and exit?
Cheers