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