blob: a0ec184486dc08a330e063a97b55990fab69f7ae [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
Wolfgang Denk54841ab2010-06-28 22:00:46 +020045int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roesece6d0c82009-03-19 15:35:50 +010046{
47 char *vol_name;
48 int ret;
49
Wolfgang Denk47e26b12010-07-17 01:06:04 +020050 if (argc != 2)
51 return cmd_usage(cmdtp);
52
Stefan Roesece6d0c82009-03-19 15:35:50 +010053 vol_name = argv[1];
54 debug("Using volume %s\n", vol_name);
55
56 if (ubifs_initialized == 0) {
57 ubifs_init();
58 ubifs_initialized = 1;
59 }
60
61 ret = ubifs_mount(vol_name);
62 if (ret)
63 return -1;
64
65 ubifs_mounted = 1;
66
67 return 0;
68}
69
Wolfgang Denk54841ab2010-06-28 22:00:46 +020070int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roesece6d0c82009-03-19 15:35:50 +010071{
72 char *filename = "/";
73 int ret;
74
75 if (!ubifs_mounted) {
76 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
77 return -1;
78 }
79
80 if (argc == 2)
81 filename = argv[1];
82 debug("Using filename %s\n", filename);
83
84 ret = ubifs_ls(filename);
85 if (ret)
86 printf("%s not found!\n", filename);
87
88 return ret;
89}
90
Wolfgang Denk54841ab2010-06-28 22:00:46 +020091int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Stefan Roesece6d0c82009-03-19 15:35:50 +010092{
93 char *filename;
Simon Kagstrom2896b582009-07-07 16:01:02 +020094 char *endp;
Stefan Roesece6d0c82009-03-19 15:35:50 +010095 int ret;
96 u32 addr;
97 u32 size = 0;
98
99 if (!ubifs_mounted) {
100 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
101 return -1;
102 }
103
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200104 if (argc < 3)
105 return cmd_usage(cmdtp);
Stefan Roesece6d0c82009-03-19 15:35:50 +0100106
Simon Kagstrom2896b582009-07-07 16:01:02 +0200107 addr = simple_strtoul(argv[1], &endp, 16);
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200108 if (endp == argv[1])
109 return cmd_usage(cmdtp);
Simon Kagstrom2896b582009-07-07 16:01:02 +0200110
Stefan Roesece6d0c82009-03-19 15:35:50 +0100111 filename = argv[2];
112
Simon Kagstrom2896b582009-07-07 16:01:02 +0200113 if (argc == 4) {
114 size = simple_strtoul(argv[3], &endp, 16);
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200115 if (endp == argv[3])
116 return cmd_usage(cmdtp);
Simon Kagstrom2896b582009-07-07 16:01:02 +0200117 }
Stefan Roesece6d0c82009-03-19 15:35:50 +0100118 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
119
120 ret = ubifs_load(filename, addr, size);
121 if (ret)
122 printf("%s not found!\n", filename);
123
124 return ret;
125}
126
127U_BOOT_CMD(
128 ubifsmount, 2, 0, do_ubifs_mount,
Mike Frysinger852dbfd2009-03-23 22:27:34 -0400129 "mount UBIFS volume",
Simon Kagstrom2896b582009-07-07 16:01:02 +0200130 "<volume-name>\n"
131 " - mount 'volume-name' volume"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200132);
Stefan Roesece6d0c82009-03-19 15:35:50 +0100133
Frans Meulenbroeks388a29d2010-07-31 15:01:53 +0200134U_BOOT_CMD(
135 ubifsls, 2, 0, do_ubifs_ls,
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200136 "list files in a directory",
137 "[directory]\n"
138 " - list files in a 'directory' (default '/')"
139);
Stefan Roesece6d0c82009-03-19 15:35:50 +0100140
Frans Meulenbroeks388a29d2010-07-31 15:01:53 +0200141U_BOOT_CMD(
142 ubifsload, 4, 0, do_ubifs_load,
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200143 "load file from an UBIFS filesystem",
144 "<addr> <filename> [bytes]\n"
145 " - load file 'filename' to address 'addr'"
146);