From patchwork Wed Sep 22 12:30:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 1531221 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=tq-group.com header.i=@tq-group.com header.a=rsa-sha256 header.s=key1 header.b=Zs8ouhMF; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.a=rsa-sha256 header.s=key1 header.b=NcKIxuUi; 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 ozlabs.org (Postfix) with ESMTPS id 4HDyMS6Hbkz9ssP for ; Wed, 22 Sep 2021 22:31:14 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1593D82D74; Wed, 22 Sep 2021 14:31:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=tq-group.com header.i=@tq-group.com header.b="Zs8ouhMF"; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="NcKIxuUi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E1EC8831D8; Wed, 22 Sep 2021 14:31:01 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7D46D82D74 for ; Wed, 22 Sep 2021 14:30:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=matthias.schiffer@ew.tq-group.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1632313858; x=1663849858; h=from:to:cc:subject:date:message-id; bh=kzS57/m2qbQzxgOQ94cQhuUvcEmImQpkCTlvs4HZ7z8=; b=Zs8ouhMFG52PprvmY091IM7N/CFm7l87f6Xnf8s4L4NJY5VTUuIx9KMI Ls52DvzNHQhnAmymsl2lXcy6e3focGDa5sOwcl3eBYeFboqJvyS/DT4r1 rW/aUV0Yzey06OMjTlp8lyApftbtHU/fzM6VZpyVlKGpP0LiMfVmdQWd6 PGixg2UBE+0S+EXmhiD2x0zEnxbPa9GvnKmrR13pfE03DfKwuqUBA0Fme OOHFGXyuh/0ChB3HwOpCyXqnJ7kHoeXkQzgWVzNbU+RIQtP8Epo/xSs1i jhlQYeD8ocmPStrCgBq8eUF0AnTVTJ/5evBsCcCdbT3yEe9ca71oZ6Wdj g==; X-IronPort-AV: E=Sophos;i="5.85,313,1624312800"; d="scan'208";a="19648593" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 22 Sep 2021 14:30:57 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Wed, 22 Sep 2021 14:30:58 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Wed, 22 Sep 2021 14:30:58 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1632313857; x=1663849857; h=from:to:cc:subject:date:message-id; bh=kzS57/m2qbQzxgOQ94cQhuUvcEmImQpkCTlvs4HZ7z8=; b=NcKIxuUiFUoFey9cpPwFqa7R5BLXL871qVN5thGPETxZm2ATRY0cdnaQ 8GvwxiBJZXkdIfY4nEn/0vgei1iiE7OfpcO4O+0aX2Vq8osfT+eARNezT owv0ToxXLG9X+mMoaV2898IflHptJqfaXfRKihhRYXFokhV3tXtwOQQ+K Aaxp8VnpxBYNRdTJdOYKr75VviYgKe+MpfZN/RnInt5nYfInGmzlgJ/p5 lHCuVYm9hqlSZ/J92EePZ10OfbKsgguEkhLiMvF3AhrkEZdbImicXrnQe PpPDeV7MeTdZuXZU+rlfcGiAaSsPtgkzwDsLW+FweP36uYv20xilTbOUm w==; X-IronPort-AV: E=Sophos;i="5.85,313,1624312800"; d="scan'208";a="19648592" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 22 Sep 2021 14:30:57 +0200 Received: from schifferm-ubuntu4.tq-net.de (schifferm-ubuntu4.tq-net.de [10.121.48.12]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id C19CB280070; Wed, 22 Sep 2021 14:30:57 +0200 (CEST) From: Matthias Schiffer To: u-boot@lists.denx.de Cc: Peng Fan , Jaehoon Chung , Markus Niebel , Matthias Schiffer Subject: [PATCH 1/2] mmc: add helper to query max enhanced part size Date: Wed, 22 Sep 2021 14:30:36 +0200 Message-Id: <1d862733e0d4ae632eb036de13aaf048b31b8bdb.1632313515.git.matthias.schiffer@ew.tq-group.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 From: Markus Niebel This helper will be used later on in an extension of the mmc command. Signed-off-by: Markus Niebel Signed-off-by: Matthias Schiffer --- drivers/mmc/mmc.c | 38 ++++++++++++++++++++++++++++++++++++++ include/mmc.h | 1 + 2 files changed, 39 insertions(+) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index d3babbfeb1c..c1b1ef7eb0b 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1039,6 +1039,44 @@ int mmc_switch_part(struct mmc *mmc, unsigned int part_num) } #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) +int mmc_max_enhanced_size_sectors(struct mmc *mmc, u64 *size) +{ + u64 sz; + int err; + + ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN); + + if (IS_SD(mmc) || mmc->version < MMC_VERSION_4_41) { + pr_err("eMMC >= 4.4 required for enhanced user data area\n"); + return -EMEDIUMTYPE; + } + + if (!(mmc->part_support & PART_SUPPORT)) { + pr_err("Card does not support partitioning\n"); + return -EMEDIUMTYPE; + } + + if (!mmc->hc_wp_grp_size) { + pr_err("Card does not define HC WP group size\n"); + return -EMEDIUMTYPE; + } + + err = mmc_send_ext_csd(mmc, ext_csd); + if (err) + return err; + + sz = + (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 2] << 16) + + (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 1] << 8) + + ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT]; + sz *= ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; + sz *= ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; + sz *= SZ_1K; + *size = sz; + + return 0; +} + int mmc_hwpart_config(struct mmc *mmc, const struct mmc_hwpart_conf *conf, enum mmc_hwpart_conf_mode mode) diff --git a/include/mmc.h b/include/mmc.h index b92e2553402..3e1fc82d9b4 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -846,6 +846,7 @@ void print_mmc_devices(char separator); */ int get_mmc_num(void); int mmc_switch_part(struct mmc *mmc, unsigned int part_num); +int mmc_max_enhanced_size_sectors(struct mmc *mmc, u64 *size); int mmc_hwpart_config(struct mmc *mmc, const struct mmc_hwpart_conf *conf, enum mmc_hwpart_conf_mode mode); From patchwork Wed Sep 22 12:30:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 1531222 X-Patchwork-Delegate: jh80.chung@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=tq-group.com header.i=@tq-group.com header.a=rsa-sha256 header.s=key1 header.b=Ll2KGF8t; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.a=rsa-sha256 header.s=key1 header.b=Ll2KGF8t; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 ozlabs.org (Postfix) with ESMTPS id 4HDyMc6QGcz9t0Y for ; Wed, 22 Sep 2021 22:31:24 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 388DE8321D; Wed, 22 Sep 2021 14:31:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=tq-group.com header.i=@tq-group.com header.b="Ll2KGF8t"; dkim=pass (2048-bit key) header.d=tq-group.com header.i=@tq-group.com header.b="Ll2KGF8t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DDD7882D74; Wed, 22 Sep 2021 14:31:02 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E1FAB82ECC for ; Wed, 22 Sep 2021 14:30:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=ew.tq-group.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=matthias.schiffer@ew.tq-group.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1632313858; x=1663849858; h=from:to:cc:subject:date:message-id; bh=lYYx+CM8P/1ZySBEo/KUu64YNMR+/rvyezgOZpVrPOM=; b=Ll2KGF8tIJe7F1xw6vXc6jcNUo7kmLys93OWTk44eGKzCD3pk/yzH0ZE X+EdgqPuie9qhzcP0bCM+zBbnLwZYYn+W/g2CNaWtBhiCItHrMcrcYAK1 H4J31jkod94zTT/uEwVsUCLEolns8vNuRFBlHaBaxXD+uRlDj387AM5Io ceEB7XIJkyJaNUDesfEjQiHHtuaZXNRi6XgU+UFNeML0Dajhy13ph7o2F 6rfZw0di3SAFgVGbqv33EujITk1a36azXsjKdHyYjlbbn8eB3VfSrT2T3 bgG7ul6aFFubxvq16psYNI1sM8jKy486rO5eDDL1/QMxHRAEaDrsr3L17 A==; X-IronPort-AV: E=Sophos;i="5.85,313,1624312800"; d="scan'208";a="19648595" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 22 Sep 2021 14:30:58 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Wed, 22 Sep 2021 14:30:58 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Wed, 22 Sep 2021 14:30:58 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1632313858; x=1663849858; h=from:to:cc:subject:date:message-id; bh=lYYx+CM8P/1ZySBEo/KUu64YNMR+/rvyezgOZpVrPOM=; b=Ll2KGF8tIJe7F1xw6vXc6jcNUo7kmLys93OWTk44eGKzCD3pk/yzH0ZE X+EdgqPuie9qhzcP0bCM+zBbnLwZYYn+W/g2CNaWtBhiCItHrMcrcYAK1 H4J31jkod94zTT/uEwVsUCLEolns8vNuRFBlHaBaxXD+uRlDj387AM5Io ceEB7XIJkyJaNUDesfEjQiHHtuaZXNRi6XgU+UFNeML0Dajhy13ph7o2F 6rfZw0di3SAFgVGbqv33EujITk1a36azXsjKdHyYjlbbn8eB3VfSrT2T3 bgG7ul6aFFubxvq16psYNI1sM8jKy486rO5eDDL1/QMxHRAEaDrsr3L17 A==; X-IronPort-AV: E=Sophos;i="5.85,313,1624312800"; d="scan'208";a="19648594" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 22 Sep 2021 14:30:58 +0200 Received: from schifferm-ubuntu4.tq-net.de (schifferm-ubuntu4.tq-net.de [10.121.48.12]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id DC5AC280075; Wed, 22 Sep 2021 14:30:57 +0200 (CEST) From: Matthias Schiffer To: u-boot@lists.denx.de Cc: Peng Fan , Jaehoon Chung , Markus Niebel , Matthias Schiffer Subject: [PATCH 2/2] cmd/mmc: add subcommand to query max enhanced partition size Date: Wed, 22 Sep 2021 14:30:37 +0200 Message-Id: <5bfd7e81fd5ed77e049d3fc3892c9175aa80e5cd.1632313515.git.matthias.schiffer@ew.tq-group.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <1d862733e0d4ae632eb036de13aaf048b31b8bdb.1632313515.git.matthias.schiffer@ew.tq-group.com> References: <1d862733e0d4ae632eb036de13aaf048b31b8bdb.1632313515.git.matthias.schiffer@ew.tq-group.com> In-Reply-To: <1d862733e0d4ae632eb036de13aaf048b31b8bdb.1632313515.git.matthias.schiffer@ew.tq-group.com> References: <1d862733e0d4ae632eb036de13aaf048b31b8bdb.1632313515.git.matthias.schiffer@ew.tq-group.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 From: Markus Niebel The new command prints the sector count and size in a human-readable format and sets an environment variable for scripted handling. The variable value is set in decimal to match what the 'mmc hwpartition' command expects. The environment variable can be used for automated partitioning scripts, for example the following would convert a whole eMMC to pSLC mode: mmc maxhwpartsectors mmc hwpartition user enh 0 ${maxhwpartsectors} wrrel on complete Signed-off-by: Markus Niebel Signed-off-by: Matthias Schiffer --- The human-readable output of the command could also be added to `mmc info`, but it would still be great to have a separate command that sets an environment variable for scripting, like this patch adds. cmd/mmc.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cmd/mmc.c b/cmd/mmc.c index f1e30d0cf64..d0b33cc0494 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -593,6 +593,33 @@ static int do_mmc_list(struct cmd_tbl *cmdtp, int flag, } #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) +static int do_mmc_maxhwpartsectors(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) +{ + struct mmc *mmc; + u64 sectors; + + mmc = init_mmc_device(curr_device, false); + if (!mmc) + return CMD_RET_FAILURE; + + if (mmc_max_enhanced_size_sectors(mmc, §ors)) + return CMD_RET_FAILURE; + + /* Ensure that the value fits in mmc_hwpart_conf::user.enh_size */ + if (sectors > UINT_MAX) { + puts("ERROR: sector count larger than UINT_MAX\n"); + return CMD_RET_FAILURE; + } + + env_set_ulong("maxhwpartsectors", sectors); + + printf("Maximum size of hardware partition: %u sectors (", + (uint)sectors); + print_size(sectors * 512, ")\n"); + + return 0; +} + static int parse_hwpart_user(struct mmc_hwpart_conf *pconf, int argc, char *const argv[]) { @@ -1021,6 +1048,7 @@ static struct cmd_tbl cmd_mmc[] = { U_BOOT_CMD_MKENT(dev, 4, 0, do_mmc_dev, "", ""), U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""), #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) + U_BOOT_CMD_MKENT(maxhwpartsectors, 1, 0, do_mmc_maxhwpartsectors, "", ""), U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""), #endif #ifdef CONFIG_SUPPORT_EMMC_BOOT @@ -1084,6 +1112,8 @@ U_BOOT_CMD( "mmc list - lists available devices\n" "mmc wp - power on write protect boot partitions\n" #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) + "mmc maxhwpartsectors - shows the maximum number of 512-byte blocks usable for hardware partitioning\n" + " Sets env var maxhwpartsectors on success.\n" "mmc hwpartition - does hardware partitioning\n" " arguments (sizes in 512-byte blocks):\n" " USER - <{on|off}>\n"