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;
73 unsigned long part = 1;
77 disk_partition_t info;
83 addr = simple_strtoul(argv[3], NULL, 16);
84 filename = getenv("bootfile");
87 addr_str = getenv("loadaddr");
89 addr = simple_strtoul(addr_str, NULL, 16);
91 addr = CONFIG_SYS_LOAD_ADDR;
101 count = simple_strtoul(argv[5], NULL, 16);
105 return cmd_usage(cmdtp);
109 puts("** No boot file defined **\n");
113 dev = (int)simple_strtoul(argv[2], &ep, 16);
114 ext4_dev_desc = get_dev(argv[1], dev);
115 if (ext4_dev_desc == NULL) {
116 printf("** Block device %s %d not supported\n", argv[1], dev);
122 puts("** Invalid boot device, use `dev[:part]' **\n");
125 part = simple_strtoul(++ep, NULL, 16);
129 if (get_partition_info(ext4_dev_desc, part, &info)) {
130 printf("** Bad partition %lu **\n", part);
134 if (strncmp((char *)info.type, BOOT_PART_TYPE,
135 strlen(BOOT_PART_TYPE)) != 0) {
136 printf("** Invalid partition type \"%s\""
137 " (expect \"" BOOT_PART_TYPE "\")\n", info.type);
140 printf("Loading file \"%s\" "
141 "from %s device %d:%lu %s\n",
142 filename, argv[1], dev, part, info.name);
144 printf("Loading file \"%s\" from %s device %d\n",
145 filename, argv[1], dev);
148 part_length = ext4fs_set_blk_dev(ext4_dev_desc, part);
149 if (part_length == 0) {
150 printf("**Bad partition - %s %d:%lu **\n", argv[1], dev, part);
155 if (!ext4fs_mount(part_length)) {
156 printf("** Bad ext2 partition or disk - %s %d:%lu **\n",
162 filelen = ext4fs_open(filename);
164 printf("** File not found %s\n", filename);
168 if ((count < filelen) && (count != 0))
171 if (ext4fs_read((char *)addr, filelen) != filelen) {
172 printf("** Unable to read \"%s\" from %s %d:%lu **\n",
173 filename, argv[1], dev, part);
179 /* Loading ok, update default load address */
182 printf("%d bytes read\n", filelen);
183 sprintf(buf, "%X", filelen);
184 setenv("filesize", buf);
191 int do_ext_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
193 const char *filename = "/";
195 unsigned long part = 1;
199 return cmd_usage(cmdtp);
201 dev = (int)simple_strtoul(argv[2], &ep, 16);
203 ext4_dev_desc = get_dev(argv[1], dev);
205 if (ext4_dev_desc == NULL) {
206 printf("\n** Block device %s %d not supported\n", argv[1], dev);
212 puts("\n** Invalid boot device, use `dev[:part]' **\n");
215 part = simple_strtoul(++ep, NULL, 16);
221 part_length = ext4fs_set_blk_dev(ext4_dev_desc, part);
222 if (part_length == 0) {
223 printf("** Bad partition - %s %d:%lu **\n", argv[1], dev, part);
228 if (!ext4fs_mount(part_length)) {
229 printf("** Bad ext2 partition or disk - %s %d:%lu **\n",
235 if (ext4fs_ls(filename)) {
236 printf("** Error extfs_ls() **\n");