From nobody Sat Apr 27 12:30:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551951691639323.2508225011883; Thu, 7 Mar 2019 01:41:31 -0800 (PST) Received: from localhost ([127.0.0.1]:48139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pWp-0008Jo-EL for importer@patchew.org; Thu, 07 Mar 2019 04:41:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pT4-0005Wg-Vm for qemu-devel@nongnu.org; Thu, 07 Mar 2019 04:37:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1pT4-0004yK-66 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 04:37:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38860) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1pT2-0004wh-1O; Thu, 07 Mar 2019 04:37:32 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46C6380472; Thu, 7 Mar 2019 09:37:31 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5831BA4FB0; Thu, 7 Mar 2019 09:37:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C411E1138661; Thu, 7 Mar 2019 10:37:23 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 10:37:20 +0100 Message-Id: <20190307093723.655-2-armbru@redhat.com> In-Reply-To: <20190307093723.655-1-armbru@redhat.com> References: <20190307093723.655-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 07 Mar 2019 09:37:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH v6 1/4] hw/block: better reporting on pflash backing file mismatch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, alex.bennee@linaro.org, philmd@redhat.com, mreitz@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Alex Benn=C3=A9e 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=C3=A9e Reviewed-by: Laszlo Ersek Signed-off-by: Markus Armbruster --- 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, Err= or **errp) } device_len =3D sector_len_per_device * blocks_per_device; =20 - /* XXX: to be fixed */ -#if 0 - if (total_len !=3D (8 * 1024 * 1024) && total_len !=3D (16 * 1024 * 10= 24) && - total_len !=3D (32 * 1024 * 1024) && total_len !=3D (64 * 1024 * 1= 024)) - 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, Err= or **errp) } =20 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 =3D 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 =3D blk_pread(pfl->blk, 0, pfl->storage, total_len); =20 --=20 2.17.2 From nobody Sat Apr 27 12:30:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155195169377716.21955286022319; Thu, 7 Mar 2019 01:41:33 -0800 (PST) Received: from localhost ([127.0.0.1]:48141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pWs-0008MB-PW for importer@patchew.org; Thu, 07 Mar 2019 04:41:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pT1-0005TB-8o for qemu-devel@nongnu.org; Thu, 07 Mar 2019 04:37:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1pT0-0004ur-Dv for qemu-devel@nongnu.org; Thu, 07 Mar 2019 04:37:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42484) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1pSy-0004tB-Av; Thu, 07 Mar 2019 04:37:28 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 925DD306548E; Thu, 7 Mar 2019 09:37:27 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 58B4A2CFA3; Thu, 7 Mar 2019 09:37:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C90C311385D4; Thu, 7 Mar 2019 10:37:23 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 10:37:21 +0100 Message-Id: <20190307093723.655-3-armbru@redhat.com> In-Reply-To: <20190307093723.655-1-armbru@redhat.com> References: <20190307093723.655-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 07 Mar 2019 09:37:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH v6 2/4] hw/block: Pad undersized read-only images with 0xFF X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, alex.bennee@linaro.org, philmd@redhat.com, mreitz@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Alex Benn=C3=A9e We reject undersized images. As of the previous commit, even with a decent error message. Still, this is a potentially confusing stumbling block when you move from using -bios to using -drive if=3Dpflash,file=3Dblob,format=3Draw,readonly for loading your firmware code. To mitigate that we automatically pad in the read-only case and warn the user when we have performed magic to enable things to Just Work (tm). Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Laszlo Ersek Signed-off-by: Markus Armbruster --- hw/block/pflash_cfi01.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 75ce8ef489..00980316dc 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -759,8 +759,9 @@ static void pflash_cfi01_realize(DeviceState *dev, Erro= r **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 =3D blk_getlength(pfl->blk); if (backing_len < 0) { @@ -769,10 +770,21 @@ static void pflash_cfi01_realize(DeviceState *dev, Er= ror **errp) } =20 if (backing_len < total_len) { - error_setg(errp, "device needs %" PRIu64 " bytes, " - "backing file provides only %" PRIu64 " bytes", - total_len, backing_len); - return; + if (pfl->ro) { + size_t pad_bytes =3D total_len - backing_len; + /* pad with NOR erase pattern */ + memset((uint8_t *)pfl->storage + backing_len, + 0xff, pad_bytes); + warn_report("device needs %" PRIu64 + " bytes, padded with %zu 0xff bytes", + total_len, pad_bytes); + total_len =3D backing_len; + } else { + 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); --=20 2.17.2 From nobody Sat Apr 27 12:30:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551951576998599.8328622490423; Thu, 7 Mar 2019 01:39:36 -0800 (PST) Received: from localhost ([127.0.0.1]:48092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pUz-0006cG-U6 for importer@patchew.org; Thu, 07 Mar 2019 04:39:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pT1-0005So-5X for qemu-devel@nongnu.org; Thu, 07 Mar 2019 04:37:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1pT0-0004uf-8o for qemu-devel@nongnu.org; Thu, 07 Mar 2019 04:37:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56538) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1pSy-0004tG-E8; Thu, 07 Mar 2019 04:37:28 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99FAC13AB2; Thu, 7 Mar 2019 09:37:27 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CC541001DE8; Thu, 7 Mar 2019 09:37:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id CCAFE11385D5; Thu, 7 Mar 2019 10:37:23 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 10:37:22 +0100 Message-Id: <20190307093723.655-4-armbru@redhat.com> In-Reply-To: <20190307093723.655-1-armbru@redhat.com> References: <20190307093723.655-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 07 Mar 2019 09:37:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH v6 3/4] fixup! hw/block: better reporting on pflash backing file mismatch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, alex.bennee@linaro.org, philmd@redhat.com, mreitz@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" --- hw/block/pflash_cfi02.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index 33779ce807..d30a351472 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -39,6 +39,7 @@ #include "hw/hw.h" #include "hw/block/flash.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "qemu/timer.h" #include "sysemu/block-backend.h" #include "qemu/host-utils.h" @@ -550,12 +551,6 @@ static void pflash_cfi02_realize(DeviceState *dev, Err= or **errp) } =20 chip_len =3D pfl->sector_len * pfl->nb_blocs; - /* XXX: to be fixed */ -#if 0 - if (total_len !=3D (8 * 1024 * 1024) && total_len !=3D (16 * 1024 * 10= 24) && - total_len !=3D (32 * 1024 * 1024) && total_len !=3D (64 * 1024 * 1= 024)) - return NULL; -#endif =20 memory_region_init_rom_device(&pfl->orig_mem, OBJECT(pfl), pfl->be ? &pflash_cfi02_ops_be : &pflash_cfi02_ops= _le, @@ -581,6 +576,27 @@ static void pflash_cfi02_realize(DeviceState *dev, Err= or **errp) } =20 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 =3D blk_getlength(pfl->blk); + if (backing_len < 0) { + error_setg(errp, "unable to check size of backing file"); + return; + } + + if (backing_len < chip_len) { + 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", + chip_len); + } + /* read the initial flash content */ ret =3D blk_pread(pfl->blk, 0, pfl->storage, chip_len); if (ret < 0) { --=20 2.17.2 From nobody Sat Apr 27 12:30:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551951565211281.70852313481055; Thu, 7 Mar 2019 01:39:25 -0800 (PST) Received: from localhost ([127.0.0.1]:48087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pUl-0006PW-0H for importer@patchew.org; Thu, 07 Mar 2019 04:39:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pT1-0005Sr-5Y for qemu-devel@nongnu.org; Thu, 07 Mar 2019 04:37:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1pT0-0004uk-AA for qemu-devel@nongnu.org; Thu, 07 Mar 2019 04:37:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1pSy-0004tH-EQ; Thu, 07 Mar 2019 04:37:28 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9DBA630D78C1; Thu, 7 Mar 2019 09:37:27 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5DD5A1001DFD; Thu, 7 Mar 2019 09:37:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D1D4A11384DA; Thu, 7 Mar 2019 10:37:23 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 10:37:23 +0100 Message-Id: <20190307093723.655-5-armbru@redhat.com> In-Reply-To: <20190307093723.655-1-armbru@redhat.com> References: <20190307093723.655-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 07 Mar 2019 09:37:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH v6 4/4] fixup! hw/block: Pad undersized read-only images with 0xFF X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, alex.bennee@linaro.org, philmd@redhat.com, mreitz@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" --- 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, Erro= r **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 =3D blk_getlength(pfl->blk); if (backing_len < 0) { @@ -588,9 +589,20 @@ static void pflash_cfi02_realize(DeviceState *dev, Err= or **errp) } =20 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 =3D 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 =3D 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", --=20 2.17.2