1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <common.h>
27#include <command.h>
28#include <malloc.h>
29#include <linux/list.h>
30#include <linux/ctype.h>
31#include <jffs2/jffs2.h>
32#include <jffs2/load_kernel.h>
33#include <cramfs/cramfs_fs.h>
34
35
36#define DEBUG_CRAMFS
37#undef DEBUG_CRAMFS
38
39#ifdef DEBUG_CRAMFS
40# define DEBUGF(fmt, args...) printf(fmt ,##args)
41#else
42# define DEBUGF(fmt, args...)
43#endif
44
45#ifdef CONFIG_CRAMFS_CMDLINE
46flash_info_t flash_info[1];
47
48#ifndef CONFIG_CMD_JFFS2
49#include <linux/stat.h>
50char *mkmodestr(unsigned long mode, char *str)
51{
52 static const char *l = "xwr";
53 int mask = 1, i;
54 char c;
55
56 switch (mode & S_IFMT) {
57 case S_IFDIR: str[0] = 'd'; break;
58 case S_IFBLK: str[0] = 'b'; break;
59 case S_IFCHR: str[0] = 'c'; break;
60 case S_IFIFO: str[0] = 'f'; break;
61 case S_IFLNK: str[0] = 'l'; break;
62 case S_IFSOCK: str[0] = 's'; break;
63 case S_IFREG: str[0] = '-'; break;
64 default: str[0] = '?';
65 }
66
67 for(i = 0; i < 9; i++) {
68 c = l[i%3];
69 str[9-i] = (mode & mask)?c:'-';
70 mask = mask<<1;
71 }
72
73 if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
74 if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
75 if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
76 str[10] = '\0';
77 return str;
78}
79#endif
80
81extern int cramfs_check (struct part_info *info);
82extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
83extern int cramfs_ls (struct part_info *info, char *filename);
84extern int cramfs_info (struct part_info *info);
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
102{
103 char *filename;
104 int size;
105 ulong offset = load_addr;
106
107 struct part_info part;
108 struct mtd_device dev;
109 struct mtdids id;
110
111 ulong addr;
112 addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
113
114
115
116
117 id.type = MTD_DEV_TYPE_NOR;
118 id.num = 0;
119 dev.id = &id;
120 part.dev = &dev;
121
122 part.offset = addr - flash_info[id.num].start[0];
123
124
125 if ((filename = getenv("bootfile")) == NULL) {
126 filename = "uImage";
127 }
128
129 if (argc == 2) {
130 filename = argv[1];
131 }
132 if (argc == 3) {
133 offset = simple_strtoul(argv[1], NULL, 0);
134 load_addr = offset;
135 filename = argv[2];
136 }
137
138 size = 0;
139 if (cramfs_check(&part))
140 size = cramfs_load ((char *) offset, &part, filename);
141
142 if (size > 0) {
143 char buf[10];
144 printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
145 size, offset);
146 sprintf(buf, "%x", size);
147 setenv("filesize", buf);
148 } else {
149 printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
150 }
151
152 return !(size > 0);
153}
154
155
156
157
158
159
160
161
162
163
164
165
166int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
167{
168 char *filename = "/";
169 int ret;
170 struct part_info part;
171 struct mtd_device dev;
172 struct mtdids id;
173
174 ulong addr;
175 addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
176
177
178
179
180 id.type = MTD_DEV_TYPE_NOR;
181 id.num = 0;
182 dev.id = &id;
183 part.dev = &dev;
184
185 part.offset = addr - flash_info[id.num].start[0];
186
187 if (argc == 2)
188 filename = argv[1];
189
190 ret = 0;
191 if (cramfs_check(&part))
192 ret = cramfs_ls (&part, filename);
193
194 return ret ? 0 : 1;
195}
196
197
198
199
200U_BOOT_CMD(
201 cramfsload, 3, 0, do_cramfs_load,
202 "load binary file from a filesystem image",
203 "[ off ] [ filename ]\n"
204 " - load binary file from address 'cramfsaddr'\n"
205 " with offset 'off'\n"
206);
207U_BOOT_CMD(
208 cramfsls, 2, 1, do_cramfs_ls,
209 "list files in a directory (default /)",
210 "[ directory ]\n"
211 " - list files in a directory.\n"
212);
213
214#endif
215
216
217