blob: a581e6f9459b385dc652b421a05b4f68a7d50e69 [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
wdenkc6097192002-11-03 00:24:07 +000041static int part_num=0;
42
43#ifndef CFG_JFFS_CUSTOM_PART
44
45static struct part_info part;
46
47struct part_info*
48jffs2_part_info(int part_num)
49{
50 extern flash_info_t flash_info[]; /* info for FLASH chips */
51 int i;
52
53 if(part_num==0){
54
55 if(part.usr_priv==(void*)1)
56 return &part;
57
58 memset(&part, 0, sizeof(part));
59
60#if defined(CFG_JFFS2_FIRST_SECTOR)
61 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
62#else
63 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
64#endif
65
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;
69
70#if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
71 part.size -=
72 flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
73 flash_info[CFG_JFFS2_FIRST_BANK].start[0];
74#endif
75
76 /* unused in current jffs2 loader */
77 part.erasesize = 0;
78
79 /* Mark the struct as ready */
80 part.usr_priv=(void*)1;
81
82 return &part;
83 }
84 return 0;
85}
86#endif /* ifndef CFG_JFFS_CUSTOM_PART */
wdenkdd875c72004-01-03 21:24:46 +000087
wdenkc6097192002-11-03 00:24:07 +000088int
89do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
90{
wdenk8bde7f72003-06-27 21:31:46 +000091 struct part_info* jffs2_part_info(int);
92 int jffs2_1pass_load(char *, struct part_info *,const char *);
wdenkdd875c72004-01-03 21:24:46 +000093 char *fsname;
wdenk8bde7f72003-06-27 21:31:46 +000094
wdenk3bac3512003-03-12 10:41:04 +000095 char *filename = "uImage";
wdenkc6097192002-11-03 00:24:07 +000096 ulong offset = CFG_LOAD_ADDR;
97 int size;
98 struct part_info *part;
99
100 if (argc == 2) {
101 filename = argv[1];
102 }
103 if (argc == 3) {
104 offset = simple_strtoul(argv[1], NULL, 16);
105 filename = argv[2];
106 }
107
108 if (0 != (part=jffs2_part_info(part_num))){
109
wdenkdd875c72004-01-03 21:24:46 +0000110 /* check partition type for cramfs */
111 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
112 printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
113
114 if (cramfs_check(part)) {
115 size = cramfs_load ((char *) offset, part, filename);
116 } else {
117 /* if this is not cramfs assume jffs2 */
118 size = jffs2_1pass_load((char *)offset, part, filename);
119 }
wdenkc6097192002-11-03 00:24:07 +0000120
121 if (size > 0) {
122 char buf[10];
wdenkdd875c72004-01-03 21:24:46 +0000123 printf("### %s load complete: %d bytes loaded to 0x%lx\n",
124 fsname, size, offset);
wdenkc6097192002-11-03 00:24:07 +0000125 sprintf(buf, "%x", size);
126 setenv("filesize", buf);
127 } else {
wdenkdd875c72004-01-03 21:24:46 +0000128 printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
wdenkc6097192002-11-03 00:24:07 +0000129 }
130
131 return !(size > 0);
132 }
133 printf("Active partition not valid\n");
134 return 0;
135}
136
137int
138do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
139{
wdenk8bde7f72003-06-27 21:31:46 +0000140 struct part_info* jffs2_part_info(int);
141 int jffs2_1pass_ls(struct part_info *,char *);
142
143 char *filename = "/";
wdenkc6097192002-11-03 00:24:07 +0000144 int ret;
145 struct part_info *part;
146
147 if (argc == 2)
148 filename = argv[1];
149
150 if (0 != (part=jffs2_part_info(part_num))){
151
wdenkdd875c72004-01-03 21:24:46 +0000152 /* check partition type for cramfs */
153 if (cramfs_check(part)) {
154 ret = cramfs_ls (part, filename);
155 } else {
156 /* if this is not cramfs assume jffs2 */
157 ret = jffs2_1pass_ls(part, filename);
158 }
wdenkc6097192002-11-03 00:24:07 +0000159
160 return (ret == 1);
161 }
162 printf("Active partition not valid\n");
163 return 0;
164}
165
166int
167do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
168{
wdenkdd875c72004-01-03 21:24:46 +0000169 struct part_info* jffs2_part_info(int);
170 int jffs2_1pass_info(struct part_info *);
wdenkc6097192002-11-03 00:24:07 +0000171 struct part_info *part;
wdenkdd875c72004-01-03 21:24:46 +0000172 char *fsname;
173 int ret;
wdenkc6097192002-11-03 00:24:07 +0000174
wdenkdd875c72004-01-03 21:24:46 +0000175 if ((part=jffs2_part_info(part_num))){
wdenkc6097192002-11-03 00:24:07 +0000176
wdenkdd875c72004-01-03 21:24:46 +0000177 /* check partition type for cramfs */
178 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
179 printf("### filesystem type is %s\n", fsname);
180
181 if (cramfs_check(part)) {
182 ret = cramfs_info (part);
183 } else {
184 /* if this is not cramfs assume jffs2 */
185 ret = jffs2_1pass_info(part);
186 }
wdenkc6097192002-11-03 00:24:07 +0000187
188 return (ret == 1);
189 }
190 printf("Active partition not valid\n");
191 return 0;
192}
193
194int
195do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
196{
197 int tmp_part;
wdenkdd875c72004-01-03 21:24:46 +0000198 char str_part_num[3];
wdenk8bde7f72003-06-27 21:31:46 +0000199 struct part_info* jffs2_part_info(int);
wdenkc6097192002-11-03 00:24:07 +0000200
wdenk8bde7f72003-06-27 21:31:46 +0000201 if (argc >= 2) {
wdenkc6097192002-11-03 00:24:07 +0000202 tmp_part = simple_strtoul(argv[1], NULL, 16);
203 }else{
204 printf("Need partition number in argument list\n");
205 return 0;
206
207 }
208
209 if (jffs2_part_info(tmp_part)){
wdenk7205e402003-09-10 22:30:53 +0000210 printf("Partition changed to %d\n",tmp_part);
wdenkc6097192002-11-03 00:24:07 +0000211 part_num=tmp_part;
wdenkdd875c72004-01-03 21:24:46 +0000212 sprintf(str_part_num, "%d", part_num);
213 setenv("partition", str_part_num);
wdenkc6097192002-11-03 00:24:07 +0000214 return 0;
215 }
216
217 printf("Partition %d is not valid partiton\n",tmp_part);
218 return 0;
219
220}
wdenk8bde7f72003-06-27 21:31:46 +0000221
222/***************************************************/
223
wdenk0d498392003-07-01 21:06:45 +0000224U_BOOT_CMD(
225 fsload, 3, 0, do_jffs2_fsload,
wdenk8bde7f72003-06-27 21:31:46 +0000226 "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"
230);
231
wdenk0d498392003-07-01 21:06:45 +0000232U_BOOT_CMD(
233 fsinfo, 1, 1, do_jffs2_fsinfo,
wdenk8bde7f72003-06-27 21:31:46 +0000234 "fsinfo - print information about filesystems\n",
235 " - print information about filesystems\n"
236);
237
wdenk0d498392003-07-01 21:06:45 +0000238U_BOOT_CMD(
239 ls, 2, 1, do_jffs2_ls,
wdenk8bde7f72003-06-27 21:31:46 +0000240 "ls - list files in a directory (default /)\n",
241 "[ directory ]\n"
242 " - list files in a directory.\n"
243);
244
wdenk0d498392003-07-01 21:06:45 +0000245U_BOOT_CMD(
246 chpart, 2, 0, do_jffs2_chpart,
wdenk8bde7f72003-06-27 21:31:46 +0000247 "chpart - change active partition\n",
248 " - change active partition\n"
249);
250
wdenkc6097192002-11-03 00:24:07 +0000251#endif /* CFG_CMD_JFFS2 */