cmd_ext4.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. * SPDX-License-Identifier: GPL-2.0+
  21. */
  22. /*
  23. * Changelog:
  24. * 0.1 - Newly created file for ext4fs support. Taken from cmd_ext2.c
  25. * file in uboot. Added ext4fs ls load and write support.
  26. */
  27. #include <common.h>
  28. #include <part.h>
  29. #include <config.h>
  30. #include <command.h>
  31. #include <image.h>
  32. #include <linux/ctype.h>
  33. #include <asm/byteorder.h>
  34. #include <ext4fs.h>
  35. #include <linux/stat.h>
  36. #include <malloc.h>
  37. #include <fs.h>
  38. #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
  39. #include <usb.h>
  40. #endif
  41. int do_ext4_size(cmd_tbl_t *cmdtp, int flag, int argc,
  42. char *const argv[])
  43. {
  44. return do_size(cmdtp, flag, argc, argv, FS_TYPE_EXT);
  45. }
  46. int do_ext4_load(cmd_tbl_t *cmdtp, int flag, int argc,
  47. char *const argv[])
  48. {
  49. return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT);
  50. }
  51. int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  52. {
  53. return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT);
  54. }
  55. #if defined(CONFIG_CMD_EXT4_WRITE)
  56. int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
  57. char *const argv[])
  58. {
  59. const char *filename = "/";
  60. int dev, part;
  61. unsigned long ram_address;
  62. unsigned long file_size;
  63. disk_partition_t info;
  64. block_dev_desc_t *dev_desc;
  65. if (argc < 6)
  66. return cmd_usage(cmdtp);
  67. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
  68. if (part < 0)
  69. return 1;
  70. dev = dev_desc->dev;
  71. /* get the filename */
  72. filename = argv[4];
  73. /* get the address in hexadecimal format (string to int) */
  74. ram_address = simple_strtoul(argv[3], NULL, 16);
  75. /* get the filesize in hexadecimal format */
  76. file_size = simple_strtoul(argv[5], NULL, 16);
  77. /* set the device as block device */
  78. ext4fs_set_blk_dev(dev_desc, &info);
  79. /* mount the filesystem */
  80. if (!ext4fs_mount(info.size)) {
  81. printf("Bad ext4 partition %s %d:%d\n", argv[1], dev, part);
  82. goto fail;
  83. }
  84. /* start write */
  85. if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) {
  86. printf("** Error ext4fs_write() **\n");
  87. goto fail;
  88. }
  89. ext4fs_close();
  90. return 0;
  91. fail:
  92. ext4fs_close();
  93. return 1;
  94. }
  95. U_BOOT_CMD(ext4write, 6, 1, do_ext4_write,
  96. "create a file in the root directory",
  97. "<interface> <dev[:part]> <addr> <absolute filename path> [sizebytes]\n"
  98. " - create a file in / directory");
  99. #endif
  100. U_BOOT_CMD(
  101. ext4size, 4, 0, do_ext4_size,
  102. "determine a file's size",
  103. "<interface> <dev[:part]> <filename>\n"
  104. " - Find file 'filename' from 'dev' on 'interface'\n"
  105. " and determine its size."
  106. );
  107. U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls,
  108. "list files in a directory (default /)",
  109. "<interface> <dev[:part]> [directory]\n"
  110. " - list files from 'dev' on 'interface' in a 'directory'");
  111. U_BOOT_CMD(ext4load, 6, 0, do_ext4_load,
  112. "load binary file from a Ext4 filesystem",
  113. "<interface> [<dev[:part]> [addr [filename [bytes [pos]]]]]\n"
  114. " - load binary file 'filename' from 'dev' on 'interface'\n"
  115. " to address 'addr' from ext4 filesystem");