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>
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2012-09-21 09:51:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <part.h>
|
|
|
|
#include <vsprintf.h>
|
|
|
|
|
|
|
|
#ifndef CONFIG_PARTITION_UUIDS
|
|
|
|
#error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
block_dev_desc_t *dev_desc;
|
|
|
|
disk_partition_t info;
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
if (argc > 3)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
part = get_device_and_partition(argv[0], argv[1], &dev_desc, &info, 0);
|
|
|
|
if (part < 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (argc > 2)
|
|
|
|
setenv(argv[2], info.uuid);
|
|
|
|
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;
|
|
|
|
block_dev_desc_t *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;
|
|
|
|
}
|
|
|
|
|
2012-09-21 09:51:01 +00:00
|
|
|
ret = get_device(argv[0], argv[1], &desc);
|
|
|
|
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-01-05 17:13:37 +00:00
|
|
|
disk_partition_t info;
|
|
|
|
|
|
|
|
for (p = 1; p < 128; p++) {
|
2015-02-25 22:23:50 +00:00
|
|
|
char t[5];
|
2015-01-05 17:13:37 +00:00
|
|
|
int r = get_partition_info(desc, p, &info);
|
|
|
|
|
2015-02-25 22:23:50 +00:00
|
|
|
if (r != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (bootable && !info.bootable)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sprintf(t, "%s%d", str[0] ? " " : "", p);
|
|
|
|
strcat(str, t);
|
2015-01-05 17:13:37 +00:00
|
|
|
}
|
2015-02-25 22:23:50 +00:00
|
|
|
setenv(var, str);
|
2015-01-05 17:13:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-21 09:51:01 +00:00
|
|
|
print_part(desc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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",
|
2014-05-07 18:19:00 +00:00
|
|
|
"part 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"
|
|
|
|
" flags can be -bootable (list only bootable partitions)"
|
2012-09-21 09:51:01 +00:00
|
|
|
);
|