]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_ubifs.c
Merge branch 'master' of git://git.denx.de/u-boot-samsung
[karo-tx-uboot.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 * const argv[])
46 {
47         char *vol_name;
48         int ret;
49
50         if (argc != 2)
51                 return cmd_usage(cmdtp);
52
53         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
70 int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71 {
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
91 int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
92 {
93         char *filename;
94         char *endp;
95         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
104         if (argc < 3)
105                 return cmd_usage(cmdtp);
106
107         addr = simple_strtoul(argv[1], &endp, 16);
108         if (endp == argv[1])
109                 return cmd_usage(cmdtp);
110
111         filename = argv[2];
112
113         if (argc == 4) {
114                 size = simple_strtoul(argv[3], &endp, 16);
115                 if (endp == argv[3])
116                         return cmd_usage(cmdtp);
117         }
118         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
127 U_BOOT_CMD(
128         ubifsmount, 2, 0, do_ubifs_mount,
129         "mount UBIFS volume",
130         "<volume-name>\n"
131         "    - mount 'volume-name' volume"
132 );
133
134 U_BOOT_CMD(ubifsls, 2, 0, do_ubifs_ls,
135         "list files in a directory",
136         "[directory]\n"
137         "    - list files in a 'directory' (default '/')"
138 );
139
140 U_BOOT_CMD(ubifsload, 4, 0, do_ubifs_load,
141         "load file from an UBIFS filesystem",
142         "<addr> <filename> [bytes]\n"
143         "    - load file 'filename' to address 'addr'"
144 );