Signed-off-by: Fam Zheng <[email protected]>
---
hw/block/pflash_cfi01.c | 10 ++++++++++
hw/block/pflash_cfi02.c | 9 +++++++++
2 files changed, 19 insertions(+)
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 62d7a56..df82471 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -76,6 +76,7 @@ struct pflash_t {
/*< public >*/
BlockBackend *blk;
+ ImageLockMode lock_mode;
uint32_t nb_blocs;
uint64_t sector_len;
uint8_t bank_width;
@@ -738,6 +739,14 @@ static void pflash_cfi01_realize(DeviceState *dev, Error
**errp)
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);
if (pfl->blk) {
+ Error *local_err = NULL;
+
+ blk_lock_image(pfl->blk, pfl->lock_mode, &local_err);
+ if (local_err) {
+ vmstate_unregister_ram(&pfl->mem, DEVICE(pfl));
+ error_propagate(errp, local_err);
+ return;
+ }
/* read the initial flash content */
ret = blk_pread(pfl->blk, 0, pfl->storage, total_len);
@@ -852,6 +861,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error
**errp)
static Property pflash_cfi01_properties[] = {
DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
+ DEFINE_PROP_LOCK_MODE("lock-mode", struct pflash_t, lock_mode),
/* num-blocks is the number of blocks actually visible to the guest,
* ie the total size of the device divided by the sector length.
* If we're emulating flash devices wired in parallel the actual
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 4f6105c..ff6a9fb 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -620,6 +620,14 @@ static void pflash_cfi02_realize(DeviceState *dev, Error
**errp)
pfl->storage = memory_region_get_ram_ptr(&pfl->orig_mem);
pfl->chip_len = chip_len;
if (pfl->blk) {
+ Error *local_err = NULL;
+
+ blk_lock_image(pfl->blk, pfl->lock_mode, &local_err);
+ if (local_err) {
+ vmstate_unregister_ram(&pfl->mem, DEVICE(pfl));
+ error_propagate(errp, local_err);
+ return;
+ }
/* read the initial flash content */
ret = blk_pread(pfl->blk, 0, pfl->storage, chip_len);
if (ret < 0) {
@@ -724,6 +732,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error
**errp)
static Property pflash_cfi02_properties[] = {
DEFINE_PROP_DRIVE("drive", struct pflash_t, blk),
+ DEFINE_PROP_LOCK_MODE("lock-mode", struct pflash_t, lock_mode),
DEFINE_PROP_UINT32("num-blocks", struct pflash_t, nb_blocs, 0),
DEFINE_PROP_UINT32("sector-length", struct pflash_t, sector_len, 0),
DEFINE_PROP_UINT8("width", struct pflash_t, width, 0),
--
2.7.4