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,
38 #if (CONFIG_COMMANDS & CFG_CMD_EXT2) || defined(CONFIG_CMD_EXT2)
42 #include <linux/ctype.h>
43 #include <asm/byteorder.h>
45 #if (((CONFIG_COMMANDS & CFG_CMD_USB) || defined(CONFIG_CMD_USB)) && defined(CONFIG_USB_STORAGE))
49 #ifndef CONFIG_DOS_PARTITION
50 #error DOS partition support must be selected
53 /* #define EXT2_DEBUG */
56 #define PRINTF(fmt,args...) printf (fmt ,##args)
58 #define PRINTF(fmt,args...)
61 int do_ext2ls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
67 block_dev_desc_t *dev_desc=NULL;
71 printf ("Usage:\n%s\n", cmdtp->usage);
74 dev = (int)simple_strtoul (argv[2], &ep, 16);
75 dev_desc = get_dev(argv[1],dev);
77 if (dev_desc == NULL) {
78 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
84 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
87 part = (int)simple_strtoul(++ep, NULL, 16);
94 PRINTF("Using device %s %d:%d, directory: %s\n", argv[1], dev, part, filename);
96 if ((part_length = ext2fs_set_blk_dev(dev_desc, part)) == 0) {
97 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
102 if (!ext2fs_mount(part_length)) {
103 printf ("** Bad ext2 partition or disk - %s %d:%d **\n", argv[1], dev, part);
108 if (ext2fs_ls (filename)) {
109 printf ("** Error ext2fs_ls() **\n");
120 ext2ls, 4, 1, do_ext2ls,
121 "ext2ls - list files in a directory (default /)\n",
122 "<interface> <dev[:part]> [directory]\n"
123 " - list files from 'dev' on 'interface' in a 'directory'\n"
126 /******************************************************************************
127 * Ext2fs boot command intepreter. Derived from diskboot
129 int do_ext2load (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
131 char *filename = NULL;
134 ulong addr = 0, part_length, filelen;
135 disk_partition_t info;
136 block_dev_desc_t *dev_desc = NULL;
143 addr_str = getenv("loadaddr");
144 if (addr_str != NULL) {
145 addr = simple_strtoul (addr_str, NULL, 16);
147 addr = CFG_LOAD_ADDR;
149 filename = getenv ("bootfile");
153 addr = simple_strtoul (argv[3], NULL, 16);
154 filename = getenv ("bootfile");
158 addr = simple_strtoul (argv[3], NULL, 16);
163 addr = simple_strtoul (argv[3], NULL, 16);
165 count = simple_strtoul (argv[5], NULL, 16);
169 printf ("Usage:\n%s\n", cmdtp->usage);
174 puts ("\n** No boot file defined **\n");
178 dev = (int)simple_strtoul (argv[2], &ep, 16);
179 dev_desc = get_dev(argv[1],dev);
180 if (dev_desc==NULL) {
181 printf ("\n** Block device %s %d not supported\n", argv[1], dev);
186 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
189 part = (int)simple_strtoul(++ep, NULL, 16);
192 PRINTF("Using device %s%d, partition %d\n", argv[1], dev, part);
195 if (get_partition_info (dev_desc, part, &info)) {
196 printf ("** Bad partition %d **\n", part);
200 if (strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
201 printf ("\n** Invalid partition type \"%.32s\""
202 " (expect \"" BOOT_PART_TYPE "\")\n",
206 PRINTF ("\nLoading from block device %s device %d, partition %d: "
207 "Name: %.32s Type: %.32s File:%s\n",
208 argv[1], dev, part, info.name, info.type, filename);
210 PRINTF ("\nLoading from block device %s device %d, File:%s\n",
211 argv[1], dev, filename);
215 if ((part_length = ext2fs_set_blk_dev(dev_desc, part)) == 0) {
216 printf ("** Bad partition - %s %d:%d **\n", argv[1], dev, part);
221 if (!ext2fs_mount(part_length)) {
222 printf ("** Bad ext2 partition or disk - %s %d:%d **\n", argv[1], dev, part);
227 filelen = ext2fs_open(filename);
229 printf("** File not found %s\n", filename);
233 if ((count < filelen) && (count != 0)) {
237 if (ext2fs_read((char *)addr, filelen) != filelen) {
238 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename, argv[1], dev, part);
245 /* Loading ok, update default load address */
248 printf ("\n%ld bytes read\n", filelen);
249 sprintf(buf, "%lX", filelen);
250 setenv("filesize", buf);
256 ext2load, 6, 0, do_ext2load,
257 "ext2load- load binary file from a Ext2 filesystem\n",
258 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
259 " - load binary file 'filename' from 'dev' on 'interface'\n"
260 " to address 'addr' from ext2 filesystem\n"
263 #endif /* CONFIG_COMMANDS & CFG_CMD_EXT2 */