2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-09-21 09:51:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
|
|
|
|
*
|
|
|
|
* made from cmd_ext2, which was:
|
|
|
|
*
|
|
|
|
* (C) Copyright 2004
|
|
|
|
* esd gmbh <www.esd-electronics.com>
|
|
|
|
* Reinhard Arlt <reinhard.arlt@esd-electronics.com>
|
|
|
|
*
|
|
|
|
* made from cmd_reiserfs by
|
|
|
|
*
|
|
|
|
* (C) Copyright 2003 - 2004
|
|
|
|
* Sysgo Real-Time Solutions, AG <www.elinos.com>
|
|
|
|
* Pavel Bartusek <pba@sysgo.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include <command.h>
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2012-09-21 09:51:01 +00:00
|
|
|
#include <part.h>
|
|
|
|
#include <vsprintf.h>
|
|
|
|
|
2018-02-26 21:18:00 +00:00
|
|
|
enum cmd_part_info {
|
|
|
|
CMD_PART_INFO_START = 0,
|
|
|
|
CMD_PART_INFO_SIZE,
|
2019-06-14 14:01:26 +00:00
|
|
|
CMD_PART_INFO_NUMBER
|
2018-02-26 21:18:00 +00:00
|
|
|
};
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_part_uuid(int argc, char *const argv[])
|
2012-09-21 09:51:01 +00:00
|
|
|
{
|
|
|
|
int part;
|
2016-02-29 22:25:34 +00:00
|
|
|
struct blk_desc *dev_desc;
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition info;
|
2012-09-21 09:51:01 +00:00
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
if (argc > 3)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2016-02-29 22:25:44 +00:00
|
|
|
part = blk_get_device_part_str(argv[0], argv[1], &dev_desc, &info, 0);
|
2012-09-21 09:51:01 +00:00
|
|
|
if (part < 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (argc > 2)
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set(argv[2], info.uuid);
|
2012-09-21 09:51:01 +00:00
|
|
|
else
|
|
|
|
printf("%s\n", info.uuid);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_part_list(int argc, char *const argv[])
|
2012-09-21 09:51:01 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2016-02-29 22:25:34 +00:00
|
|
|
struct blk_desc *desc;
|
2015-02-25 22:23:50 +00:00
|
|
|
char *var = NULL;
|
|
|
|
bool bootable = false;
|
|
|
|
int i;
|
2012-09-21 09:51:01 +00:00
|
|
|
|
2015-02-25 22:23:50 +00:00
|
|
|
if (argc < 2)
|
2012-09-21 09:51:01 +00:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2015-02-25 22:23:50 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-29 22:25:43 +00:00
|
|
|
ret = blk_get_device_by_str(argv[0], argv[1], &desc);
|
2012-09-21 09:51:01 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return 1;
|
|
|
|
|
2015-02-25 22:23:50 +00:00
|
|
|
if (var != NULL) {
|
2015-01-05 17:13:37 +00:00
|
|
|
int p;
|
2022-01-11 15:03:38 +00:00
|
|
|
char str[3 * MAX_SEARCH_PARTITIONS] = { '\0', };
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition info;
|
2015-01-05 17:13:37 +00:00
|
|
|
|
2022-01-11 15:03:38 +00:00
|
|
|
for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
|
2015-02-25 22:23:50 +00:00
|
|
|
char t[5];
|
2016-02-29 22:25:48 +00:00
|
|
|
int r = part_get_info(desc, p, &info);
|
2015-01-05 17:13:37 +00:00
|
|
|
|
2015-02-25 22:23:50 +00:00
|
|
|
if (r != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (bootable && !info.bootable)
|
|
|
|
continue;
|
|
|
|
|
2015-12-09 16:48:04 +00:00
|
|
|
sprintf(t, "%s%x", str[0] ? " " : "", p);
|
2015-02-25 22:23:50 +00:00
|
|
|
strcat(str, t);
|
2015-01-05 17:13:37 +00:00
|
|
|
}
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set(var, str);
|
2015-01-05 17:13:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-29 22:25:48 +00:00
|
|
|
part_print(desc);
|
2012-09-21 09:51:01 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_part_info(int argc, char *const argv[], enum cmd_part_info param)
|
2015-06-15 19:35:05 +00:00
|
|
|
{
|
2016-02-29 22:25:34 +00:00
|
|
|
struct blk_desc *desc;
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition info;
|
2015-06-15 19:35:05 +00:00
|
|
|
char buf[512] = { 0 };
|
2018-02-26 21:17:59 +00:00
|
|
|
char *endp;
|
2015-06-15 19:35:05 +00:00
|
|
|
int part;
|
|
|
|
int err;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (argc < 3)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
if (argc > 4)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2016-02-29 22:25:43 +00:00
|
|
|
ret = blk_get_device_by_str(argv[0], argv[1], &desc);
|
2015-06-15 19:35:05 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return 1;
|
|
|
|
|
2018-02-26 21:17:59 +00:00
|
|
|
part = simple_strtoul(argv[2], &endp, 0);
|
|
|
|
if (*endp == '\0') {
|
|
|
|
err = part_get_info(desc, part, &info);
|
|
|
|
if (err)
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
part = part_get_info_by_name(desc, argv[2], &info);
|
2021-06-22 09:40:01 +00:00
|
|
|
if (part < 0)
|
2018-02-26 21:17:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2015-06-15 19:35:05 +00:00
|
|
|
|
2018-02-26 21:18:00 +00:00
|
|
|
switch (param) {
|
|
|
|
case CMD_PART_INFO_START:
|
|
|
|
snprintf(buf, sizeof(buf), LBAF, info.start);
|
|
|
|
break;
|
|
|
|
case CMD_PART_INFO_SIZE:
|
|
|
|
snprintf(buf, sizeof(buf), LBAF, info.size);
|
|
|
|
break;
|
2019-06-14 14:01:26 +00:00
|
|
|
case CMD_PART_INFO_NUMBER:
|
2019-09-20 13:59:18 +00:00
|
|
|
snprintf(buf, sizeof(buf), "0x%x", part);
|
2019-06-14 14:01:26 +00:00
|
|
|
break;
|
2018-02-26 21:18:00 +00:00
|
|
|
default:
|
|
|
|
printf("** Unknown cmd_part_info value: %d\n", param);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-06-15 19:35:05 +00:00
|
|
|
|
|
|
|
if (argc > 3)
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set(argv[3], buf);
|
2015-06-15 19:35:05 +00:00
|
|
|
else
|
|
|
|
printf("%s\n", buf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_part_start(int argc, char *const argv[])
|
2015-06-15 19:35:05 +00:00
|
|
|
{
|
2018-02-26 21:18:00 +00:00
|
|
|
return do_part_info(argc, argv, CMD_PART_INFO_START);
|
|
|
|
}
|
2015-06-15 19:35:05 +00:00
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_part_size(int argc, char *const argv[])
|
2018-02-26 21:18:00 +00:00
|
|
|
{
|
|
|
|
return do_part_info(argc, argv, CMD_PART_INFO_SIZE);
|
2015-06-15 19:35:05 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_part_number(int argc, char *const argv[])
|
2019-06-14 14:01:26 +00:00
|
|
|
{
|
|
|
|
return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
|
|
|
|
}
|
|
|
|
|
2020-03-24 15:17:03 +00:00
|
|
|
static int do_part_types(int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
struct part_driver *drv = ll_entry_start(struct part_driver,
|
|
|
|
part_driver);
|
|
|
|
const int n_ents = ll_entry_count(struct part_driver, part_driver);
|
|
|
|
struct part_driver *entry;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
puts("Supported partition tables");
|
|
|
|
|
|
|
|
for (entry = drv; entry != drv + n_ents; entry++) {
|
|
|
|
printf("%c %s", i ? ',' : ':', entry->name);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (!i)
|
|
|
|
puts(": <none>");
|
|
|
|
puts("\n");
|
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_part(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2012-09-21 09:51:01 +00:00
|
|
|
{
|
|
|
|
if (argc < 2)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
if (!strcmp(argv[1], "uuid"))
|
|
|
|
return do_part_uuid(argc - 2, argv + 2);
|
|
|
|
else if (!strcmp(argv[1], "list"))
|
|
|
|
return do_part_list(argc - 2, argv + 2);
|
2015-06-15 19:35:05 +00:00
|
|
|
else if (!strcmp(argv[1], "start"))
|
|
|
|
return do_part_start(argc - 2, argv + 2);
|
|
|
|
else if (!strcmp(argv[1], "size"))
|
|
|
|
return do_part_size(argc - 2, argv + 2);
|
2019-06-14 14:01:26 +00:00
|
|
|
else if (!strcmp(argv[1], "number"))
|
|
|
|
return do_part_number(argc - 2, argv + 2);
|
2020-03-24 15:17:03 +00:00
|
|
|
else if (!strcmp(argv[1], "types"))
|
|
|
|
return do_part_types(argc - 2, argv + 2);
|
2012-09-21 09:51:01 +00:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
2015-02-25 22:23:50 +00:00
|
|
|
part, CONFIG_SYS_MAXARGS, 1, do_part,
|
2012-09-21 09:51:01 +00:00
|
|
|
"disk partition related commands",
|
2015-04-27 23:44:58 +00:00
|
|
|
"uuid <interface> <dev>:<part>\n"
|
2012-09-21 09:51:01 +00:00
|
|
|
" - print partition UUID\n"
|
|
|
|
"part uuid <interface> <dev>:<part> <varname>\n"
|
|
|
|
" - set environment variable to partition UUID\n"
|
|
|
|
"part list <interface> <dev>\n"
|
2015-01-05 17:13:37 +00:00
|
|
|
" - print a device's partition table\n"
|
2015-02-25 22:23:50 +00:00
|
|
|
"part list <interface> <dev> [flags] <varname>\n"
|
|
|
|
" - set environment variable to the list of partitions\n"
|
2015-06-15 19:35:05 +00:00
|
|
|
" flags can be -bootable (list only bootable partitions)\n"
|
|
|
|
"part start <interface> <dev> <part> <varname>\n"
|
|
|
|
" - set environment variable to the start of the partition (in blocks)\n"
|
2018-02-26 21:17:59 +00:00
|
|
|
" part can be either partition number or partition name\n"
|
2015-06-15 19:35:05 +00:00
|
|
|
"part size <interface> <dev> <part> <varname>\n"
|
2018-02-26 21:17:59 +00:00
|
|
|
" - set environment variable to the size of the partition (in blocks)\n"
|
2019-06-14 14:01:26 +00:00
|
|
|
" part can be either partition number or partition name\n"
|
|
|
|
"part number <interface> <dev> <part> <varname>\n"
|
|
|
|
" - set environment variable to the partition number using the partition name\n"
|
2020-03-24 15:17:03 +00:00
|
|
|
" part must be specified as partition name\n"
|
|
|
|
"part types\n"
|
|
|
|
" - list supported partition table types"
|
2012-09-21 09:51:01 +00:00
|
|
|
);
|