From patchwork Thu Aug 16 23:15:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 178122 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id B64C42C0085 for ; Fri, 17 Aug 2012 09:16:10 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3D5E228297; Fri, 17 Aug 2012 01:16:06 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DSPBPwU+x++5; Fri, 17 Aug 2012 01:16:05 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 091AA2827C; Fri, 17 Aug 2012 01:15:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 45D4328270 for ; Fri, 17 Aug 2012 01:15:55 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VKSST-rxWcLp for ; Fri, 17 Aug 2012 01:15:54 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from avon.wwwdotorg.org (avon.wwwdotorg.org [70.85.31.133]) by theia.denx.de (Postfix) with ESMTPS id 56EA328271 for ; Fri, 17 Aug 2012 01:15:52 +0200 (CEST) Received: from severn.wwwdotorg.org (unknown [192.168.65.5]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPS id 75D726349; Thu, 16 Aug 2012 17:22:34 -0600 (MDT) Received: from localhost.localdomain (localhost [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by severn.wwwdotorg.org (Postfix) with ESMTPSA id 6444BE461E; Thu, 16 Aug 2012 17:15:49 -0600 (MDT) From: Stephen Warren To: u-boot@lists.denx.de Date: Thu, 16 Aug 2012 17:15:41 -0600 Message-Id: <1345158942-31512-2-git-send-email-swarren@wwwdotorg.org> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1345158942-31512-1-git-send-email-swarren@wwwdotorg.org> References: <1345158942-31512-1-git-send-email-swarren@wwwdotorg.org> X-NVConfidentiality: public X-Virus-Scanned: clamav-milter 0.96.5 at avon.wwwdotorg.org X-Virus-Status: Clean Cc: Stephen Warren , Tom Warren Subject: [U-Boot] [PATCH 2/3] cmd_partuuid: add command to retrieve a partition's UUID X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Stephen Warren This implements the following: partuuid mmc 0:1 -> prints the partition's UUID. partuuic mmc 0:1 uuid -> sets environment variable "uuid" to the partition's UUID. 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.: partuuid ${devtype} ${devnum}:${rootpart} uuid setenv bootargs root=PARTUUID=${uuid} ... Signed-off-by: Stephen Warren --- common/Makefile | 1 + common/cmd_partuuid.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 0 deletions(-) create mode 100644 common/cmd_partuuid.c diff --git a/common/Makefile b/common/Makefile index 483eb4d..bc39997 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_PARTUUID) += cmd_partuuid.o ifdef CONFIG_PCI COBJS-$(CONFIG_CMD_PCI) += cmd_pci.o endif diff --git a/common/cmd_partuuid.c b/common/cmd_partuuid.c new file mode 100644 index 0000000..c85606c --- /dev/null +++ b/common/cmd_partuuid.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. + * + * made from cmd_ext2, which was: + * + * (C) Copyright 2004 + * esd gmbh + * Reinhard Arlt + * + * made from cmd_reiserfs by + * + * (C) Copyright 2003 - 2004 + * Sysgo Real-Time Solutions, AG + * Pavel Bartusek + * + * 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 . + */ + +#include +#include +#include +#include +#include + +int do_partuuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + int dev; + int part; + char *ep; + block_dev_desc_t *dev_desc; + disk_partition_t info; + + if (argc < 3) + return CMD_RET_USAGE; + + dev = (int)simple_strtoul(argv[2], &ep, 16); + dev_desc = get_dev(argv[1], dev); + if (dev_desc == NULL) { + printf("Block device %s %d not supported\n", argv[1], 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 > 3) + setenv(argv[3], info.uuid); + else + printf("%s\n", info.uuid); + + return 0; +} + +U_BOOT_CMD( + partuuid, 4, 1, do_partuuid, + "partition UUID retrieval", + " \n" + " - show filesystem UUID of specified partition" + " \n" + " - write filesystem UUID to environmane variable" +);