cmd_ext4.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * (C) Copyright 2011 - 2012 Samsung Electronics
  3. * EXT4 filesystem implementation in Uboot by
  4. * Uma Shankar <uma.shankar@samsung.com>
  5. * Manjunatha C Achar <a.manjunatha@samsung.com>
  6. *
  7. * Ext4fs support
  8. * made from existing cmd_ext2.c file of Uboot
  9. *
  10. * (C) Copyright 2004
  11. * esd gmbh <www.esd-electronics.com>
  12. * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
  13. *
  14. * made from cmd_reiserfs by
  15. *
  16. * (C) Copyright 2003 - 2004
  17. * Sysgo Real-Time Solutions, AG <www.elinos.com>
  18. * Pavel Bartusek <pba@sysgo.com>
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation; either version 2 of
  23. * the License, or (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33. * MA 02111-1307 USA
  34. *
  35. */
  36. /*
  37. * Changelog:
  38. * 0.1 - Newly created file for ext4fs support. Taken from cmd_ext2.c
  39. * file in uboot. Added ext4fs ls load and write support.
  40. */
  41. #include <common.h>
  42. #include <part.h>
  43. #include <config.h>
  44. #include <command.h>
  45. #include <image.h>
  46. #include <linux/ctype.h>
  47. #include <asm/byteorder.h>
  48. #include <ext4fs.h>
  49. #include <linux/stat.h>
  50. #include <malloc.h>
  51. #include <fs.h>
  52. #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
  53. #include <usb.h>
  54. #endif
  55. int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
  56. char *const argv[])
  57. {
  58. return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT, 16);
  59. }
  60. int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  61. {
  62. return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT);
  63. }
  64. #if defined(CONFIG_CMD_EXT4_WRITE)
  65. int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
  66. char *const argv[])
  67. {
  68. const char *filename = "/";
  69. int dev, part;
  70. unsigned long ram_address;
  71. unsigned long file_size;
  72. disk_partition_t info;
  73. block_dev_desc_t *dev_desc;
  74. if (argc < 6)
  75. return cmd_usage(cmdtp);
  76. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
  77. if (part < 0)
  78. return 1;
  79. dev = dev_desc->dev;
  80. /* get the filename */
  81. filename = argv[4];
  82. /* get the address in hexadecimal format (string to int) */
  83. ram_address = simple_strtoul(argv[3], NULL, 16);
  84. /* get the filesize in base 10 format */
  85. file_size = simple_strtoul(argv[5], NULL, 10);
  86. /* set the device as block device */
  87. ext4fs_set_blk_dev(dev_desc, &info);
  88. /* mount the filesystem */
  89. if (!ext4fs_mount(info.size)) {
  90. printf("Bad ext4 partition %s %d:%d\n", argv[1], dev, part);
  91. goto fail;
  92. }
  93. /* start write */
  94. if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) {
  95. printf("** Error ext4fs_write() **\n");
  96. goto fail;
  97. }
  98. ext4fs_close();
  99. return 0;
  100. fail:
  101. ext4fs_close();
  102. return 1;
  103. }
  104. U_BOOT_CMD(ext4write, 6, 1, do_ext4_write,
  105. "create a file in the root directory",
  106. "<interface> <dev[:part]> <addr> <absolute filename path> [sizebytes]\n"
  107. " - create a file in / directory");
  108. #endif
  109. U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls,
  110. "list files in a directory (default /)",
  111. "<interface> <dev[:part]> [directory]\n"
  112. " - list files from 'dev' on 'interface' in a 'directory'");
  113. U_BOOT_CMD(ext4load, 6, 0, do_ext4_load,
  114. "load binary file from a Ext4 filesystem",
  115. "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
  116. " - load binary file 'filename' from 'dev' on 'interface'\n"
  117. " to address 'addr' from ext4 filesystem.\n"
  118. " All numeric parameters are assumed to be hex.");