2 * SPDX-License-Identifier: GPL-2.0+
4 * based on: cmd_jffs2.c
6 * Add support for a CRAMFS located in RAM
16 #include <linux/list.h>
17 #include <linux/ctype.h>
18 #include <jffs2/jffs2.h>
19 #include <jffs2/load_kernel.h>
20 #include <cramfs/cramfs_fs.h>
22 /* enable/disable debugging messages */
27 # define DEBUGF(fmt, args...) printf(fmt ,##args)
29 # define DEBUGF(fmt, args...)
34 #ifndef CONFIG_MTD_NOR_FLASH
35 # define OFFSET_ADJUSTMENT 0
37 # define OFFSET_ADJUSTMENT (flash_info[id.num].start[0])
40 #ifndef CONFIG_CMD_JFFS2
41 #include <linux/stat.h>
42 char *mkmodestr(unsigned long mode, char *str)
44 static const char *l = "xwr";
48 switch (mode & S_IFMT) {
49 case S_IFDIR: str[0] = 'd'; break;
50 case S_IFBLK: str[0] = 'b'; break;
51 case S_IFCHR: str[0] = 'c'; break;
52 case S_IFIFO: str[0] = 'f'; break;
53 case S_IFLNK: str[0] = 'l'; break;
54 case S_IFSOCK: str[0] = 's'; break;
55 case S_IFREG: str[0] = '-'; break;
56 default: str[0] = '?';
59 for(i = 0; i < 9; i++) {
61 str[9-i] = (mode & mask)?c:'-';
65 if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
66 if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
67 if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
71 #endif /* CONFIG_CMD_JFFS2 */
73 extern int cramfs_check (struct part_info *info);
74 extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
75 extern int cramfs_ls (struct part_info *info, char *filename);
76 extern int cramfs_info (struct part_info *info);
78 /***************************************************/
80 /***************************************************/
83 * Routine implementing fsload u-boot command. This routine tries to load
84 * a requested file from cramfs filesystem at location 'cramfsaddr'.
85 * cramfsaddr is an evironment variable.
87 * @param cmdtp command internal data
88 * @param flag command flag
89 * @param argc number of arguments supplied to the command
90 * @param argv arguments list
91 * @return 0 on success, 1 otherwise
93 int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
97 ulong offset = load_addr;
99 struct part_info part;
100 struct mtd_device dev;
104 addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
107 /* cramfs_* only supports NOR flash chips */
108 /* fake the device type */
109 id.type = MTD_DEV_TYPE_NOR;
113 /* fake the address offset */
114 part.offset = addr - OFFSET_ADJUSTMENT;
116 /* pre-set Boot file name */
117 if ((filename = getenv("bootfile")) == NULL) {
125 offset = simple_strtoul(argv[1], NULL, 0);
131 if (cramfs_check(&part))
132 size = cramfs_load ((char *) offset, &part, filename);
135 printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
137 setenv_hex("filesize", size);
139 printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
146 * Routine implementing u-boot ls command which lists content of a given
147 * directory at location 'cramfsaddr'.
148 * cramfsaddr is an evironment variable.
150 * @param cmdtp command internal data
151 * @param flag command flag
152 * @param argc number of arguments supplied to the command
153 * @param argv arguments list
154 * @return 0 on success, 1 otherwise
156 int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
158 char *filename = "/";
160 struct part_info part;
161 struct mtd_device dev;
165 addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
168 /* cramfs_* only supports NOR flash chips */
169 /* fake the device type */
170 id.type = MTD_DEV_TYPE_NOR;
174 /* fake the address offset */
175 part.offset = addr - OFFSET_ADJUSTMENT;
181 if (cramfs_check(&part))
182 ret = cramfs_ls (&part, filename);
187 /* command line only */
189 /***************************************************/
191 cramfsload, 3, 0, do_cramfs_load,
192 "load binary file from a filesystem image",
193 "[ off ] [ filename ]\n"
194 " - load binary file from address 'cramfsaddr'\n"
195 " with offset 'off'\n"
198 cramfsls, 2, 1, do_cramfs_ls,
199 "list files in a directory (default /)",
201 " - list files in a directory.\n"