From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: alex.bennee@linaro.org, lersek@redhat.com, philmd@redhat.com,
kwolf@redhat.com, mreitz@redhat.com, qemu-block@nongnu.org
Subject: [Qemu-devel] [RFC PATCH v6 1/4] hw/block: better reporting on pflash backing file mismatch
Date: Thu, 7 Mar 2019 10:37:20 +0100 [thread overview]
Message-ID: <20190307093723.655-2-armbru@redhat.com> (raw)
In-Reply-To: <20190307093723.655-1-armbru@redhat.com>
From: Alex Bennée <alex.bennee@linaro.org>
It looks like there was going to be code to check we had some sort of
alignment so let's replace it with an actual check. Reject undersized
images with "device needs N bytes, backing file provides only M
bytes". This is a bit more useful than the enigmatic "failed to read
the initial flash content" when we attempt to read the number of bytes
the device should have. Continue to accept oversized images, but warn
"device needs N bytes, rest ignored".
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
hw/block/pflash_cfi01.c | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 9d1c356eb6..75ce8ef489 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -45,6 +45,7 @@
#include "qemu/bitops.h"
#include "qemu/host-utils.h"
#include "qemu/log.h"
+#include "qemu/error-report.h"
#include "hw/sysbus.h"
#include "sysemu/sysemu.h"
#include "trace.h"
@@ -730,13 +731,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp)
}
device_len = sector_len_per_device * blocks_per_device;
- /* XXX: to be fixed */
-#if 0
- if (total_len != (8 * 1024 * 1024) && total_len != (16 * 1024 * 1024) &&
- total_len != (32 * 1024 * 1024) && total_len != (64 * 1024 * 1024))
- return NULL;
-#endif
-
memory_region_init_rom_device(
&pfl->mem, OBJECT(dev),
&pflash_cfi01_ops,
@@ -763,6 +757,27 @@ static void pflash_cfi01_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.
+ */
+ int64_t backing_len = blk_getlength(pfl->blk);
+ if (backing_len < 0) {
+ error_setg(errp, "unable to check size of backing file");
+ return;
+ }
+
+ if (backing_len < total_len) {
+ error_setg(errp, "device needs %" PRIu64 " bytes, "
+ "backing file provides only %" PRIu64 " bytes",
+ total_len, backing_len);
+ return;
+ } else if (backing_len > total_len) {
+ warn_report("device needs %" PRIu64 " bytes, rest ignored",
+ total_len);
+ }
+
/* read the initial flash content */
ret = blk_pread(pfl->blk, 0, pfl->storage, total_len);
--
2.17.2
next prev parent reply other threads:[~2019-03-07 9:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-07 9:37 [Qemu-devel] [RFC PATCH v6 0/4] hw/block: better reporting on pflash backing file mismatch Markus Armbruster
2019-03-07 9:37 ` Markus Armbruster [this message]
2019-03-07 15:05 ` [Qemu-devel] [RFC PATCH v6 1/4] " Alex Bennée
2019-03-07 17:14 ` Markus Armbruster
2019-03-07 9:37 ` [Qemu-devel] [RFC PATCH v6 2/4] hw/block: Pad undersized read-only images with 0xFF Markus Armbruster
2019-03-07 10:05 ` Markus Armbruster
2019-03-07 14:55 ` Kevin Wolf
2019-03-07 17:55 ` Eric Blake
2019-03-07 17:57 ` Markus Armbruster
2019-03-07 18:01 ` Laszlo Ersek
2019-03-07 9:37 ` [Qemu-devel] [RFC PATCH v6 3/4] fixup! hw/block: better reporting on pflash backing file mismatch Markus Armbruster
2019-03-07 9:37 ` [Qemu-devel] [RFC PATCH v6 4/4] fixup! hw/block: Pad undersized read-only images with 0xFF Markus Armbruster
2019-03-07 9:44 ` [Qemu-devel] [RFC PATCH v6 0/4] hw/block: better reporting on pflash backing file mismatch no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190307093723.655-2-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=kwolf@redhat.com \
--cc=lersek@redhat.com \
--cc=mreitz@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).