From patchwork Mon Jan 17 21:54:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1580965 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=jciB11Zn; dkim=pass (2048-bit key) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=Nn1Tlv9S; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jd5Kq1WSQz9sXM for ; Tue, 18 Jan 2022 08:54:53 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 44AFC837BB; Mon, 17 Jan 2022 22:54:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1642456482; bh=JjZ6HAREf8tzaR2LH5sR8McZ8sTWj3nftdcxJpHfxsU=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=jciB11ZnlspwBSg0RklVF3x88qGU5cyGIl+B1LDkquNMjKGqrv4/1cgVdnsH56FmG 7iLT0kl1GZXADleGZd9BNWGbroSfR8xLIf9VG7t6bOfF1VzxBLXZ+knYbwMIBv0xdp IZFIglQQB3abfIvBK8P4+ouDKpI72u82XBOPVkHSj4JRjaklRwTohqZKsNHO58lkU7 DcqDwdKNGzn7Yfs5MU38XGrBIESY1ZC9ojqjjfCskTDoDjBt63Gq7Aa5Tc6wpClh+p SXm85BXecn1GgcmnMdF+XmMHmvMCO5CtQuKeum21OM5XqPuCHCY+Jsf/xZQGGZ+lum Xz+6dpv+QPvxQ== Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz [89.176.112.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 62BEE832DB; Mon, 17 Jan 2022 22:54:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1642456479; bh=JjZ6HAREf8tzaR2LH5sR8McZ8sTWj3nftdcxJpHfxsU=; h=From:To:Cc:Subject:Date:From; b=Nn1Tlv9SrjujQEEwyXUpIlLm31N1GBbPKKnwuupY6zvwSbCYPHASXHirNEZhFF2Yd JgWxqH0mqBogDQI3pbgLVMNk+hUl0dZRBcPC4/qri6jufDYRUKPoXZx0BmPyp5lV13 TmN9bdNuGje1N2VNdnCPRdwnPLI32O6GSrskgAuJXEzfUCxVUV1epwli8b0WVum0Ry IQe+ki5oyltdeG9clU6iE6nspiAsWCM6+HouwE+M+mn6YP8zyg27G4RFjRGH10wjAW wzIR17/0NCglHm1qghAgqEoEaJp0xh7mCwSeIh342kNjeZ2+oStj5pStfYo+QIW1c1 +9uXja6cO5SyA== From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut , Fabio Estevam , Jaehoon Chung , Peng Fan , Stefano Babic Subject: [PATCH] cmd: mmc: Consider GP partitions in mmc hwpartition user enh start - Date: Mon, 17 Jan 2022 22:54:29 +0100 Message-Id: <20220117215429.88037-1-marex@denx.de> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean In case the eMMC contains any GP partitions or user sets up new GP partitions, the size of these GP partitions reduce the size of the USER partition. Subtract the size of those GP partitions from the calculated size of USER partition when using `user enh start -`. The following test used to fail before: ``` u-boot=> mmc hwpartition gp1 524288 enh user enh 0 - wrrel on check Partition configuration: User Enhanced Start: 0 Bytes User Enhanced Size: 1.8 GiB User partition write reliability: on GP1 Capacity: 256 MiB ENH No GP2 partition No GP3 partition No GP4 partition Total enhanced size exceeds maximum (261 > 229) Failed! ``` The test now passes: ``` u-boot=> mmc hwpartition gp1 524288 enh user enh 0 - wrrel on check Partition configuration: User Enhanced Start: 0 Bytes User Enhanced Size: 1.5 GiB User partition write reliability: on GP1 Capacity: 256 MiB ENH No GP2 partition No GP3 partition No GP4 partition ``` Signed-off-by: Marek Vasut Cc: Fabio Estevam Cc: Jaehoon Chung Cc: Peng Fan Cc: Stefano Babic Reviewed-by: Fabio Estevam Reviewed-by: Jaehoon Chung --- cmd/mmc.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/mmc.c b/cmd/mmc.c index 96d81ffdf36..503dbb6199c 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -597,7 +597,7 @@ static void parse_hwpart_user_enh_size(struct mmc *mmc, struct mmc_hwpart_conf *pconf, char *argv) { - int ret; + int i, ret; pconf->user.enh_size = 0; @@ -606,7 +606,7 @@ static void parse_hwpart_user_enh_size(struct mmc *mmc, ret = mmc_send_ext_csd(mmc, ext_csd); if (ret) return; - /* This value is in 512B block units */ + /* The enh_size value is in 512B block units */ pconf->user.enh_size = ((ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 2] << 16) + (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 1] << 8) + @@ -614,6 +614,24 @@ static void parse_hwpart_user_enh_size(struct mmc *mmc, ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] * ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; pconf->user.enh_size -= pconf->user.enh_start; + for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) { + /* + * If the eMMC already has GP partitions set, + * subtract their size from the maximum USER + * partition size. + * + * Else, if the command was used to configure new + * GP partitions, subtract their size from maximum + * USER partition size. + */ + if (mmc->capacity_gp[i]) { + /* The capacity_gp is in 1B units */ + pconf->user.enh_size -= mmc->capacity_gp[i] >> 9; + } else if (pconf->gp_part[i].size) { + /* The gp_part[].size is in 512B units */ + pconf->user.enh_size -= pconf->gp_part[i].size; + } + } } else { pconf->user.enh_size = dectoul(argv, NULL); }