blob: ed0e9db2ac27577ff12e7ca673f027bb60b57856 [file] [log] [blame]
Stefan Roese5c721272009-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
36static int ubifs_initialized;
37static int ubifs_mounted;
38
39/* Prototypes */
40int ubifs_init(void);
41int ubifs_mount(char *vol_name);
42int ubifs_ls(char *dir_name);
43int ubifs_load(char *filename, u32 addr, u32 size);
44
45int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
46{
47 char *vol_name;
48 int ret;
49
Simon Kagstrom9dae38a2009-07-07 16:01:02 +020050 if (argc != 2) {
51 cmd_usage(cmdtp);
52 return 1;
53 }
Stefan Roese5c721272009-03-19 15:35:50 +010054 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
71int 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
92int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
93{
94 char *filename;
Simon Kagstrom9dae38a2009-07-07 16:01:02 +020095 char *endp;
Stefan Roese5c721272009-03-19 15:35:50 +010096 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) {
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200106 cmd_usage(cmdtp);
Stefan Roese5c721272009-03-19 15:35:50 +0100107 return -1;
108 }
109
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200110 addr = simple_strtoul(argv[1], &endp, 16);
111 if (endp == argv[1]) {
112 cmd_usage(cmdtp);
113 return 1;
114 }
115
Stefan Roese5c721272009-03-19 15:35:50 +0100116 filename = argv[2];
117
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200118 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 }
Stefan Roese5c721272009-03-19 15:35:50 +0100125 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
134U_BOOT_CMD(
135 ubifsmount, 2, 0, do_ubifs_mount,
Mike Frysinger27e1e622009-03-23 22:27:34 -0400136 "mount UBIFS volume",
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200137 "<volume-name>\n"
138 " - mount 'volume-name' volume"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200139);
Stefan Roese5c721272009-03-19 15:35:50 +0100140
141U_BOOT_CMD(ubifsls, 2, 0, do_ubifs_ls,
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200142 "list files in a directory",
143 "[directory]\n"
144 " - list files in a 'directory' (default '/')"
145);
Stefan Roese5c721272009-03-19 15:35:50 +0100146
147U_BOOT_CMD(ubifsload, 4, 0, do_ubifs_load,
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200148 "load file from an UBIFS filesystem",
149 "<addr> <filename> [bytes]\n"
150 " - load file 'filename' to address 'addr'"
151);