blob: 5e9d357cd7d6f0a3d03d7e6634b7a1ad41060dfa [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese5c721272009-03-19 15:35:50 +01006 */
7
8
9/*
10 * UBIFS command support
11 */
12
13#undef DEBUG
14
15#include <common.h>
16#include <config.h>
17#include <command.h>
Hans de Goedea1644772015-09-17 18:46:56 -040018#include <ubifs_uboot.h>
Stefan Roeseff980532010-10-28 14:09:22 +020019
Stefan Roese5c721272009-03-19 15:35:50 +010020static int ubifs_initialized;
21static int ubifs_mounted;
22
Jeroen Hofsteef384fbf2014-06-23 00:22:08 +020023static int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc,
24 char * const argv[])
Stefan Roese5c721272009-03-19 15:35:50 +010025{
26 char *vol_name;
27 int ret;
28
Wolfgang Denk3b683112010-07-17 01:06:04 +020029 if (argc != 2)
Simon Glassa06dfc72011-12-10 08:44:01 +000030 return CMD_RET_USAGE;
Wolfgang Denk3b683112010-07-17 01:06:04 +020031
Stefan Roese5c721272009-03-19 15:35:50 +010032 vol_name = argv[1];
33 debug("Using volume %s\n", vol_name);
34
35 if (ubifs_initialized == 0) {
36 ubifs_init();
37 ubifs_initialized = 1;
38 }
39
Heiko Schocherf5895d12014-06-24 10:10:04 +020040 ret = uboot_ubifs_mount(vol_name);
Stefan Roese5c721272009-03-19 15:35:50 +010041 if (ret)
42 return -1;
43
44 ubifs_mounted = 1;
45
46 return 0;
47}
48
Stefan Roese408c6c42010-11-01 17:28:22 +010049int ubifs_is_mounted(void)
50{
51 return ubifs_mounted;
52}
53
54void cmd_ubifs_umount(void)
55{
Hans de Goedea1644772015-09-17 18:46:56 -040056 uboot_ubifs_umount();
Stefan Roese408c6c42010-11-01 17:28:22 +010057 ubifs_mounted = 0;
58 ubifs_initialized = 0;
59}
60
Jeroen Hofsteef384fbf2014-06-23 00:22:08 +020061static int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc,
62 char * const argv[])
Stefan Roeseff980532010-10-28 14:09:22 +020063{
64 if (argc != 1)
Simon Glassa06dfc72011-12-10 08:44:01 +000065 return CMD_RET_USAGE;
Stefan Roeseff980532010-10-28 14:09:22 +020066
67 if (ubifs_initialized == 0) {
68 printf("No UBIFS volume mounted!\n");
69 return -1;
70 }
71
Stefan Roese408c6c42010-11-01 17:28:22 +010072 cmd_ubifs_umount();
Stefan Roeseff980532010-10-28 14:09:22 +020073
74 return 0;
75}
76
Jeroen Hofsteef384fbf2014-06-23 00:22:08 +020077static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc,
78 char * const argv[])
Stefan Roese5c721272009-03-19 15:35:50 +010079{
80 char *filename = "/";
81 int ret;
82
83 if (!ubifs_mounted) {
Stefan Roese67a0f522010-10-28 14:09:29 +020084 printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
Stefan Roese5c721272009-03-19 15:35:50 +010085 return -1;
86 }
87
88 if (argc == 2)
89 filename = argv[1];
90 debug("Using filename %s\n", filename);
91
92 ret = ubifs_ls(filename);
Tim Harvey8d66edc2013-10-10 01:32:26 +020093 if (ret) {
94 printf("** File not found %s **\n", filename);
95 ret = CMD_RET_FAILURE;
96 }
Stefan Roese5c721272009-03-19 15:35:50 +010097
98 return ret;
99}
100
Jeroen Hofsteef384fbf2014-06-23 00:22:08 +0200101static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc,
102 char * const argv[])
Stefan Roese5c721272009-03-19 15:35:50 +0100103{
104 char *filename;
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200105 char *endp;
Stefan Roese5c721272009-03-19 15:35:50 +0100106 int ret;
107 u32 addr;
108 u32 size = 0;
109
110 if (!ubifs_mounted) {
111 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
112 return -1;
113 }
114
Wolfgang Denk3b683112010-07-17 01:06:04 +0200115 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000116 return CMD_RET_USAGE;
Stefan Roese5c721272009-03-19 15:35:50 +0100117
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200118 addr = simple_strtoul(argv[1], &endp, 16);
Wolfgang Denk3b683112010-07-17 01:06:04 +0200119 if (endp == argv[1])
Simon Glassa06dfc72011-12-10 08:44:01 +0000120 return CMD_RET_USAGE;
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200121
Stefan Roese5c721272009-03-19 15:35:50 +0100122 filename = argv[2];
123
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200124 if (argc == 4) {
125 size = simple_strtoul(argv[3], &endp, 16);
Wolfgang Denk3b683112010-07-17 01:06:04 +0200126 if (endp == argv[3])
Simon Glassa06dfc72011-12-10 08:44:01 +0000127 return CMD_RET_USAGE;
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200128 }
Stefan Roese5c721272009-03-19 15:35:50 +0100129 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
130
131 ret = ubifs_load(filename, addr, size);
Tim Harvey8d66edc2013-10-10 01:32:26 +0200132 if (ret) {
133 printf("** File not found %s **\n", filename);
134 ret = CMD_RET_FAILURE;
135 }
Stefan Roese5c721272009-03-19 15:35:50 +0100136
137 return ret;
138}
139
140U_BOOT_CMD(
141 ubifsmount, 2, 0, do_ubifs_mount,
Mike Frysinger27e1e622009-03-23 22:27:34 -0400142 "mount UBIFS volume",
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200143 "<volume-name>\n"
144 " - mount 'volume-name' volume"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200145);
Stefan Roese5c721272009-03-19 15:35:50 +0100146
Frans Meulenbroeks7675a092010-07-31 15:01:53 +0200147U_BOOT_CMD(
Stefan Roeseff980532010-10-28 14:09:22 +0200148 ubifsumount, 1, 0, do_ubifs_umount,
149 "unmount UBIFS volume",
150 " - unmount current volume"
151);
152
153U_BOOT_CMD(
Frans Meulenbroeks7675a092010-07-31 15:01:53 +0200154 ubifsls, 2, 0, do_ubifs_ls,
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200155 "list files in a directory",
156 "[directory]\n"
157 " - list files in a 'directory' (default '/')"
158);
Stefan Roese5c721272009-03-19 15:35:50 +0100159
Frans Meulenbroeks7675a092010-07-31 15:01:53 +0200160U_BOOT_CMD(
161 ubifsload, 4, 0, do_ubifs_load,
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200162 "load file from an UBIFS filesystem",
163 "<addr> <filename> [bytes]\n"
164 " - load file 'filename' to address 'addr'"
165);