From patchwork Thu Mar 7 09:37:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 159815 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7222933jad; Thu, 7 Mar 2019 01:40:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwMQCGEUzmOSkan6EPjRi3MceAENRPC2rp2arOz8ordWFcCgjlQ9Zi/PSX8H4DJ4Iv3P8G2 X-Received: by 2002:a81:1dc1:: with SMTP id d184mr8910241ywd.379.1551951633264; Thu, 07 Mar 2019 01:40:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551951633; cv=none; d=google.com; s=arc-20160816; b=uJaF7ZqOJzCYC7WwP/l++qm7TV292/bfWBsr2DCpaORdGc3/fw3+9U/ww1GkazFee1 ZJOws7g40u+ho2R+9e1nzWBHqV/Bs2ZDsfnKuQZ8VsfHEaJkLkU2mRhqwr4wevo4wuC+ E7EBBMZ4sMi62+/YK4Rq376/mCUZPTTnCp1QhNL4MPxJcl4zemlHidnVdenYXl5bL7vA zS8/2olep9Z6jAyc6ePQUmfw93glqWO6q7b+cKwu3ZF8bM/x2RiFeacJ0kdbUgSzNFg0 xSxKX4FX2YYeq2kS+2tsLSKiOW44lwY3/SBET+tVVXEI1cxTx2Zz041Xa/cXV12yuQvS 7Riw== 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:references:in-reply-to :message-id:date:to:from; bh=nWrcSXXc6XBCJIa8SjXw7NBbaMmmLJAOk4nHaeefcgg=; b=LtyjrnU+JTT7AuBPej0isu5XRarXLqaGg08UiTnLkBFjvNUN2tSS1DtHovOF0882J9 EHZhHruL1R9mlnWo9tjiVyWPI+8Oa1DTty74sRIMFcuA2SYsLjRJFc9mDf9zGEkSCy1Z iPiQk6m0ccM8f2SUEA7cJ1wYnR24ogsW/N9gDm6QaCJGmEBBdOzwyom/dFCEi+JyYGv7 ipYEndtXOJ1Y4J/NmyiRPoTYuj0y46jB7bJQFKIaPynp2Yk1jxMfOwbXtCngAH+BVfOO PyYgQBmrt00dlEr+0+5u50vEbaCPmHEBA4StYx83sPiEGKbDLzG/d/qXnfe6F21QKsR5 llCg== ARC-Authentication-Results: i=1; mx.google.com; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i1si2334700ybk.389.2019.03.07.01.40.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Mar 2019 01:40:33 -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; 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=redhat.com Received: from localhost ([127.0.0.1]:48129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pVw-0007c5-RB for patch@linaro.org; Thu, 07 Mar 2019 04:40:32 -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) 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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=pflash,file=blob,format=raw,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ée Reviewed-by: Laszlo Ersek Signed-off-by: Markus Armbruster --- hw/block/pflash_cfi01.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) -- 2.17.2 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, Error **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 = blk_getlength(pfl->blk); if (backing_len < 0) { @@ -769,10 +770,21 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) } 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 = 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 = 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);