]> git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_ubifs.c
correct a syntax typo in at91_matrix.h
[people/ms/u-boot.git] / common / cmd_ubifs.c
1 /*
2 * (C) Copyright 2008
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 */
24
25
26 /*
27 * UBIFS command support
28 */
29
30 #undef DEBUG
31
32 #include <common.h>
33 #include <config.h>
34 #include <command.h>
35
36 static int ubifs_initialized;
37 static int ubifs_mounted;
38
39 /* Prototypes */
40 int ubifs_init(void);
41 int ubifs_mount(char *vol_name);
42 int ubifs_ls(char *dir_name);
43 int ubifs_load(char *filename, u32 addr, u32 size);
44
45 int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
46 {
47 char *vol_name;
48 int ret;
49
50 if (argc != 2) {
51 cmd_usage(cmdtp);
52 return 1;
53 }
54 vol_name = argv[1];
55 debug("Using volume %s\n", vol_name);
56
57 if (ubifs_initialized == 0) {
58 ubifs_init();
59 ubifs_initialized = 1;
60 }
61
62 ret = ubifs_mount(vol_name);
63 if (ret)
64 return -1;
65
66 ubifs_mounted = 1;
67
68 return 0;
69 }
70
71 int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
72 {
73 char *filename = "/";
74 int ret;
75
76 if (!ubifs_mounted) {
77 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
78 return -1;
79 }
80
81 if (argc == 2)
82 filename = argv[1];
83 debug("Using filename %s\n", filename);
84
85 ret = ubifs_ls(filename);
86 if (ret)
87 printf("%s not found!\n", filename);
88
89 return ret;
90 }
91
92 int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
93 {
94 char *filename;
95 char *endp;
96 int ret;
97 u32 addr;
98 u32 size = 0;
99
100 if (!ubifs_mounted) {
101 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
102 return -1;
103 }
104
105 if (argc < 3) {
106 cmd_usage(cmdtp);
107 return -1;
108 }
109
110 addr = simple_strtoul(argv[1], &endp, 16);
111 if (endp == argv[1]) {
112 cmd_usage(cmdtp);
113 return 1;
114 }
115
116 filename = argv[2];
117
118 if (argc == 4) {
119 size = simple_strtoul(argv[3], &endp, 16);
120 if (endp == argv[3]) {
121 cmd_usage(cmdtp);
122 return 1;
123 }
124 }
125 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
126
127 ret = ubifs_load(filename, addr, size);
128 if (ret)
129 printf("%s not found!\n", filename);
130
131 return ret;
132 }
133
134 U_BOOT_CMD(
135 ubifsmount, 2, 0, do_ubifs_mount,
136 "mount UBIFS volume",
137 "<volume-name>\n"
138 " - mount 'volume-name' volume"
139 );
140
141 U_BOOT_CMD(ubifsls, 2, 0, do_ubifs_ls,
142 "list files in a directory",
143 "[directory]\n"
144 " - list files in a 'directory' (default '/')"
145 );
146
147 U_BOOT_CMD(ubifsload, 4, 0, do_ubifs_load,
148 "load file from an UBIFS filesystem",
149 "<addr> <filename> [bytes]\n"
150 " - load file 'filename' to address 'addr'"
151 );