cmd_ubifs.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * (C) Copyright 2008
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. */
  24. /*
  25. * UBIFS command support
  26. */
  27. #undef DEBUG
  28. #include <common.h>
  29. #include <config.h>
  30. #include <command.h>
  31. static int ubifs_initialized;
  32. static int ubifs_mounted;
  33. /* Prototypes */
  34. int ubifs_init(void);
  35. int ubifs_mount(char *vol_name);
  36. int ubifs_ls(char *dir_name);
  37. int ubifs_load(char *filename, u32 addr, u32 size);
  38. int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  39. {
  40. char *vol_name;
  41. int ret;
  42. vol_name = argv[1];
  43. debug("Using volume %s\n", vol_name);
  44. if (ubifs_initialized == 0) {
  45. ubifs_init();
  46. ubifs_initialized = 1;
  47. }
  48. ret = ubifs_mount(vol_name);
  49. if (ret)
  50. return -1;
  51. ubifs_mounted = 1;
  52. return 0;
  53. }
  54. int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  55. {
  56. char *filename = "/";
  57. int ret;
  58. if (!ubifs_mounted) {
  59. printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
  60. return -1;
  61. }
  62. if (argc == 2)
  63. filename = argv[1];
  64. debug("Using filename %s\n", filename);
  65. ret = ubifs_ls(filename);
  66. if (ret)
  67. printf("%s not found!\n", filename);
  68. return ret;
  69. }
  70. int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  71. {
  72. char *filename;
  73. int ret;
  74. u32 addr;
  75. u32 size = 0;
  76. if (!ubifs_mounted) {
  77. printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
  78. return -1;
  79. }
  80. if (argc < 3) {
  81. printf("Usage:\n%s\n", cmdtp->usage);
  82. return -1;
  83. }
  84. addr = simple_strtoul(argv[1], NULL, 16);
  85. filename = argv[2];
  86. if (argc == 4)
  87. size = simple_strtoul(argv[3], NULL, 16);
  88. debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
  89. ret = ubifs_load(filename, addr, size);
  90. if (ret)
  91. printf("%s not found!\n", filename);
  92. return ret;
  93. }
  94. U_BOOT_CMD(
  95. ubifsmount, 2, 0, do_ubifs_mount,
  96. "mount UBIFS volume",
  97. "\n");
  98. U_BOOT_CMD(ubifsls, 2, 0, do_ubifs_ls,
  99. "list files in a directory",
  100. "[directory]\n"
  101. " - list files in a 'directory' (default '/')\n");
  102. U_BOOT_CMD(ubifsload, 4, 0, do_ubifs_load,
  103. "load file from an UBIFS filesystem",
  104. "<addr> <filename> [bytes]\n"
  105. " - load file 'filename' to address 'addr'\n");