blob: c4f5a971570ad4d4ceccaebe01938b13a58d8809 [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
52struct part_info*
53jffs2_part_info(int part_num)
54{
55 extern flash_info_t flash_info[]; /* info for FLASH chips */
56 int i;
57
58 if(part_num==0){
59
60 if(part.usr_priv==(void*)1)
61 return &part;
62
63 memset(&part, 0, sizeof(part));
64
65#if defined(CFG_JFFS2_FIRST_SECTOR)
66 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
67#else
68 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
69#endif
70
71 /* Figure out flash partition size */
72 for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
73 part.size += flash_info[i].size;
74
75#if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
76 part.size -=
77 flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
78 flash_info[CFG_JFFS2_FIRST_BANK].start[0];
79#endif
80
81 /* unused in current jffs2 loader */
82 part.erasesize = 0;
83
84 /* Mark the struct as ready */
85 part.usr_priv=(void*)1;
86
87 return &part;
88 }
89 return 0;
90}
91#endif /* ifndef CFG_JFFS_CUSTOM_PART */
wdenkdd875c72004-01-03 21:24:46 +000092
wdenkc6097192002-11-03 00:24:07 +000093int
94do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
95{
wdenk8bde7f72003-06-27 21:31:46 +000096 struct part_info* jffs2_part_info(int);
97 int jffs2_1pass_load(char *, struct part_info *,const char *);
wdenkdd875c72004-01-03 21:24:46 +000098 char *fsname;
wdenk8bde7f72003-06-27 21:31:46 +000099
wdenk3bac3512003-03-12 10:41:04 +0000100 char *filename = "uImage";
wdenk4b9206e2004-03-23 22:14:11 +0000101 ulong offset = load_addr;
wdenkc6097192002-11-03 00:24:07 +0000102 int size;
103 struct part_info *part;
104
105 if (argc == 2) {
106 filename = argv[1];
107 }
108 if (argc == 3) {
109 offset = simple_strtoul(argv[1], NULL, 16);
wdenk4b9206e2004-03-23 22:14:11 +0000110 load_addr = offset;
wdenkc6097192002-11-03 00:24:07 +0000111 filename = argv[2];
112 }
113
114 if (0 != (part=jffs2_part_info(part_num))){
115
wdenkdd875c72004-01-03 21:24:46 +0000116 /* check partition type for cramfs */
117 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
118 printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
119
120 if (cramfs_check(part)) {
121 size = cramfs_load ((char *) offset, part, filename);
122 } else {
123 /* if this is not cramfs assume jffs2 */
124 size = jffs2_1pass_load((char *)offset, part, filename);
125 }
wdenkc6097192002-11-03 00:24:07 +0000126
127 if (size > 0) {
128 char buf[10];
wdenkdd875c72004-01-03 21:24:46 +0000129 printf("### %s load complete: %d bytes loaded to 0x%lx\n",
130 fsname, size, offset);
wdenkc6097192002-11-03 00:24:07 +0000131 sprintf(buf, "%x", size);
132 setenv("filesize", buf);
133 } else {
wdenkdd875c72004-01-03 21:24:46 +0000134 printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
wdenkc6097192002-11-03 00:24:07 +0000135 }
136
137 return !(size > 0);
138 }
wdenk4b9206e2004-03-23 22:14:11 +0000139 puts ("Active partition not valid\n");
wdenkc6097192002-11-03 00:24:07 +0000140 return 0;
141}
142
143int
144do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
145{
wdenk8bde7f72003-06-27 21:31:46 +0000146 struct part_info* jffs2_part_info(int);
147 int jffs2_1pass_ls(struct part_info *,char *);
148
149 char *filename = "/";
wdenkc6097192002-11-03 00:24:07 +0000150 int ret;
151 struct part_info *part;
152
153 if (argc == 2)
154 filename = argv[1];
155
156 if (0 != (part=jffs2_part_info(part_num))){
157
wdenkdd875c72004-01-03 21:24:46 +0000158 /* check partition type for cramfs */
159 if (cramfs_check(part)) {
160 ret = cramfs_ls (part, filename);
161 } else {
162 /* if this is not cramfs assume jffs2 */
163 ret = jffs2_1pass_ls(part, filename);
164 }
wdenkc6097192002-11-03 00:24:07 +0000165
166 return (ret == 1);
167 }
wdenk4b9206e2004-03-23 22:14:11 +0000168 puts ("Active partition not valid\n");
wdenkc6097192002-11-03 00:24:07 +0000169 return 0;
170}
171
172int
173do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
174{
wdenkdd875c72004-01-03 21:24:46 +0000175 struct part_info* jffs2_part_info(int);
176 int jffs2_1pass_info(struct part_info *);
wdenkc6097192002-11-03 00:24:07 +0000177 struct part_info *part;
wdenkdd875c72004-01-03 21:24:46 +0000178 char *fsname;
179 int ret;
wdenkc6097192002-11-03 00:24:07 +0000180
wdenkdd875c72004-01-03 21:24:46 +0000181 if ((part=jffs2_part_info(part_num))){
wdenkc6097192002-11-03 00:24:07 +0000182
wdenkdd875c72004-01-03 21:24:46 +0000183 /* check partition type for cramfs */
184 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
185 printf("### filesystem type is %s\n", fsname);
186
187 if (cramfs_check(part)) {
188 ret = cramfs_info (part);
189 } else {
190 /* if this is not cramfs assume jffs2 */
191 ret = jffs2_1pass_info(part);
192 }
wdenkc6097192002-11-03 00:24:07 +0000193
194 return (ret == 1);
195 }
wdenk4b9206e2004-03-23 22:14:11 +0000196 puts ("Active partition not valid\n");
wdenkc6097192002-11-03 00:24:07 +0000197 return 0;
198}
199
200int
201do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
202{
203 int tmp_part;
wdenkdd875c72004-01-03 21:24:46 +0000204 char str_part_num[3];
wdenk8bde7f72003-06-27 21:31:46 +0000205 struct part_info* jffs2_part_info(int);
wdenkc6097192002-11-03 00:24:07 +0000206
wdenk8bde7f72003-06-27 21:31:46 +0000207 if (argc >= 2) {
wdenkc6097192002-11-03 00:24:07 +0000208 tmp_part = simple_strtoul(argv[1], NULL, 16);
209 }else{
wdenk4b9206e2004-03-23 22:14:11 +0000210 puts ("Need partition number in argument list\n");
wdenkc6097192002-11-03 00:24:07 +0000211 return 0;
212
213 }
214
215 if (jffs2_part_info(tmp_part)){
wdenk7205e402003-09-10 22:30:53 +0000216 printf("Partition changed to %d\n",tmp_part);
wdenkc6097192002-11-03 00:24:07 +0000217 part_num=tmp_part;
wdenkdd875c72004-01-03 21:24:46 +0000218 sprintf(str_part_num, "%d", part_num);
219 setenv("partition", str_part_num);
wdenkc6097192002-11-03 00:24:07 +0000220 return 0;
221 }
222
223 printf("Partition %d is not valid partiton\n",tmp_part);
224 return 0;
225
226}
wdenk8bde7f72003-06-27 21:31:46 +0000227
228/***************************************************/
229
wdenk0d498392003-07-01 21:06:45 +0000230U_BOOT_CMD(
231 fsload, 3, 0, do_jffs2_fsload,
wdenk8bde7f72003-06-27 21:31:46 +0000232 "fsload - load binary file from a filesystem image\n",
233 "[ off ] [ filename ]\n"
234 " - load binary file from flash bank\n"
235 " with offset 'off'\n"
236);
237
wdenk0d498392003-07-01 21:06:45 +0000238U_BOOT_CMD(
239 fsinfo, 1, 1, do_jffs2_fsinfo,
wdenk8bde7f72003-06-27 21:31:46 +0000240 "fsinfo - print information about filesystems\n",
241 " - print information about filesystems\n"
242);
243
wdenk0d498392003-07-01 21:06:45 +0000244U_BOOT_CMD(
245 ls, 2, 1, do_jffs2_ls,
wdenk8bde7f72003-06-27 21:31:46 +0000246 "ls - list files in a directory (default /)\n",
247 "[ directory ]\n"
248 " - list files in a directory.\n"
249);
250
wdenk0d498392003-07-01 21:06:45 +0000251U_BOOT_CMD(
252 chpart, 2, 0, do_jffs2_chpart,
wdenk8bde7f72003-06-27 21:31:46 +0000253 "chpart - change active partition\n",
254 " - change active partition\n"
255);
256
wdenkc6097192002-11-03 00:24:07 +0000257#endif /* CFG_CMD_JFFS2 */