]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_ext2.c
6ee60c66f2169b672c3e9ffd8d2f4310d2351552
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,
40 #include <linux/ctype.h>
41 #include <asm/byteorder.h>
43 #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
47 #if !defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_EFI_PARTITION)
48 #error DOS or EFI partition support must be selected
51 /* #define EXT2_DEBUG */
54 #define PRINTF(fmt,args...) printf (fmt ,##args)
56 #define PRINTF(fmt,args...)
59 int do_ext2ls (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
65 block_dev_desc_t
*dev_desc
=NULL
;
72 dev
= (int)simple_strtoul (argv
[2], &ep
, 16);
73 dev_desc
= get_dev(argv
[1],dev
);
75 if (dev_desc
== NULL
) {
76 printf ("\n** Block device %s %d not supported\n", argv
[1], dev
);
82 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
85 part
= (int)simple_strtoul(++ep
, NULL
, 16);
92 PRINTF("Using device %s %d:%d, directory: %s\n", argv
[1], dev
, part
, filename
);
94 if ((part_length
= ext2fs_set_blk_dev(dev_desc
, part
)) == 0) {
95 printf ("** Bad partition - %s %d:%d **\n", argv
[1], dev
, part
);
100 if (!ext2fs_mount(part_length
)) {
101 printf ("** Bad ext2 partition or disk - %s %d:%d **\n", argv
[1], dev
, part
);
106 if (ext2fs_ls (filename
)) {
107 printf ("** Error ext2fs_ls() **\n");
118 ext2ls
, 4, 1, do_ext2ls
,
119 "list files in a directory (default /)",
120 "<interface> <dev[:part]> [directory]\n"
121 " - list files from 'dev' on 'interface' in a 'directory'"
124 /******************************************************************************
125 * Ext2fs boot command intepreter. Derived from diskboot
127 int do_ext2load (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
129 char *filename
= NULL
;
132 ulong addr
= 0, part_length
;
134 disk_partition_t info
;
135 block_dev_desc_t
*dev_desc
= NULL
;
142 addr_str
= getenv("loadaddr");
143 if (addr_str
!= NULL
) {
144 addr
= simple_strtoul (addr_str
, NULL
, 16);
146 addr
= CONFIG_SYS_LOAD_ADDR
;
148 filename
= getenv ("bootfile");
152 addr
= simple_strtoul (argv
[3], NULL
, 16);
153 filename
= getenv ("bootfile");
157 addr
= simple_strtoul (argv
[3], NULL
, 16);
162 addr
= simple_strtoul (argv
[3], NULL
, 16);
164 count
= simple_strtoul (argv
[5], NULL
, 16);
173 puts ("\n** No boot file defined **\n");
177 dev
= (int)simple_strtoul (argv
[2], &ep
, 16);
178 dev_desc
= get_dev(argv
[1],dev
);
179 if (dev_desc
==NULL
) {
180 printf ("\n** Block device %s %d not supported\n", argv
[1], dev
);
185 puts ("\n** Invalid boot device, use `dev[:part]' **\n");
188 part
= (int)simple_strtoul(++ep
, NULL
, 16);
191 PRINTF("Using device %s%d, partition %d\n", argv
[1], dev
, part
);
194 if (get_partition_info (dev_desc
, part
, &info
)) {
195 printf ("** Bad partition %d **\n", part
);
199 if (strncmp((char *)info
.type
, BOOT_PART_TYPE
, sizeof(info
.type
)) != 0) {
200 printf ("\n** Invalid partition type \"%.32s\""
201 " (expect \"" BOOT_PART_TYPE
"\")\n",
205 PRINTF ("\nLoading from block device %s device %d, partition %d: "
206 "Name: %.32s Type: %.32s File:%s\n",
207 argv
[1], dev
, part
, info
.name
, info
.type
, filename
);
209 PRINTF ("\nLoading from block device %s device %d, File:%s\n",
210 argv
[1], dev
, filename
);
214 if ((part_length
= ext2fs_set_blk_dev(dev_desc
, part
)) == 0) {
215 printf ("** Bad partition - %s %d:%d **\n", argv
[1], dev
, part
);
220 if (!ext2fs_mount(part_length
)) {
221 printf ("** Bad ext2 partition or disk - %s %d:%d **\n", argv
[1], dev
, part
);
226 filelen
= ext2fs_open(filename
);
228 printf("** File not found %s\n", filename
);
232 if ((count
< filelen
) && (count
!= 0)) {
236 if (ext2fs_read((char *)addr
, filelen
) != filelen
) {
237 printf("\n** Unable to read \"%s\" from %s %d:%d **\n", filename
, argv
[1], dev
, part
);
244 /* Loading ok, update default load address */
247 printf ("\n%d bytes read\n", filelen
);
248 sprintf(buf
, "%X", filelen
);
249 setenv("filesize", buf
);
255 ext2load
, 6, 0, do_ext2load
,
256 "load binary file from a Ext2 filesystem",
257 "<interface> <dev[:part]> [addr] [filename] [bytes]\n"
258 " - load binary file 'filename' from 'dev' on 'interface'\n"
259 " to address 'addr' from ext2 filesystem"