]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_reiser.c
Merge with /home/wd/git/u-boot/custodian/u-boot-mpc83xx
[karo-tx-uboot.git] / common / cmd_reiser.c
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 /*
27  * Reiserfs support
28  */
29 #include <common.h>
30
31 #if defined(CONFIG_CMD_REISER)
32 #include <config.h>
33 #include <command.h>
34 #include <image.h>
35 #include <linux/ctype.h>
36 #include <asm/byteorder.h>
37 #include <reiserfs.h>
38 #include <part.h>
39
40 #ifndef CONFIG_DOS_PARTITION
41 #error DOS partition support must be selected
42 #endif
43
44 /* #define      REISER_DEBUG */
45
46 #ifdef  REISER_DEBUG
47 #define PRINTF(fmt,args...)     printf (fmt ,##args)
48 #else
49 #define PRINTF(fmt,args...)
50 #endif
51
52 int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
53 {
54         char *filename = "/";
55         int dev=0;
56         int part=1;
57         char *ep;
58         block_dev_desc_t *dev_desc=NULL;
59         int part_length;
60
61         if (argc < 3) {
62                 printf ("Usage:\n%s\n", cmdtp->usage);
63                 return 1;
64         }
65         dev = (int)simple_strtoul (argv[2], &ep, 16);
66         dev_desc = get_dev(argv[1],dev);
67
68         if (dev_desc == NULL) {
69                 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
70                 return 1;
71         }
72
73         if (*ep) {
74                 if (*ep != ':') {
75                         puts ("\n** Invalid boot device, use `dev[:part]' **\n");
76                         return 1;
77                 }
78                 part = (int)simple_strtoul(++ep, NULL, 16);
79         }
80
81         if (argc == 4) {
82             filename = argv[3];
83         }
84
85         PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
86
87         if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
88                 printf ("** Bad partition - %s %d:%d **\n",  argv[1], dev, part);
89                 return 1;
90         }
91
92         if (!reiserfs_mount(part_length)) {
93                 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n",  argv[1], dev, part);
94                 return 1;
95         }
96
97         if (reiserfs_ls (filename)) {
98                 printf ("** Error reiserfs_ls() **\n");
99                 return 1;
100         };
101
102         return 0;
103 }
104
105 U_BOOT_CMD(
106         reiserls,       4,      1,      do_reiserls,
107         "reiserls- list files in a directory (default /)\n",
108         "<interface> <dev[:part]> [directory]\n"
109         "    - list files from 'dev' on 'interface' in a 'directory'\n"
110 );
111
112 /******************************************************************************
113  * Reiserfs boot command intepreter. Derived from diskboot
114  */
115 int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
116 {
117         char *filename = NULL;
118         char *ep;
119         int dev, part = 0;
120         ulong addr = 0, part_length, filelen;
121         disk_partition_t info;
122         block_dev_desc_t *dev_desc = NULL;
123         char buf [12];
124         unsigned long count;
125         char *addr_str;
126
127         switch (argc) {
128         case 3:
129                 addr_str = getenv("loadaddr");
130                 if (addr_str != NULL) {
131                         addr = simple_strtoul (addr_str, NULL, 16);
132                 } else {
133                         addr = CFG_LOAD_ADDR;
134                 }
135                 filename = getenv ("bootfile");
136                 count = 0;
137                 break;
138         case 4:
139                 addr = simple_strtoul (argv[3], NULL, 16);
140                 filename = getenv ("bootfile");
141                 count = 0;
142                 break;
143         case 5:
144                 addr = simple_strtoul (argv[3], NULL, 16);
145                 filename = argv[4];
146                 count = 0;
147                 break;
148         case 6:
149                 addr = simple_strtoul (argv[3], NULL, 16);
150                 filename = argv[4];
151                 count = simple_strtoul (argv[5], NULL, 16);
152                 break;
153
154         default:
155                 printf ("Usage:\n%s\n", cmdtp->usage);
156                 return 1;
157         }
158
159         if (!filename) {
160                 puts ("\n** No boot file defined **\n");
161                 return 1;
162         }
163
164         dev = (int)simple_strtoul (argv[2], &ep, 16);
165         dev_desc = get_dev(argv[1],dev);
166         if (dev_desc==NULL) {
167                 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
168                 return 1;
169         }
170         if (*ep) {
171                 if (*ep != ':') {
172                         puts ("\n** Invalid boot device, use `dev[:part]' **\n");
173                         return 1;
174                 }
175                 part = (int)simple_strtoul(++ep, NULL, 16);
176         }
177
178         PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
179
180         if (part != 0) {
181                 if (get_partition_info (dev_desc, part, &info)) {
182                         printf ("** Bad partition %d **\n", part);
183                         return 1;
184                 }
185
186                 if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
187                         printf ("\n** Invalid partition type \"%.32s\""
188                                 " (expect \"" BOOT_PART_TYPE "\")\n",
189                                 info.type);
190                         return 1;
191                 }
192                 PRINTF ("\nLoading from block device %s device %d, partition %d: "
193                         "Name: %.32s  Type: %.32s  File:%s\n",
194                         argv[1], dev, part, info.name, info.type, filename);
195         } else {
196                 PRINTF ("\nLoading from block device %s device %d, File:%s\n",
197                         argv[1], dev, filename);
198         }
199
200
201         if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
202                 printf ("** Bad partition - %s %d:%d **\n",  argv[1], dev, part);
203                 return 1;
204         }
205
206         if (!reiserfs_mount(part_length)) {
207                 printf ("** Bad Reiserfs partition or disk - %s %d:%d **\n",  argv[1], dev, part);
208                 return 1;
209         }
210
211         filelen = reiserfs_open(filename);
212         if (filelen < 0) {
213                 printf("** File not found %s\n", filename);
214                 return 1;
215         }
216         if ((count < filelen) && (count != 0)) {
217             filelen = count;
218         }
219
220         if (reiserfs_read((char *)addr, filelen) != filelen) {
221                 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
222                 return 1;
223         }
224
225         /* Loading ok, update default load address */
226         load_addr = addr;
227
228         printf ("\n%ld bytes read\n", filelen);
229         sprintf(buf, "%lX", filelen);
230         setenv("filesize", buf);
231
232         return filelen;
233 }
234
235 U_BOOT_CMD(
236         reiserload,     6,      0,      do_reiserload,
237         "reiserload- load binary file from a Reiser filesystem\n",
238         "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
239         "    - load binary file 'filename' from 'dev' on 'interface'\n"
240         "      to address 'addr' from dos filesystem\n"
241 );
242
243 #endif