From nobody Sun Nov 9 11:48:56 2025 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; dkim=fail; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550775040140408.986234247383; Thu, 21 Feb 2019 10:50:40 -0800 (PST) Received: from localhost ([127.0.0.1]:36736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwtQZ-0001Nt-HF for importer@patchew.org; Thu, 21 Feb 2019 13:50:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwtP7-0000Bw-LA for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:49:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwtP6-0002NE-Rk for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:49:05 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:38796) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwtP6-0002ML-Ev for qemu-devel@nongnu.org; Thu, 21 Feb 2019 13:49:04 -0500 Received: by mail-wr1-x444.google.com with SMTP id v13so31763886wrw.5 for ; Thu, 21 Feb 2019 10:49:04 -0800 (PST) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n11sm17630034wrw.60.2019.02.21.10.49.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Feb 2019 10:49:02 -0800 (PST) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 005561FF80; Thu, 21 Feb 2019 18:49:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+RSB+PD024ov3tcn94kfmu7kejcaBvwIj3dxVbt/pVc=; b=lOLWaDomJG5manJBGrJH0BJ9FxKdFgU7xIGjWrlPOrLth72d272+qR2BidrprIHR6F j/mTYtBstqd0KW5KRw+ggBPorNg/7Y8M2pPS+O5OD91oE98CCANVGNgcjoUIYJhaPfJp MuN527k7PlxllFEael/cSmcMxjqbxeOo73nZAoewSzAhdE1WKDBo3NF6TJNiHZxBjfY3 z2Sn+8trSd7oCbLdr/X4BL0/oBZrb9efTMM/Nlzv+Z67jowVpYCPX9Ygq1aAgh3H/pMB lI/5WoZ9h75J3/lSoy8+UkVtYz5XwFK2rnsgIiAmbZ7/Nmw8M7Reu8ZUW8IIbjUEWtGo j8vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+RSB+PD024ov3tcn94kfmu7kejcaBvwIj3dxVbt/pVc=; b=ZdgacxTvir0go/bdq4qwzo1PmpEocCqCJGvKfPZylgFpN3NmFAvqMPYT3K530u16Zl ri7eDem1zPhWmcCKR6KPLIFlnAMKTQLhkyd1h8jEpHOrQL/ACDi3NPBtX0xvQ4KcvgMu seq/igQU/p24W6DK8gTWFs4DJeszYT92Su/Jcb/xvgMUdvu4d0MeZ0pco1ufmPYKEyJL gzW73XFSllKdS4+EB1vqmXANBTlHXZhFqtrR4EJwy1nYjReNiaBXfYmkpcGi9M4DU7ZL OxA64SdmPTYexOYbw+a0PvqlsULE+PwWPFGrNWUv3dzolxo+1rz0R8edc1D04xbCZb8v XBWg== X-Gm-Message-State: AHQUAuZQUecS+TcVjZYoyAS1r702OWEWUYPVTpHNwB4Xd+gWagg9Ph60 6Mkr+8LCoY7psBMRHV5K1kXq9g== X-Google-Smtp-Source: AHgI3IZfgdmoWYXsYhZjJhtsH7z+2TVPkVpKiYxb8GRUXFbV1WsdQU9qQ2SDhwpwF4VXZXz+sGemOw== X-Received: by 2002:a5d:68c2:: with SMTP id p2mr27866437wrw.23.1550774943021; Thu, 21 Feb 2019 10:49:03 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 21 Feb 2019 18:48:57 +0000 Message-Id: <20190221184857.22434-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v3] 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: stappers@stappers.nl, =?UTF-8?q?Alex=20Benn=C3=A9e?= , lersek@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) It looks like there was going to be code to check we had some sort of alignment so lets replace it with an actual check. 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. This is a potential 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. Signed-off-by: Alex Benn=C3=A9e --- v3 - tweak commit title/commentary - use total_len instead of device_len for checks - if the device is read-only do the padding for them - accept baking_len > total_len (how to warn_report with NULL *errp?) --- hw/block/pflash_cfi01.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 00c2efd0d7..37d7513c45 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -714,13 +714,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, @@ -747,6 +740,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. It should be padded to a multiple of the flash + * block size. If the device is read-only we can elide the + * check and just null pad the region first. If the user + * supplies a larger file we silently accept it. + */ + uint64_t backing_len =3D blk_getlength(pfl->blk); + + if (backing_len < total_len) { + if (pfl->ro) { + memset(pfl->storage, 0, total_len); + total_len =3D backing_len; + } else { + error_setg(errp, "device(s) needs %" PRIu64 " bytes, " + "backing file provides only %" PRIu64 " bytes", + total_len, backing_len); + return; + } + } + /* read the initial flash content */ ret =3D blk_pread(pfl->blk, 0, pfl->storage, total_len); =20 --=20 2.20.1