blob: 63fddf657a3a4686b4df6505baea3cdbebab1750 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenkae65f502004-01-03 21:24:46 +00004 * (C) Copyright 2002
5 * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
6 * (C) Copyright 2003
7 * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
wdenkc6097192002-11-03 00:24:07 +00008 *
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>
wdenkc6097192002-11-03 00:24:07 +000033#include <s_record.h>
wdenk57b2d802003-06-27 21:31:46 +000034#include <jffs2/load_kernel.h>
wdenkc6097192002-11-03 00:24:07 +000035#include <net.h>
36
37#if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
wdenkae65f502004-01-03 21:24:46 +000038
39#include <cramfs/cramfs_fs.h>
40
wdenkad276f22004-01-04 16:28:35 +000041extern int cramfs_check (struct part_info *info);
42extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
43extern int cramfs_ls (struct part_info *info, char *filename);
44extern int cramfs_info (struct part_info *info);
45
wdenkc6097192002-11-03 00:24:07 +000046static int part_num=0;
47
48#ifndef CFG_JFFS_CUSTOM_PART
49
wdenkda04a8b2004-08-02 23:22:59 +000050#define CFG_JFFS_SINGLE_PART 1
51
wdenkc6097192002-11-03 00:24:07 +000052static struct part_info part;
53
wdenk8886a662004-04-18 19:43:36 +000054#ifndef CONFIG_JFFS2_NAND
55
wdenkc6097192002-11-03 00:24:07 +000056struct part_info*
57jffs2_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 &part;
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
wdenkc6097192002-11-03 00:24:07 +000085 /* Mark the struct as ready */
86 part.usr_priv=(void*)1;
87
wdenk8886a662004-04-18 19:43:36 +000088 return &part;
89 }
90 return 0;
91}
92
93#else /* CONFIG_JFFS2_NAND */
94
95struct part_info*
96jffs2_part_info(int part_num)
97{
98 if(part_num==0){
99
100 if(part.usr_priv==(void*)1)
101 return &part;
102
103 memset(&part, 0, sizeof(part));
104
wdenkefc6f362004-06-10 21:34:36 +0000105 part.offset = (char *)CONFIG_JFFS2_NAND_OFF;
wdenk8886a662004-04-18 19:43:36 +0000106 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);
wdenkc6097192002-11-03 00:24:07 +0000113 return &part;
114 }
115 return 0;
116}
wdenk8886a662004-04-18 19:43:36 +0000117
118#endif /* CONFIG_JFFS2_NAND */
wdenkc6097192002-11-03 00:24:07 +0000119#endif /* ifndef CFG_JFFS_CUSTOM_PART */
wdenkae65f502004-01-03 21:24:46 +0000120
wdenkc6097192002-11-03 00:24:07 +0000121int
122do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
123{
wdenkf2140d52004-07-01 16:30:44 +0000124 struct part_info* jffs2_part_info(int);
125 int jffs2_1pass_load(char *, struct part_info *,const char *);
126 char *fsname;
wdenk3c711762004-06-09 13:37:52 +0000127 char *filename;
wdenkf2140d52004-07-01 16:30:44 +0000128 int size;
129 struct part_info *part;
130 ulong offset = load_addr;
wdenk3c711762004-06-09 13:37:52 +0000131
132 /* pre-set Boot file name */
133 if ((filename = getenv("bootfile")) == NULL) {
134 filename = "uImage";
135 }
136
wdenkc6097192002-11-03 00:24:07 +0000137 if (argc == 2) {
138 filename = argv[1];
139 }
140 if (argc == 3) {
141 offset = simple_strtoul(argv[1], NULL, 16);
wdenk42c05472004-03-23 22:14:11 +0000142 load_addr = offset;
wdenkc6097192002-11-03 00:24:07 +0000143 filename = argv[2];
144 }
145
146 if (0 != (part=jffs2_part_info(part_num))){
147
wdenkae65f502004-01-03 21:24:46 +0000148 /* 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 }
wdenkc6097192002-11-03 00:24:07 +0000158
159 if (size > 0) {
160 char buf[10];
wdenkae65f502004-01-03 21:24:46 +0000161 printf("### %s load complete: %d bytes loaded to 0x%lx\n",
162 fsname, size, offset);
wdenkc6097192002-11-03 00:24:07 +0000163 sprintf(buf, "%x", size);
164 setenv("filesize", buf);
165 } else {
wdenkae65f502004-01-03 21:24:46 +0000166 printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
wdenkc6097192002-11-03 00:24:07 +0000167 }
168
169 return !(size > 0);
170 }
wdenk42c05472004-03-23 22:14:11 +0000171 puts ("Active partition not valid\n");
wdenkc6097192002-11-03 00:24:07 +0000172 return 0;
173}
174
175int
176do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
177{
wdenk57b2d802003-06-27 21:31:46 +0000178 struct part_info* jffs2_part_info(int);
179 int jffs2_1pass_ls(struct part_info *,char *);
180
181 char *filename = "/";
wdenkc6097192002-11-03 00:24:07 +0000182 int ret;
183 struct part_info *part;
184
185 if (argc == 2)
186 filename = argv[1];
187
188 if (0 != (part=jffs2_part_info(part_num))){
189
wdenkae65f502004-01-03 21:24:46 +0000190 /* check partition type for cramfs */
191 if (cramfs_check(part)) {
192 ret = cramfs_ls (part, filename);
193 } else {
194 /* if this is not cramfs assume jffs2 */
195 ret = jffs2_1pass_ls(part, filename);
196 }
wdenkc6097192002-11-03 00:24:07 +0000197
198 return (ret == 1);
199 }
wdenk42c05472004-03-23 22:14:11 +0000200 puts ("Active partition not valid\n");
wdenkc6097192002-11-03 00:24:07 +0000201 return 0;
202}
203
204int
205do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
206{
wdenkae65f502004-01-03 21:24:46 +0000207 struct part_info* jffs2_part_info(int);
208 int jffs2_1pass_info(struct part_info *);
wdenkc6097192002-11-03 00:24:07 +0000209 struct part_info *part;
wdenkae65f502004-01-03 21:24:46 +0000210 char *fsname;
211 int ret;
wdenkc6097192002-11-03 00:24:07 +0000212
wdenkae65f502004-01-03 21:24:46 +0000213 if ((part=jffs2_part_info(part_num))){
214
215 /* check partition type for cramfs */
216 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
217 printf("### filesystem type is %s\n", fsname);
wdenkc6097192002-11-03 00:24:07 +0000218
wdenkae65f502004-01-03 21:24:46 +0000219 if (cramfs_check(part)) {
220 ret = cramfs_info (part);
221 } else {
222 /* if this is not cramfs assume jffs2 */
223 ret = jffs2_1pass_info(part);
224 }
wdenkc6097192002-11-03 00:24:07 +0000225
226 return (ret == 1);
227 }
wdenk42c05472004-03-23 22:14:11 +0000228 puts ("Active partition not valid\n");
wdenkc6097192002-11-03 00:24:07 +0000229 return 0;
230}
231
wdenkda04a8b2004-08-02 23:22:59 +0000232#ifndef CFG_JFFS_SINGLE_PART
wdenkc6097192002-11-03 00:24:07 +0000233int
234do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
235{
236 int tmp_part;
wdenkae65f502004-01-03 21:24:46 +0000237 char str_part_num[3];
wdenk57b2d802003-06-27 21:31:46 +0000238 struct part_info* jffs2_part_info(int);
wdenkc6097192002-11-03 00:24:07 +0000239
wdenk57b2d802003-06-27 21:31:46 +0000240 if (argc >= 2) {
wdenkc6097192002-11-03 00:24:07 +0000241 tmp_part = simple_strtoul(argv[1], NULL, 16);
242 }else{
wdenk42c05472004-03-23 22:14:11 +0000243 puts ("Need partition number in argument list\n");
wdenkc6097192002-11-03 00:24:07 +0000244 return 0;
245
246 }
247
248 if (jffs2_part_info(tmp_part)){
wdenk2c9b05d2003-09-10 22:30:53 +0000249 printf("Partition changed to %d\n",tmp_part);
wdenkc6097192002-11-03 00:24:07 +0000250 part_num=tmp_part;
wdenkae65f502004-01-03 21:24:46 +0000251 sprintf(str_part_num, "%d", part_num);
252 setenv("partition", str_part_num);
wdenkc6097192002-11-03 00:24:07 +0000253 return 0;
254 }
255
256 printf("Partition %d is not valid partiton\n",tmp_part);
257 return 0;
258
259}
wdenka0ebde52004-09-08 22:03:11 +0000260
261U_BOOT_CMD(
262 chpart, 2, 0, do_jffs2_chpart,
263 "chpart\t- change active partition\n",
264 " - change active partition\n"
265);
wdenkda04a8b2004-08-02 23:22:59 +0000266#endif /* CFG_JFFS_SINGLE_PART */
wdenk57b2d802003-06-27 21:31:46 +0000267
268/***************************************************/
269
wdenkf287a242003-07-01 21:06:45 +0000270U_BOOT_CMD(
271 fsload, 3, 0, do_jffs2_fsload,
wdenk6568eaa2004-06-09 12:42:26 +0000272 "fsload\t- load binary file from a filesystem image\n",
wdenk57b2d802003-06-27 21:31:46 +0000273 "[ off ] [ filename ]\n"
274 " - load binary file from flash bank\n"
275 " with offset 'off'\n"
276);
277
wdenkf287a242003-07-01 21:06:45 +0000278U_BOOT_CMD(
279 fsinfo, 1, 1, do_jffs2_fsinfo,
wdenk6568eaa2004-06-09 12:42:26 +0000280 "fsinfo\t- print information about filesystems\n",
wdenk57b2d802003-06-27 21:31:46 +0000281 " - print information about filesystems\n"
282);
283
wdenkf287a242003-07-01 21:06:45 +0000284U_BOOT_CMD(
285 ls, 2, 1, do_jffs2_ls,
wdenk6568eaa2004-06-09 12:42:26 +0000286 "ls\t- list files in a directory (default /)\n",
wdenk57b2d802003-06-27 21:31:46 +0000287 "[ directory ]\n"
288 " - list files in a directory.\n"
289);
290
wdenkc6097192002-11-03 00:24:07 +0000291#endif /* CFG_CMD_JFFS2 */