]>
Commit | Line | Data |
---|---|---|
ce6d0c8d SR |
1 | /* |
2 | * (C) Copyright 2008 | |
3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
ce6d0c8d SR |
6 | */ |
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> | |
18 | ||
cb9c09d4 SR |
19 | #include "../fs/ubifs/ubifs.h" |
20 | ||
ce6d0c8d SR |
21 | static int ubifs_initialized; |
22 | static int ubifs_mounted; | |
23 | ||
0e350f81 JH |
24 | static int do_ubifs_mount(cmd_tbl_t *cmdtp, int flag, int argc, |
25 | char * const argv[]) | |
ce6d0c8d SR |
26 | { |
27 | char *vol_name; | |
28 | int ret; | |
29 | ||
47e26b1b | 30 | if (argc != 2) |
4c12eeb8 | 31 | return CMD_RET_USAGE; |
47e26b1b | 32 | |
ce6d0c8d SR |
33 | vol_name = argv[1]; |
34 | debug("Using volume %s\n", vol_name); | |
35 | ||
36 | if (ubifs_initialized == 0) { | |
37 | ubifs_init(); | |
38 | ubifs_initialized = 1; | |
39 | } | |
40 | ||
ff94bc40 | 41 | ret = uboot_ubifs_mount(vol_name); |
ce6d0c8d SR |
42 | if (ret) |
43 | return -1; | |
44 | ||
45 | ubifs_mounted = 1; | |
46 | ||
47 | return 0; | |
48 | } | |
49 | ||
2f15cfd1 SR |
50 | int ubifs_is_mounted(void) |
51 | { | |
52 | return ubifs_mounted; | |
53 | } | |
54 | ||
55 | void cmd_ubifs_umount(void) | |
56 | { | |
57 | ||
58 | if (ubifs_sb) { | |
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); | |
62 | } | |
63 | ||
64 | ubifs_sb = NULL; | |
65 | ubifs_mounted = 0; | |
66 | ubifs_initialized = 0; | |
67 | } | |
68 | ||
0e350f81 JH |
69 | static int do_ubifs_umount(cmd_tbl_t *cmdtp, int flag, int argc, |
70 | char * const argv[]) | |
cb9c09d4 SR |
71 | { |
72 | if (argc != 1) | |
4c12eeb8 | 73 | return CMD_RET_USAGE; |
cb9c09d4 SR |
74 | |
75 | if (ubifs_initialized == 0) { | |
76 | printf("No UBIFS volume mounted!\n"); | |
77 | return -1; | |
78 | } | |
79 | ||
2f15cfd1 | 80 | cmd_ubifs_umount(); |
cb9c09d4 SR |
81 | |
82 | return 0; | |
83 | } | |
84 | ||
0e350f81 JH |
85 | static int do_ubifs_ls(cmd_tbl_t *cmdtp, int flag, int argc, |
86 | char * const argv[]) | |
ce6d0c8d SR |
87 | { |
88 | char *filename = "/"; | |
89 | int ret; | |
90 | ||
91 | if (!ubifs_mounted) { | |
9a2ea578 | 92 | printf("UBIFS not mounted, use ubifsmount to mount volume first!\n"); |
ce6d0c8d SR |
93 | return -1; |
94 | } | |
95 | ||
96 | if (argc == 2) | |
97 | filename = argv[1]; | |
98 | debug("Using filename %s\n", filename); | |
99 | ||
100 | ret = ubifs_ls(filename); | |
7cdebc32 TH |
101 | if (ret) { |
102 | printf("** File not found %s **\n", filename); | |
103 | ret = CMD_RET_FAILURE; | |
104 | } | |
ce6d0c8d SR |
105 | |
106 | return ret; | |
107 | } | |
108 | ||
0e350f81 JH |
109 | static int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, |
110 | char * const argv[]) | |
ce6d0c8d SR |
111 | { |
112 | char *filename; | |
2896b585 | 113 | char *endp; |
ce6d0c8d SR |
114 | int ret; |
115 | u32 addr; | |
116 | u32 size = 0; | |
117 | ||
118 | if (!ubifs_mounted) { | |
119 | printf("UBIFS not mounted, use ubifs mount to mount volume first!\n"); | |
120 | return -1; | |
121 | } | |
122 | ||
47e26b1b | 123 | if (argc < 3) |
4c12eeb8 | 124 | return CMD_RET_USAGE; |
ce6d0c8d | 125 | |
2896b585 | 126 | addr = simple_strtoul(argv[1], &endp, 16); |
47e26b1b | 127 | if (endp == argv[1]) |
4c12eeb8 | 128 | return CMD_RET_USAGE; |
2896b585 | 129 | |
ce6d0c8d SR |
130 | filename = argv[2]; |
131 | ||
2896b585 SK |
132 | if (argc == 4) { |
133 | size = simple_strtoul(argv[3], &endp, 16); | |
47e26b1b | 134 | if (endp == argv[3]) |
4c12eeb8 | 135 | return CMD_RET_USAGE; |
2896b585 | 136 | } |
ce6d0c8d SR |
137 | debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size); |
138 | ||
139 | ret = ubifs_load(filename, addr, size); | |
7cdebc32 TH |
140 | if (ret) { |
141 | printf("** File not found %s **\n", filename); | |
142 | ret = CMD_RET_FAILURE; | |
143 | } | |
ce6d0c8d SR |
144 | |
145 | return ret; | |
146 | } | |
147 | ||
148 | U_BOOT_CMD( | |
149 | ubifsmount, 2, 0, do_ubifs_mount, | |
852dbfdd | 150 | "mount UBIFS volume", |
2896b585 SK |
151 | "<volume-name>\n" |
152 | " - mount 'volume-name' volume" | |
a89c33db | 153 | ); |
ce6d0c8d | 154 | |
cb9c09d4 SR |
155 | U_BOOT_CMD( |
156 | ubifsumount, 1, 0, do_ubifs_umount, | |
157 | "unmount UBIFS volume", | |
158 | " - unmount current volume" | |
159 | ); | |
160 | ||
388a29d0 FM |
161 | U_BOOT_CMD( |
162 | ubifsls, 2, 0, do_ubifs_ls, | |
a89c33db WD |
163 | "list files in a directory", |
164 | "[directory]\n" | |
165 | " - list files in a 'directory' (default '/')" | |
166 | ); | |
ce6d0c8d | 167 | |
388a29d0 FM |
168 | U_BOOT_CMD( |
169 | ubifsload, 4, 0, do_ubifs_load, | |
a89c33db WD |
170 | "load file from an UBIFS filesystem", |
171 | "<addr> <filename> [bytes]\n" | |
172 | " - load file 'filename' to address 'addr'" | |
173 | ); |