2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
4 * made from cmd_ext2, which was:
7 * esd gmbh <www.esd-electronics.com>
8 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
10 * made from cmd_reiserfs by
12 * (C) Copyright 2003 - 2004
13 * Sysgo Real-Time Solutions, AG <www.elinos.com>
14 * Pavel Bartusek <pba@sysgo.com>
16 * SPDX-License-Identifier: GPL-2.0+
25 #ifndef CONFIG_PARTITION_UUIDS
26 #error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled
29 static int do_part_uuid(int argc, char * const argv[])
32 block_dev_desc_t *dev_desc;
33 disk_partition_t info;
40 part = get_device_and_partition(argv[0], argv[1], &dev_desc, &info, 0);
45 setenv(argv[2], info.uuid);
47 printf("%s\n", info.uuid);
52 static int do_part_list(int argc, char * const argv[])
55 block_dev_desc_t *desc;
57 bool bootable = false;
64 for (i = 2; i < argc ; i++) {
65 if (argv[i][0] == '-') {
66 if (!strcmp(argv[i], "-bootable")) {
69 printf("Unknown option %s\n", argv[i]);
78 /* Loops should have been exited at the last argument, which
79 * as it contained the variable */
84 ret = get_device(argv[0], argv[1], &desc);
90 char str[512] = { '\0', };
91 disk_partition_t info;
93 for (p = 1; p < 128; p++) {
95 int r = get_partition_info(desc, p, &info);
100 if (bootable && !info.bootable)
103 sprintf(t, "%s%x", str[0] ? " " : "", p);
115 static int do_part_start(int argc, char * const argv[])
117 block_dev_desc_t *desc;
118 disk_partition_t info;
119 char buf[512] = { 0 };
125 return CMD_RET_USAGE;
127 return CMD_RET_USAGE;
129 part = simple_strtoul(argv[2], NULL, 0);
131 ret = get_device(argv[0], argv[1], &desc);
135 err = get_partition_info(desc, part, &info);
139 snprintf(buf, sizeof(buf), LBAF, info.start);
142 setenv(argv[3], buf);
149 static int do_part_size(int argc, char * const argv[])
151 block_dev_desc_t *desc;
152 disk_partition_t info;
153 char buf[512] = { 0 };
159 return CMD_RET_USAGE;
161 return CMD_RET_USAGE;
163 part = simple_strtoul(argv[2], NULL, 0);
165 ret = get_device(argv[0], argv[1], &desc);
169 err = get_partition_info(desc, part, &info);
173 snprintf(buf, sizeof(buf), LBAF, info.size);
176 setenv(argv[3], buf);
183 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
186 return CMD_RET_USAGE;
188 if (!strcmp(argv[1], "uuid"))
189 return do_part_uuid(argc - 2, argv + 2);
190 else if (!strcmp(argv[1], "list"))
191 return do_part_list(argc - 2, argv + 2);
192 else if (!strcmp(argv[1], "start"))
193 return do_part_start(argc - 2, argv + 2);
194 else if (!strcmp(argv[1], "size"))
195 return do_part_size(argc - 2, argv + 2);
197 return CMD_RET_USAGE;
201 part, CONFIG_SYS_MAXARGS, 1, do_part,
202 "disk partition related commands",
203 "uuid <interface> <dev>:<part>\n"
204 " - print partition UUID\n"
205 "part uuid <interface> <dev>:<part> <varname>\n"
206 " - set environment variable to partition UUID\n"
207 "part list <interface> <dev>\n"
208 " - print a device's partition table\n"
209 "part list <interface> <dev> [flags] <varname>\n"
210 " - set environment variable to the list of partitions\n"
211 " flags can be -bootable (list only bootable partitions)\n"
212 "part start <interface> <dev> <part> <varname>\n"
213 " - set environment variable to the start of the partition (in blocks)\n"
214 "part size <interface> <dev> <part> <varname>\n"
215 " - set environment variable to the size of the partition (in blocks)"