blob: b79f074f841aa21c53ad53ccec61ef92a5510d93 [file] [log] [blame]
Stephen Warren5cf41dc2012-09-21 09:51:01 +00001/*
2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
3 *
4 * made from cmd_ext2, which was:
5 *
6 * (C) Copyright 2004
7 * esd gmbh <www.esd-electronics.com>
8 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
9 *
10 * made from cmd_reiserfs by
11 *
12 * (C) Copyright 2003 - 2004
13 * Sysgo Real-Time Solutions, AG <www.elinos.com>
14 * Pavel Bartusek <pba@sysgo.com>
15 *
16 * See file CREDITS for list of people who contributed to this
17 * project.
18 *
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License as
21 * published by the Free Software Foundation; either version 2 of
22 * the License, or (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 */
32
33#include <common.h>
34#include <config.h>
35#include <command.h>
36#include <part.h>
37#include <vsprintf.h>
38
39#ifndef CONFIG_PARTITION_UUIDS
40#error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled
41#endif
42
43int do_part_uuid(int argc, char * const argv[])
44{
45 int part;
46 block_dev_desc_t *dev_desc;
47 disk_partition_t info;
48
49 if (argc < 2)
50 return CMD_RET_USAGE;
51 if (argc > 3)
52 return CMD_RET_USAGE;
53
54 part = get_device_and_partition(argv[0], argv[1], &dev_desc, &info, 0);
55 if (part < 0)
56 return 1;
57
58 if (argc > 2)
59 setenv(argv[2], info.uuid);
60 else
61 printf("%s\n", info.uuid);
62
63 return 0;
64}
65
66int do_part_list(int argc, char * const argv[])
67{
68 int ret;
69 block_dev_desc_t *desc;
70
71 if (argc != 2)
72 return CMD_RET_USAGE;
73
74 ret = get_device(argv[0], argv[1], &desc);
75 if (ret < 0)
76 return 1;
77
78 print_part(desc);
79
80 return 0;
81}
82
83int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
84{
85 if (argc < 2)
86 return CMD_RET_USAGE;
87
88 if (!strcmp(argv[1], "uuid"))
89 return do_part_uuid(argc - 2, argv + 2);
90 else if (!strcmp(argv[1], "list"))
91 return do_part_list(argc - 2, argv + 2);
92
93 return CMD_RET_USAGE;
94}
95
96U_BOOT_CMD(
97 part, 5, 1, do_part,
98 "disk partition related commands",
Stephen Warren92668d62013-02-28 15:05:34 +000099 "uuid <interface> <dev>:<part>\n"
Stephen Warren5cf41dc2012-09-21 09:51:01 +0000100 " - print partition UUID\n"
101 "part uuid <interface> <dev>:<part> <varname>\n"
102 " - set environment variable to partition UUID\n"
103 "part list <interface> <dev>\n"
104 " - print a device's partition table"
105);