blob: e45a2ced00fb8e8b6b8197aa5b14b3cb2022d958 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * Boot support
26 */
27#include <common.h>
28#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000029#include <s_record.h>
wdenk8bde7f72003-06-27 21:31:46 +000030#include <jffs2/load_kernel.h>
wdenkc6097192002-11-03 00:24:07 +000031#include <net.h>
32
33#if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
wdenkc6097192002-11-03 00:24:07 +000034static int part_num=0;
35
36#ifndef CFG_JFFS_CUSTOM_PART
37
38static struct part_info part;
39
40struct part_info*
41jffs2_part_info(int part_num)
42{
43 extern flash_info_t flash_info[]; /* info for FLASH chips */
44 int i;
45
46 if(part_num==0){
47
48 if(part.usr_priv==(void*)1)
49 return &part;
50
51 memset(&part, 0, sizeof(part));
52
53#if defined(CFG_JFFS2_FIRST_SECTOR)
54 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
55#else
56 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
57#endif
58
59 /* Figure out flash partition size */
60 for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
61 part.size += flash_info[i].size;
62
63#if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
64 part.size -=
65 flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
66 flash_info[CFG_JFFS2_FIRST_BANK].start[0];
67#endif
68
69 /* unused in current jffs2 loader */
70 part.erasesize = 0;
71
72 /* Mark the struct as ready */
73 part.usr_priv=(void*)1;
74
75 return &part;
76 }
77 return 0;
78}
79#endif /* ifndef CFG_JFFS_CUSTOM_PART */
80int
81do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
82{
wdenk8bde7f72003-06-27 21:31:46 +000083 struct part_info* jffs2_part_info(int);
84 int jffs2_1pass_load(char *, struct part_info *,const char *);
85
wdenk3bac3512003-03-12 10:41:04 +000086 char *filename = "uImage";
wdenkc6097192002-11-03 00:24:07 +000087 ulong offset = CFG_LOAD_ADDR;
88 int size;
89 struct part_info *part;
90
91 if (argc == 2) {
92 filename = argv[1];
93 }
94 if (argc == 3) {
95 offset = simple_strtoul(argv[1], NULL, 16);
96 filename = argv[2];
97 }
98
99 if (0 != (part=jffs2_part_info(part_num))){
100
101 printf("### JFFS2 loading '%s' to 0x%lx\n", filename, offset);
102 size = jffs2_1pass_load((char *)offset, part, filename);
103
104 if (size > 0) {
105 char buf[10];
106 printf("### JFFS2 load complete: %d bytes loaded to 0x%lx\n",
107 size, offset);
108 sprintf(buf, "%x", size);
109 setenv("filesize", buf);
110 } else {
111 printf("### JFFS2 LOAD ERROR<%x> for %s!\n", size, filename);
112 }
113
114 return !(size > 0);
115 }
116 printf("Active partition not valid\n");
117 return 0;
118}
119
120int
121do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
122{
wdenk8bde7f72003-06-27 21:31:46 +0000123 struct part_info* jffs2_part_info(int);
124 int jffs2_1pass_ls(struct part_info *,char *);
125
126 char *filename = "/";
wdenkc6097192002-11-03 00:24:07 +0000127 int ret;
128 struct part_info *part;
129
130 if (argc == 2)
131 filename = argv[1];
132
133 if (0 != (part=jffs2_part_info(part_num))){
134
135 ret = jffs2_1pass_ls(jffs2_part_info(part_num), filename);
136
137 return (ret == 1);
138 }
139 printf("Active partition not valid\n");
140 return 0;
141}
142
143int
144do_jffs2_fsinfo(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_info(struct part_info *);
148
wdenkc6097192002-11-03 00:24:07 +0000149 int ret;
150 struct part_info *part;
151
152 if (0 != (part=jffs2_part_info(part_num))){
153
154 ret = jffs2_1pass_info(jffs2_part_info(part_num));
155
156 return (ret == 1);
157 }
158 printf("Active partition not valid\n");
159 return 0;
160}
161
162int
163do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
164{
165 int tmp_part;
wdenk8bde7f72003-06-27 21:31:46 +0000166 struct part_info* jffs2_part_info(int);
wdenkc6097192002-11-03 00:24:07 +0000167
wdenk8bde7f72003-06-27 21:31:46 +0000168 if (argc >= 2) {
wdenkc6097192002-11-03 00:24:07 +0000169 tmp_part = simple_strtoul(argv[1], NULL, 16);
170 }else{
171 printf("Need partition number in argument list\n");
172 return 0;
173
174 }
175
176 if (jffs2_part_info(tmp_part)){
177 printf("Partiton changed to %d\n",tmp_part);
178 part_num=tmp_part;
179 return 0;
180 }
181
182 printf("Partition %d is not valid partiton\n",tmp_part);
183 return 0;
184
185}
wdenk8bde7f72003-06-27 21:31:46 +0000186
187/***************************************************/
188
189cmd_tbl_t U_BOOT_CMD(JFFS2_FSLOAD) = MK_CMD_ENTRY(
190 "fsload", 3, 0, do_jffs2_fsload,
191 "fsload - load binary file from a filesystem image\n",
192 "[ off ] [ filename ]\n"
193 " - load binary file from flash bank\n"
194 " with offset 'off'\n"
195);
196
197cmd_tbl_t U_BOOT_CMD(JFFS2_FSINFO) = MK_CMD_ENTRY(
198 "fsinfo", 1, 1, do_jffs2_fsinfo,
199 "fsinfo - print information about filesystems\n",
200 " - print information about filesystems\n"
201);
202
203cmd_tbl_t U_BOOT_CMD(JFFS2_LS) = MK_CMD_ENTRY(
204 "ls", 2, 1, do_jffs2_ls,
205 "ls - list files in a directory (default /)\n",
206 "[ directory ]\n"
207 " - list files in a directory.\n"
208);
209
210cmd_tbl_t U_BOOT_CMD(JFFS2_CHPART) = MK_CMD_ENTRY(
211 "chpart", 2, 0, do_jffs2_chpart,
212 "chpart - change active partition\n",
213 " - change active partition\n"
214);
215
wdenkc6097192002-11-03 00:24:07 +0000216#endif /* CFG_CMD_JFFS2 */