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%d", str[0] ? " " : "", p);
115 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
118 return CMD_RET_USAGE;
120 if (!strcmp(argv[1], "uuid"))
121 return do_part_uuid(argc - 2, argv + 2);
122 else if (!strcmp(argv[1], "list"))
123 return do_part_list(argc - 2, argv + 2);
125 return CMD_RET_USAGE;
129 part, CONFIG_SYS_MAXARGS, 1, do_part,
130 "disk partition related commands",
131 "part uuid <interface> <dev>:<part>\n"
132 " - print partition UUID\n"
133 "part uuid <interface> <dev>:<part> <varname>\n"
134 " - set environment variable to partition UUID\n"
135 "part list <interface> <dev>\n"
136 " - print a device's partition table\n"
137 "part list <interface> <dev> [flags] <varname>\n"
138 " - set environment variable to the list of partitions\n"
139 " flags can be -bootable (list only bootable partitions)"