]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_jffs2.c
* Switch LWMON board default config from FRAM to EEPROM;
[karo-tx-uboot.git] / common / cmd_jffs2.c
1 /*
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>
29 #include <cmd_boot.h>
30 #include <cmd_autoscript.h>
31 #include <s_record.h>
32 #include <net.h>
33
34 #if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
35
36 #include <jffs2/jffs2.h>
37 static int part_num=0;
38
39 #ifndef CFG_JFFS_CUSTOM_PART
40
41 static struct part_info part;
42
43 struct part_info*
44 jffs2_part_info(int part_num)
45 {
46         extern flash_info_t flash_info[];       /* info for FLASH chips */
47         int i;
48
49         if(part_num==0){
50
51                 if(part.usr_priv==(void*)1)
52                         return &part;
53
54                 memset(&part, 0, sizeof(part));
55
56 #if defined(CFG_JFFS2_FIRST_SECTOR)
57                 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR];
58 #else
59                 part.offset = (unsigned char *) flash_info[CFG_JFFS2_FIRST_BANK].start[0];
60 #endif
61
62                 /* Figure out flash partition size */
63                 for (i = CFG_JFFS2_FIRST_BANK; i < CFG_JFFS2_NUM_BANKS+CFG_JFFS2_FIRST_BANK; i++)
64                         part.size += flash_info[i].size;
65
66 #if defined(CFG_JFFS2_FIRST_SECTOR) && (CFG_JFFS2_FIRST_SECTOR > 0)
67                 part.size -=
68                         flash_info[CFG_JFFS2_FIRST_BANK].start[CFG_JFFS2_FIRST_SECTOR] -
69                         flash_info[CFG_JFFS2_FIRST_BANK].start[0];
70 #endif
71
72                 /* unused in current jffs2 loader */
73                 part.erasesize = 0;
74
75                 /* Mark the struct as ready */
76                 part.usr_priv=(void*)1;
77
78                 return &part;
79         }
80         return 0;
81 }
82 #endif /* ifndef CFG_JFFS_CUSTOM_PART */
83 int
84 do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
85 {
86         char *filename = "pImage";
87         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
120 int
121 do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
122 {
123         char *filename = "/";
124         int ret;
125         struct part_info *part;
126
127         if (argc == 2)
128                 filename = argv[1];
129
130         if (0 != (part=jffs2_part_info(part_num))){
131
132                 ret = jffs2_1pass_ls(jffs2_part_info(part_num), filename);
133
134                 return (ret == 1);
135         }
136         printf("Active partition not valid\n");
137         return 0;
138 }
139
140 int
141 do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
142 {
143         int ret;
144         struct part_info *part;
145
146         if (0 != (part=jffs2_part_info(part_num))){
147
148                 ret = jffs2_1pass_info(jffs2_part_info(part_num));
149
150                 return (ret == 1);
151         }
152         printf("Active partition not valid\n");
153         return 0;
154 }
155
156 int
157 do_jffs2_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
158 {
159         int tmp_part;
160
161         if (argc >= 2) {
162                 tmp_part = simple_strtoul(argv[1], NULL, 16);
163         }else{
164                 printf("Need partition number in argument list\n");
165                 return 0;
166
167         }
168
169         if (jffs2_part_info(tmp_part)){
170                 printf("Partiton changed to %d\n",tmp_part);
171                 part_num=tmp_part;
172                 return 0;
173         }
174
175         printf("Partition %d is not valid partiton\n",tmp_part);
176         return 0;
177
178 }
179 #endif /* CFG_CMD_JFFS2 */