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;
78 struct ext_filesystem *fs;
84 addr = simple_strtoul(argv[3], NULL, 16);
85 filename = getenv("bootfile");
88 addr_str = getenv("loadaddr");
90 addr = simple_strtoul(addr_str, NULL, 16);
92 addr = CONFIG_SYS_LOAD_ADDR;
102 count = simple_strtoul(argv[5], NULL, 16);
106 return cmd_usage(cmdtp);
110 puts("** No boot file defined **\n");
114 dev = (int)simple_strtoul(argv[2], &ep, 16);
115 ext4_dev_desc = get_dev(argv[1], dev);
116 if (ext4_dev_desc == NULL) {
117 printf("** Block device %s %d not supported\n", argv[1], dev);
120 if (init_fs(ext4_dev_desc))
126 puts("** Invalid boot device, use `dev[:part]' **\n");
129 part = simple_strtoul(++ep, NULL, 16);
133 if (get_partition_info(fs->dev_desc, part, &info)) {
134 printf("** Bad partition %lu **\n", part);
138 if (strncmp((char *)info.type, BOOT_PART_TYPE,
139 strlen(BOOT_PART_TYPE)) != 0) {
140 printf("** Invalid partition type \"%s\""
141 " (expect \"" BOOT_PART_TYPE "\")\n", info.type);
144 printf("Loading file \"%s\" "
145 "from %s device %d:%lu %s\n",
146 filename, argv[1], dev, part, info.name);
148 printf("Loading file \"%s\" from %s device %d\n",
149 filename, argv[1], dev);
152 part_length = ext4fs_set_blk_dev(fs->dev_desc, part);
153 if (part_length == 0) {
154 printf("**Bad partition - %s %d:%lu **\n", argv[1], dev, part);
159 if (!ext4fs_mount(part_length)) {
160 printf("** Bad ext2 partition or disk - %s %d:%lu **\n",
166 filelen = ext4fs_open(filename);
168 printf("** File not found %s\n", filename);
172 if ((count < filelen) && (count != 0))
175 if (ext4fs_read((char *)addr, filelen) != filelen) {
176 printf("** Unable to read \"%s\" from %s %d:%lu **\n",
177 filename, argv[1], dev, part);
183 deinit_fs(fs->dev_desc);
184 /* Loading ok, update default load address */
187 printf("%d bytes read\n", filelen);
188 sprintf(buf, "%X", filelen);
189 setenv("filesize", buf);
193 deinit_fs(fs->dev_desc);
197 int do_ext_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
199 const char *filename = "/";
201 unsigned long part = 1;
203 struct ext_filesystem *fs;
206 return cmd_usage(cmdtp);
208 dev = (int)simple_strtoul(argv[2], &ep, 16);
210 ext4_dev_desc = get_dev(argv[1], dev);
212 if (ext4_dev_desc == NULL) {
213 printf("\n** Block device %s %d not supported\n", argv[1], dev);
217 if (init_fs(ext4_dev_desc))
223 puts("\n** Invalid boot device, use `dev[:part]' **\n");
226 part = simple_strtoul(++ep, NULL, 16);
232 part_length = ext4fs_set_blk_dev(fs->dev_desc, part);
233 if (part_length == 0) {
234 printf("** Bad partition - %s %d:%lu **\n", argv[1], dev, part);
239 if (!ext4fs_mount(part_length)) {
240 printf("** Bad ext2 partition or disk - %s %d:%lu **\n",
246 if (ext4fs_ls(filename)) {
247 printf("** Error extfs_ls() **\n");
253 deinit_fs(fs->dev_desc);
257 deinit_fs(fs->dev_desc);