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