1 // SPDX-License-Identifier: GPL-2.0+
8 * UBIFS command support
16 #include <ubifs_uboot.h>
19 static int ubifs_initialized;
20 static int ubifs_mounted;
22 int cmd_ubifs_mount(char *vol_name)
26 debug("Using volume %s\n", vol_name);
28 if (ubifs_initialized == 0) {
30 ubifs_initialized = 1;
33 ret = uboot_ubifs_mount(vol_name);
35 return CMD_RET_FAILURE;
42 static int do_ubifs_mount(struct cmd_tbl *cmdtp, int flag, int argc,
52 return cmd_ubifs_mount(vol_name);
55 int ubifs_is_mounted(void)
60 int cmd_ubifs_umount(void)
62 if (ubifs_initialized == 0) {
63 printf("No UBIFS volume mounted!\n");
64 return CMD_RET_FAILURE;
69 ubifs_initialized = 0;
74 static int do_ubifs_umount(struct cmd_tbl *cmdtp, int flag, int argc,
80 return cmd_ubifs_umount();
83 static int do_ubifs_ls(struct cmd_tbl *cmdtp, int flag, int argc,
90 printf("UBIFS not mounted, use ubifsmount to mount volume first!\n");
91 return CMD_RET_FAILURE;
96 debug("Using filename %s\n", filename);
98 ret = ubifs_ls(filename);
100 printf("** File not found %s **\n", filename);
101 ret = CMD_RET_FAILURE;
107 static int do_ubifs_load(struct cmd_tbl *cmdtp, int flag, int argc,
116 if (!ubifs_mounted) {
117 printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
118 return CMD_RET_FAILURE;
122 return CMD_RET_USAGE;
124 addr = hextoul(argv[1], &endp);
126 return CMD_RET_USAGE;
131 size = hextoul(argv[3], &endp);
133 return CMD_RET_USAGE;
135 debug("Loading file '%s' to address 0x%08lx (size %d)\n", filename, addr, size);
137 ret = ubifs_load(filename, addr, size);
139 printf("** File not found %s **\n", filename);
140 ret = CMD_RET_FAILURE;
147 ubifsmount, 2, 0, do_ubifs_mount,
148 "mount UBIFS volume",
150 " - mount 'volume-name' volume"
154 ubifsumount, 1, 0, do_ubifs_umount,
155 "unmount UBIFS volume",
156 " - unmount current volume"
160 ubifsls, 2, 0, do_ubifs_ls,
161 "list files in a directory",
163 " - list files in a 'directory' (default '/')"
167 ubifsload, 4, 0, do_ubifs_load,
168 "load file from an UBIFS filesystem",
169 "<addr> <filename> [bytes]\n"
170 " - load file 'filename' to address 'addr'"