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
48 #ifdef CONFIG_SYS_NO_FLASH
49 # define OFFSET_ADJUSTMENT 0
51 # define OFFSET_ADJUSTMENT (flash_info[id.num].start[0])
54 #ifndef CONFIG_CMD_JFFS2
55 #include <linux/stat.h>
56 char *mkmodestr(unsigned long mode, char *str)
58 static const char *l = "xwr";
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] = '?';
73 for(i = 0; i < 9; i++) {
75 str[9-i] = (mode & mask)?c:'-';
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';
85 #endif /* CONFIG_CMD_JFFS2 */
87 extern int cramfs_check (struct part_info *info);
88 extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
89 extern int cramfs_ls (struct part_info *info, char *filename);
90 extern int cramfs_info (struct part_info *info);
92 /***************************************************/
94 /***************************************************/
97 * Routine implementing fsload u-boot command. This routine tries to load
98 * a requested file from cramfs filesystem at location 'cramfsaddr'.
99 * cramfsaddr is an evironment variable.
101 * @param cmdtp command internal data
102 * @param flag command flag
103 * @param argc number of arguments supplied to the command
104 * @param argv arguments list
105 * @return 0 on success, 1 otherwise
107 int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
111 ulong offset = load_addr;
113 struct part_info part;
114 struct mtd_device dev;
118 addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
121 /* cramfs_* only supports NOR flash chips */
122 /* fake the device type */
123 id.type = MTD_DEV_TYPE_NOR;
127 /* fake the address offset */
128 part.offset = addr - OFFSET_ADJUSTMENT;
130 /* pre-set Boot file name */
131 if ((filename = getenv("bootfile")) == NULL) {
139 offset = simple_strtoul(argv[1], NULL, 0);
145 if (cramfs_check(&part))
146 size = cramfs_load ((char *) offset, &part, filename);
150 printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
152 sprintf(buf, "%x", size);
153 setenv("filesize", buf);
155 printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
162 * Routine implementing u-boot ls command which lists content of a given
163 * directory at location 'cramfsaddr'.
164 * cramfsaddr is an evironment variable.
166 * @param cmdtp command internal data
167 * @param flag command flag
168 * @param argc number of arguments supplied to the command
169 * @param argv arguments list
170 * @return 0 on success, 1 otherwise
172 int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
174 char *filename = "/";
176 struct part_info part;
177 struct mtd_device dev;
181 addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
184 /* cramfs_* only supports NOR flash chips */
185 /* fake the device type */
186 id.type = MTD_DEV_TYPE_NOR;
190 /* fake the address offset */
191 part.offset = addr - OFFSET_ADJUSTMENT;
197 if (cramfs_check(&part))
198 ret = cramfs_ls (&part, filename);
203 /* command line only */
205 /***************************************************/
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"
214 cramfsls, 2, 1, do_cramfs_ls,
215 "list files in a directory (default /)",
217 " - list files in a directory.\n"
220 #endif /* #ifdef CONFIG_CRAMFS_CMDLINE */
222 /***************************************************/