]> Git Repo - u-boot.git/blame - common/cmd_jffs2.c
Patch by Tolunay Orkun, 14 May 2004:
[u-boot.git] / common / cmd_jffs2.c
CommitLineData
c609719b
WD
1/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, [email protected].
dd875c76
WD
4 * (C) Copyright 2002
5 * Robert Schwebel, Pengutronix, <[email protected]>
6 * (C) Copyright 2003
7 * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <[email protected]>
c609719b
WD
8 *
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>
c609719b 33#include <s_record.h>
8bde7f77 34#include <jffs2/load_kernel.h>
c609719b
WD
35#include <net.h>
36
37#if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
dd875c76
WD
38
39#include <cramfs/cramfs_fs.h>
40
180d3f74
WD
41extern 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
c609719b
WD
46static int part_num=0;
47
48#ifndef CFG_JFFS_CUSTOM_PART
49
50static struct part_info part;
51
998eaaec
WD
52#ifndef CONFIG_JFFS2_NAND
53
c609719b
WD
54struct 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
fc1cfcdb
WD
83 /* unused in current jffs2 loader */
84 part.erasesize = 0;
c609719b
WD
85
86 /* Mark the struct as ready */
87 part.usr_priv=(void*)1;
88
89 return &part;
90 }
91 return 0;
92}
998eaaec
WD
93
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 */
c609719b 120#endif /* ifndef CFG_JFFS_CUSTOM_PART */
dd875c76 121
c609719b
WD
122int
123do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
124{
8bde7f77
WD
125 struct part_info* jffs2_part_info(int);
126 int jffs2_1pass_load(char *, struct part_info *,const char *);
dd875c76 127 char *fsname;
8bde7f77 128
3bac3513 129 char *filename = "uImage";
4b9206ed 130 ulong offset = load_addr;
c609719b
WD
131 int size;
132 struct part_info *part;
133
134 if (argc == 2) {
135 filename = argv[1];
136 }
137 if (argc == 3) {
138 offset = simple_strtoul(argv[1], NULL, 16);
4b9206ed 139 load_addr = offset;
c609719b
WD
140 filename = argv[2];
141 }
142
143 if (0 != (part=jffs2_part_info(part_num))){
144
dd875c76
WD
145 /* check partition type for cramfs */
146 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
147 printf("### %s loading '%s' to 0x%lx\n", fsname, filename, offset);
148
149 if (cramfs_check(part)) {
150 size = cramfs_load ((char *) offset, part, filename);
151 } else {
152 /* if this is not cramfs assume jffs2 */
153 size = jffs2_1pass_load((char *)offset, part, filename);
154 }
c609719b
WD
155
156 if (size > 0) {
157 char buf[10];
dd875c76
WD
158 printf("### %s load complete: %d bytes loaded to 0x%lx\n",
159 fsname, size, offset);
c609719b
WD
160 sprintf(buf, "%x", size);
161 setenv("filesize", buf);
162 } else {
dd875c76 163 printf("### %s LOAD ERROR<%x> for %s!\n", fsname, size, filename);
c609719b
WD
164 }
165
166 return !(size > 0);
167 }
4b9206ed 168 puts ("Active partition not valid\n");
c609719b
WD
169 return 0;
170}
171
172int
173do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
174{
8bde7f77
WD
175 struct part_info* jffs2_part_info(int);
176 int jffs2_1pass_ls(struct part_info *,char *);
177
178 char *filename = "/";
c609719b
WD
179 int ret;
180 struct part_info *part;
181
182 if (argc == 2)
183 filename = argv[1];
184
185 if (0 != (part=jffs2_part_info(part_num))){
186
dd875c76
WD
187 /* check partition type for cramfs */
188 if (cramfs_check(part)) {
189 ret = cramfs_ls (part, filename);
190 } else {
191 /* if this is not cramfs assume jffs2 */
192 ret = jffs2_1pass_ls(part, filename);
193 }
c609719b
WD
194
195 return (ret == 1);
196 }
4b9206ed 197 puts ("Active partition not valid\n");
c609719b
WD
198 return 0;
199}
200
201int
202do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
203{
dd875c76
WD
204 struct part_info* jffs2_part_info(int);
205 int jffs2_1pass_info(struct part_info *);
c609719b 206 struct part_info *part;
dd875c76
WD
207 char *fsname;
208 int ret;
c609719b 209
dd875c76
WD
210 if ((part=jffs2_part_info(part_num))){
211
212 /* check partition type for cramfs */
213 fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
214 printf("### filesystem type is %s\n", fsname);
c609719b 215
dd875c76
WD
216 if (cramfs_check(part)) {
217 ret = cramfs_info (part);
218 } else {
219 /* if this is not cramfs assume jffs2 */
220 ret = jffs2_1pass_info(part);
221 }
c609719b
WD
222
223 return (ret == 1);
224 }
4b9206ed 225 puts ("Active partition not valid\n");
c609719b
WD
226 return 0;
227}
228
229int
230do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
231{
232 int tmp_part;
dd875c76 233 char str_part_num[3];
8bde7f77 234 struct part_info* jffs2_part_info(int);
c609719b 235
8bde7f77 236 if (argc >= 2) {
c609719b
WD
237 tmp_part = simple_strtoul(argv[1], NULL, 16);
238 }else{
4b9206ed 239 puts ("Need partition number in argument list\n");
c609719b
WD
240 return 0;
241
242 }
243
244 if (jffs2_part_info(tmp_part)){
7205e407 245 printf("Partition changed to %d\n",tmp_part);
c609719b 246 part_num=tmp_part;
dd875c76
WD
247 sprintf(str_part_num, "%d", part_num);
248 setenv("partition", str_part_num);
c609719b
WD
249 return 0;
250 }
251
252 printf("Partition %d is not valid partiton\n",tmp_part);
253 return 0;
254
255}
8bde7f77
WD
256
257/***************************************************/
258
0d498393
WD
259U_BOOT_CMD(
260 fsload, 3, 0, do_jffs2_fsload,
aa5590b6 261 "fsload\t- load binary file from a filesystem image\n",
8bde7f77
WD
262 "[ off ] [ filename ]\n"
263 " - load binary file from flash bank\n"
264 " with offset 'off'\n"
265);
266
0d498393
WD
267U_BOOT_CMD(
268 fsinfo, 1, 1, do_jffs2_fsinfo,
aa5590b6 269 "fsinfo\t- print information about filesystems\n",
8bde7f77
WD
270 " - print information about filesystems\n"
271);
272
0d498393
WD
273U_BOOT_CMD(
274 ls, 2, 1, do_jffs2_ls,
aa5590b6 275 "ls\t- list files in a directory (default /)\n",
8bde7f77
WD
276 "[ directory ]\n"
277 " - list files in a directory.\n"
278);
279
0d498393
WD
280U_BOOT_CMD(
281 chpart, 2, 0, do_jffs2_chpart,
aa5590b6 282 "chpart\t- change active partition\n",
8bde7f77
WD
283 " - change active partition\n"
284);
285
c609719b 286#endif /* CFG_CMD_JFFS2 */
This page took 0.07412 seconds and 4 git commands to generate.