cmd_reiser.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * (C) Copyright 2003 - 2004
  3. * Sysgo Real-Time Solutions, AG <www.elinos.com>
  4. * Pavel Bartusek <pba@sysgo.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. *
  24. */
  25. /*
  26. * Reiserfs support
  27. */
  28. #include <common.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 <reiserfs.h>
  35. #include <part.h>
  36. #ifndef CONFIG_DOS_PARTITION
  37. #error DOS partition support must be selected
  38. #endif
  39. /* #define REISER_DEBUG */
  40. #ifdef REISER_DEBUG
  41. #define PRINTF(fmt,args...) printf (fmt ,##args)
  42. #else
  43. #define PRINTF(fmt,args...)
  44. #endif
  45. int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  46. {
  47. char *filename = "/";
  48. int dev=0;
  49. int part=1;
  50. char *ep;
  51. block_dev_desc_t *dev_desc=NULL;
  52. int part_length;
  53. if (argc < 3) {
  54. cmd_usage(cmdtp);
  55. return 1;
  56. }
  57. dev = (int)simple_strtoul (argv[2], &ep, 16);
  58. dev_desc = get_dev(argv[1],dev);
  59. if (dev_desc == NULL) {
  60. printf ("\n** Block device %s %d not supported\n", argv[1], dev);
  61. return 1;
  62. }
  63. if (*ep) {
  64. if (*ep != ':') {
  65. puts ("\n** Invalid boot device, use `dev[:part]' **\n");
  66. return 1;
  67. }
  68. part = (int)simple_strtoul(++ep, NULL, 16);
  69. }
  70. if (argc == 4) {
  71. filename = argv[3];
  72. }
  73. PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
  74. if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
  75. printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
  76. return 1;
  77. }
  78. if (!reiserfs_mount(part_length)) {
  79. printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
  80. return 1;
  81. }
  82. if (reiserfs_ls (filename)) {
  83. printf ("** Error reiserfs_ls() **\n");
  84. return 1;
  85. };
  86. return 0;
  87. }
  88. U_BOOT_CMD(
  89. reiserls, 4, 1, do_reiserls,
  90. "list files in a directory (default /)",
  91. "<interface> <dev[:part]> [directory]\n"
  92. " - list files from 'dev' on 'interface' in a 'directory'"
  93. );
  94. /******************************************************************************
  95. * Reiserfs boot command intepreter. Derived from diskboot
  96. */
  97. int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  98. {
  99. char *filename = NULL;
  100. char *ep;
  101. int dev, part = 0;
  102. ulong addr = 0, part_length, filelen;
  103. disk_partition_t info;
  104. block_dev_desc_t *dev_desc = NULL;
  105. char buf [12];
  106. unsigned long count;
  107. char *addr_str;
  108. switch (argc) {
  109. case 3:
  110. addr_str = getenv("loadaddr");
  111. if (addr_str != NULL) {
  112. addr = simple_strtoul (addr_str, NULL, 16);
  113. } else {
  114. addr = CONFIG_SYS_LOAD_ADDR;
  115. }
  116. filename = getenv ("bootfile");
  117. count = 0;
  118. break;
  119. case 4:
  120. addr = simple_strtoul (argv[3], NULL, 16);
  121. filename = getenv ("bootfile");
  122. count = 0;
  123. break;
  124. case 5:
  125. addr = simple_strtoul (argv[3], NULL, 16);
  126. filename = argv[4];
  127. count = 0;
  128. break;
  129. case 6:
  130. addr = simple_strtoul (argv[3], NULL, 16);
  131. filename = argv[4];
  132. count = simple_strtoul (argv[5], NULL, 16);
  133. break;
  134. default:
  135. cmd_usage(cmdtp);
  136. return 1;
  137. }
  138. if (!filename) {
  139. puts ("\n** No boot file defined **\n");
  140. return 1;
  141. }
  142. dev = (int)simple_strtoul (argv[2], &ep, 16);
  143. dev_desc = get_dev(argv[1],dev);
  144. if (dev_desc==NULL) {
  145. printf ("\n** Block device %s %d not supported\n", argv[1], dev);
  146. return 1;
  147. }
  148. if (*ep) {
  149. if (*ep != ':') {
  150. puts ("\n** Invalid boot device, use `dev[:part]' **\n");
  151. return 1;
  152. }
  153. part = (int)simple_strtoul(++ep, NULL, 16);
  154. }
  155. PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
  156. if (part != 0) {
  157. if (get_partition_info (dev_desc, part, &info)) {
  158. printf ("** Bad partition %d **\n", part);
  159. return 1;
  160. }
  161. if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
  162. printf ("\n** Invalid partition type \"%.32s\""
  163. " (expect \"" BOOT_PART_TYPE "\")\n",
  164. info.type);
  165. return 1;
  166. }
  167. PRINTF ("\nLoading from block device %s device %d, partition %d: "
  168. "Name: %.32s Type: %.32s File:%s\n",
  169. argv[1], dev, part, info.name, info.type, filename);
  170. } else {
  171. PRINTF ("\nLoading from block device %s device %d, File:%s\n",
  172. argv[1], dev, filename);
  173. }
  174. if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
  175. printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
  176. return 1;
  177. }
  178. if (!reiserfs_mount(part_length)) {
  179. printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
  180. return 1;
  181. }
  182. filelen = reiserfs_open(filename);
  183. if (filelen < 0) {
  184. printf("** File not found %s\n", filename);
  185. return 1;
  186. }
  187. if ((count < filelen) && (count != 0)) {
  188. filelen = count;
  189. }
  190. if (reiserfs_read((char *)addr, filelen) != filelen) {
  191. printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
  192. return 1;
  193. }
  194. /* Loading ok, update default load address */
  195. load_addr = addr;
  196. printf ("\n%ld bytes read\n", filelen);
  197. sprintf(buf, "%lX", filelen);
  198. setenv("filesize", buf);
  199. return filelen;
  200. }
  201. U_BOOT_CMD(
  202. reiserload, 6, 0, do_reiserload,
  203. "load binary file from a Reiser filesystem",
  204. "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
  205. " - load binary file 'filename' from 'dev' on 'interface'\n"
  206. " to address 'addr' from dos filesystem"
  207. );