2018-05-07 05:58:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-09-21 17:51:01 +08: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 23:46:51 +08:00
|
|
|
#include <env.h>
|
2012-09-21 17:51:01 +08:00
|
|
|
#include <part.h>
|
|
|
|
#include <vsprintf.h>
|
|
|
|
|
2018-02-27 05:18:00 +08:00
|
|
|
enum cmd_part_info {
|
|
|
|
CMD_PART_INFO_START = 0,
|
|
|
|
CMD_PART_INFO_SIZE,
|
2019-06-14 22:01:26 +08:00
|
|
|
CMD_PART_INFO_NUMBER
|
2018-02-27 05:18:00 +08:00
|
|
|
};
|
|
|
|
|
2014-06-23 06:22:08 +08:00
|
|
|
static int do_part_uuid(int argc, char * const argv[])
|
2012-09-21 17:51:01 +08:00
|
|
|
{
|
|
|
|
int part;
|
2016-03-01 06:25:34 +08:00
|
|
|
struct blk_desc *dev_desc;
|
2012-09-21 17:51:01 +08:00
|
|
|
disk_partition_t info;
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
if (argc > 3)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2016-03-01 06:25:44 +08:00
|
|
|
part = blk_get_device_part_str(argv[0], argv[1], &dev_desc, &info, 0);
|
2012-09-21 17:51:01 +08:00
|
|
|
if (part < 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (argc > 2)
|
2017-08-04 02:22:09 +08:00
|
|
|
env_set(argv[2], info.uuid);
|
2012-09-21 17:51:01 +08:00
|
|
|
else
|
|
|
|
printf("%s\n", info.uuid);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-23 06:22:08 +08:00
|
|
|
static int do_part_list(int argc, char * const argv[])
|
2012-09-21 17:51:01 +08:00
|
|
|
{
|
|
|
|
int ret;
|
2016-03-01 06:25:34 +08:00
|
|
|
struct blk_desc *desc;
|
2015-02-26 06:23:50 +08:00
|
|
|
char *var = NULL;
|
|
|
|
bool bootable = false;
|
|
|
|
int i;
|
2012-09-21 17:51:01 +08:00
|
|
|
|
2015-02-26 06:23:50 +08:00
|
|
|
if (argc < 2)
|
2012-09-21 17:51:01 +08:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2015-02-26 06:23:50 +08: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-03-01 06:25:43 +08:00
|
|
|
ret = blk_get_device_by_str(argv[0], argv[1], &desc);
|
2012-09-21 17:51:01 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return 1;
|
|
|
|
|
2015-02-26 06:23:50 +08:00
|
|
|
if (var != NULL) {
|
2015-01-06 01:13:37 +08:00
|
|
|
int p;
|
2015-02-26 06:23:50 +08:00
|
|
|
char str[512] = { '\0', };
|
2015-06-16 03:35:04 +08:00
|
|
|
disk_partition_t info;
|
2015-01-06 01:13:37 +08:00
|
|
|
|
2018-09-07 17:37:36 +08:00
|
|
|
for (p = 1; p < MAX_SEARCH_PARTITIONS; p++) {
|
2015-02-26 06:23:50 +08:00
|
|
|
char t[5];
|
2016-03-01 06:25:48 +08:00
|
|
|
int r = part_get_info(desc, p, &info);
|
2015-01-06 01:13:37 +08:00
|
|
|
|
2015-02-26 06:23:50 +08:00
|
|
|
if (r != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (bootable && !info.bootable)
|
|
|
|
continue;
|
|
|
|
|
2015-12-10 00:48:04 +08:00
|
|
|
sprintf(t, "%s%x", str[0] ? " " : "", p);
|
2015-02-26 06:23:50 +08:00
|
|
|
strcat(str, t);
|
2015-01-06 01:13:37 +08:00
|
|
|
}
|
2017-08-04 02:22:09 +08:00
|
|
|
env_set(var, str);
|
2015-01-06 01:13:37 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-01 06:25:48 +08:00
|
|
|
part_print(desc);
|
2012-09-21 17:51:01 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-27 05:18:00 +08:00
|
|
|
static int do_part_info(int argc, char * const argv[], enum cmd_part_info param)
|
2015-06-16 03:35:05 +08:00
|
|
|
{
|
2016-03-01 06:25:34 +08:00
|
|
|
struct blk_desc *desc;
|
2015-06-16 03:35:05 +08:00
|
|
|
disk_partition_t info;
|
|
|
|
char buf[512] = { 0 };
|
2018-02-27 05:17:59 +08:00
|
|
|
char *endp;
|
2015-06-16 03:35:05 +08:00
|
|
|
int part;
|
|
|
|
int err;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (argc < 3)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
if (argc > 4)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2016-03-01 06:25:43 +08:00
|
|
|
ret = blk_get_device_by_str(argv[0], argv[1], &desc);
|
2015-06-16 03:35:05 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return 1;
|
|
|
|
|
2018-02-27 05:17:59 +08: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-16 03:35:05 +08:00
|
|
|
|
2018-02-27 05:18:00 +08: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 22:01:26 +08:00
|
|
|
case CMD_PART_INFO_NUMBER:
|
2019-09-20 21:59:18 +08:00
|
|
|
snprintf(buf, sizeof(buf), "0x%x", part);
|
2019-06-14 22:01:26 +08:00
|
|
|
break;
|
2018-02-27 05:18:00 +08:00
|
|
|
default:
|
|
|
|
printf("** Unknown cmd_part_info value: %d\n", param);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-06-16 03:35:05 +08:00
|
|
|
|
|
|
|
if (argc > 3)
|
2017-08-04 02:22:09 +08:00
|
|
|
env_set(argv[3], buf);
|
2015-06-16 03:35:05 +08:00
|
|
|
else
|
|
|
|
printf("%s\n", buf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-27 05:18:00 +08:00
|
|
|
static int do_part_start(int argc, char * const argv[])
|
2015-06-16 03:35:05 +08:00
|
|
|
{
|
2018-02-27 05:18:00 +08:00
|
|
|
return do_part_info(argc, argv, CMD_PART_INFO_START);
|
|
|
|
}
|
2015-06-16 03:35:05 +08:00
|
|
|
|
2018-02-27 05:18:00 +08:00
|
|
|
static int do_part_size(int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
return do_part_info(argc, argv, CMD_PART_INFO_SIZE);
|
2015-06-16 03:35:05 +08:00
|
|
|
}
|
|
|
|
|
2019-06-14 22:01:26 +08:00
|
|
|
static int do_part_number(int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
|
|
|
|
}
|
|
|
|
|
2014-06-23 06:22:08 +08:00
|
|
|
static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
2012-09-21 17:51:01 +08: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-16 03:35:05 +08: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 22:01:26 +08:00
|
|
|
else if (!strcmp(argv[1], "number"))
|
|
|
|
return do_part_number(argc - 2, argv + 2);
|
2012-09-21 17:51:01 +08:00
|
|
|
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
2015-02-26 06:23:50 +08:00
|
|
|
part, CONFIG_SYS_MAXARGS, 1, do_part,
|
2012-09-21 17:51:01 +08:00
|
|
|
"disk partition related commands",
|
2015-04-28 07:44:58 +08:00
|
|
|
"uuid <interface> <dev>:<part>\n"
|
2012-09-21 17:51:01 +08: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-06 01:13:37 +08:00
|
|
|
" - print a device's partition table\n"
|
2015-02-26 06:23:50 +08:00
|
|
|
"part list <interface> <dev> [flags] <varname>\n"
|
|
|
|
" - set environment variable to the list of partitions\n"
|
2015-06-16 03:35:05 +08: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-27 05:17:59 +08:00
|
|
|
" part can be either partition number or partition name\n"
|
2015-06-16 03:35:05 +08:00
|
|
|
"part size <interface> <dev> <part> <varname>\n"
|
2018-02-27 05:17:59 +08:00
|
|
|
" - set environment variable to the size of the partition (in blocks)\n"
|
2019-06-14 22:01:26 +08: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 17:51:01 +08:00
|
|
|
);
|