From patchwork Fri Feb 15 12:28:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 158511 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp648806jaa; Fri, 15 Feb 2019 04:29:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IZLzrxD9jGUKVvf6MesdZ+8j4t9knkP2s0VQRnW4TT8pICSCt3oa8u2f4mVZqxX3P0uOt3K X-Received: by 2002:a81:3c47:: with SMTP id j68mr7725677ywa.69.1550233772638; Fri, 15 Feb 2019 04:29:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550233772; cv=none; d=google.com; s=arc-20160816; b=DBRwYiDRYmGSbPWWosTFbaC6E9zRQaBNj23UUMvjnJ10thinuEs5bIxFsSTBsElBTx /ApYESz/CHs6JsJkVKsbUGOT3IuTjgMp9Lk44GeE1uhrWNywq5WKtOM7k8O3TLbCaMDy c8rgc/bN4KwsNeQ3TnWoRCwwW62eKawSmf/0dMAYGmqsFXXFk/rip2jQWjs2+vKVBTpj Vi+oP/VhCHb2pdsY+Wtbv1yRweSeSpXqTeVc+rTZDAvtn+aa7D2uHl78477G5jshrgyl ym4hzolNK2u9hh+Hm0UxFBxZ+IBgaoUPk0uHlC+QKcGkg6+JHVX7gfQdxJx0hbPXsBIy hJog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:message-id:date:to:from :dkim-signature; bh=V+ER6voJ5V7iZY2UeNKYDPMaSUVCcgGMEdkzK7VyxMM=; b=bsP9f6PIwMBaN1M5Ueti+wu5zhcHhLw6AYUh3dVXlcJ01Q//FVWuMGc5xrVhbNwgHB B6BxtIeFM4YlTAz1rmpb5UvkMVcRooD5K/ALZ57IZecl7VHzmouUOId9ECyjWoVXpHGk 6oenGAOuB8IKJJRpftQsDsH+LZgsTA2QRQVeOKJDv8Nfo0fYEn8MxmS1AU8IgS0F0i6/ G0PLKW6ZDDjwE8UDd2b67kuQgHfG9bcuMTvr6XTSuO4MCos73y6bkee0ffHsGeqX8qIK AwNpmljRBuXDnkvo0LyrzDSrzXDsquD1hrC9I6o/KNv8ouKNCw0acSrL/uHgiYUCRN1g 1dAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="BjW/KFVm"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 8si1970095ybp.132.2019.02.15.04.29.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 15 Feb 2019 04:29:32 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="BjW/KFVm"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:38583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1guccW-0000Po-93 for patch@linaro.org; Fri, 15 Feb 2019 07:29:32 -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) 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-Received: by 2002:a1c:9e4a:: with SMTP id h71mr6663928wme.82.1550233696683; Fri, 15 Feb 2019 04:28:16 -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) From: =?utf-8?q?Alex_Benn=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 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_Benn=C3=A9e?= , lersek@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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=pflash,file=blob,format=raw,readonly for loading your firmware code. Signed-off-by: Alex Bennée --- v2 - use PRIu64 instead of PRId64 - tweaked message output --- hw/block/pflash_cfi01.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) -- 2.20.1 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, Error **errp) } device_len = sector_len_per_device * blocks_per_device; - /* XXX: to be fixed */ -#if 0 - if (total_len != (8 * 1024 * 1024) && total_len != (16 * 1024 * 1024) && - total_len != (32 * 1024 * 1024) && total_len != (64 * 1024 * 1024)) - 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 = blk_getlength(pfl->blk); + if (device_len != backing_len) { + error_setg(errp, "device needs %" PRIu64 " bytes, " + "backing file provides only %" PRIu64 " bytes", + device_len, backing_len); + return; + } + } memory_region_init_rom_device( &pfl->mem, OBJECT(dev),