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 static int do_part_uuid(int argc, char * const argv[])
28 struct blk_desc *dev_desc;
29 disk_partition_t info;
36 part = blk_get_device_part_str(argv[0], argv[1], &dev_desc, &info, 0);
41 setenv(argv[2], info.uuid);
43 printf("%s\n", info.uuid);
48 static int do_part_list(int argc, char * const argv[])
51 struct blk_desc *desc;
53 bool bootable = false;
60 for (i = 2; i < argc ; i++) {
61 if (argv[i][0] == '-') {
62 if (!strcmp(argv[i], "-bootable")) {
65 printf("Unknown option %s\n", argv[i]);
74 /* Loops should have been exited at the last argument, which
75 * as it contained the variable */
80 ret = blk_get_device_by_str(argv[0], argv[1], &desc);
86 char str[512] = { '\0', };
87 disk_partition_t info;
89 for (p = 1; p < 128; p++) {
91 int r = part_get_info(desc, p, &info);
96 if (bootable && !info.bootable)
99 sprintf(t, "%s%x", str[0] ? " " : "", p);
111 static int do_part_start(int argc, char * const argv[])
113 struct blk_desc *desc;
114 disk_partition_t info;
115 char buf[512] = { 0 };
121 return CMD_RET_USAGE;
123 return CMD_RET_USAGE;
125 part = simple_strtoul(argv[2], NULL, 0);
127 ret = blk_get_device_by_str(argv[0], argv[1], &desc);
131 err = part_get_info(desc, part, &info);
135 snprintf(buf, sizeof(buf), LBAF, info.start);
138 setenv(argv[3], buf);
145 static int do_part_size(int argc, char * const argv[])
147 struct blk_desc *desc;
148 disk_partition_t info;
149 char buf[512] = { 0 };
155 return CMD_RET_USAGE;
157 return CMD_RET_USAGE;
159 part = simple_strtoul(argv[2], NULL, 0);
161 ret = blk_get_device_by_str(argv[0], argv[1], &desc);
165 err = part_get_info(desc, part, &info);
169 snprintf(buf, sizeof(buf), LBAF, info.size);
172 setenv(argv[3], buf);
179 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
182 return CMD_RET_USAGE;
184 if (!strcmp(argv[1], "uuid"))
185 return do_part_uuid(argc - 2, argv + 2);
186 else if (!strcmp(argv[1], "list"))
187 return do_part_list(argc - 2, argv + 2);
188 else if (!strcmp(argv[1], "start"))
189 return do_part_start(argc - 2, argv + 2);
190 else if (!strcmp(argv[1], "size"))
191 return do_part_size(argc - 2, argv + 2);
193 return CMD_RET_USAGE;
197 part, CONFIG_SYS_MAXARGS, 1, do_part,
198 "disk partition related commands",
199 "uuid <interface> <dev>:<part>\n"
200 " - print partition UUID\n"
201 "part uuid <interface> <dev>:<part> <varname>\n"
202 " - set environment variable to partition UUID\n"
203 "part list <interface> <dev>\n"
204 " - print a device's partition table\n"
205 "part list <interface> <dev> [flags] <varname>\n"
206 " - set environment variable to the list of partitions\n"
207 " flags can be -bootable (list only bootable partitions)\n"
208 "part start <interface> <dev> <part> <varname>\n"
209 " - set environment variable to the start of the partition (in blocks)\n"
210 "part size <interface> <dev> <part> <varname>\n"
211 " - set environment variable to the size of the partition (in blocks)"