3 * esd gmbh <www.esd-electronics.com>
4 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
6 * made from cmd_reiserfs by
8 * (C) Copyright 2003 - 2004
9 * Sysgo Real-Time Solutions, AG <www.elinos.com>
10 * Pavel Bartusek <pba@sysgo.com>
12 * See file CREDITS for list of people who contributed to this
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37 #if (CONFIG_COMMANDS & CFG_CMD_EXT2)
41 #include <linux/ctype.h>
42 #include <asm/byteorder.h>
44 #if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
48 #ifndef CONFIG_DOS_PARTITION
49 #error DOS partition support must be selected
52 /* #define EXT2_DEBUG */
55 #define PRINTF(fmt,args...) printf (fmt ,##args)
57 #define PRINTF(fmt,args...)
60 static block_dev_desc_t
*get_dev (char* ifname
, int dev
)
62 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
63 if (strncmp(ifname
,"ide",3)==0) {
64 extern block_dev_desc_t
* ide_get_dev(int dev
);
65 return((dev
>= CFG_IDE_MAXDEVICE
) ? NULL
: ide_get_dev(dev
));
68 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
69 if (strncmp(ifname
,"scsi",4)==0) {
70 extern block_dev_desc_t
* scsi_get_dev(int dev
);
71 return((dev
>= CFG_SCSI_MAXDEVICE
) ? NULL
: scsi_get_dev(dev
));
74 #if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
75 if (strncmp(ifname
,"usb",3)==0) {
76 extern block_dev_desc_t
* usb_stor_get_dev(int dev
);
77 return((dev
>= USB_MAX_STOR_DEV
) ? NULL
: usb_stor_get_dev(dev
));
80 #if defined(CONFIG_MMC)
81 if (strncmp(ifname
,"mmc",3)==0) {
82 extern block_dev_desc_t
* mmc_get_dev(int dev
);
83 return((dev
>= 1) ? NULL
: mmc_get_dev(dev
));
86 #if defined(CONFIG_SYSTEMACE)
87 if (strcmp(ifname
,"ace")==0) {
88 extern block_dev_desc_t
* systemace_get_dev(int dev
);
89 return((dev
>= 1) ? NULL
: systemace_get_dev(dev
));
95 int do_ext2ls (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
101 block_dev_desc_t
*dev_desc
=NULL
;
105 printf ("Usage:\n%s\n", cmdtp
->usage
);
108 dev
= (int)simple_strtoul (argv
[2], &ep
, 16);
109 dev_desc
=get_dev(argv
[1],dev
);
111 if (dev_desc
== NULL
) {
112 printf ("\n** Block device %s %d not supported\n", argv
[1], dev
);
118 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
121 part
= (int)simple_strtoul(++ep
, NULL
, 16);
128 PRINTF("Using device %s %d:%d, directory: %s\n", argv
[1], dev
, part
, filename
);
130 if ((part_length
= ext2fs_set_blk_dev(dev_desc
, part
)) == 0) {
131 printf ("** Bad partition - %s %d:%d **\n", argv
[1], dev
, part
);
136 if (!ext2fs_mount(part_length
)) {
137 printf ("** Bad ext2 partition or disk - %s %d:%d **\n", argv
[1], dev
, part
);
142 if (ext2fs_ls (filename
)) {
143 printf ("** Error ext2fs_ls() **\n");
154 ext2ls
, 4, 1, do_ext2ls
,
155 "ext2ls - list files in a directory (default /)\n",
156 "<interface> <dev[:part]> [directory]\n"
157 " - list files from 'dev' on 'interface' in a 'directory'\n"
160 /******************************************************************************
161 * Ext2fs boot command intepreter. Derived from diskboot
163 int do_ext2load (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
165 char *filename
= NULL
;
168 ulong addr
= 0, part_length
, filelen
;
169 disk_partition_t info
;
170 block_dev_desc_t
*dev_desc
= NULL
;
177 addr_str
= getenv("loadaddr");
178 if (addr_str
!= NULL
) {
179 addr
= simple_strtoul (addr_str
, NULL
, 16);
181 addr
= CFG_LOAD_ADDR
;
183 filename
= getenv ("bootfile");
187 addr
= simple_strtoul (argv
[3], NULL
, 16);
188 filename
= getenv ("bootfile");
192 addr
= simple_strtoul (argv
[3], NULL
, 16);
197 addr
= simple_strtoul (argv
[3], NULL
, 16);
199 count
= simple_strtoul (argv
[5], NULL
, 16);
203 printf ("Usage:\n%s\n", cmdtp
->usage
);
208 puts ("\n** No boot file defined **\n");
212 dev
= (int)simple_strtoul (argv
[2], &ep
, 16);
213 dev_desc
=get_dev(argv
[1],dev
);
214 if (dev_desc
==NULL
) {
215 printf ("\n** Block device %s %d not supported\n", argv
[1], dev
);
220 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
223 part
= (int)simple_strtoul(++ep
, NULL
, 16);
226 PRINTF("Using device %s%d, partition %d\n", argv
[1], dev
, part
);
229 if (get_partition_info (dev_desc
, part
, &info
)) {
230 printf ("** Bad partition %d **\n", part
);
234 if (strncmp((char *)info
.type
, BOOT_PART_TYPE
, sizeof(info
.type
)) != 0) {
235 printf ("\n** Invalid partition type \"%.32s\""
236 " (expect \"" BOOT_PART_TYPE
"\")\n",
240 PRINTF ("\nLoading from block device %s device %d, partition %d: "
241 "Name: %.32s Type: %.32s File:%s\n",
242 argv
[1], dev
, part
, info
.name
, info
.type
, filename
);
244 PRINTF ("\nLoading from block device %s device %d, File:%s\n",
245 argv
[1], dev
, filename
);
249 if ((part_length
= ext2fs_set_blk_dev(dev_desc
, part
)) == 0) {
250 printf ("** Bad partition - %s %d:%d **\n", argv
[1], dev
, part
);
255 if (!ext2fs_mount(part_length
)) {
256 printf ("** Bad ext2 partition or disk - %s %d:%d **\n", argv
[1], dev
, part
);
261 filelen
= ext2fs_open(filename
);
263 printf("** File not found %s\n", filename
);
267 if ((count
< filelen
) && (count
!= 0)) {
271 if (ext2fs_read((char *)addr
, filelen
) != filelen
) {
272 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename
, argv
[1], dev
, part
);
279 /* Loading ok, update default load address */
282 printf ("\n%ld bytes read\n", filelen
);
283 sprintf(buf
, "%lX", filelen
);
284 setenv("filesize", buf
);
290 ext2load
, 6, 0, do_ext2load
,
291 "ext2load- load binary file from a Ext2 filesystem\n",
292 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
293 " - load binary file 'filename' from 'dev' on 'interface'\n"
294 " to address 'addr' from ext2 filesystem\n"
297 #endif /* CONFIG_COMMANDS & CFG_CMD_EXT2 */