From patchwork Fri Dec 16 10:12:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 13074866 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 09706C4332F for ; Fri, 16 Dec 2022 10:13:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p67hs-0006Q9-DZ; Fri, 16 Dec 2022 05:12:44 -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 1p67hq-0006PQ-Mh for qemu-devel@nongnu.org; Fri, 16 Dec 2022 05:12:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p67ho-0003Cm-W2 for qemu-devel@nongnu.org; Fri, 16 Dec 2022 05:12:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671185560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LEl9gsuHlzpldUb2Z6yWcZInakI5OdtYZvcj2nrA2DA=; b=STGowQOxXxATsdBQF7OcfuyVKv12oBMf63g8xK0MTs1qG2ItRrPnxKyZNH+t+CdVJ24eAq OqQpK4+429s422NVGcD4jnad8iiGVGwzGsCYHPcBUl8+YuW9uF6BSFtCHyK+Xpy9Na2zVX 1USf7FGGGMebHUVTpaDC/uhgZzbi/Y8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-207-U2KxhMZJOx-5eCoonTnJ7w-1; Fri, 16 Dec 2022 05:12:36 -0500 X-MC-Unique: U2KxhMZJOx-5eCoonTnJ7w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5502E85A588; Fri, 16 Dec 2022 10:12:36 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.83]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1489E51EF; Fri, 16 Dec 2022 10:12:36 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id D9AE81801B2C; Fri, 16 Dec 2022 11:12:34 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Cc: Kashyap Chamarthy , qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Dani?= =?utf-8?q?el_P=2E_Berrang=C3=A9?= , Peter Maydell , Gerd Hoffmann Subject: [PATCH 1/2] hw/arm: allow flash images being smaller than the available space Date: Fri, 16 Dec 2022 11:12:33 +0100 Message-Id: <20221216101234.2202009-2-kraxel@redhat.com> In-Reply-To: <20221216101234.2202009-1-kraxel@redhat.com> References: <20221216101234.2202009-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass client-ip=170.10.129.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Query block device backing flash for size and use that instead of requiring the block device being exactly 64M in size. This allows to use edk2 firmware builds without padding, i.e. use QEMU_EFI.fd (which is /way/ smaller than 64M) as-is. -rw-r--r--. 1 root root 67108864 Dec 12 23:45 QEMU_EFI-pflash.raw -rw-r--r--. 1 root root 2097152 Dec 12 23:45 QEMU_EFI.fd Signed-off-by: Gerd Hoffmann --- hw/arm/virt.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index b87135085610..c71ae2cd73f7 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -43,6 +43,7 @@ #include "hw/vfio/vfio-amd-xgbe.h" #include "hw/display/ramfb.h" #include "net/net.h" +#include "sysemu/block-backend.h" #include "sysemu/device_tree.h" #include "sysemu/numa.h" #include "sysemu/runstate.h" @@ -1134,6 +1135,21 @@ static void virt_flash_map1(PFlashCFI01 *flash, MemoryRegion *sysmem) { DeviceState *dev = DEVICE(flash); + BlockBackend *blk; + + blk = pflash_cfi01_get_blk(flash); + if (blk) { + hwaddr blksize = blk_getlength(blk); + + if (blksize == 0 || blksize > size || + !QEMU_IS_ALIGNED(size, VIRT_FLASH_SECTOR_SIZE)) { + error_report("system firmware block device %s" + " has invalid size %" PRId64, + blk_name(blk), size); + exit(1); + } + size = blksize; + } assert(QEMU_IS_ALIGNED(size, VIRT_FLASH_SECTOR_SIZE)); assert(size / VIRT_FLASH_SECTOR_SIZE <= UINT32_MAX);