2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of
5 * the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17 * based on: cmd_jffs2.c
19 * Add support for a CRAMFS located in RAM
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>
35 /* enable/disable debugging messages */
40 # define DEBUGF(fmt, args...) printf(fmt ,##args)
42 # define DEBUGF(fmt, args...)
45 #ifdef CONFIG_CRAMFS_CMDLINE
46 flash_info_t flash_info[1];
48 #ifndef CONFIG_CMD_JFFS2
49 #include <linux/stat.h>
50 char *mkmodestr(unsigned long mode, char *str)
52 static const char *l = "xwr";
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] = '?';
67 for(i = 0; i < 9; i++) {
69 str[9-i] = (mode & mask)?c:'-';
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';
79 #endif /* CONFIG_CMD_JFFS2 */
81 extern int cramfs_check (struct part_info *info);
82 extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
83 extern int cramfs_ls (struct part_info *info, char *filename);
84 extern int cramfs_info (struct part_info *info);
86 /***************************************************/
88 /***************************************************/
91 * Routine implementing fsload u-boot command. This routine tries to load
92 * a requested file from cramfs filesystem at location 'cramfsaddr'.
93 * cramfsaddr is an evironment variable.
95 * @param cmdtp command internal data
96 * @param flag command flag
97 * @param argc number of arguments supplied to the command
98 * @param argv arguments list
99 * @return 0 on success, 1 otherwise
101 int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
105 ulong offset = load_addr;
107 struct part_info part;
108 struct mtd_device dev;
112 addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
115 /* cramfs_* only supports NOR flash chips */
116 /* fake the device type */
117 id.type = MTD_DEV_TYPE_NOR;
121 /* fake the address offset */
122 part.offset = addr - flash_info[id.num].start[0];
124 /* pre-set Boot file name */
125 if ((filename = getenv("bootfile")) == NULL) {
133 offset = simple_strtoul(argv[1], NULL, 0);
139 if (cramfs_check(&part))
140 size = cramfs_load ((char *) offset, &part, filename);
144 printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
146 sprintf(buf, "%x", size);
147 setenv("filesize", buf);
149 printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
156 * Routine implementing u-boot ls command which lists content of a given
157 * directory at location 'cramfsaddr'.
158 * cramfsaddr is an evironment variable.
160 * @param cmdtp command internal data
161 * @param flag command flag
162 * @param argc number of arguments supplied to the command
163 * @param argv arguments list
164 * @return 0 on success, 1 otherwise
166 int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
168 char *filename = "/";
170 struct part_info part;
171 struct mtd_device dev;
175 addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
178 /* cramfs_* only supports NOR flash chips */
179 /* fake the device type */
180 id.type = MTD_DEV_TYPE_NOR;
184 /* fake the address offset */
185 part.offset = addr - flash_info[id.num].start[0];
191 if (cramfs_check(&part))
192 ret = cramfs_ls (&part, filename);
197 /* command line only */
199 /***************************************************/
201 cramfsload, 3, 0, do_cramfs_load,
202 "cramfsload\t- load binary file from a filesystem image",
203 "[ off ] [ filename ]\n"
204 " - load binary file from address 'cramfsaddr'\n"
205 " with offset 'off'\n"
208 cramfsls, 2, 1, do_cramfs_ls,
209 "cramfsls\t- list files in a directory (default /)",
211 " - list files in a directory.\n"
214 #endif /* #ifdef CONFIG_CRAMFS_CMDLINE */
216 /***************************************************/