blob: 3cd2d8fa824a074a0b42684cd183818f6000a48f [file] [log] [blame]
Stefan Roesece6d0c82009-03-19 15:35:50 +01001/*
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
Stefan Roesecb9c09d2010-10-28 14:09:22 +020036#include "../fs/ubifs/ubifs.h"
37
Stefan Roesece6d0c82009-03-19 15:35:50 +010038static int ubifs_initialized;
39static int ubifs_mounted;
40
Stefan Roesecb9c09d2010-10-28 14:09:22 +020041extern struct super_block *ubifs_sb;
42
Stefan Roesece6d0c82009-03-19 15:35:50 +010043/* Prototypes */
44int ubifs_init(void);
45int ubifs_mount(char *vol_name);
Stefan Roesecb9c09d2010-10-28 14:09:22 +020046void ubifs_umount(struct ubifs_info *c);
Stefan Roesece6d0c82009-03-19 15:35:50 +010047int ubifs_ls(char *dir_name);
48int ubifs_load(char *filename, u32 addr, u32 size);
49
Wolfgang Denk54841ab2010-06-28 22:00:46 +020050int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roesece6d0c82009-03-19 15:35:50 +010051{
52 char *vol_name;
53 int ret;
54
Wolfgang Denk47e26b12010-07-17 01:06:04 +020055 if (argc != 2)
56 return cmd_usage(cmdtp);
57
Stefan Roesece6d0c82009-03-19 15:35:50 +010058 vol_name = argv[1];
59 debug("Using volume %s\n", vol_name);
60
61 if (ubifs_initialized == 0) {
62 ubifs_init();
63 ubifs_initialized = 1;
64 }
65
66 ret = ubifs_mount(vol_name);
67 if (ret)
68 return -1;
69
70 ubifs_mounted = 1;
71
72 return 0;
73}
74
Stefan Roese2f15cfd2010-11-01 17:28:22 +010075int ubifs_is_mounted(void)
76{
77 return ubifs_mounted;
78}
79
80void cmd_ubifs_umount(void)
81{
82
83 if (ubifs_sb) {
84 printf("Unmounting UBIFS volume %s!\n",
85 ((struct ubifs_info *)(ubifs_sb->s_fs_info))->vi.name);
86 ubifs_umount(ubifs_sb->s_fs_info);
87 }
88
89 ubifs_sb = NULL;
90 ubifs_mounted = 0;
91 ubifs_initialized = 0;
92}
93
Stefan Roesecb9c09d2010-10-28 14:09:22 +020094int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
95{
96 if (argc != 1)
97 return cmd_usage(cmdtp);
98
99 if (ubifs_initialized == 0) {
100 printf("No UBIFS volume mounted!\n");
101 return -1;
102 }
103
Stefan Roese2f15cfd2010-11-01 17:28:22 +0100104 cmd_ubifs_umount();
Stefan Roesecb9c09d2010-10-28 14:09:22 +0200105
106 return 0;
107}
108
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200109int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roesece6d0c82009-03-19 15:35:50 +0100110{
111 char *filename = "/";
112 int ret;
113
114 if (!ubifs_mounted) {
Stefan Roese9a2ea572010-10-28 14:09:29 +0200115 printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
Stefan Roesece6d0c82009-03-19 15:35:50 +0100116 return -1;
117 }
118
119 if (argc == 2)
120 filename = argv[1];
121 debug("Using filename %s\n", filename);
122
123 ret = ubifs_ls(filename);
124 if (ret)
125 printf("%s not found!\n", filename);
126
127 return ret;
128}
129
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200130int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roesece6d0c82009-03-19 15:35:50 +0100131{
132 char *filename;
Simon Kagstrom2896b582009-07-07 16:01:02 +0200133 char *endp;
Stefan Roesece6d0c82009-03-19 15:35:50 +0100134 int ret;
135 u32 addr;
136 u32 size = 0;
137
138 if (!ubifs_mounted) {
139 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
140 return -1;
141 }
142
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200143 if (argc < 3)
144 return cmd_usage(cmdtp);
Stefan Roesece6d0c82009-03-19 15:35:50 +0100145
Simon Kagstrom2896b582009-07-07 16:01:02 +0200146 addr = simple_strtoul(argv[1], &endp, 16);
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200147 if (endp == argv[1])
148 return cmd_usage(cmdtp);
Simon Kagstrom2896b582009-07-07 16:01:02 +0200149
Stefan Roesece6d0c82009-03-19 15:35:50 +0100150 filename = argv[2];
151
Simon Kagstrom2896b582009-07-07 16:01:02 +0200152 if (argc == 4) {
153 size = simple_strtoul(argv[3], &endp, 16);
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200154 if (endp == argv[3])
155 return cmd_usage(cmdtp);
Simon Kagstrom2896b582009-07-07 16:01:02 +0200156 }
Stefan Roesece6d0c82009-03-19 15:35:50 +0100157 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
158
159 ret = ubifs_load(filename, addr, size);
160 if (ret)
161 printf("%s not found!\n", filename);
162
163 return ret;
164}
165
166U_BOOT_CMD(
167 ubifsmount, 2, 0, do_ubifs_mount,
Mike Frysinger852dbfd2009-03-23 22:27:34 -0400168 "mount UBIFS volume",
Simon Kagstrom2896b582009-07-07 16:01:02 +0200169 "<volume-name>\n"
170 " - mount 'volume-name' volume"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200171);
Stefan Roesece6d0c82009-03-19 15:35:50 +0100172
Frans Meulenbroeks388a29d2010-07-31 15:01:53 +0200173U_BOOT_CMD(
Stefan Roesecb9c09d2010-10-28 14:09:22 +0200174 ubifsumount, 1, 0, do_ubifs_umount,
175 "unmount UBIFS volume",
176 " - unmount current volume"
177);
178
179U_BOOT_CMD(
Frans Meulenbroeks388a29d2010-07-31 15:01:53 +0200180 ubifsls, 2, 0, do_ubifs_ls,
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200181 "list files in a directory",
182 "[directory]\n"
183 " - list files in a 'directory' (default '/')"
184);
Stefan Roesece6d0c82009-03-19 15:35:50 +0100185
Frans Meulenbroeks388a29d2010-07-31 15:01:53 +0200186U_BOOT_CMD(
187 ubifsload, 4, 0, do_ubifs_load,
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200188 "load file from an UBIFS filesystem",
189 "<addr> <filename> [bytes]\n"
190 " - load file 'filename' to address 'addr'"
191);