cmd_ext4.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_load(cmd_tbl_t *cmdtp, int flag, int argc,
  42. char *const argv[])
  43. {
  44. return do_load(cmdtp, flag, argc, argv, FS_TYPE_EXT);
  45. }
  46. int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  47. {
  48. return do_ls(cmdtp, flag, argc, argv, FS_TYPE_EXT);
  49. }
  50. #if defined(CONFIG_CMD_EXT4_WRITE)
  51. int do_ext4_write(cmd_tbl_t *cmdtp, int flag, int argc,
  52. char *const argv[])
  53. {
  54. const char *filename = "/";
  55. int dev, part;
  56. unsigned long ram_address;
  57. unsigned long file_size;
  58. disk_partition_t info;
  59. block_dev_desc_t *dev_desc;
  60. if (argc < 6)
  61. return cmd_usage(cmdtp);
  62. part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
  63. if (part < 0)
  64. return 1;
  65. dev = dev_desc->dev;
  66. /* get the filename */
  67. filename = argv[4];
  68. /* get the address in hexadecimal format (string to int) */
  69. ram_address = simple_strtoul(argv[3], NULL, 16);
  70. /* get the filesize in base 10 format */
  71. file_size = simple_strtoul(argv[5], NULL, 10);
  72. /* set the device as block device */
  73. ext4fs_set_blk_dev(dev_desc, &info);
  74. /* mount the filesystem */
  75. if (!ext4fs_mount(info.size)) {
  76. printf("Bad ext4 partition %s %d:%d\n", argv[1], dev, part);
  77. goto fail;
  78. }
  79. /* start write */
  80. if (ext4fs_write(filename, (unsigned char *)ram_address, file_size)) {
  81. printf("** Error ext4fs_write() **\n");
  82. goto fail;
  83. }
  84. ext4fs_close();
  85. return 0;
  86. fail:
  87. ext4fs_close();
  88. return 1;
  89. }
  90. U_BOOT_CMD(ext4write, 6, 1, do_ext4_write,
  91. "create a file in the root directory",
  92. "<interface> <dev[:part]> <addr> <absolute filename path> [sizebytes]\n"
  93. " - create a file in / directory");
  94. #endif
  95. U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls,
  96. "list files in a directory (default /)",
  97. "<interface> <dev[:part]> [directory]\n"
  98. " - list files from 'dev' on 'interface' in a 'directory'");
  99. U_BOOT_CMD(ext4load, 6, 0, do_ext4_load,
  100. "load binary file from a Ext4 filesystem",
  101. "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
  102. " - load binary file 'filename' from 'dev' on 'interface'\n"
  103. " to address 'addr' from ext4 filesystem");