blob: 14248548d9fede555a90902d84a4787ab7cbf10f [file] [log] [blame]
Stephen Warren3a529102012-09-21 09:51:01 +00001/*
2 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
3 *
4 * made from cmd_ext2, which was:
5 *
6 * (C) Copyright 2004
7 * esd gmbh <www.esd-electronics.com>
8 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
9 *
10 * made from cmd_reiserfs by
11 *
12 * (C) Copyright 2003 - 2004
13 * Sysgo Real-Time Solutions, AG <www.elinos.com>
14 * Pavel Bartusek <pba@sysgo.com>
15 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020016 * SPDX-License-Identifier: GPL-2.0+
Stephen Warren3a529102012-09-21 09:51:01 +000017 */
18
19#include <common.h>
20#include <config.h>
21#include <command.h>
22#include <part.h>
23#include <vsprintf.h>
24
25#ifndef CONFIG_PARTITION_UUIDS
26#error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled
27#endif
28
29int do_part_uuid(int argc, char * const argv[])
30{
31 int part;
32 block_dev_desc_t *dev_desc;
33 disk_partition_t info;
34
35 if (argc < 2)
36 return CMD_RET_USAGE;
37 if (argc > 3)
38 return CMD_RET_USAGE;
39
40 part = get_device_and_partition(argv[0], argv[1], &dev_desc, &info, 0);
41 if (part < 0)
42 return 1;
43
44 if (argc > 2)
45 setenv(argv[2], info.uuid);
46 else
47 printf("%s\n", info.uuid);
48
49 return 0;
50}
51
52int do_part_list(int argc, char * const argv[])
53{
54 int ret;
55 block_dev_desc_t *desc;
56
57 if (argc != 2)
58 return CMD_RET_USAGE;
59
60 ret = get_device(argv[0], argv[1], &desc);
61 if (ret < 0)
62 return 1;
63
64 print_part(desc);
65
66 return 0;
67}
68
69int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
70{
71 if (argc < 2)
72 return CMD_RET_USAGE;
73
74 if (!strcmp(argv[1], "uuid"))
75 return do_part_uuid(argc - 2, argv + 2);
76 else if (!strcmp(argv[1], "list"))
77 return do_part_list(argc - 2, argv + 2);
78
79 return CMD_RET_USAGE;
80}
81
82U_BOOT_CMD(
83 part, 5, 1, do_part,
84 "disk partition related commands",
Stephen Warren53601422013-02-28 15:05:34 +000085 "uuid <interface> <dev>:<part>\n"
Stephen Warren3a529102012-09-21 09:51:01 +000086 " - print partition UUID\n"
87 "part uuid <interface> <dev>:<part> <varname>\n"
88 " - set environment variable to partition UUID\n"
89 "part list <interface> <dev>\n"
90 " - print a device's partition table"
91);