cmd_jffs2.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 <cmd_boot.h>
  29. #include <cmd_autoscript.h>
  30. #include <s_record.h>
  31. #include <net.h>
  32. #if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
  33. #include <jffs2/jffs2.h>
  34. static int part_num=0;
  35. #ifndef CFG_JFFS_CUSTOM_PART
  36. static struct part_info part;
  37. struct part_info*
  38. jffs2_part_info(int part_num)
  39. {
  40. extern flash_info_t flash_info[]; /* info for FLASH chips */
  41. int i;
  42. if(part_num==0){
  43. if(part.usr_priv==(void*)1)
  44. return &part;
  45. memset(&part, 0, sizeof(part));
  46. #if defined(CFG_JFFS2_FIRST_SECTOR)
  47. part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
  48. #else
  49. part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
  50. #endif
  51. /* Figure out flash partition size */
  52. for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
  53. part.size += flash_info[i].size;
  54. #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
  55. part.size -=
  56. flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
  57. flash_info[CFG_JFFS2_FIRST_BANK].start[0];
  58. #endif
  59. /* unused in current jffs2 loader */
  60. part.erasesize = 0;
  61. /* Mark the struct as ready */
  62. part.usr_priv=(void*)1;
  63. return &part;
  64. }
  65. return 0;
  66. }
  67. #endif /* ifndef CFG_JFFS_CUSTOM_PART */
  68. int
  69. do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  70. {
  71. char *filename = "pImage";
  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. char *filename = "/";
  103. int ret;
  104. struct part_info *part;
  105. if (argc == 2)
  106. filename = argv[1];
  107. if (0 != (part=jffs2_part_info(part_num))){
  108. ret = jffs2_1pass_ls(jffs2_part_info(part_num), filename);
  109. return (ret == 1);
  110. }
  111. printf("Active partition not valid\n");
  112. return 0;
  113. }
  114. int
  115. do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  116. {
  117. int ret;
  118. struct part_info *part;
  119. if (0 != (part=jffs2_part_info(part_num))){
  120. ret = jffs2_1pass_info(jffs2_part_info(part_num));
  121. return (ret == 1);
  122. }
  123. printf("Active partition not valid\n");
  124. return 0;
  125. }
  126. int
  127. do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  128. {
  129. int tmp_part;
  130. if (argc >= 2) {
  131. tmp_part = simple_strtoul(argv[1], NULL, 16);
  132. }else{
  133. printf("Need partition number in argument list\n");
  134. return 0;
  135. }
  136. if (jffs2_part_info(tmp_part)){
  137. printf("Partiton changed to %d\n",tmp_part);
  138. part_num=tmp_part;
  139. return 0;
  140. }
  141. printf("Partition %d is not valid partiton\n",tmp_part);
  142. return 0;
  143. }
  144. #endif /* CFG_CMD_JFFS2 */