cmd_jffs2.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@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. * Boot support
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <s_record.h>
  29. #include <jffs2/load_kernel.h>
  30. #include <net.h>
  31. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
  32. static int part_num=0;
  33. #ifndef CFG_JFFS_CUSTOM_PART
  34. static struct part_info part;
  35. struct part_info*
  36. jffs2_part_info(int part_num)
  37. {
  38. extern flash_info_t flash_info[]; /* info for FLASH chips */
  39. int i;
  40. if(part_num==0){
  41. if(part.usr_priv==(void*)1)
  42. return &part;
  43. memset(&part, 0, sizeof(part));
  44. #if defined(CFG_JFFS2_FIRST_SECTOR)
  45. part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
  46. #else
  47. part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
  48. #endif
  49. /* Figure out flash partition size */
  50. for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
  51. part.size += flash_info[i].size;
  52. #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
  53. part.size -=
  54. flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
  55. flash_info[CFG_JFFS2_FIRST_BANK].start[0];
  56. #endif
  57. /* unused in current jffs2 loader */
  58. part.erasesize = 0;
  59. /* Mark the struct as ready */
  60. part.usr_priv=(void*)1;
  61. return &part;
  62. }
  63. return 0;
  64. }
  65. #endif /* ifndef CFG_JFFS_CUSTOM_PART */
  66. int
  67. do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  68. {
  69. struct part_info* jffs2_part_info(int);
  70. int jffs2_1pass_load(char *, struct part_info *,const char *);
  71. char *filename = "uImage";
  72. ulong offset = CFG_LOAD_ADDR;
  73. int size;
  74. struct part_info *part;
  75. if (argc == 2) {
  76. filename = argv[1];
  77. }
  78. if (argc == 3) {
  79. offset = simple_strtoul(argv[1], NULL, 16);
  80. filename = argv[2];
  81. }
  82. if (0 != (part=jffs2_part_info(part_num))){
  83. printf("### JFFS2 loading '%s' to 0x%lx\n", filename, offset);
  84. size = jffs2_1pass_load((char *)offset, part, filename);
  85. if (size > 0) {
  86. char buf[10];
  87. printf("### JFFS2 load complete: %d bytes loaded to 0x%lx\n",
  88. size, offset);
  89. sprintf(buf, "%x", size);
  90. setenv("filesize", buf);
  91. } else {
  92. printf("### JFFS2 LOAD ERROR<%x> for %s!\n", size, filename);
  93. }
  94. return !(size > 0);
  95. }
  96. printf("Active partition not valid\n");
  97. return 0;
  98. }
  99. int
  100. do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  101. {
  102. struct part_info* jffs2_part_info(int);
  103. int jffs2_1pass_ls(struct part_info *,char *);
  104. char *filename = "/";
  105. int ret;
  106. struct part_info *part;
  107. if (argc == 2)
  108. filename = argv[1];
  109. if (0 != (part=jffs2_part_info(part_num))){
  110. ret = jffs2_1pass_ls(jffs2_part_info(part_num), filename);
  111. return (ret == 1);
  112. }
  113. printf("Active partition not valid\n");
  114. return 0;
  115. }
  116. int
  117. do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  118. {
  119. struct part_info* jffs2_part_info(int);
  120. int jffs2_1pass_info(struct part_info *);
  121. int ret;
  122. struct part_info *part;
  123. if (0 != (part=jffs2_part_info(part_num))){
  124. ret = jffs2_1pass_info(jffs2_part_info(part_num));
  125. return (ret == 1);
  126. }
  127. printf("Active partition not valid\n");
  128. return 0;
  129. }
  130. int
  131. do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  132. {
  133. int tmp_part;
  134. struct part_info* jffs2_part_info(int);
  135. if (argc >= 2) {
  136. tmp_part = simple_strtoul(argv[1], NULL, 16);
  137. }else{
  138. printf("Need partition number in argument list\n");
  139. return 0;
  140. }
  141. if (jffs2_part_info(tmp_part)){
  142. printf("Partiton changed to %d\n",tmp_part);
  143. part_num=tmp_part;
  144. return 0;
  145. }
  146. printf("Partition %d is not valid partiton\n",tmp_part);
  147. return 0;
  148. }
  149. /***************************************************/
  150. U_BOOT_CMD(
  151. fsload, 3, 0, do_jffs2_fsload,
  152. "fsload - load binary file from a filesystem image\n",
  153. "[ off ] [ filename ]\n"
  154. " - load binary file from flash bank\n"
  155. " with offset 'off'\n"
  156. );
  157. U_BOOT_CMD(
  158. fsinfo, 1, 1, do_jffs2_fsinfo,
  159. "fsinfo - print information about filesystems\n",
  160. " - print information about filesystems\n"
  161. );
  162. U_BOOT_CMD(
  163. ls, 2, 1, do_jffs2_ls,
  164. "ls - list files in a directory (default /)\n",
  165. "[ directory ]\n"
  166. " - list files in a directory.\n"
  167. );
  168. U_BOOT_CMD(
  169. chpart, 2, 0, do_jffs2_chpart,
  170. "chpart - change active partition\n",
  171. " - change active partition\n"
  172. );
  173. #endif /* CFG_CMD_JFFS2 */