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 static int part_num=0;
43 #ifndef CFG_JFFS_CUSTOM_PART
45 static struct part_info part;
48 jffs2_part_info(int part_num)
50 extern flash_info_t flash_info[]; /* info for FLASH chips */
55 if(part.usr_priv==(void*)1)
58 memset(&part, 0, sizeof(part));
60 #if defined(CFG_JFFS2_FIRST_SECTOR)
61 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
63 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
66 /* Figure out flash partition size */
67 for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
68 part.size += flash_info[i].size;
70 #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
72 flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
73 flash_info[CFG_JFFS2_FIRST_BANK].start[0];
76 /* unused in current jffs2 loader */
79 /* Mark the struct as ready */
80 part.usr_priv=(void*)1;
86 #endif /* ifndef CFG_JFFS_CUSTOM_PART */
89 do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
91 struct part_info* jffs2_part_info(int);
92 int jffs2_1pass_load(char *, struct part_info *,const char *);
95 char *filename = "uImage";
96 ulong offset = CFG_LOAD_ADDR;
98 struct part_info *part;
104 offset = simple_strtoul(argv[1], NULL, 16);
108 if (0 != (part=jffs2_part_info(part_num))){
110 /* check partition type for cramfs */
111 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
112 printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
114 if (cramfs_check(part)) {
115 size = cramfs_load ((char *) offset, part, filename);
117 /* if this is not cramfs assume jffs2 */
118 size = jffs2_1pass_load((char *)offset, part, filename);
123 printf("### %s load complete: %d bytes loaded to 0x%lx\n",
124 fsname, size, offset);
125 sprintf(buf, "%x", size);
126 setenv("filesize", buf);
128 printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
133 printf("Active partition not valid\n");
138 do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
140 struct part_info* jffs2_part_info(int);
141 int jffs2_1pass_ls(struct part_info *,char *);
143 char *filename = "/";
145 struct part_info *part;
150 if (0 != (part=jffs2_part_info(part_num))){
152 /* check partition type for cramfs */
153 if (cramfs_check(part)) {
154 ret = cramfs_ls (part, filename);
156 /* if this is not cramfs assume jffs2 */
157 ret = jffs2_1pass_ls(part, filename);
162 printf("Active partition not valid\n");
167 do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
169 struct part_info* jffs2_part_info(int);
170 int jffs2_1pass_info(struct part_info *);
171 struct part_info *part;
175 if ((part=jffs2_part_info(part_num))){
177 /* check partition type for cramfs */
178 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
179 printf("### filesystem type is %s\n", fsname);
181 if (cramfs_check(part)) {
182 ret = cramfs_info (part);
184 /* if this is not cramfs assume jffs2 */
185 ret = jffs2_1pass_info(part);
190 printf("Active partition not valid\n");
195 do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
198 char str_part_num[3];
199 struct part_info* jffs2_part_info(int);
202 tmp_part = simple_strtoul(argv[1], NULL, 16);
204 printf("Need partition number in argument list\n");
209 if (jffs2_part_info(tmp_part)){
210 printf("Partition changed to %d\n",tmp_part);
212 sprintf(str_part_num, "%d", part_num);
213 setenv("partition", str_part_num);
217 printf("Partition %d is not valid partiton\n",tmp_part);
222 /***************************************************/
225 fsload, 3, 0, do_jffs2_fsload,
226 "fsload - load binary file from a filesystem image\n",
227 "[ off ] [ filename ]\n"
228 " - load binary file from flash bank\n"
229 " with offset 'off'\n"
233 fsinfo, 1, 1, do_jffs2_fsinfo,
234 "fsinfo - print information about filesystems\n",
235 " - print information about filesystems\n"
239 ls, 2, 1, do_jffs2_ls,
240 "ls - list files in a directory (default /)\n",
242 " - list files in a directory.\n"
246 chpart, 2, 0, do_jffs2_chpart,
247 "chpart - change active partition\n",
248 " - change active partition\n"
251 #endif /* CFG_CMD_JFFS2 */