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 extern struct super_block *ubifs_sb;
28 int ubifs_mount(char *vol_name);
29 void ubifs_umount(struct ubifs_info *c);
30 int ubifs_ls(char *dir_name);
31 int ubifs_load(char *filename, u32 addr, u32 size);
33 int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
42 debug("Using volume %s\n", vol_name);
44 if (ubifs_initialized == 0) {
46 ubifs_initialized = 1;
49 ret = ubifs_mount(vol_name);
58 int ubifs_is_mounted(void)
63 void cmd_ubifs_umount(void)
67 printf("Unmounting UBIFS volume %s!\n",
68 ((struct ubifs_info *)(ubifs_sb->s_fs_info))->vi.name);
69 ubifs_umount(ubifs_sb->s_fs_info);
74 ubifs_initialized = 0;
77 int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
82 if (ubifs_initialized == 0) {
83 printf("No UBIFS volume mounted!\n");
92 int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
98 printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
104 debug("Using filename %s\n", filename);
106 ret = ubifs_ls(filename);
108 printf("** File not found %s **\n", filename);
109 ret = CMD_RET_FAILURE;
115 int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
123 if (!ubifs_mounted) {
124 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
129 return CMD_RET_USAGE;
131 addr = simple_strtoul(argv[1], &endp, 16);
133 return CMD_RET_USAGE;
138 size = simple_strtoul(argv[3], &endp, 16);
140 return CMD_RET_USAGE;
142 debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
144 ret = ubifs_load(filename, addr, size);
146 printf("** File not found %s **\n", filename);
147 ret = CMD_RET_FAILURE;
154 ubifsmount, 2, 0, do_ubifs_mount,
155 "mount UBIFS volume",
157 " - mount 'volume-name' volume"
161 ubifsumount, 1, 0, do_ubifs_umount,
162 "unmount UBIFS volume",
163 " - unmount current volume"
167 ubifsls, 2, 0, do_ubifs_ls,
168 "list files in a directory",
170 " - list files in a 'directory' (default '/')"
174 ubifsload, 4, 0, do_ubifs_load,
175 "load file from an UBIFS filesystem",
176 "<addr> <filename> [bytes]\n"
177 " - load file 'filename' to address 'addr'"