Stephen Warren | 3a52910 | 2012-09-21 09:51:01 +0000 | [diff] [blame] | 1 | /* |
| 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 16 | * SPDX-License-Identifier: GPL-2.0+ |
Stephen Warren | 3a52910 | 2012-09-21 09:51:01 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <common.h> |
| 20 | #include <config.h> |
| 21 | #include <command.h> |
| 22 | #include <part.h> |
| 23 | #include <vsprintf.h> |
| 24 | |
| 25 | #ifndef CONFIG_PARTITION_UUIDS |
| 26 | #error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled |
| 27 | #endif |
| 28 | |
Jeroen Hofstee | f384fbf | 2014-06-23 00:22:08 +0200 | [diff] [blame] | 29 | static int do_part_uuid(int argc, char * const argv[]) |
Stephen Warren | 3a52910 | 2012-09-21 09:51:01 +0000 | [diff] [blame] | 30 | { |
| 31 | int part; |
| 32 | block_dev_desc_t *dev_desc; |
| 33 | disk_partition_t info; |
| 34 | |
| 35 | if (argc < 2) |
| 36 | return CMD_RET_USAGE; |
| 37 | if (argc > 3) |
| 38 | return CMD_RET_USAGE; |
| 39 | |
| 40 | part = get_device_and_partition(argv[0], argv[1], &dev_desc, &info, 0); |
| 41 | if (part < 0) |
| 42 | return 1; |
| 43 | |
| 44 | if (argc > 2) |
| 45 | setenv(argv[2], info.uuid); |
| 46 | else |
| 47 | printf("%s\n", info.uuid); |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
Jeroen Hofstee | f384fbf | 2014-06-23 00:22:08 +0200 | [diff] [blame] | 52 | static int do_part_list(int argc, char * const argv[]) |
Stephen Warren | 3a52910 | 2012-09-21 09:51:01 +0000 | [diff] [blame] | 53 | { |
| 54 | int ret; |
| 55 | block_dev_desc_t *desc; |
| 56 | |
Sjoerd Simons | ca8982b | 2015-01-05 18:13:37 +0100 | [diff] [blame] | 57 | if (argc < 2 || argc > 3) |
Stephen Warren | 3a52910 | 2012-09-21 09:51:01 +0000 | [diff] [blame] | 58 | return CMD_RET_USAGE; |
| 59 | |
| 60 | ret = get_device(argv[0], argv[1], &desc); |
| 61 | if (ret < 0) |
| 62 | return 1; |
| 63 | |
Sjoerd Simons | ca8982b | 2015-01-05 18:13:37 +0100 | [diff] [blame] | 64 | if (argc == 3) { |
| 65 | int p; |
| 66 | char str[512] = { 0, }; |
| 67 | disk_partition_t info; |
| 68 | |
| 69 | for (p = 1; p < 128; p++) { |
| 70 | int r = get_partition_info(desc, p, &info); |
| 71 | |
| 72 | if (r == 0) { |
| 73 | char t[5]; |
| 74 | sprintf(t, "%s%d", str[0] ? " " : "", p); |
| 75 | strcat(str, t); |
| 76 | } |
| 77 | } |
| 78 | setenv(argv[2], str); |
| 79 | return 0; |
| 80 | } |
| 81 | |
Stephen Warren | 3a52910 | 2012-09-21 09:51:01 +0000 | [diff] [blame] | 82 | print_part(desc); |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
Jeroen Hofstee | f384fbf | 2014-06-23 00:22:08 +0200 | [diff] [blame] | 87 | static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Stephen Warren | 3a52910 | 2012-09-21 09:51:01 +0000 | [diff] [blame] | 88 | { |
| 89 | if (argc < 2) |
| 90 | return CMD_RET_USAGE; |
| 91 | |
| 92 | if (!strcmp(argv[1], "uuid")) |
| 93 | return do_part_uuid(argc - 2, argv + 2); |
| 94 | else if (!strcmp(argv[1], "list")) |
| 95 | return do_part_list(argc - 2, argv + 2); |
| 96 | |
| 97 | return CMD_RET_USAGE; |
| 98 | } |
| 99 | |
| 100 | U_BOOT_CMD( |
| 101 | part, 5, 1, do_part, |
| 102 | "disk partition related commands", |
Stephen Warren | 9b2eed6 | 2014-05-07 12:19:00 -0600 | [diff] [blame] | 103 | "part uuid <interface> <dev>:<part>\n" |
Stephen Warren | 3a52910 | 2012-09-21 09:51:01 +0000 | [diff] [blame] | 104 | " - print partition UUID\n" |
| 105 | "part uuid <interface> <dev>:<part> <varname>\n" |
| 106 | " - set environment variable to partition UUID\n" |
| 107 | "part list <interface> <dev>\n" |
Sjoerd Simons | ca8982b | 2015-01-05 18:13:37 +0100 | [diff] [blame] | 108 | " - print a device's partition table\n" |
| 109 | "part list <interface> <dev> <varname>\n" |
| 110 | " - set environment variable to the list of partitions" |
Stephen Warren | 3a52910 | 2012-09-21 09:51:01 +0000 | [diff] [blame] | 111 | ); |