cmd_part.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  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. *
  16. * See file CREDITS for list of people who contributed to this
  17. * project.
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License as
  21. * published by the Free Software Foundation; either version 2 of
  22. * the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. */
  32. #include <common.h>
  33. #include <config.h>
  34. #include <command.h>
  35. #include <part.h>
  36. #include <vsprintf.h>
  37. #ifndef CONFIG_PARTITION_UUIDS
  38. #error CONFIG_PARTITION_UUIDS must be enabled for CONFIG_CMD_PART to be enabled
  39. #endif
  40. int do_part_uuid(int argc, char * const argv[])
  41. {
  42. int part;
  43. block_dev_desc_t *dev_desc;
  44. disk_partition_t info;
  45. if (argc < 2)
  46. return CMD_RET_USAGE;
  47. if (argc > 3)
  48. return CMD_RET_USAGE;
  49. part = get_device_and_partition(argv[0], argv[1], &dev_desc, &info, 0);
  50. if (part < 0)
  51. return 1;
  52. if (argc > 2)
  53. setenv(argv[2], info.uuid);
  54. else
  55. printf("%s\n", info.uuid);
  56. return 0;
  57. }
  58. int do_part_list(int argc, char * const argv[])
  59. {
  60. int ret;
  61. block_dev_desc_t *desc;
  62. if (argc != 2)
  63. return CMD_RET_USAGE;
  64. ret = get_device(argv[0], argv[1], &desc);
  65. if (ret < 0)
  66. return 1;
  67. print_part(desc);
  68. return 0;
  69. }
  70. int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  71. {
  72. if (argc < 2)
  73. return CMD_RET_USAGE;
  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. return CMD_RET_USAGE;
  79. }
  80. U_BOOT_CMD(
  81. part, 5, 1, do_part,
  82. "disk partition related commands",
  83. "uuid <interface> <dev>:<part>\n"
  84. " - print partition UUID\n"
  85. "part uuid <interface> <dev>:<part> <varname>\n"
  86. " - set environment variable to partition UUID\n"
  87. "part list <interface> <dev>\n"
  88. " - print a device's partition table"
  89. );