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
|
|
|
};
|
|
|
|
|
2014-06-22 22:22:08 +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;
|
2012-09-21 09:51:01 +00:00
|
|
|
disk_partition_t info;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-06-22 22:22:08 +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;
|
2015-02-25 22:23:50 +00:00
|
|
|
char str[512] = { '\0', };
|
2015-06-15 19:35:04 +00:00
|
|
|
disk_partition_t info;
|
2015-01-05 17:13:37 +00:00
|
|
|
|
2018-09-07 09:37:36 +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;
|
|
|
|
}
|
|
|
|
|
2018-02-26 21:18:00 +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;
|
2015-06-15 19:35:05 +00:00
|
|
|
disk_partition_t info;
|
|
|
|
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);
|
|
|
|
if (part == -1)
|
|
|
|
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:
|
|
|
|
snprintf(buf, sizeof(buf), "%d", part);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-26 21:18:00 +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
|
|
|
|
2018-02-26 21:18:00 +00:00
|
|
|
static int do_part_size(int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
return do_part_info(argc, argv, CMD_PART_INFO_SIZE);
|
2015-06-15 19:35:05 +00:00
|
|
|
}
|
|
|
|
|
2019-06-14 14:01:26 +00:00
|
|
|
static int do_part_number(int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
|
|
|
|
}
|
|
|
|
|
2014-06-22 22:22:08 +00:00
|
|
|
static int do_part(cmd_tbl_t *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);
|
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"
|
|
|
|
" part must be specified as partition name"
|
2012-09-21 09:51:01 +00:00
|
|
|
);
|