qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Peter Delevoryas" <peter@pjd.dev>,
	"Cédric Le Goater" <clg@kaod.org>,
	qemu-block <qemu-block@nongnu.org>,
	"Xiang Zheng" <zhengxiang9@huawei.com>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org,
	qemu-block@nongnu.org, Joel Stanley <joel@jms.id.au>,
	Andrew Jeffery <andrew@aj.id.au>,
	Markus Armbruster <armbru@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Alistair Francis <alistair.francis@wdc.com>
Subject: Re: [PATCH 1/8] m25p80: Improve error when the backend file size does not match the device
Date: Thu, 16 Feb 2023 09:47:07 +0100	[thread overview]
Message-ID: <a3970b81-89e6-66c3-4a62-13bd610096b6@linaro.org> (raw)
In-Reply-To: <Y+038bMA0BaPLUr8@pdel-mbp.dhcp.thefacebook.com>

On 15/2/23 20:52, Peter Delevoryas wrote:
> On Tue, Feb 14, 2023 at 06:18:23PM +0100, Cédric Le Goater wrote:
>> Currently, when a block backend is attached to a m25p80 device and the
>> associated file size does not match the flash model, QEMU complains
>> with the error message "failed to read the initial flash content".
>> This is confusing for the user.
>>
>> Use blk_check_size_and_read_all() instead of blk_pread() to improve
>> the reported error.

Could you reference commit 06f1521795?

>> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> Reviewed-by: Peter Delevoryas <peter@pjd.dev>
>> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>> Message-Id: <20221115151000.2080833-1-clg@kaod.org>
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>> ---
>>
>>    breakage with commit a4b15a8b9e ("pflash: Only read non-zero parts
>>    of backend image") when using -snaphot.
> 
> 
> I guess it's not obvious to me, what broke?
> 
> 1. BlockBackend *blk = -drive file=blob.mtd,format=raw,if=mtd,snapshot=on
> 2. uint8_t *storage = malloc(...)
> 3. blk_check_size_and_read_all(blk, storage, size)
> 4. commit a4b15a8b9e
>      for sector in blk:
>          if any(b != 0 for b in sector):
>              memcpy(&storage[...], sector, sizeof(sector))
>          else:
>              # Skip memcpy of zeroes
> 
> But this is probably a regression for us because we actually expect the zeroes
> to be copied?

Yes... Commit a4b15a8b9e mostly considered cloud payload optimization.

Since EEPROMs are usually "small", this could be kludged as:

-- >8 --
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -1615,6 +1615,7 @@ static void m25p80_realize(SSIPeripheral *ss, 
Error **errp)
          trace_m25p80_binding(s);
          s->storage = blk_blockalign(s->blk, s->size);

+        memset(s->storage, ERASED_BYTE, s->size);
          if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
              error_setg(errp, "failed to read the initial flash content");
              return;
---

On emulation, it is simpler to ask the user to provide a block image
with the same size of the emulated device. See commit 06f1521795
("pflash: Require backend size to match device, improve errors") for
more information.

>> diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
>> index 802d2eb021..dc5ffbc4ff 100644
>> --- a/hw/block/m25p80.c
>> +++ b/hw/block/m25p80.c
>> @@ -24,6 +24,7 @@
>>   #include "qemu/osdep.h"
>>   #include "qemu/units.h"
>>   #include "sysemu/block-backend.h"
>> +#include "hw/block/block.h"
>>   #include "hw/qdev-properties.h"
>>   #include "hw/qdev-properties-system.h"
>>   #include "hw/ssi/ssi.h"
>> @@ -1615,8 +1616,7 @@ static void m25p80_realize(SSIPeripheral *ss, Error **errp)
>>           trace_m25p80_binding(s);
>>           s->storage = blk_blockalign(s->blk, s->size);
>>   
>> -        if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
>> -            error_setg(errp, "failed to read the initial flash content");
>> +        if (!blk_check_size_and_read_all(s->blk, s->storage, s->size, errp)) {
>>               return;
>>           }
>>       } else {
>> -- 
>> 2.39.1
>>



  reply	other threads:[~2023-02-16  8:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14 17:18 [PATCH 0/8] aspeed: I2C fixes, -drive removal (first step) Cédric Le Goater
2023-02-14 17:18 ` [PATCH 1/8] m25p80: Improve error when the backend file size does not match the device Cédric Le Goater
2023-02-15 19:52   ` Peter Delevoryas
2023-02-16  8:47     ` Philippe Mathieu-Daudé [this message]
2023-02-14 17:18 ` [PATCH 2/8] hw/i2c: only schedule pending master when bus is idle Cédric Le Goater
2023-02-14 17:18 ` [PATCH 3/8] hw/misc: add a toy i2c echo device Cédric Le Goater
2023-02-15 10:55   ` Philippe Mathieu-Daudé
2023-02-15 11:09     ` Cédric Le Goater
2023-02-15 12:26       ` Philippe Mathieu-Daudé
2023-02-17  8:24         ` Cédric Le Goater
2023-02-14 17:18 ` [PATCH 4/8] tests/avocado/machine_aspeed.py: Add I2C slave tests Cédric Le Goater
2023-02-14 17:18 ` [PATCH 5/8] aspeed/smc: Replace SysBus IRQs with GPIO lines Cédric Le Goater
2023-02-15 10:56   ` Philippe Mathieu-Daudé
2023-02-14 17:18 ` [PATCH 6/8] aspeed/smc: Wire CS lines at reset Cédric Le Goater
2023-02-14 17:18 ` [PATCH 7/8] aspeed: Introduce a spi_boot region under the SoC Cédric Le Goater
2023-02-15 11:02   ` Philippe Mathieu-Daudé
2023-03-01 13:27     ` Cédric Le Goater
2023-02-14 17:18 ` [PATCH 8/8] aspeed: Add a boot_rom overlap region in the SoC spi_boot container Cédric Le Goater
2023-02-15  6:38 ` [PATCH 0/8] aspeed: I2C fixes, -drive removal (first step) Markus Armbruster
2023-02-15  8:32   ` Cédric Le Goater
2023-02-15 12:35     ` Markus Armbruster
2023-02-17  8:22       ` Cédric Le Goater
2023-02-15 10:45 ` Philippe Mathieu-Daudé
2023-02-17  8:26   ` Cédric Le Goater

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=a3970b81-89e6-66c3-4a62-13bd610096b6@linaro.org \
    --to=philmd@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=andrew@aj.id.au \
    --cc=armbru@redhat.com \
    --cc=clg@kaod.org \
    --cc=joel@jms.id.au \
    --cc=peter.maydell@linaro.org \
    --cc=peter@pjd.dev \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=zhengxiang9@huawei.com \
    /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).