cmd_reiser.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 * const 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. return cmd_usage(cmdtp);
  55. dev = (int)simple_strtoul (argv[2], &ep, 16);
  56. dev_desc = get_dev(argv[1],dev);
  57. if (dev_desc == NULL) {
  58. printf ("\n** Block device %s %d not supported\n", argv[1], dev);
  59. return 1;
  60. }
  61. if (*ep) {
  62. if (*ep != ':') {
  63. puts ("\n** Invalid boot device, use `dev[:part]' **\n");
  64. return 1;
  65. }
  66. part = (int)simple_strtoul(++ep, NULL, 16);
  67. }
  68. if (argc == 4) {
  69. filename = argv[3];
  70. }
  71. PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
  72. if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
  73. printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
  74. return 1;
  75. }
  76. if (!reiserfs_mount(part_length)) {
  77. printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
  78. return 1;
  79. }
  80. if (reiserfs_ls (filename)) {
  81. printf ("** Error reiserfs_ls() **\n");
  82. return 1;
  83. };
  84. return 0;
  85. }
  86. U_BOOT_CMD(
  87. reiserls, 4, 1, do_reiserls,
  88. "list files in a directory (default /)",
  89. "<interface> <dev[:part]> [directory]\n"
  90. " - list files from 'dev' on 'interface' in a 'directory'"
  91. );
  92. /******************************************************************************
  93. * Reiserfs boot command intepreter. Derived from diskboot
  94. */
  95. int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  96. {
  97. char *filename = NULL;
  98. char *ep;
  99. int dev, part = 0;
  100. ulong addr = 0, part_length, filelen;
  101. disk_partition_t info;
  102. block_dev_desc_t *dev_desc = NULL;
  103. char buf [12];
  104. unsigned long count;
  105. char *addr_str;
  106. switch (argc) {
  107. case 3:
  108. addr_str = getenv("loadaddr");
  109. if (addr_str != NULL) {
  110. addr = simple_strtoul (addr_str, NULL, 16);
  111. } else {
  112. addr = CONFIG_SYS_LOAD_ADDR;
  113. }
  114. filename = getenv ("bootfile");
  115. count = 0;
  116. break;
  117. case 4:
  118. addr = simple_strtoul (argv[3], NULL, 16);
  119. filename = getenv ("bootfile");
  120. count = 0;
  121. break;
  122. case 5:
  123. addr = simple_strtoul (argv[3], NULL, 16);
  124. filename = argv[4];
  125. count = 0;
  126. break;
  127. case 6:
  128. addr = simple_strtoul (argv[3], NULL, 16);
  129. filename = argv[4];
  130. count = simple_strtoul (argv[5], NULL, 16);
  131. break;
  132. default:
  133. return cmd_usage(cmdtp);
  134. }
  135. if (!filename) {
  136. puts ("\n** No boot file defined **\n");
  137. return 1;
  138. }
  139. dev = (int)simple_strtoul (argv[2], &ep, 16);
  140. dev_desc = get_dev(argv[1],dev);
  141. if (dev_desc==NULL) {
  142. printf ("\n** Block device %s %d not supported\n", argv[1], dev);
  143. return 1;
  144. }
  145. if (*ep) {
  146. if (*ep != ':') {
  147. puts ("\n** Invalid boot device, use `dev[:part]' **\n");
  148. return 1;
  149. }
  150. part = (int)simple_strtoul(++ep, NULL, 16);
  151. }
  152. PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
  153. if (part != 0) {
  154. if (get_partition_info (dev_desc, part, &info)) {
  155. printf ("** Bad partition %d **\n", part);
  156. return 1;
  157. }
  158. if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
  159. printf ("\n** Invalid partition type \"%.32s\""
  160. " (expect \"" BOOT_PART_TYPE "\")\n",
  161. info.type);
  162. return 1;
  163. }
  164. PRINTF ("\nLoading from block device %s device %d, partition %d: "
  165. "Name: %.32s Type: %.32s File:%s\n",
  166. argv[1], dev, part, info.name, info.type, filename);
  167. } else {
  168. PRINTF ("\nLoading from block device %s device %d, File:%s\n",
  169. argv[1], dev, filename);
  170. }
  171. if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
  172. printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
  173. return 1;
  174. }
  175. if (!reiserfs_mount(part_length)) {
  176. printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n", argv[1], dev, part);
  177. return 1;
  178. }
  179. filelen = reiserfs_open(filename);
  180. if (filelen < 0) {
  181. printf("** File not found %s\n", filename);
  182. return 1;
  183. }
  184. if ((count < filelen) && (count != 0)) {
  185. filelen = count;
  186. }
  187. if (reiserfs_read((char *)addr, filelen) != filelen) {
  188. printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
  189. return 1;
  190. }
  191. /* Loading ok, update default load address */
  192. load_addr = addr;
  193. printf ("\n%ld bytes read\n", filelen);
  194. sprintf(buf, "%lX", filelen);
  195. setenv("filesize", buf);
  196. return filelen;
  197. }
  198. U_BOOT_CMD(
  199. reiserload, 6, 0, do_reiserload,
  200. "load binary file from a Reiser filesystem",
  201. "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
  202. " - load binary file 'filename' from 'dev' on 'interface'\n"
  203. " to address 'addr' from dos filesystem"
  204. );