3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
10 * UBIFS command support
19 #include "../fs/ubifs/ubifs.h"
21 static int ubifs_initialized;
22 static int ubifs_mounted;
24 static int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc,
34 debug("Using volume %s\n", vol_name);
36 if (ubifs_initialized == 0) {
38 ubifs_initialized = 1;
41 ret = uboot_ubifs_mount(vol_name);
50 int ubifs_is_mounted(void)
55 void cmd_ubifs_umount(void)
59 printf("Unmounting UBIFS volume %s!\n",
60 ((struct ubifs_info *)(ubifs_sb->s_fs_info))->vi.name);
61 ubifs_umount(ubifs_sb->s_fs_info);
66 ubifs_initialized = 0;
69 static int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc,
75 if (ubifs_initialized == 0) {
76 printf("No UBIFS volume mounted!\n");
85 static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc,
92 printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
98 debug("Using filename %s\n", filename);
100 ret = ubifs_ls(filename);
102 printf("** File not found %s **\n", filename);
103 ret = CMD_RET_FAILURE;
109 static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc,
118 if (!ubifs_mounted) {
119 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
124 return CMD_RET_USAGE;
126 addr = simple_strtoul(argv[1], &endp, 16);
128 return CMD_RET_USAGE;
133 size = simple_strtoul(argv[3], &endp, 16);
135 return CMD_RET_USAGE;
137 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
139 ret = ubifs_load(filename, addr, size);
141 printf("** File not found %s **\n", filename);
142 ret = CMD_RET_FAILURE;
149 ubifsmount, 2, 0, do_ubifs_mount,
150 "mount UBIFS volume",
152 " - mount 'volume-name' volume"
156 ubifsumount, 1, 0, do_ubifs_umount,
157 "unmount UBIFS volume",
158 " - unmount current volume"
162 ubifsls, 2, 0, do_ubifs_ls,
163 "list files in a directory",
165 " - list files in a 'directory' (default '/')"
169 ubifsload, 4, 0, do_ubifs_load,
170 "load file from an UBIFS filesystem",
171 "<addr> <filename> [bytes]\n"
172 " - load file 'filename' to address 'addr'"