2 * (C) Copyright 2011 - 2012 Samsung Electronics
3 * EXT2/4 filesystem implementation in Uboot by
4 * Uma Shankar <uma.shankar@samsung.com>
5 * Manjunatha C Achar <a.manjunatha@samsung.com>
8 * made from existing cmd_ext2.c file of Uboot
11 * esd gmbh <www.esd-electronics.com>
12 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
14 * made from cmd_reiserfs by
16 * (C) Copyright 2003 - 2004
17 * Sysgo Real-Time Solutions, AG <www.elinos.com>
18 * Pavel Bartusek <pba@sysgo.com>
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License as
22 * published by the Free Software Foundation; either version 2 of
23 * the License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
39 * 0.1 - Newly created file for ext4fs support. Taken from cmd_ext2.c
40 * file in uboot. Added ext4fs ls load and write support.
48 #include <linux/ctype.h>
49 #include <asm/byteorder.h>
50 #include <ext_common.h>
52 #include <linux/stat.h>
55 #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE)
59 #if !defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_EFI_PARTITION)
60 #error DOS or EFI partition support must be selected
63 #define DOS_PART_MAGIC_OFFSET 0x1fe
64 #define DOS_FS_TYPE_OFFSET 0x36
65 #define DOS_FS32_TYPE_OFFSET 0x52
67 int do_ext_load(cmd_tbl_t *cmdtp, int flag, int argc,
70 char *filename = NULL;
74 disk_partition_t info;
75 block_dev_desc_t *dev_desc;
81 addr = simple_strtoul(argv[3], NULL, 16);
82 filename = getenv("bootfile");
85 addr_str = getenv("loadaddr");
87 addr = simple_strtoul(addr_str, NULL, 16);
89 addr = CONFIG_SYS_LOAD_ADDR;
99 count = simple_strtoul(argv[5], NULL, 16);
103 return cmd_usage(cmdtp);
107 puts("** No boot file defined **\n");
111 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
116 printf("Loading file \"%s\" from %s device %d%c%c\n",
117 filename, argv[1], dev,
118 part ? ':' : ' ', part ? part + '0' : ' ');
120 ext4fs_set_blk_dev(dev_desc, &info);
122 if (!ext4fs_mount(info.size)) {
123 printf("** Bad ext2 partition or disk - %s %d:%d **\n",
129 filelen = ext4fs_open(filename);
131 printf("** File not found %s\n", filename);
135 if ((count < filelen) && (count != 0))
138 if (ext4fs_read((char *)addr, filelen) != filelen) {
139 printf("** Unable to read \"%s\" from %s %d:%d **\n",
140 filename, argv[1], dev, part);
146 /* Loading ok, update default load address */
149 printf("%d bytes read\n", filelen);
150 sprintf(buf, "%X", filelen);
151 setenv("filesize", buf);
158 int do_ext_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
160 const char *filename = "/";
163 block_dev_desc_t *dev_desc;
164 disk_partition_t info;
167 return cmd_usage(cmdtp);
169 part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
177 ext4fs_set_blk_dev(dev_desc, &info);
179 if (!ext4fs_mount(info.size)) {
180 printf("** Bad ext2 partition or disk - %s %d:%d **\n",
186 if (ext4fs_ls(filename)) {
187 printf("** Error extfs_ls() **\n");