From nobody Fri May 10 03:05:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1668522165017891.2213347545716; Tue, 15 Nov 2022 06:22:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouwpR-0005Yv-Dr; Tue, 15 Nov 2022 09:22:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouwpO-0005Uw-45; Tue, 15 Nov 2022 09:22:18 -0500 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouwpL-0004Xh-LA; Tue, 15 Nov 2022 09:22:17 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NBSzv04wcz4xYV; Wed, 16 Nov 2022 01:22:03 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4NBSzq3dmhz4xTg; Wed, 16 Nov 2022 01:21:59 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Alistair Francis Cc: Francisco Iglesias , Kevin Wolf , Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell , Peter Delevoryas , qemu-block@nongnu.org, qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH] m25p80: Warn the user when the backend file is too small for the device Date: Tue, 15 Nov 2022 15:21:41 +0100 Message-Id: <20221115142141.2073761-1-clg@kaod.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=jlKb=3P=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1668522167492100003 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. Improve the reported error with a new message regarding the file size. Signed-off-by: C=C3=A9dric Le Goater --- hw/block/m25p80.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index 02adc87527..e0515e2a1e 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -1606,6 +1606,14 @@ static void m25p80_realize(SSIPeripheral *ss, Error = **errp) if (s->blk) { uint64_t perm =3D BLK_PERM_CONSISTENT_READ | (blk_supports_write_perm(s->blk) ? BLK_PERM_WRITE = : 0); + + if (blk_getlength(s->blk) < s->size) { + error_setg(errp, + "backend file is too small for flash device %s (%d = MB)", + object_class_get_name(OBJECT_CLASS(mc)), s->size >>= 20); + return; + } + ret =3D blk_set_perm(s->blk, perm, BLK_PERM_ALL, errp); if (ret < 0) { return; --=20 2.38.1