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 #define CFG_JFFS_SINGLE_PART 1
52 static struct part_info part;
54 #ifndef CONFIG_JFFS2_NAND
57 jffs2_part_info(int part_num)
59 extern flash_info_t flash_info[]; /* info for FLASH chips */
64 if(part.usr_priv==(void*)1)
67 memset(&part, 0, sizeof(part));
69 #if defined(CFG_JFFS2_FIRST_SECTOR)
70 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
72 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
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;
79 #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
81 flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
82 flash_info[CFG_JFFS2_FIRST_BANK].start[0];
85 /* Mark the struct as ready */
86 part.usr_priv=(void*)1;
93 #else /* CONFIG_JFFS2_NAND */
96 jffs2_part_info(int part_num)
100 if(part.usr_priv==(void*)1)
103 memset(&part, 0, sizeof(part));
105 part.offset = (char *)CONFIG_JFFS2_NAND_OFF;
106 part.size = CONFIG_JFFS2_NAND_SIZE; /* the bigger size the slower jffs2 */
108 #ifndef CONFIG_JFFS2_NAND_DEV
109 #define CONFIG_JFFS2_NAND_DEV 0
111 /* nand device with the JFFS2 parition plus 1 */
112 part.usr_priv = (void*)(CONFIG_JFFS2_NAND_DEV+1);
118 #endif /* CONFIG_JFFS2_NAND */
119 #endif /* ifndef CFG_JFFS_CUSTOM_PART */
122 do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
124 struct part_info* jffs2_part_info(int);
125 int jffs2_1pass_load(char *, struct part_info *,const char *);
129 struct part_info *part;
130 ulong offset = load_addr;
132 /* pre-set Boot file name */
133 if ((filename = getenv("bootfile")) == NULL) {
141 offset = simple_strtoul(argv[1], NULL, 16);
146 if (0 != (part=jffs2_part_info(part_num))){
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);
152 if (cramfs_check(part)) {
153 size = cramfs_load ((char *) offset, part, filename);
155 /* if this is not cramfs assume jffs2 */
156 size = jffs2_1pass_load((char *)offset, part, filename);
161 printf("### %s load complete: %d bytes loaded to 0x%lx\n",
162 fsname, size, offset);
163 sprintf(buf, "%x", size);
164 setenv("filesize", buf);
166 printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
171 puts ("Active partition not valid\n");
176 do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
178 struct part_info* jffs2_part_info(int);
179 int jffs2_1pass_ls(struct part_info *,char *);
181 char *filename = "/";
183 struct part_info *part;
188 if (0 != (part=jffs2_part_info(part_num))){
190 /* check partition type for cramfs */
191 if (cramfs_check(part)) {
192 ret = cramfs_ls (part, filename);
194 /* if this is not cramfs assume jffs2 */
195 ret = jffs2_1pass_ls(part, filename);
200 puts ("Active partition not valid\n");
205 do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
207 struct part_info* jffs2_part_info(int);
208 int jffs2_1pass_info(struct part_info *);
209 struct part_info *part;
213 if ((part=jffs2_part_info(part_num))){
215 /* check partition type for cramfs */
216 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
217 printf("### filesystem type is %s\n", fsname);
219 if (cramfs_check(part)) {
220 ret = cramfs_info (part);
222 /* if this is not cramfs assume jffs2 */
223 ret = jffs2_1pass_info(part);
228 puts ("Active partition not valid\n");
232 #ifndef CFG_JFFS_SINGLE_PART
234 do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
237 char str_part_num[3];
238 struct part_info* jffs2_part_info(int);
241 tmp_part = simple_strtoul(argv[1], NULL, 16);
243 puts ("Need partition number in argument list\n");
248 if (jffs2_part_info(tmp_part)){
249 printf("Partition changed to %d\n",tmp_part);
251 sprintf(str_part_num, "%d", part_num);
252 setenv("partition", str_part_num);
256 printf("Partition %d is not valid partiton\n",tmp_part);
262 chpart, 2, 0, do_jffs2_chpart,
263 "chpart\t- change active partition\n",
264 " - change active partition\n"
266 #endif /* CFG_JFFS_SINGLE_PART */
268 /***************************************************/
271 fsload, 3, 0, do_jffs2_fsload,
272 "fsload\t- load binary file from a filesystem image\n",
273 "[ off ] [ filename ]\n"
274 " - load binary file from flash bank\n"
275 " with offset 'off'\n"
279 fsinfo, 1, 1, do_jffs2_fsinfo,
280 "fsinfo\t- print information about filesystems\n",
281 " - print information about filesystems\n"
285 ls, 2, 1, do_jffs2_ls,
286 "ls\t- list files in a directory (default /)\n",
288 " - list files in a directory.\n"
291 #endif /* CFG_CMD_JFFS2 */