]> Git Repo - J-u-boot.git/blame - cmd/cramfs.c
common: Move reset_cpu() to the CPU header
[J-u-boot.git] / cmd / cramfs.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
88ffb266 2/*
88ffb266
HS
3 *
4 * based on: cmd_jffs2.c
5 *
6 * Add support for a CRAMFS located in RAM
7 */
8
9
10/*
11 * CRAMFS support
12 */
13#include <common.h>
14#include <command.h>
c7694dd4 15#include <env.h>
88ffb266 16#include <malloc.h>
511c66b1 17#include <mapmem.h>
88ffb266
HS
18#include <linux/list.h>
19#include <linux/ctype.h>
20#include <jffs2/jffs2.h>
21#include <jffs2/load_kernel.h>
22#include <cramfs/cramfs_fs.h>
511c66b1 23#include <asm/io.h>
88ffb266
HS
24
25/* enable/disable debugging messages */
26#define DEBUG_CRAMFS
27#undef DEBUG_CRAMFS
28
29#ifdef DEBUG_CRAMFS
30# define DEBUGF(fmt, args...) printf(fmt ,##args)
31#else
32# define DEBUGF(fmt, args...)
33#endif
34
ee8bc961 35#include <flash.h>
88ffb266 36
e856bdcf 37#ifndef CONFIG_MTD_NOR_FLASH
62a813bc
HS
38# define OFFSET_ADJUSTMENT 0
39#else
40# define OFFSET_ADJUSTMENT (flash_info[id.num].start[0])
41#endif
42
59e12a4a 43#ifndef CONFIG_FS_JFFS2
88ffb266
HS
44#include <linux/stat.h>
45char *mkmodestr(unsigned long mode, char *str)
46{
47 static const char *l = "xwr";
48 int mask = 1, i;
49 char c;
50
51 switch (mode & S_IFMT) {
52 case S_IFDIR: str[0] = 'd'; break;
53 case S_IFBLK: str[0] = 'b'; break;
54 case S_IFCHR: str[0] = 'c'; break;
55 case S_IFIFO: str[0] = 'f'; break;
56 case S_IFLNK: str[0] = 'l'; break;
57 case S_IFSOCK: str[0] = 's'; break;
58 case S_IFREG: str[0] = '-'; break;
59 default: str[0] = '?';
60 }
61
62 for(i = 0; i < 9; i++) {
63 c = l[i%3];
64 str[9-i] = (mode & mask)?c:'-';
65 mask = mask<<1;
66 }
67
68 if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
69 if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
70 if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
71 str[10] = '\0';
72 return str;
73}
59e12a4a 74#endif /* CONFIG_FS_JFFS2 */
88ffb266
HS
75
76extern int cramfs_check (struct part_info *info);
77extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
78extern int cramfs_ls (struct part_info *info, char *filename);
79extern int cramfs_info (struct part_info *info);
80
81/***************************************************/
a187559e 82/* U-Boot commands */
88ffb266
HS
83/***************************************************/
84
85/**
86 * Routine implementing fsload u-boot command. This routine tries to load
87 * a requested file from cramfs filesystem at location 'cramfsaddr'.
88 * cramfsaddr is an evironment variable.
89 *
90 * @param cmdtp command internal data
91 * @param flag command flag
92 * @param argc number of arguments supplied to the command
93 * @param argv arguments list
94 * @return 0 on success, 1 otherwise
95 */
54841ab5 96int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
88ffb266
HS
97{
98 char *filename;
99 int size;
100 ulong offset = load_addr;
511c66b1 101 char *offset_virt;
88ffb266
HS
102
103 struct part_info part;
104 struct mtd_device dev;
105 struct mtdids id;
106
107 ulong addr;
00caae6d 108 addr = simple_strtoul(env_get("cramfsaddr"), NULL, 16);
88ffb266
HS
109
110 /* hack! */
111 /* cramfs_* only supports NOR flash chips */
112 /* fake the device type */
113 id.type = MTD_DEV_TYPE_NOR;
114 id.num = 0;
115 dev.id = &id;
116 part.dev = &dev;
117 /* fake the address offset */
511c66b1 118 part.offset = (u64)(uintptr_t) map_sysmem(addr - OFFSET_ADJUSTMENT, 0);
88ffb266
HS
119
120 /* pre-set Boot file name */
00caae6d
SG
121 filename = env_get("bootfile");
122 if (!filename)
88ffb266 123 filename = "uImage";
88ffb266
HS
124
125 if (argc == 2) {
126 filename = argv[1];
127 }
128 if (argc == 3) {
129 offset = simple_strtoul(argv[1], NULL, 0);
130 load_addr = offset;
131 filename = argv[2];
132 }
133
511c66b1 134 offset_virt = map_sysmem(offset, 0);
88ffb266
HS
135 size = 0;
136 if (cramfs_check(&part))
511c66b1 137 size = cramfs_load (offset_virt, &part, filename);
88ffb266
HS
138
139 if (size > 0) {
88ffb266
HS
140 printf("### CRAMFS load complete: %d bytes loaded to 0x%lx\n",
141 size, offset);
018f5303 142 env_set_hex("filesize", size);
88ffb266
HS
143 } else {
144 printf("### CRAMFS LOAD ERROR<%x> for %s!\n", size, filename);
145 }
146
511c66b1
TH
147 unmap_sysmem(offset_virt);
148 unmap_sysmem((void *)(uintptr_t)part.offset);
149
88ffb266
HS
150 return !(size > 0);
151}
152
153/**
154 * Routine implementing u-boot ls command which lists content of a given
155 * directory at location 'cramfsaddr'.
156 * cramfsaddr is an evironment variable.
157 *
158 * @param cmdtp command internal data
159 * @param flag command flag
160 * @param argc number of arguments supplied to the command
161 * @param argv arguments list
162 * @return 0 on success, 1 otherwise
163 */
54841ab5 164int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
88ffb266
HS
165{
166 char *filename = "/";
167 int ret;
168 struct part_info part;
169 struct mtd_device dev;
170 struct mtdids id;
171
172 ulong addr;
00caae6d 173 addr = simple_strtoul(env_get("cramfsaddr"), NULL, 16);
88ffb266
HS
174
175 /* hack! */
176 /* cramfs_* only supports NOR flash chips */
177 /* fake the device type */
178 id.type = MTD_DEV_TYPE_NOR;
179 id.num = 0;
180 dev.id = &id;
181 part.dev = &dev;
182 /* fake the address offset */
511c66b1 183 part.offset = (u64)(uintptr_t) map_sysmem(addr - OFFSET_ADJUSTMENT, 0);
88ffb266
HS
184
185 if (argc == 2)
186 filename = argv[1];
187
188 ret = 0;
189 if (cramfs_check(&part))
190 ret = cramfs_ls (&part, filename);
511c66b1 191 unmap_sysmem((void *)(uintptr_t)part.offset);
88ffb266
HS
192
193 return ret ? 0 : 1;
194}
195
196/* command line only */
197
198/***************************************************/
199U_BOOT_CMD(
200 cramfsload, 3, 0, do_cramfs_load,
cc9f607b 201 "load binary file from a filesystem image",
88ffb266
HS
202 "[ off ] [ filename ]\n"
203 " - load binary file from address 'cramfsaddr'\n"
204 " with offset 'off'\n"
205);
206U_BOOT_CMD(
207 cramfsls, 2, 1, do_cramfs_ls,
cc9f607b 208 "list files in a directory (default /)",
88ffb266
HS
209 "[ directory ]\n"
210 " - list files in a directory.\n"
211);
This page took 0.418295 seconds and 4 git commands to generate.