]>
Commit | Line | Data |
---|---|---|
a1596438 US |
1 | /* |
2 | * (C) Copyright 2011 - 2012 Samsung Electronics | |
3 | * EXT2/4 filesystem implementation in Uboot by | |
4 | * Uma Shankar <[email protected]> | |
5 | * Manjunatha C Achar <[email protected]> | |
6 | * | |
7 | * Ext4fs support | |
8 | * made from existing cmd_ext2.c file of Uboot | |
9 | * | |
10 | * (C) Copyright 2004 | |
11 | * esd gmbh <www.esd-electronics.com> | |
12 | * Reinhard Arlt <[email protected]> | |
13 | * | |
14 | * made from cmd_reiserfs by | |
15 | * | |
16 | * (C) Copyright 2003 - 2004 | |
17 | * Sysgo Real-Time Solutions, AG <www.elinos.com> | |
18 | * Pavel Bartusek <[email protected]> | |
19 | * | |
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. | |
24 | * | |
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. | |
29 | * | |
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, | |
33 | * MA 02111-1307 USA | |
34 | * | |
35 | */ | |
36 | ||
37 | /* | |
38 | * Changelog: | |
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. | |
41 | */ | |
42 | ||
43 | #include <common.h> | |
44 | #include <part.h> | |
45 | #include <config.h> | |
46 | #include <command.h> | |
47 | #include <image.h> | |
48 | #include <linux/ctype.h> | |
49 | #include <asm/byteorder.h> | |
50 | #include <ext_common.h> | |
51 | #include <ext4fs.h> | |
52 | #include <linux/stat.h> | |
53 | #include <malloc.h> | |
54 | ||
55 | #if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_STORAGE) | |
56 | #include <usb.h> | |
57 | #endif | |
58 | ||
59 | #if !defined(CONFIG_DOS_PARTITION) && !defined(CONFIG_EFI_PARTITION) | |
60 | #error DOS or EFI partition support must be selected | |
61 | #endif | |
62 | ||
63 | #define DOS_PART_MAGIC_OFFSET 0x1fe | |
64 | #define DOS_FS_TYPE_OFFSET 0x36 | |
65 | #define DOS_FS32_TYPE_OFFSET 0x52 | |
66 | ||
67 | int do_ext_load(cmd_tbl_t *cmdtp, int flag, int argc, | |
68 | char *const argv[]) | |
69 | { | |
70 | char *filename = NULL; | |
81180819 | 71 | int dev, part; |
a1596438 | 72 | ulong addr = 0; |
a1596438 US |
73 | int filelen; |
74 | disk_partition_t info; | |
81180819 | 75 | block_dev_desc_t *dev_desc; |
a1596438 US |
76 | char buf[12]; |
77 | unsigned long count; | |
78 | const char *addr_str; | |
79 | ||
80 | count = 0; | |
81 | addr = simple_strtoul(argv[3], NULL, 16); | |
82 | filename = getenv("bootfile"); | |
83 | switch (argc) { | |
84 | case 3: | |
85 | addr_str = getenv("loadaddr"); | |
86 | if (addr_str != NULL) | |
87 | addr = simple_strtoul(addr_str, NULL, 16); | |
88 | else | |
89 | addr = CONFIG_SYS_LOAD_ADDR; | |
90 | ||
91 | break; | |
92 | case 4: | |
93 | break; | |
94 | case 5: | |
95 | filename = argv[4]; | |
96 | break; | |
97 | case 6: | |
98 | filename = argv[4]; | |
99 | count = simple_strtoul(argv[5], NULL, 16); | |
100 | break; | |
101 | ||
102 | default: | |
103 | return cmd_usage(cmdtp); | |
104 | } | |
105 | ||
106 | if (!filename) { | |
107 | puts("** No boot file defined **\n"); | |
108 | return 1; | |
109 | } | |
110 | ||
10a37fd7 | 111 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
81180819 | 112 | if (part < 0) |
a1596438 | 113 | return 1; |
a1596438 | 114 | |
81180819 RH |
115 | dev = dev_desc->dev; |
116 | printf("Loading file \"%s\" from %s device %d%c%c\n", | |
117 | filename, argv[1], dev, | |
118 | part ? ':' : ' ', part ? part + '0' : ' '); | |
a1596438 | 119 | |
81180819 | 120 | ext4fs_set_blk_dev(dev_desc, &info); |
a1596438 | 121 | |
81180819 RH |
122 | if (!ext4fs_mount(info.size)) { |
123 | printf("** Bad ext2 partition or disk - %s %d:%d **\n", | |
a1596438 US |
124 | argv[1], dev, part); |
125 | ext4fs_close(); | |
126 | goto fail; | |
127 | } | |
128 | ||
129 | filelen = ext4fs_open(filename); | |
130 | if (filelen < 0) { | |
131 | printf("** File not found %s\n", filename); | |
132 | ext4fs_close(); | |
133 | goto fail; | |
134 | } | |
135 | if ((count < filelen) && (count != 0)) | |
136 | filelen = count; | |
137 | ||
138 | if (ext4fs_read((char *)addr, filelen) != filelen) { | |
81180819 | 139 | printf("** Unable to read \"%s\" from %s %d:%d **\n", |
a1596438 US |
140 | filename, argv[1], dev, part); |
141 | ext4fs_close(); | |
142 | goto fail; | |
143 | } | |
144 | ||
145 | ext4fs_close(); | |
a1596438 US |
146 | /* Loading ok, update default load address */ |
147 | load_addr = addr; | |
148 | ||
149 | printf("%d bytes read\n", filelen); | |
150 | sprintf(buf, "%X", filelen); | |
151 | setenv("filesize", buf); | |
152 | ||
153 | return 0; | |
154 | fail: | |
a1596438 US |
155 | return 1; |
156 | } | |
157 | ||
158 | int do_ext_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | |
159 | { | |
160 | const char *filename = "/"; | |
161 | int dev; | |
81180819 RH |
162 | int part; |
163 | block_dev_desc_t *dev_desc; | |
164 | disk_partition_t info; | |
a1596438 | 165 | |
81180819 RH |
166 | if (argc < 2) |
167 | return cmd_usage(cmdtp); | |
a1596438 | 168 | |
10a37fd7 | 169 | part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1); |
81180819 | 170 | if (part < 0) |
a1596438 | 171 | return 1; |
a1596438 US |
172 | |
173 | if (argc == 4) | |
174 | filename = argv[3]; | |
175 | ||
81180819 RH |
176 | dev = dev_desc->dev; |
177 | ext4fs_set_blk_dev(dev_desc, &info); | |
a1596438 | 178 | |
81180819 RH |
179 | if (!ext4fs_mount(info.size)) { |
180 | printf("** Bad ext2 partition or disk - %s %d:%d **\n", | |
a1596438 US |
181 | argv[1], dev, part); |
182 | ext4fs_close(); | |
183 | goto fail; | |
184 | } | |
185 | ||
186 | if (ext4fs_ls(filename)) { | |
187 | printf("** Error extfs_ls() **\n"); | |
188 | ext4fs_close(); | |
189 | goto fail; | |
190 | }; | |
191 | ||
192 | ext4fs_close(); | |
a1596438 US |
193 | return 0; |
194 | ||
195 | fail: | |
a1596438 US |
196 | return 1; |
197 | } |