[PATCH 2/2] cmd/mmc: add subcommand to query max enhanced partition size

Jaehoon Chung jh80.chung at samsung.com
Thu Sep 23 14:03:24 CEST 2021


On 9/22/21 9:30 PM, Matthias Schiffer wrote:
> From: Markus Niebel <Markus.Niebel at ew.tq-group.com>
> 
> 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


I don't have any objection about this patch.
If we can use more simpler variable name than maxhwpartsectors, I think that it's more useful.
But it's not important. :)

And Could you update doc/usage/mmc.rst about this command?

Best Regards,
Jaehoon Chung

> 
> Signed-off-by: Markus Niebel <Markus.Niebel at ew.tq-group.com>
> Signed-off-by: Matthias Schiffer <matthias.schiffer at ew.tq-group.com>
> ---
> 
> 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, &sectors))
> +		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 <USER> <GP> <MODE> - does hardware partitioning\n"
>  	"  arguments (sizes in 512-byte blocks):\n"
>  	"   USER - <user> <enh> <start> <cnt> <wrrel> <{on|off}>\n"
> 



More information about the U-Boot mailing list