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