1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
5 * made from cmd_ext2, which was:
8 * esd gmbh <www.esd-electronics.com>
9 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
11 * made from cmd_reiserfs by
13 * (C) Copyright 2003 - 2004
14 * Sysgo Real-Time Solutions, AG <www.elinos.com>
15 * Pavel Bartusek <pba@sysgo.com>
25 CMD_PART_INFO_START = 0,
29 static int do_part_uuid(int argc, char * const argv[])
32 struct blk_desc *dev_desc;
33 disk_partition_t info;
40 part = blk_get_device_part_str(argv[0], argv[1], &dev_desc, &info, 0);
45 env_set(argv[2], info.uuid);
47 printf("%s\n", info.uuid);
52 static int do_part_list(int argc, char * const argv[])
55 struct blk_desc *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 = blk_get_device_by_str(argv[0], argv[1], &desc);
90 char str[512] = { '\0', };
91 disk_partition_t info;
93 for (p = 1; p < MAX_SEARCH_PARTITIONS; p++) {
95 int r = part_get_info(desc, p, &info);
100 if (bootable && !info.bootable)
103 sprintf(t, "%s%x", str[0] ? " " : "", p);
115 static int do_part_info(int argc, char * const argv[], enum cmd_part_info param)
117 struct blk_desc *desc;
118 disk_partition_t info;
119 char buf[512] = { 0 };
126 return CMD_RET_USAGE;
128 return CMD_RET_USAGE;
130 ret = blk_get_device_by_str(argv[0], argv[1], &desc);
134 part = simple_strtoul(argv[2], &endp, 0);
136 err = part_get_info(desc, part, &info);
140 part = part_get_info_by_name(desc, argv[2], &info);
146 case CMD_PART_INFO_START:
147 snprintf(buf, sizeof(buf), LBAF, info.start);
149 case CMD_PART_INFO_SIZE:
150 snprintf(buf, sizeof(buf), LBAF, info.size);
153 printf("** Unknown cmd_part_info value: %d\n", param);
158 env_set(argv[3], buf);
165 static int do_part_start(int argc, char * const argv[])
167 return do_part_info(argc, argv, CMD_PART_INFO_START);
170 static int do_part_size(int argc, char * const argv[])
172 return do_part_info(argc, argv, CMD_PART_INFO_SIZE);
175 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
178 return CMD_RET_USAGE;
180 if (!strcmp(argv[1], "uuid"))
181 return do_part_uuid(argc - 2, argv + 2);
182 else if (!strcmp(argv[1], "list"))
183 return do_part_list(argc - 2, argv + 2);
184 else if (!strcmp(argv[1], "start"))
185 return do_part_start(argc - 2, argv + 2);
186 else if (!strcmp(argv[1], "size"))
187 return do_part_size(argc - 2, argv + 2);
189 return CMD_RET_USAGE;
193 part, CONFIG_SYS_MAXARGS, 1, do_part,
194 "disk partition related commands",
195 "uuid <interface> <dev>:<part>\n"
196 " - print partition UUID\n"
197 "part uuid <interface> <dev>:<part> <varname>\n"
198 " - set environment variable to partition UUID\n"
199 "part list <interface> <dev>\n"
200 " - print a device's partition table\n"
201 "part list <interface> <dev> [flags] <varname>\n"
202 " - set environment variable to the list of partitions\n"
203 " flags can be -bootable (list only bootable partitions)\n"
204 "part start <interface> <dev> <part> <varname>\n"
205 " - set environment variable to the start of the partition (in blocks)\n"
206 " part can be either partition number or partition name\n"
207 "part size <interface> <dev> <part> <varname>\n"
208 " - set environment variable to the size of the partition (in blocks)\n"
209 " part can be either partition number or partition name"