From nobody Sat Nov 23 18:20:14 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 1730132655498740.6124050462179; Mon, 28 Oct 2024 09:24:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5SWz-000419-1J; Mon, 28 Oct 2024 12:23:49 -0400 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 1t5SWu-00040N-6R for qemu-devel@nongnu.org; Mon, 28 Oct 2024 12:23:44 -0400 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t5SWs-0007U9-6p for qemu-devel@nongnu.org; Mon, 28 Oct 2024 12:23:43 -0400 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t5SWa-0007ML-0S; Mon, 28 Oct 2024 17:23:24 +0100 Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1t5SWY-000t4Z-2z; Mon, 28 Oct 2024 17:23:22 +0100 Received: from jlu by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1t5SWY-00921s-2h; Mon, 28 Oct 2024 17:23:22 +0100 From: Jan Luebbe To: qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: Jan Luebbe , Guenter Roeck , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell , Thomas Huth , Joel Stanley , qemu-arm@nongnu.org, qemu-block@nongnu.org Subject: [PATCH] hw/sd/sdcard: Fix calculation of size when using eMMC boot partitions Date: Mon, 28 Oct 2024 17:23:08 +0100 Message-Id: <20241028162308.2152712-1-jlu@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <1bce4c22-9281-44c5-8acb-860881dc271c@kaod.org> References: <1bce4c22-9281-44c5-8acb-860881dc271c@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: jlu@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: qemu-devel@nongnu.org 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=2a0a:edc0:2:b01:1d::104; envelope-from=jlu@pengutronix.de; helo=metis.whiteo.stw.pengutronix.de X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: 1730132657027116600 The sd_bootpart_offset() function calculates the *runtime* offset which changes as the guest switches between accessing the main user data area and the boot partitions by writing to the EXT_CSD_PART_CONFIG_ACC_MASK bits, so it shouldn't be used to calculate the main user data area size. Instead, subtract the boot_part_size directly (twice, as there are two identical boot partitions defined by the eMMC spec). Suggested-by: C=C3=A9dric Le Goater Signed-off-by: Jan Luebbe Acked-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: C=C3=A9dric Le Goater Tested-by: Guenter Roeck --- hw/sd/sd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 2d3467c3d956..8430d5ae361c 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -826,7 +826,9 @@ static void sd_reset(DeviceState *dev) sect =3D 0; } size =3D sect << HWBLOCK_SHIFT; - size -=3D sd_bootpart_offset(sd); + if (sd_is_emmc(sd)) { + size -=3D sd->boot_part_size * 2; + } =20 sect =3D sd_addr_to_wpnum(size) + 1; =20 --=20 2.39.5