All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rob Herring <robherring2@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2 4/4] cmd_part: add partition-related command
Date: Wed, 05 Sep 2012 18:51:58 -0500	[thread overview]
Message-ID: <5047E59E.8060503@gmail.com> (raw)
In-Reply-To: <1346882624-12783-4-git-send-email-swarren@wwwdotorg.org>

On 09/05/2012 05:03 PM, Stephen Warren wrote:
> From: Stephen Warren <swarren@nvidia.com>
> 
> This implements the following:
> 
> part uuid mmc 0:1
>   -> print partition UUID
> part uuid mmc 0:1 uuid
>   -> set environment variable to partition UUID

What's the reason to not always both print out and set the uuid env var?

Perhaps the env name should be partuuid or part_uuid as you could have
uuid's for other purposes?

> 
> This can be useful when writing a bootcmd which searches all known
> devices for something bootable, and then wants the kernel to use the
> same partition as the root device, e.g.:
> 
> part uuid ${devtype} ${devnum}:${rootpart} uuid
> setenv bootargs root=PARTUUID=${uuid} ...
> 
> It is expected that further part sub-commands will be added later, e.g.
> to find which partition on a disk is marked bootable, to write new
> partition tables to disk, etc.

A list command would be useful and would be better located here than
under scsi or other interface commands. Perhaps instead of printing a
single part uuid, you should make a list command that prints all
partitions and their UUIDs. That would address my first question.

Rob

> 
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
> v2: validate that CONFIG_PARTITION_UUID is defined when CONFIG_CMD_PART is
> 
> Note: If Rob Herring's proposed patch "disk/part: introduce
> get_device_and_partition" is applied, the body of do_partuuid() should
> be reworked to use Rob's new function get_device_and_partition().
> ---
>  common/Makefile   |    1 +
>  common/cmd_part.c |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 105 insertions(+), 0 deletions(-)
>  create mode 100644 common/cmd_part.c
> 
> diff --git a/common/Makefile b/common/Makefile
> index 3d62775..449b390 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -129,6 +129,7 @@ COBJS-$(CONFIG_CMD_NAND) += cmd_nand.o
>  COBJS-$(CONFIG_CMD_NET) += cmd_net.o
>  COBJS-$(CONFIG_CMD_ONENAND) += cmd_onenand.o
>  COBJS-$(CONFIG_CMD_OTP) += cmd_otp.o
> +COBJS-$(CONFIG_CMD_PART) += cmd_part.o
>  ifdef CONFIG_PCI
>  COBJS-$(CONFIG_CMD_PCI) += cmd_pci.o
>  endif
> diff --git a/common/cmd_part.c b/common/cmd_part.c
> new file mode 100644
> index 0000000..1b15ae9
> --- /dev/null
> +++ b/common/cmd_part.c
> @@ -0,0 +1,104 @@
> +/*
> + * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
> + *
> + * made from cmd_ext2, which was:
> + *
> + * (C) Copyright 2004
> + * esd gmbh <www.esd-electronics.com>
> + * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
> + *
> + * made from cmd_reiserfs by
> + *
> + * (C) Copyright 2003 - 2004
> + * Sysgo Real-Time Solutions, AG <www.elinos.com>
> + * Pavel Bartusek <pba@sysgo.com>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <common.h>
> +#include <config.h>
> +#include <command.h>
> +#include <part.h>
> +#include <vsprintf.h>
> +
> +#ifndef CONFIG_PARTITION_UUIDS
> +#error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled
> +#endif
> +
> +int do_partuuid(int argc, char * const argv[])
> +{
> +	int dev;
> +	int part;
> +	char *ep;
> +	block_dev_desc_t *dev_desc;
> +	disk_partition_t info;
> +
> +	if (argc < 2)
> +		return CMD_RET_USAGE;
> +	if (argc > 3)
> +		return CMD_RET_USAGE;
> +
> +	dev = (int)simple_strtoul(argv[1], &ep, 16);
> +	dev_desc = get_dev(argv[0], dev);
> +	if (dev_desc == NULL) {
> +		printf("Block device %s %d not supported\n", argv[0], dev);
> +		return 1;
> +	}
> +
> +	if (*ep) {
> +		if (*ep != ':') {
> +			puts("Invalid device; use dev[:part]\n");
> +			return 1;
> +		}
> +		part = (int)simple_strtoul(++ep, NULL, 16);
> +	} else {
> +		part = 1;
> +	}
> +
> +	if (get_partition_info(dev_desc, part, &info)) {
> +		printf("Bad partition %d\n", part);
> +		return 1;
> +	}
> +
> +	if (argc > 2)
> +		setenv(argv[2], info.uuid);
> +	else
> +		printf("%s\n", info.uuid);
> +
> +	return 0;
> +}
> +
> +int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> +{
> +	if (argc < 2)
> +		return CMD_RET_USAGE;
> +
> +	if (!strcmp(argv[1], "uuid"))
> +		return do_partuuid(argc - 2, argv + 2);
> +
> +	return CMD_RET_USAGE;
> +}
> +
> +U_BOOT_CMD(
> +	part,	5,	1,	do_part,
> +	"disk partition related commands",
> +	"part uuid <interface> <dev[:part]>\n"
> +	"    - print partition UUID\n"
> +	"part uuid <interface> <dev[:part]> <varname>\n"
> +	"    - set environment variable to partition UUID"
> +);
> 

  reply	other threads:[~2012-09-05 23:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-05 22:03 [U-Boot] [PATCH V2 1/4] disk: part_efi: range-check partition number Stephen Warren
2012-09-05 22:03 ` [U-Boot] [PATCH V2 2/4] disk: part_efi: parse and store partition UUID Stephen Warren
2012-09-05 23:24   ` Tom Rini
2012-09-05 22:03 ` [U-Boot] [PATCH V2 3/4] disk: part_msdos: " Stephen Warren
2012-09-05 22:03 ` [U-Boot] [PATCH V2 4/4] cmd_part: add partition-related command Stephen Warren
2012-09-05 23:51   ` Rob Herring [this message]
2012-09-05 23:58     ` Tom Rini
2012-09-07 19:42       ` Stephen Warren
2012-09-11 22:52       ` Stephen Warren
2012-09-12  7:00         ` Lukasz Majewski
2012-09-12 16:48           ` Tom Rini
2012-09-12 16:47         ` Tom Rini
2012-09-06  2:38     ` Stephen Warren
2012-09-06 17:12       ` Tom Rini
2012-09-06 18:46         ` Stephen Warren
2012-09-06 22:45           ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5047E59E.8060503@gmail.com \
    --to=robherring2@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.