--- hw/block/pflash_cfi02.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index d30a351472..db1c39499c 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -578,8 +578,9 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp) if (pfl->blk) { /* * Validate the backing store is the right size for pflash - * devices. If the user supplies a larger file we ignore the - * tail. + * devices. If the device is read-only we can elide the check + * and just pad the region first. If the user supplies a + * larger file we ignore the tail. */ int64_t backing_len = blk_getlength(pfl->blk); if (backing_len < 0) { @@ -588,9 +589,20 @@ static void pflash_cfi02_realize(DeviceState *dev, Error **errp) } if (backing_len < chip_len) { - error_setg(errp, "device needs %" PRIu32 " bytes, " - "backing file provides only %" PRIu64 " bytes", - chip_len, backing_len); + if (pfl->ro) { + size_t pad_bytes = chip_len - backing_len; + /* pad with NOR erase pattern */ + memset((uint8_t *)pfl->storage + backing_len, + 0xff, pad_bytes); + warn_report("device needs %" PRIu32 + " bytes, padded with %zu 0xff bytes", + chip_len, pad_bytes); + chip_len = backing_len; + } else { + error_setg(errp, "device needs %" PRIu32 " bytes, " + "backing file provides only %" PRIu64 " bytes", + chip_len, backing_len); + } return; } else if (backing_len > chip_len) { warn_report("device needs %" PRIu32 " bytes, rest ignored", -- 2.17.2