blob: e4000b7ad19dd466940fc7394bc5c45f8f80e54c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese5c721272009-03-19 15:35:50 +01002/*
3 * (C) Copyright 2008
4 * Stefan Roese, DENX Software Engineering, sr@denx.de.
Stefan Roese5c721272009-03-19 15:35:50 +01005 */
6
7
8/*
9 * UBIFS command support
10 */
11
12#undef DEBUG
13
14#include <common.h>
15#include <config.h>
16#include <command.h>
Hans de Goedea1644772015-09-17 18:46:56 -040017#include <ubifs_uboot.h>
Stefan Roeseff980532010-10-28 14:09:22 +020018
Stefan Roese5c721272009-03-19 15:35:50 +010019static int ubifs_initialized;
20static int ubifs_mounted;
21
Tien Fong Cheebb7387f2018-07-06 16:26:01 +080022int cmd_ubifs_mount(char *vol_name)
Stefan Roese5c721272009-03-19 15:35:50 +010023{
Stefan Roese5c721272009-03-19 15:35:50 +010024 int ret;
25
Stefan Roese5c721272009-03-19 15:35:50 +010026 debug("Using volume %s\n", vol_name);
27
28 if (ubifs_initialized == 0) {
29 ubifs_init();
30 ubifs_initialized = 1;
31 }
32
Heiko Schocherf5895d12014-06-24 10:10:04 +020033 ret = uboot_ubifs_mount(vol_name);
Stefan Roese5c721272009-03-19 15:35:50 +010034 if (ret)
35 return -1;
36
37 ubifs_mounted = 1;
38
Tien Fong Cheebb7387f2018-07-06 16:26:01 +080039 return ret;
40}
41static int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc,
42 char * const argv[])
43{
44 char *vol_name;
45
46 if (argc != 2)
47 return CMD_RET_USAGE;
48
49 vol_name = argv[1];
50
51 return cmd_ubifs_mount(vol_name);
Stefan Roese5c721272009-03-19 15:35:50 +010052}
53
Stefan Roese408c6c42010-11-01 17:28:22 +010054int ubifs_is_mounted(void)
55{
56 return ubifs_mounted;
57}
58
Tien Fong Cheedbc9d852018-07-06 16:25:12 +080059int cmd_ubifs_umount(void)
Stefan Roese408c6c42010-11-01 17:28:22 +010060{
Tien Fong Cheedbc9d852018-07-06 16:25:12 +080061 if (ubifs_initialized == 0) {
62 printf("No UBIFS volume mounted!\n");
63 return -1;
64 }
65
Hans de Goedea1644772015-09-17 18:46:56 -040066 uboot_ubifs_umount();
Stefan Roese408c6c42010-11-01 17:28:22 +010067 ubifs_mounted = 0;
68 ubifs_initialized = 0;
Tien Fong Cheedbc9d852018-07-06 16:25:12 +080069
70 return 0;
Stefan Roese408c6c42010-11-01 17:28:22 +010071}
72
Jeroen Hofsteef384fbf2014-06-23 00:22:08 +020073static int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc,
74 char * const argv[])
Stefan Roeseff980532010-10-28 14:09:22 +020075{
76 if (argc != 1)
Simon Glassa06dfc72011-12-10 08:44:01 +000077 return CMD_RET_USAGE;
Stefan Roeseff980532010-10-28 14:09:22 +020078
Tien Fong Cheedbc9d852018-07-06 16:25:12 +080079 return cmd_ubifs_umount();
Stefan Roeseff980532010-10-28 14:09:22 +020080}
81
Jeroen Hofsteef384fbf2014-06-23 00:22:08 +020082static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc,
83 char * const argv[])
Stefan Roese5c721272009-03-19 15:35:50 +010084{
85 char *filename = "/";
86 int ret;
87
88 if (!ubifs_mounted) {
Stefan Roese67a0f522010-10-28 14:09:29 +020089 printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
Stefan Roese5c721272009-03-19 15:35:50 +010090 return -1;
91 }
92
93 if (argc == 2)
94 filename = argv[1];
95 debug("Using filename %s\n", filename);
96
97 ret = ubifs_ls(filename);
Tim Harvey8d66edc2013-10-10 01:32:26 +020098 if (ret) {
99 printf("** File not found %s **\n", filename);
100 ret = CMD_RET_FAILURE;
101 }
Stefan Roese5c721272009-03-19 15:35:50 +0100102
103 return ret;
104}
105
Jeroen Hofsteef384fbf2014-06-23 00:22:08 +0200106static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc,
107 char * const argv[])
Stefan Roese5c721272009-03-19 15:35:50 +0100108{
109 char *filename;
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200110 char *endp;
Stefan Roese5c721272009-03-19 15:35:50 +0100111 int ret;
112 u32 addr;
113 u32 size = 0;
114
115 if (!ubifs_mounted) {
116 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
117 return -1;
118 }
119
Wolfgang Denk3b683112010-07-17 01:06:04 +0200120 if (argc < 3)
Simon Glassa06dfc72011-12-10 08:44:01 +0000121 return CMD_RET_USAGE;
Stefan Roese5c721272009-03-19 15:35:50 +0100122
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200123 addr = simple_strtoul(argv[1], &endp, 16);
Wolfgang Denk3b683112010-07-17 01:06:04 +0200124 if (endp == argv[1])
Simon Glassa06dfc72011-12-10 08:44:01 +0000125 return CMD_RET_USAGE;
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200126
Stefan Roese5c721272009-03-19 15:35:50 +0100127 filename = argv[2];
128
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200129 if (argc == 4) {
130 size = simple_strtoul(argv[3], &endp, 16);
Wolfgang Denk3b683112010-07-17 01:06:04 +0200131 if (endp == argv[3])
Simon Glassa06dfc72011-12-10 08:44:01 +0000132 return CMD_RET_USAGE;
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200133 }
Stefan Roese5c721272009-03-19 15:35:50 +0100134 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
135
136 ret = ubifs_load(filename, addr, size);
Tim Harvey8d66edc2013-10-10 01:32:26 +0200137 if (ret) {
138 printf("** File not found %s **\n", filename);
139 ret = CMD_RET_FAILURE;
140 }
Stefan Roese5c721272009-03-19 15:35:50 +0100141
142 return ret;
143}
144
145U_BOOT_CMD(
146 ubifsmount, 2, 0, do_ubifs_mount,
Mike Frysinger27e1e622009-03-23 22:27:34 -0400147 "mount UBIFS volume",
Simon Kagstrom9dae38a2009-07-07 16:01:02 +0200148 "<volume-name>\n"
149 " - mount 'volume-name' volume"
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200150);
Stefan Roese5c721272009-03-19 15:35:50 +0100151
Frans Meulenbroeks7675a092010-07-31 15:01:53 +0200152U_BOOT_CMD(
Stefan Roeseff980532010-10-28 14:09:22 +0200153 ubifsumount, 1, 0, do_ubifs_umount,
154 "unmount UBIFS volume",
155 " - unmount current volume"
156);
157
158U_BOOT_CMD(
Frans Meulenbroeks7675a092010-07-31 15:01:53 +0200159 ubifsls, 2, 0, do_ubifs_ls,
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200160 "list files in a directory",
161 "[directory]\n"
162 " - list files in a 'directory' (default '/')"
163);
Stefan Roese5c721272009-03-19 15:35:50 +0100164
Frans Meulenbroeks7675a092010-07-31 15:01:53 +0200165U_BOOT_CMD(
166 ubifsload, 4, 0, do_ubifs_load,
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200167 "load file from an UBIFS filesystem",
168 "<addr> <filename> [bytes]\n"
169 " - load file 'filename' to address 'addr'"
170);