]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_part.c
Combine bootm_find_<thing> functions together
[karo-tx-uboot.git] / common / cmd_part.c
index d997597c1e1e7b0d0260135afa10ba779a9b6934..8483c1230d583fd074dc185b7b0891b728cc30a4 100644 (file)
  * Sysgo Real-Time Solutions, AG <www.elinos.com>
  * Pavel Bartusek <pba@sysgo.com>
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -40,7 +26,7 @@
 #error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled
 #endif
 
-int do_part_uuid(int argc, char * const argv[])
+static int do_part_uuid(int argc, char * const argv[])
 {
        int part;
        block_dev_desc_t *dev_desc;
@@ -63,24 +49,70 @@ int do_part_uuid(int argc, char * const argv[])
        return 0;
 }
 
-int do_part_list(int argc, char * const argv[])
+static int do_part_list(int argc, char * const argv[])
 {
        int ret;
        block_dev_desc_t *desc;
+       char *var = NULL;
+       bool bootable = false;
+       int i;
 
-       if (argc != 2)
+       if (argc < 2)
                return CMD_RET_USAGE;
 
+       if (argc > 2) {
+               for (i = 2; i < argc ; i++) {
+                       if (argv[i][0] == '-') {
+                               if (!strcmp(argv[i], "-bootable")) {
+                                       bootable = true;
+                               } else {
+                                       printf("Unknown option %s\n", argv[i]);
+                                       return CMD_RET_USAGE;
+                               }
+                       } else {
+                               var = argv[i];
+                               break;
+                       }
+               }
+
+               /* Loops should have been exited at the last argument, which
+                * as it contained the variable */
+               if (argc != i + 1)
+                       return CMD_RET_USAGE;
+       }
+
        ret = get_device(argv[0], argv[1], &desc);
        if (ret < 0)
                return 1;
 
+       if (var != NULL) {
+               int p;
+               char str[512] = { '\0', };
+         disk_partition_t info;
+
+               for (p = 1; p < 128; p++) {
+                       char t[5];
+                       int r = get_partition_info(desc, p, &info);
+
+                       if (r != 0)
+                               continue;
+
+                       if (bootable && !info.bootable)
+                               continue;
+
+                       sprintf(t, "%s%d", str[0] ? " " : "", p);
+                       strcat(str, t);
+               }
+               setenv(var, str);
+               return 0;
+       }
+
        print_part(desc);
 
        return 0;
 }
 
-int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        if (argc < 2)
                return CMD_RET_USAGE;
@@ -94,12 +126,15 @@ int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 }
 
 U_BOOT_CMD(
-       part,   5,      1,      do_part,
+       part,   CONFIG_SYS_MAXARGS,     1,      do_part,
        "disk partition related commands",
-       "part uuid <interface> <dev>:<part>\n"
+       "uuid <interface> <dev>:<part>\n"
        "    - print partition UUID\n"
        "part uuid <interface> <dev>:<part> <varname>\n"
        "    - set environment variable to partition UUID\n"
        "part list <interface> <dev>\n"
-       "    - print a device's partition table"
+       "    - print a device's partition table\n"
+       "part list <interface> <dev> [flags] <varname>\n"
+       "    - set environment variable to the list of partitions\n"
+       "      flags can be -bootable (list only bootable partitions)"
 );