blob: b2e0f4fdfea7dbbdb9ab72926224f9b246ed3b5a [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
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
50 vol_name = argv[1];
51 debug("Using volume %s\n", vol_name);
52
53 if (ubifs_initialized == 0) {
54 ubifs_init();
55 ubifs_initialized = 1;
56 }
57
58 ret = ubifs_mount(vol_name);
59 if (ret)
60 return -1;
61
62 ubifs_mounted = 1;
63
64 return 0;
65}
66
67int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
68{
69 char *filename = "/";
70 int ret;
71
72 if (!ubifs_mounted) {
73 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
74 return -1;
75 }
76
77 if (argc == 2)
78 filename = argv[1];
79 debug("Using filename %s\n", filename);
80
81 ret = ubifs_ls(filename);
82 if (ret)
83 printf("%s not found!\n", filename);
84
85 return ret;
86}
87
88int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
89{
90 char *filename;
91 int ret;
92 u32 addr;
93 u32 size = 0;
94
95 if (!ubifs_mounted) {
96 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
97 return -1;
98 }
99
100 if (argc < 3) {
101 printf("Usage:\n%s\n", cmdtp->usage);
102 return -1;
103 }
104
105 addr = simple_strtoul(argv[1], NULL, 16);
106 filename = argv[2];
107
108 if (argc == 4)
109 size = simple_strtoul(argv[3], NULL, 16);
110 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
111
112 ret = ubifs_load(filename, addr, size);
113 if (ret)
114 printf("%s not found!\n", filename);
115
116 return ret;
117}
118
119U_BOOT_CMD(
120 ubifsmount, 2, 0, do_ubifs_mount,
121 "ubifsmount- mount UBIFS volume\n",
122 "\n");
123
124U_BOOT_CMD(ubifsls, 2, 0, do_ubifs_ls,
125 "ubifsls - list files in a directory\n",
126 "[directory]\n"
127 " - list files in a 'directory' (default '/')\n");
128
129U_BOOT_CMD(ubifsload, 4, 0, do_ubifs_load,
130 "ubifsload- load file from an UBIFS filesystem\n",
131 "<addr> <filename> [bytes]\n"
132 " - load file 'filename' to address 'addr'\n");