]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/cmd_reiser.c
Merge with /home/sr/git/u-boot/avr32
[people/ms/u-boot.git] / common / cmd_reiser.c
CommitLineData
518e2e1a
WD
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 (CONFIG_COMMANDS & CFG_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
39#ifndef CONFIG_DOS_PARTITION
40#error DOS partition support must be selected
41#endif
42
43/* #define REISER_DEBUG */
44
45#ifdef REISER_DEBUG
46#define PRINTF(fmt,args...) printf (fmt ,##args)
47#else
48#define PRINTF(fmt,args...)
49#endif
50
51static block_dev_desc_t *get_dev (char* ifname, int dev)
52{
53#if (CONFIG_COMMANDS & CFG_CMD_IDE)
54 if (strncmp(ifname,"ide",3)==0) {
55 extern block_dev_desc_t * ide_get_dev(int dev);
56 return((dev >= CFG_IDE_MAXDEVICE) ? NULL : ide_get_dev(dev));
57 }
58#endif
59#if (CONFIG_COMMANDS & CFG_CMD_SCSI)
60 if (strncmp(ifname,"scsi",4)==0) {
61 extern block_dev_desc_t * scsi_get_dev(int dev);
62 return((dev >= CFG_SCSI_MAXDEVICE) ? NULL : scsi_get_dev(dev));
63 }
64#endif
65#if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
66 if (strncmp(ifname,"usb",3)==0) {
67 extern block_dev_desc_t * usb_stor_get_dev(int dev);
68 return((dev >= USB_MAX_STOR_DEV) ? NULL : usb_stor_get_dev(dev));
69 }
70#endif
71#if defined(CONFIG_MMC)
72 if (strncmp(ifname,"mmc",3)==0) {
73 extern block_dev_desc_t * mmc_get_dev(int dev);
74 return((dev >= 1) ? NULL : mmc_get_dev(dev));
75 }
76#endif
77#if defined(CONFIG_SYSTEMACE)
78 if (strcmp(ifname,"ace")==0) {
79 extern block_dev_desc_t * systemace_get_dev(int dev);
80 return((dev >= 1) ? NULL : systemace_get_dev(dev));
81 }
82#endif
83 return NULL;
84}
85
86int do_reiserls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
87{
88 char *filename = "/";
89 int dev=0;
90 int part=1;
91 char *ep;
92 block_dev_desc_t *dev_desc=NULL;
93 int part_length;
94
95 if (argc < 3) {
96 printf ("Usage:\n%s\n", cmdtp->usage);
97 return 1;
98 }
99 dev = (int)simple_strtoul (argv[2], &ep, 16);
100 dev_desc=get_dev(argv[1],dev);
101
102 if (dev_desc == NULL) {
103 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
104 return 1;
105 }
106
107 if (*ep) {
108 if (*ep != ':') {
109 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
110 return 1;
111 }
112 part = (int)simple_strtoul(++ep, NULL, 16);
113 }
114
115 if (argc == 4) {
116 filename = argv[3];
117 }
118
119 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
120
121 if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
122 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
123 return 1;
124 }
125
126 if (!reiserfs_mount(part_length)) {
127 printf ("** Bad Reisefs partition or disk - %s %d:%d **\n", argv[1], dev, part);
128 return 1;
129 }
130
131 if (reiserfs_ls (filename)) {
132 printf ("** Error reiserfs_ls() **\n");
133 return 1;
134 };
135
136 return 0;
137}
138
139U_BOOT_CMD(
140 reiserls, 4, 1, do_reiserls,
141 "reiserls- list files in a directory (default /)\n",
142 "<interface> <dev[:part]> [directory]\n"
143 " - list files from 'dev' on 'interface' in a 'directory'\n"
144);
145
146/******************************************************************************
147 * Reiserfs boot command intepreter. Derived from diskboot
148 */
149int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
150{
151 char *filename = NULL;
152 char *ep;
153 int dev, part = 0;
154 ulong addr = 0, part_length, filelen;
155 disk_partition_t info;
156 block_dev_desc_t *dev_desc = NULL;
157 char buf [12];
158 unsigned long count;
159 char *addr_str;
160
161 switch (argc) {
162 case 3:
163 addr_str = getenv("loadaddr");
164 if (addr_str != NULL) {
165 addr = simple_strtoul (addr_str, NULL, 16);
166 } else {
167 addr = CFG_LOAD_ADDR;
168 }
169 filename = getenv ("bootfile");
170 count = 0;
171 break;
172 case 4:
173 addr = simple_strtoul (argv[3], NULL, 16);
174 filename = getenv ("bootfile");
175 count = 0;
176 break;
177 case 5:
178 addr = simple_strtoul (argv[3], NULL, 16);
179 filename = argv[4];
180 count = 0;
181 break;
182 case 6:
183 addr = simple_strtoul (argv[3], NULL, 16);
184 filename = argv[4];
185 count = simple_strtoul (argv[5], NULL, 16);
186 break;
187
188 default:
189 printf ("Usage:\n%s\n", cmdtp->usage);
190 return 1;
191 }
192
193 if (!filename) {
194 puts ("\n** No boot file defined **\n");
195 return 1;
196 }
197
198 dev = (int)simple_strtoul (argv[2], &ep, 16);
199 dev_desc=get_dev(argv[1],dev);
200 if (dev_desc==NULL) {
201 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
202 return 1;
203 }
204 if (*ep) {
205 if (*ep != ':') {
206 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
207 return 1;
208 }
209 part = (int)simple_strtoul(++ep, NULL, 16);
210 }
211
212 PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
213
214 if (part != 0) {
b05dcb58 215 if (get_partition_info (dev_desc, part, &info)) {
518e2e1a
WD
216 printf ("** Bad partition %d **\n", part);
217 return 1;
218 }
219
220 if (strncmp(info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
221 printf ("\n** Invalid partition type \"%.32s\""
222 " (expect \"" BOOT_PART_TYPE "\")\n",
223 info.type);
224 return 1;
225 }
226 PRINTF ("\nLoading from block device %s device %d, partition %d: "
227 "Name: %.32s Type: %.32s File:%s\n",
228 argv[1], dev, part, info.name, info.type, filename);
229 } else {
230 PRINTF ("\nLoading from block device %s device %d, File:%s\n",
231 argv[1], dev, filename);
232 }
233
234
235 if ((part_length = reiserfs_set_blk_dev(dev_desc, part)) == 0) {
236 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
237 return 1;
238 }
239
240 if (!reiserfs_mount(part_length)) {
241 printf ("** Bad Reisefs partition or disk - %s %d:%d **\n", argv[1], dev, part);
242 return 1;
243 }
244
245 filelen = reiserfs_open(filename);
246 if (filelen < 0) {
247 printf("** File not found %s\n", filename);
248 return 1;
249 }
250 if ((count < filelen) && (count != 0)) {
251 filelen = count;
252 }
253
254 if (reiserfs_read((char *)addr, filelen) != filelen) {
255 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
256 return 1;
257 }
258
259 /* Loading ok, update default load address */
260 load_addr = addr;
261
262 printf ("\n%ld bytes read\n", filelen);
263 sprintf(buf, "%lX", filelen);
264 setenv("filesize", buf);
265
266 return filelen;
267}
268
269U_BOOT_CMD(
270 reiserload, 6, 0, do_reiserload,
271 "reiserload- load binary file from a Reiser filesystem\n",
272 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
273 " - load binary file 'filename' from 'dev' on 'interface'\n"
274 " to address 'addr' from dos filesystem\n"
275);
276
277#endif /* CONFIG_COMMANDS & CFG_CMD_REISER */