blob: 207c211e8a53feaf9e97e5b7832bf9988b2e2e5f [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenkdd875c72004-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>
wdenk8bde7f72003-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)
wdenkdd875c72004-01-03 21:24:46 +000038
39#include <cramfs/cramfs_fs.h>
40
wdenk180d3f72004-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
50static struct part_info part;
51
wdenk998eaae2004-04-18 19:43:36 +000052#ifndef CONFIG_JFFS2_NAND
53
wdenkc6097192002-11-03 00:24:07 +000054struct part_info*
55jffs2_part_info(int part_num)
56{
57 extern flash_info_t flash_info[]; /* info for FLASH chips */
58 int i;
59
60 if(part_num==0){
61
62 if(part.usr_priv==(void*)1)
63 return &part;
64
65 memset(&part, 0, sizeof(part));
66
67#if defined(CFG_JFFS2_FIRST_SECTOR)
68 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
69#else
70 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
71#endif
72
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;
76
77#if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
78 part.size -=
79 flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
80 flash_info[CFG_JFFS2_FIRST_BANK].start[0];
81#endif
82
wdenkfc1cfcd2004-04-25 15:41:35 +000083 /* unused in current jffs2 loader */
84 part.erasesize = 0;
wdenkc6097192002-11-03 00:24:07 +000085
86 /* Mark the struct as ready */
87 part.usr_priv=(void*)1;
88
89 return &part;
90 }
91 return 0;
92}
wdenk998eaae2004-04-18 19:43:36 +000093
94#else /* CONFIG_JFFS2_NAND */
95
96struct part_info*
97jffs2_part_info(int part_num)
98{
99 if(part_num==0){
100
101 if(part.usr_priv==(void*)1)
102 return &part;
103
104 memset(&part, 0, sizeof(part));
105
106 part.offset = CONFIG_JFFS2_NAND_OFF;
107 part.size = CONFIG_JFFS2_NAND_SIZE; /* the bigger size the slower jffs2 */
108
109#ifndef CONFIG_JFFS2_NAND_DEV
110#define CONFIG_JFFS2_NAND_DEV 0
111#endif
112 /* nand device with the JFFS2 parition plus 1 */
113 part.usr_priv = (void*)(CONFIG_JFFS2_NAND_DEV+1);
114 return &part;
115 }
116 return 0;
117}
118
119#endif /* CONFIG_JFFS2_NAND */
wdenkc6097192002-11-03 00:24:07 +0000120#endif /* ifndef CFG_JFFS_CUSTOM_PART */
wdenkdd875c72004-01-03 21:24:46 +0000121
wdenkc6097192002-11-03 00:24:07 +0000122int
123do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
124{
wdenk8bde7f72003-06-27 21:31:46 +0000125 struct part_info* jffs2_part_info(int);
126 int jffs2_1pass_load(char *, struct part_info *,const char *);
wdenkdd875c72004-01-03 21:24:46 +0000127 char *fsname;
wdenk8bde7f72003-06-27 21:31:46 +0000128
wdenkf39748a2004-06-09 13:37:52 +0000129 char *filename;
130
131 /* pre-set Boot file name */
132 if ((filename = getenv("bootfile")) == NULL) {
133 filename = "uImage";
134 }
135
wdenk4b9206e2004-03-23 22:14:11 +0000136 ulong offset = load_addr;
wdenkc6097192002-11-03 00:24:07 +0000137 int size;
138 struct part_info *part;
139
140 if (argc == 2) {
141 filename = argv[1];
142 }
143 if (argc == 3) {
144 offset = simple_strtoul(argv[1], NULL, 16);
wdenk4b9206e2004-03-23 22:14:11 +0000145 load_addr = offset;
wdenkc6097192002-11-03 00:24:07 +0000146 filename = argv[2];
147 }
148
149 if (0 != (part=jffs2_part_info(part_num))){
150
wdenkdd875c72004-01-03 21:24:46 +0000151 /* check partition type for cramfs */
152 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
153 printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
154
155 if (cramfs_check(part)) {
156 size = cramfs_load ((char *) offset, part, filename);
157 } else {
158 /* if this is not cramfs assume jffs2 */
159 size = jffs2_1pass_load((char *)offset, part, filename);
160 }
wdenkc6097192002-11-03 00:24:07 +0000161
162 if (size > 0) {
163 char buf[10];
wdenkdd875c72004-01-03 21:24:46 +0000164 printf("### %s load complete: %d bytes loaded to 0x%lx\n",
165 fsname, size, offset);
wdenkc6097192002-11-03 00:24:07 +0000166 sprintf(buf, "%x", size);
167 setenv("filesize", buf);
168 } else {
wdenkdd875c72004-01-03 21:24:46 +0000169 printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
wdenkc6097192002-11-03 00:24:07 +0000170 }
171
172 return !(size > 0);
173 }
wdenk4b9206e2004-03-23 22:14:11 +0000174 puts ("Active partition not valid\n");
wdenkc6097192002-11-03 00:24:07 +0000175 return 0;
176}
177
178int
179do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
180{
wdenk8bde7f72003-06-27 21:31:46 +0000181 struct part_info* jffs2_part_info(int);
182 int jffs2_1pass_ls(struct part_info *,char *);
183
184 char *filename = "/";
wdenkc6097192002-11-03 00:24:07 +0000185 int ret;
186 struct part_info *part;
187
188 if (argc == 2)
189 filename = argv[1];
190
191 if (0 != (part=jffs2_part_info(part_num))){
192
wdenkdd875c72004-01-03 21:24:46 +0000193 /* check partition type for cramfs */
194 if (cramfs_check(part)) {
195 ret = cramfs_ls (part, filename);
196 } else {
197 /* if this is not cramfs assume jffs2 */
198 ret = jffs2_1pass_ls(part, filename);
199 }
wdenkc6097192002-11-03 00:24:07 +0000200
201 return (ret == 1);
202 }
wdenk4b9206e2004-03-23 22:14:11 +0000203 puts ("Active partition not valid\n");
wdenkc6097192002-11-03 00:24:07 +0000204 return 0;
205}
206
207int
208do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
209{
wdenkdd875c72004-01-03 21:24:46 +0000210 struct part_info* jffs2_part_info(int);
211 int jffs2_1pass_info(struct part_info *);
wdenkc6097192002-11-03 00:24:07 +0000212 struct part_info *part;
wdenkdd875c72004-01-03 21:24:46 +0000213 char *fsname;
214 int ret;
wdenkc6097192002-11-03 00:24:07 +0000215
wdenkdd875c72004-01-03 21:24:46 +0000216 if ((part=jffs2_part_info(part_num))){
wdenkc6097192002-11-03 00:24:07 +0000217
wdenkdd875c72004-01-03 21:24:46 +0000218 /* check partition type for cramfs */
219 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
220 printf("### filesystem type is %s\n", fsname);
221
222 if (cramfs_check(part)) {
223 ret = cramfs_info (part);
224 } else {
225 /* if this is not cramfs assume jffs2 */
226 ret = jffs2_1pass_info(part);
227 }
wdenkc6097192002-11-03 00:24:07 +0000228
229 return (ret == 1);
230 }
wdenk4b9206e2004-03-23 22:14:11 +0000231 puts ("Active partition not valid\n");
wdenkc6097192002-11-03 00:24:07 +0000232 return 0;
233}
234
235int
236do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
237{
238 int tmp_part;
wdenkdd875c72004-01-03 21:24:46 +0000239 char str_part_num[3];
wdenk8bde7f72003-06-27 21:31:46 +0000240 struct part_info* jffs2_part_info(int);
wdenkc6097192002-11-03 00:24:07 +0000241
wdenk8bde7f72003-06-27 21:31:46 +0000242 if (argc >= 2) {
wdenkc6097192002-11-03 00:24:07 +0000243 tmp_part = simple_strtoul(argv[1], NULL, 16);
244 }else{
wdenk4b9206e2004-03-23 22:14:11 +0000245 puts ("Need partition number in argument list\n");
wdenkc6097192002-11-03 00:24:07 +0000246 return 0;
247
248 }
249
250 if (jffs2_part_info(tmp_part)){
wdenk7205e402003-09-10 22:30:53 +0000251 printf("Partition changed to %d\n",tmp_part);
wdenkc6097192002-11-03 00:24:07 +0000252 part_num=tmp_part;
wdenkdd875c72004-01-03 21:24:46 +0000253 sprintf(str_part_num, "%d", part_num);
254 setenv("partition", str_part_num);
wdenkc6097192002-11-03 00:24:07 +0000255 return 0;
256 }
257
258 printf("Partition %d is not valid partiton\n",tmp_part);
259 return 0;
260
261}
wdenk8bde7f72003-06-27 21:31:46 +0000262
263/***************************************************/
264
wdenk0d498392003-07-01 21:06:45 +0000265U_BOOT_CMD(
266 fsload, 3, 0, do_jffs2_fsload,
wdenkaa5590b2004-06-09 12:42:26 +0000267 "fsload\t- load binary file from a filesystem image\n",
wdenk8bde7f72003-06-27 21:31:46 +0000268 "[ off ] [ filename ]\n"
269 " - load binary file from flash bank\n"
270 " with offset 'off'\n"
271);
272
wdenk0d498392003-07-01 21:06:45 +0000273U_BOOT_CMD(
274 fsinfo, 1, 1, do_jffs2_fsinfo,
wdenkaa5590b2004-06-09 12:42:26 +0000275 "fsinfo\t- print information about filesystems\n",
wdenk8bde7f72003-06-27 21:31:46 +0000276 " - print information about filesystems\n"
277);
278
wdenk0d498392003-07-01 21:06:45 +0000279U_BOOT_CMD(
280 ls, 2, 1, do_jffs2_ls,
wdenkaa5590b2004-06-09 12:42:26 +0000281 "ls\t- list files in a directory (default /)\n",
wdenk8bde7f72003-06-27 21:31:46 +0000282 "[ directory ]\n"
283 " - list files in a directory.\n"
284);
285
wdenk0d498392003-07-01 21:06:45 +0000286U_BOOT_CMD(
287 chpart, 2, 0, do_jffs2_chpart,
wdenkaa5590b2004-06-09 12:42:26 +0000288 "chpart\t- change active partition\n",
wdenk8bde7f72003-06-27 21:31:46 +0000289 " - change active partition\n"
290);
291
wdenkc6097192002-11-03 00:24:07 +0000292#endif /* CFG_CMD_JFFS2 */