3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
7 * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
9 * See file CREDITS for list of people who contributed to this
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.
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.
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,
34 #include <jffs2/load_kernel.h>
37 #if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
39 #include <cramfs/cramfs_fs.h>
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);
46 static int part_num=0;
48 #ifndef CFG_JFFS_CUSTOM_PART
50 static struct part_info part;
53 jffs2_part_info(int part_num)
55 extern flash_info_t flash_info[]; /* info for FLASH chips */
60 if(part.usr_priv==(void*)1)
63 memset(&part, 0, sizeof(part));
65 #if defined(CFG_JFFS2_FIRST_SECTOR)
66 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
68 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
71 /* Figure out flash partition size */
72 for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
73 part.size += flash_info[i].size;
75 #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
77 flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
78 flash_info[CFG_JFFS2_FIRST_BANK].start[0];
81 /* unused in current jffs2 loader */
84 /* Mark the struct as ready */
85 part.usr_priv=(void*)1;
91 #endif /* ifndef CFG_JFFS_CUSTOM_PART */
94 do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
96 struct part_info* jffs2_part_info(int);
97 int jffs2_1pass_load(char *, struct part_info *,const char *);
100 char *filename = "uImage";
101 ulong offset = load_addr;
103 struct part_info *part;
109 offset = simple_strtoul(argv[1], NULL, 16);
114 if (0 != (part=jffs2_part_info(part_num))){
116 /* check partition type for cramfs */
117 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
118 printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
120 if (cramfs_check(part)) {
121 size = cramfs_load ((char *) offset, part, filename);
123 /* if this is not cramfs assume jffs2 */
124 size = jffs2_1pass_load((char *)offset, part, filename);
129 printf("### %s load complete: %d bytes loaded to 0x%lx\n",
130 fsname, size, offset);
131 sprintf(buf, "%x", size);
132 setenv("filesize", buf);
134 printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
139 puts ("Active partition not valid\n");
144 do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
146 struct part_info* jffs2_part_info(int);
147 int jffs2_1pass_ls(struct part_info *,char *);
149 char *filename = "/";
151 struct part_info *part;
156 if (0 != (part=jffs2_part_info(part_num))){
158 /* check partition type for cramfs */
159 if (cramfs_check(part)) {
160 ret = cramfs_ls (part, filename);
162 /* if this is not cramfs assume jffs2 */
163 ret = jffs2_1pass_ls(part, filename);
168 puts ("Active partition not valid\n");
173 do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
175 struct part_info* jffs2_part_info(int);
176 int jffs2_1pass_info(struct part_info *);
177 struct part_info *part;
181 if ((part=jffs2_part_info(part_num))){
183 /* check partition type for cramfs */
184 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
185 printf("### filesystem type is %s\n", fsname);
187 if (cramfs_check(part)) {
188 ret = cramfs_info (part);
190 /* if this is not cramfs assume jffs2 */
191 ret = jffs2_1pass_info(part);
196 puts ("Active partition not valid\n");
201 do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
204 char str_part_num[3];
205 struct part_info* jffs2_part_info(int);
208 tmp_part = simple_strtoul(argv[1], NULL, 16);
210 puts ("Need partition number in argument list\n");
215 if (jffs2_part_info(tmp_part)){
216 printf("Partition changed to %d\n",tmp_part);
218 sprintf(str_part_num, "%d", part_num);
219 setenv("partition", str_part_num);
223 printf("Partition %d is not valid partiton\n",tmp_part);
228 /***************************************************/
231 fsload, 3, 0, do_jffs2_fsload,
232 "fsload - load binary file from a filesystem image\n",
233 "[ off ] [ filename ]\n"
234 " - load binary file from flash bank\n"
235 " with offset 'off'\n"
239 fsinfo, 1, 1, do_jffs2_fsinfo,
240 "fsinfo - print information about filesystems\n",
241 " - print information about filesystems\n"
245 ls, 2, 1, do_jffs2_ls,
246 "ls - list files in a directory (default /)\n",
248 " - list files in a directory.\n"
252 chpart, 2, 0, do_jffs2_chpart,
253 "chpart - change active partition\n",
254 " - change active partition\n"
257 #endif /* CFG_CMD_JFFS2 */