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;
52 #ifndef CONFIG_JFFS2_NAND
55 jffs2_part_info(int part_num)
57 extern flash_info_t flash_info[]; /* info for FLASH chips */
62 if(part.usr_priv==(void*)1)
65 memset(&part, 0, sizeof(part));
67 #if defined(CFG_JFFS2_FIRST_SECTOR)
68 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
70 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
73 /* Figure out flash partition size */
74 for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
75 part.size += flash_info[i].size;
77 #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
79 flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
80 flash_info[CFG_JFFS2_FIRST_BANK].start[0];
83 /* FIXME: Fast hack to get erase size set */
85 /* We assume that our JFFS2 partition has
86 * all erase blocks with the same size
87 * If we have a clue about the erasesize
88 * we can skip empty blocks
90 part.erasesize = PHYS_FLASH_SECT_SIZE;
92 /* Mark the struct as ready */
93 part.usr_priv=(void*)1;
100 #else /* CONFIG_JFFS2_NAND */
103 jffs2_part_info(int part_num)
107 if(part.usr_priv==(void*)1)
110 memset(&part, 0, sizeof(part));
112 part.offset = CONFIG_JFFS2_NAND_OFF;
113 part.size = CONFIG_JFFS2_NAND_SIZE; /* the bigger size the slower jffs2 */
115 #ifndef CONFIG_JFFS2_NAND_DEV
116 #define CONFIG_JFFS2_NAND_DEV 0
118 /* nand device with the JFFS2 parition plus 1 */
119 part.usr_priv = (void*)(CONFIG_JFFS2_NAND_DEV+1);
125 #endif /* CONFIG_JFFS2_NAND */
126 #endif /* ifndef CFG_JFFS_CUSTOM_PART */
129 do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
131 struct part_info* jffs2_part_info(int);
132 int jffs2_1pass_load(char *, struct part_info *,const char *);
135 char *filename = "uImage";
136 ulong offset = load_addr;
138 struct part_info *part;
144 offset = simple_strtoul(argv[1], NULL, 16);
149 if (0 != (part=jffs2_part_info(part_num))){
151 /* check partition type for cramfs */
152 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
153 printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
155 if (cramfs_check(part)) {
156 size = cramfs_load ((char *) offset, part, filename);
158 /* if this is not cramfs assume jffs2 */
159 size = jffs2_1pass_load((char *)offset, part, filename);
164 printf("### %s load complete: %d bytes loaded to 0x%lx\n",
165 fsname, size, offset);
166 sprintf(buf, "%x", size);
167 setenv("filesize", buf);
169 printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
174 puts ("Active partition not valid\n");
179 do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
181 struct part_info* jffs2_part_info(int);
182 int jffs2_1pass_ls(struct part_info *,char *);
184 char *filename = "/";
186 struct part_info *part;
191 if (0 != (part=jffs2_part_info(part_num))){
193 /* check partition type for cramfs */
194 if (cramfs_check(part)) {
195 ret = cramfs_ls (part, filename);
197 /* if this is not cramfs assume jffs2 */
198 ret = jffs2_1pass_ls(part, filename);
203 puts ("Active partition not valid\n");
208 do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
210 struct part_info* jffs2_part_info(int);
211 int jffs2_1pass_info(struct part_info *);
212 struct part_info *part;
216 if ((part=jffs2_part_info(part_num))){
218 /* check partition type for cramfs */
219 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
220 printf("### filesystem type is %s\n", fsname);
222 if (cramfs_check(part)) {
223 ret = cramfs_info (part);
225 /* if this is not cramfs assume jffs2 */
226 ret = jffs2_1pass_info(part);
231 puts ("Active partition not valid\n");
236 do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
239 char str_part_num[3];
240 struct part_info* jffs2_part_info(int);
243 tmp_part = simple_strtoul(argv[1], NULL, 16);
245 puts ("Need partition number in argument list\n");
250 if (jffs2_part_info(tmp_part)){
251 printf("Partition changed to %d\n",tmp_part);
253 sprintf(str_part_num, "%d", part_num);
254 setenv("partition", str_part_num);
258 printf("Partition %d is not valid partiton\n",tmp_part);
263 /***************************************************/
266 fsload, 3, 0, do_jffs2_fsload,
267 "fsload - load binary file from a filesystem image\n",
268 "[ off ] [ filename ]\n"
269 " - load binary file from flash bank\n"
270 " with offset 'off'\n"
274 fsinfo, 1, 1, do_jffs2_fsinfo,
275 "fsinfo - print information about filesystems\n",
276 " - print information about filesystems\n"
280 ls, 2, 1, do_jffs2_ls,
281 "ls - list files in a directory (default /)\n",
283 " - list files in a directory.\n"
287 chpart, 2, 0, do_jffs2_chpart,
288 "chpart - change active partition\n",
289 " - change active partition\n"
292 #endif /* CFG_CMD_JFFS2 */