From nobody Sun Apr 28 13:38:36 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; 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 1550233755296256.63463695380426; Fri, 15 Feb 2019 04:29:15 -0800 (PST) Received: from localhost ([127.0.0.1]:38583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guccA-0000Po-QM for importer@patchew.org; Fri, 15 Feb 2019 07:29:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:32848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gucbN-000056-JL for qemu-devel@nongnu.org; Fri, 15 Feb 2019 07:28:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gucbL-0003bg-Hd for qemu-devel@nongnu.org; Fri, 15 Feb 2019 07:28:21 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:36774) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gucbL-0003Zm-5X for qemu-devel@nongnu.org; Fri, 15 Feb 2019 07:28:19 -0500 Received: by mail-wm1-x334.google.com with SMTP id j125so9459011wmj.1 for ; Fri, 15 Feb 2019 04:28:18 -0800 (PST) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id u12sm3303027wrt.2.2019.02.15.04.28.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Feb 2019 04:28:16 -0800 (PST) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 953A21FF80; Fri, 15 Feb 2019 12:28:15 +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=V+ER6voJ5V7iZY2UeNKYDPMaSUVCcgGMEdkzK7VyxMM=; b=BjW/KFVmr+sJhqIxcefgJVi+rlAWABFgP7+Tkf31n8GP/c4/kguxJqHT84WYoWAXpt thUw6JoxnXLSqFgjX3ViwD1ijEvvv79E4trIpvBmZMtD3sYspSeRWJWs/Dr+dHEpEmTU tj890TFIk6wqhXT2Xx3hlnGhXqvSPrVLJESJhrSl6yi4d62BFww5vHUBlVmezCJdqE3e GX2iMmE//HBRakA5QGM+ZMPuL2YMcHO58kuzbDzsPx60EPUG0N+pCefi4clQvL6ddmuz adeaJHiJWo2ql9qXCzz9WEOaOsniQHMl4fewvxKbiHWqjTjwsn+2lGxzD0efjS31wOLZ Jd/g== 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=V+ER6voJ5V7iZY2UeNKYDPMaSUVCcgGMEdkzK7VyxMM=; b=jqU8TCq66EpIbX0dP0ZLapSsauEwYdF9dV3pA2Q7UqjA6Q/HiioUx9R7OLSLjPrRqb 4DFYJAlzwKdOddhLtEz9zGFIP0o+Lca0Zw4JQrO3YNLC1g2WZN2Ya5i+zBXoo6xFy5iC wQGupgxbK6zm9c5njzWpxYaIlORddBJMag7fpBi6XJ5IsGSoYrrRUTzVb5q6Ecqf947H rMwV8Z+mYdxifj1SPrjKR//g7pv3RE1wEDCQgWlmWLkDJUM0GlXln48aoe/mGoHcI8Jm 4Wr+Osp9qgwPZDDSg3ToajbAlUMR9nqivVxsFEhxD81uB1rbxlOoeQh1t5ytrT/kWDHy aUeA== X-Gm-Message-State: AHQUAuaN7JqRqiTbnegyk+LK2SjYTqjl17BDxtoFG0957frWigduiDnW 7jceMuXxErMpuIXf63OQiEUb6w== X-Google-Smtp-Source: AHgI3IZHLLpIQlogMrApgdIGU/AalDXAn0tY+WzEMemmJMBWQVdAenPEbvvuQttgVUPcuZRDjItZBQ== X-Received: by 2002:a1c:9e4a:: with SMTP id h71mr6663928wme.82.1550233696683; Fri, 15 Feb 2019 04:28:16 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Fri, 15 Feb 2019 12:28:08 +0000 Message-Id: <20190215122808.22301-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::334 Subject: [Qemu-devel] [PATCH v2] hw/block: report when pflash backing file isn't aligned 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. Signed-off-by: Alex Benn=C3=A9e --- v2 - use PRIu64 instead of PRId64 - tweaked message output --- hw/block/pflash_cfi01.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index bffb4c40e7..7532c8d8e8 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -722,12 +722,20 @@ static void pflash_cfi01_realize(DeviceState *dev, Er= ror **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 + /* + * Validate the backing store is the right size for pflash + * devices. It has to be padded to a multiple of the flash block + * size. + */ + if (pfl->blk) { + uint64_t backing_len =3D blk_getlength(pfl->blk); + if (device_len !=3D backing_len) { + error_setg(errp, "device needs %" PRIu64 " bytes, " + "backing file provides only %" PRIu64 " bytes", + device_len, backing_len); + return; + } + } =20 memory_region_init_rom_device( &pfl->mem, OBJECT(dev), --=20 2.20.1