]>
Commit | Line | Data |
---|---|---|
c609719b WD |
1 | /* |
2 | * (C) Copyright 2002 | |
3 | * Wolfgang Denk, DENX Software Engineering, [email protected]. | |
dd875c76 WD |
4 | * (C) Copyright 2002 |
5 | * Robert Schwebel, Pengutronix, <[email protected]> | |
6 | * (C) Copyright 2003 | |
7 | * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <[email protected]> | |
c609719b WD |
8 | * |
9 | * See file CREDITS for list of people who contributed to this | |
10 | * project. | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU General Public License as | |
14 | * published by the Free Software Foundation; either version 2 of | |
15 | * the License, or (at your option) any later version. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License | |
23 | * along with this program; if not, write to the Free Software | |
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
25 | * MA 02111-1307 USA | |
26 | */ | |
27 | ||
28 | /* | |
29 | * Boot support | |
30 | */ | |
31 | #include <common.h> | |
32 | #include <command.h> | |
c609719b | 33 | #include <s_record.h> |
8bde7f77 | 34 | #include <jffs2/load_kernel.h> |
c609719b WD |
35 | #include <net.h> |
36 | ||
37 | #if (CONFIG_COMMANDS & CFG_CMD_JFFS2) | |
dd875c76 WD |
38 | |
39 | #include <cramfs/cramfs_fs.h> | |
40 | ||
180d3f74 WD |
41 | extern int cramfs_check (struct part_info *info); |
42 | extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename); | |
43 | extern int cramfs_ls (struct part_info *info, char *filename); | |
44 | extern int cramfs_info (struct part_info *info); | |
45 | ||
c609719b WD |
46 | static int part_num=0; |
47 | ||
48 | #ifndef CFG_JFFS_CUSTOM_PART | |
49 | ||
6705d81e WD |
50 | #define CFG_JFFS_SINGLE_PART 1 |
51 | ||
c609719b WD |
52 | static struct part_info part; |
53 | ||
998eaaec WD |
54 | #ifndef CONFIG_JFFS2_NAND |
55 | ||
c609719b WD |
56 | struct part_info* |
57 | jffs2_part_info(int part_num) | |
58 | { | |
59 | extern flash_info_t flash_info[]; /* info for FLASH chips */ | |
60 | int i; | |
61 | ||
62 | if(part_num==0){ | |
63 | ||
64 | if(part.usr_priv==(void*)1) | |
65 | return ∂ | |
66 | ||
67 | memset(&part, 0, sizeof(part)); | |
68 | ||
69 | #if defined(CFG_JFFS2_FIRST_SECTOR) | |
70 | part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR]; | |
71 | #else | |
72 | part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0]; | |
73 | #endif | |
74 | ||
75 | /* Figure out flash partition size */ | |
76 | for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++) | |
77 | part.size += flash_info[i].size; | |
78 | ||
79 | #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0) | |
80 | part.size -= | |
81 | flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] - | |
82 | flash_info[CFG_JFFS2_FIRST_BANK].start[0]; | |
83 | #endif | |
84 | ||
c609719b WD |
85 | /* Mark the struct as ready */ |
86 | part.usr_priv=(void*)1; | |
87 | ||
88 | return ∂ | |
89 | } | |
90 | return 0; | |
91 | } | |
998eaaec WD |
92 | |
93 | #else /* CONFIG_JFFS2_NAND */ | |
94 | ||
95 | struct part_info* | |
96 | jffs2_part_info(int part_num) | |
97 | { | |
98 | if(part_num==0){ | |
99 | ||
100 | if(part.usr_priv==(void*)1) | |
101 | return ∂ | |
102 | ||
103 | memset(&part, 0, sizeof(part)); | |
104 | ||
b54d32b4 | 105 | part.offset = (char *)CONFIG_JFFS2_NAND_OFF; |
998eaaec WD |
106 | part.size = CONFIG_JFFS2_NAND_SIZE; /* the bigger size the slower jffs2 */ |
107 | ||
108 | #ifndef CONFIG_JFFS2_NAND_DEV | |
109 | #define CONFIG_JFFS2_NAND_DEV 0 | |
110 | #endif | |
111 | /* nand device with the JFFS2 parition plus 1 */ | |
112 | part.usr_priv = (void*)(CONFIG_JFFS2_NAND_DEV+1); | |
113 | return ∂ | |
114 | } | |
115 | return 0; | |
116 | } | |
117 | ||
118 | #endif /* CONFIG_JFFS2_NAND */ | |
c609719b | 119 | #endif /* ifndef CFG_JFFS_CUSTOM_PART */ |
dd875c76 | 120 | |
c609719b WD |
121 | int |
122 | do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) | |
123 | { | |
39539887 WD |
124 | struct part_info* jffs2_part_info(int); |
125 | int jffs2_1pass_load(char *, struct part_info *,const char *); | |
126 | char *fsname; | |
f39748ae | 127 | char *filename; |
39539887 WD |
128 | int size; |
129 | struct part_info *part; | |
130 | ulong offset = load_addr; | |
f39748ae WD |
131 | |
132 | /* pre-set Boot file name */ | |
133 | if ((filename = getenv("bootfile")) == NULL) { | |
134 | filename = "uImage"; | |
135 | } | |
136 | ||
c609719b WD |
137 | if (argc == 2) { |
138 | filename = argv[1]; | |
139 | } | |
140 | if (argc == 3) { | |
141 | offset = simple_strtoul(argv[1], NULL, 16); | |
4b9206ed | 142 | load_addr = offset; |
c609719b WD |
143 | filename = argv[2]; |
144 | } | |
145 | ||
146 | if (0 != (part=jffs2_part_info(part_num))){ | |
147 | ||
dd875c76 WD |
148 | /* check partition type for cramfs */ |
149 | fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2"); | |
150 | printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset); | |
151 | ||
152 | if (cramfs_check(part)) { | |
153 | size = cramfs_load ((char *) offset, part, filename); | |
154 | } else { | |
155 | /* if this is not cramfs assume jffs2 */ | |
156 | size = jffs2_1pass_load((char *)offset, part, filename); | |
157 | } | |
c609719b WD |
158 | |
159 | if (size > 0) { | |
160 | char buf[10]; | |
dd875c76 WD |
161 | printf("### %s load complete: %d bytes loaded to 0x%lx\n", |
162 | fsname, size, offset); | |
c609719b WD |
163 | sprintf(buf, "%x", size); |
164 | setenv("filesize", buf); | |
165 | } else { | |
dd875c76 | 166 | printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename); |
c609719b WD |
167 | } |
168 | ||
169 | return !(size > 0); | |
170 | } | |
4b9206ed | 171 | puts ("Active partition not valid\n"); |
c609719b WD |
172 | return 0; |
173 | } | |
174 | ||
175 | int | |
176 | do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) | |
177 | { | |
a87589da WD |
178 | struct part_info* jffs2_part_info(int); |
179 | int jffs2_1pass_ls(struct part_info *,char *); | |
180 | char *filename = "/"; | |
c609719b WD |
181 | int ret; |
182 | struct part_info *part; | |
183 | ||
184 | if (argc == 2) | |
185 | filename = argv[1]; | |
186 | ||
187 | if (0 != (part=jffs2_part_info(part_num))){ | |
188 | ||
dd875c76 WD |
189 | /* check partition type for cramfs */ |
190 | if (cramfs_check(part)) { | |
191 | ret = cramfs_ls (part, filename); | |
192 | } else { | |
193 | /* if this is not cramfs assume jffs2 */ | |
194 | ret = jffs2_1pass_ls(part, filename); | |
195 | } | |
c609719b WD |
196 | |
197 | return (ret == 1); | |
198 | } | |
4b9206ed | 199 | puts ("Active partition not valid\n"); |
c609719b WD |
200 | return 0; |
201 | } | |
202 | ||
203 | int | |
204 | do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) | |
205 | { | |
dd875c76 WD |
206 | struct part_info* jffs2_part_info(int); |
207 | int jffs2_1pass_info(struct part_info *); | |
c609719b | 208 | struct part_info *part; |
dd875c76 WD |
209 | char *fsname; |
210 | int ret; | |
c609719b | 211 | |
dd875c76 WD |
212 | if ((part=jffs2_part_info(part_num))){ |
213 | ||
214 | /* check partition type for cramfs */ | |
215 | fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2"); | |
216 | printf("### filesystem type is %s\n", fsname); | |
c609719b | 217 | |
dd875c76 WD |
218 | if (cramfs_check(part)) { |
219 | ret = cramfs_info (part); | |
220 | } else { | |
221 | /* if this is not cramfs assume jffs2 */ | |
222 | ret = jffs2_1pass_info(part); | |
223 | } | |
c609719b WD |
224 | |
225 | return (ret == 1); | |
226 | } | |
4b9206ed | 227 | puts ("Active partition not valid\n"); |
c609719b WD |
228 | return 0; |
229 | } | |
230 | ||
6705d81e | 231 | #ifndef CFG_JFFS_SINGLE_PART |
c609719b WD |
232 | int |
233 | do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) | |
234 | { | |
235 | int tmp_part; | |
dd875c76 | 236 | char str_part_num[3]; |
a87589da | 237 | struct part_info* jffs2_part_info(int); |
c609719b | 238 | |
a87589da | 239 | if (argc >= 2) { |
c609719b | 240 | tmp_part = simple_strtoul(argv[1], NULL, 16); |
a87589da | 241 | } else { |
4b9206ed | 242 | puts ("Need partition number in argument list\n"); |
c609719b WD |
243 | return 0; |
244 | ||
245 | } | |
246 | ||
247 | if (jffs2_part_info(tmp_part)){ | |
7205e407 | 248 | printf("Partition changed to %d\n",tmp_part); |
c609719b | 249 | part_num=tmp_part; |
dd875c76 WD |
250 | sprintf(str_part_num, "%d", part_num); |
251 | setenv("partition", str_part_num); | |
c609719b WD |
252 | return 0; |
253 | } | |
254 | ||
255 | printf("Partition %d is not valid partiton\n",tmp_part); | |
256 | return 0; | |
257 | ||
258 | } | |
eedcd078 WD |
259 | |
260 | U_BOOT_CMD( | |
261 | chpart, 2, 0, do_jffs2_chpart, | |
262 | "chpart\t- change active partition\n", | |
263 | " - change active partition\n" | |
264 | ); | |
6705d81e | 265 | #endif /* CFG_JFFS_SINGLE_PART */ |
8bde7f77 WD |
266 | |
267 | /***************************************************/ | |
268 | ||
0d498393 WD |
269 | U_BOOT_CMD( |
270 | fsload, 3, 0, do_jffs2_fsload, | |
aa5590b6 | 271 | "fsload\t- load binary file from a filesystem image\n", |
8bde7f77 WD |
272 | "[ off ] [ filename ]\n" |
273 | " - load binary file from flash bank\n" | |
274 | " with offset 'off'\n" | |
275 | ); | |
276 | ||
0d498393 WD |
277 | U_BOOT_CMD( |
278 | fsinfo, 1, 1, do_jffs2_fsinfo, | |
aa5590b6 | 279 | "fsinfo\t- print information about filesystems\n", |
8bde7f77 WD |
280 | " - print information about filesystems\n" |
281 | ); | |
282 | ||
0d498393 WD |
283 | U_BOOT_CMD( |
284 | ls, 2, 1, do_jffs2_ls, | |
aa5590b6 | 285 | "ls\t- list files in a directory (default /)\n", |
8bde7f77 WD |
286 | "[ directory ]\n" |
287 | " - list files in a directory.\n" | |
288 | ); | |
289 | ||
c609719b | 290 | #endif /* CFG_CMD_JFFS2 */ |