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>
45 #ifndef CONFIG_DOS_PARTITION
46 #error DOS partition support must be selected
49 /* #define EXT2_DEBUG */
52 #define PRINTF(fmt,args...) printf (fmt ,##args)
54 #define PRINTF(fmt,args...)
57 static block_dev_desc_t *get_dev (char* ifname, int dev)
59 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
60 if (strncmp(ifname,"ide",3)==0) {
61 extern block_dev_desc_t * ide_get_dev(int dev);
62 return((dev >= CFG_IDE_MAXDEVICE) ? NULL : ide_get_dev(dev));
65 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
66 if (strncmp(ifname,"scsi",4)==0) {
67 extern block_dev_desc_t * scsi_get_dev(int dev);
68 return((dev >= CFG_SCSI_MAXDEVICE) ? NULL : scsi_get_dev(dev));
71 #if ((CONFIG_COMMANDS & CFG_CMD_USB) && defined(CONFIG_USB_STORAGE))
72 if (strncmp(ifname,"usb",3)==0) {
73 extern block_dev_desc_t * usb_stor_get_dev(int dev);
74 return((dev >= USB_MAX_STOR_DEV) ? NULL : usb_stor_get_dev(dev));
77 #if defined(CONFIG_MMC)
78 if (strncmp(ifname,"mmc",3)==0) {
79 extern block_dev_desc_t * mmc_get_dev(int dev);
80 return((dev >= 1) ? NULL : mmc_get_dev(dev));
83 #if defined(CONFIG_SYSTEMACE)
84 if (strcmp(ifname,"ace")==0) {
85 extern block_dev_desc_t * systemace_get_dev(int dev);
86 return((dev >= 1) ? NULL : systemace_get_dev(dev));
92 int do_ext2ls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
98 block_dev_desc_t *dev_desc=NULL;
102 printf ("Usage:\n%s\n", cmdtp->usage);
105 dev = (int)simple_strtoul (argv[2], &ep, 16);
106 dev_desc=get_dev(argv[1],dev);
108 if (dev_desc == NULL) {
109 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
115 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
118 part = (int)simple_strtoul(++ep, NULL, 16);
125 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
127 if ((part_length = ext2fs_set_blk_dev(dev_desc, part)) == 0) {
128 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
133 if (!ext2fs_mount(part_length)) {
134 printf ("** Bad ext2 partition or disk - %s %d:%d **\n", argv[1], dev, part);
139 if (ext2fs_ls (filename)) {
140 printf ("** Error ext2fs_ls() **\n");
151 ext2ls, 4, 1, do_ext2ls,
152 "ext2ls- list files in a directory (default /)\n",
153 "<interface> <dev[:part]> [directory]\n"
154 " - list files from 'dev' on 'interface' in a 'directory'\n"
157 /******************************************************************************
158 * Ext2fs boot command intepreter. Derived from diskboot
160 int do_ext2load (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
162 char *filename = NULL;
165 ulong addr = 0, part_length, filelen;
166 disk_partition_t info;
167 block_dev_desc_t *dev_desc = NULL;
174 addr_str = getenv("loadaddr");
175 if (addr_str != NULL) {
176 addr = simple_strtoul (addr_str, NULL, 16);
178 addr = CFG_LOAD_ADDR;
180 filename = getenv ("bootfile");
184 addr = simple_strtoul (argv[3], NULL, 16);
185 filename = getenv ("bootfile");
189 addr = simple_strtoul (argv[3], NULL, 16);
194 addr = simple_strtoul (argv[3], NULL, 16);
196 count = simple_strtoul (argv[5], NULL, 16);
200 printf ("Usage:\n%s\n", cmdtp->usage);
205 puts ("\n** No boot file defined **\n");
209 dev = (int)simple_strtoul (argv[2], &ep, 16);
210 dev_desc=get_dev(argv[1],dev);
211 if (dev_desc==NULL) {
212 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
217 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
220 part = (int)simple_strtoul(++ep, NULL, 16);
223 PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
226 if (get_partition_info (&dev_desc[dev], part, &info)) {
227 printf ("** Bad partition %d **\n", part);
231 if (strncmp(info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
232 printf ("\n** Invalid partition type \"%.32s\""
233 " (expect \"" BOOT_PART_TYPE "\")\n",
237 PRINTF ("\nLoading from block device %s device %d, partition %d: "
238 "Name: %.32s Type: %.32s File:%s\n",
239 argv[1], dev, part, info.name, info.type, filename);
241 PRINTF ("\nLoading from block device %s device %d, File:%s\n",
242 argv[1], dev, filename);
246 if ((part_length = ext2fs_set_blk_dev(dev_desc, part)) == 0) {
247 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
252 if (!ext2fs_mount(part_length)) {
253 printf ("** Bad ext2 partition or disk - %s %d:%d **\n", argv[1], dev, part);
258 filelen = ext2fs_open(filename);
260 printf("** File not found %s\n", filename);
264 if ((count < filelen) && (count != 0)) {
268 if (ext2fs_read((char *)addr, filelen) != filelen) {
269 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
276 /* Loading ok, update default load address */
279 printf ("\n%ld bytes read\n", filelen);
280 sprintf(buf, "%lX", filelen);
281 setenv("filesize", buf);
287 ext2load, 6, 0, do_ext2load,
288 "ext2load- load binary file from a Ext2 filesystem\n",
289 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
290 " - load binary file 'filename' from 'dev' on 'interface'\n"
291 " to address 'addr' from ext2 filesystem\n"
294 #endif /* CONFIG_COMMANDS & CFG_CMD_EXT2 */