2 * Copyright (c) 2012 Mike Frysinger <vapier@gentoo.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/ioctl.h>
31 /* The mtd api changes quickly, so we have to keep a local copy */
32 #include <linux/version.h>
33 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
36 # include <mtd/mtd-abi.h>
38 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
39 # include "ubi-user.h"
41 # include <mtd/ubi-user.h>
44 #include "xlat/mtd_mode_options.h"
45 #include "xlat/mtd_type_options.h"
46 #include "xlat/mtd_flags_options.h"
47 #include "xlat/mtd_otp_options.h"
48 #include "xlat/mtd_nandecc_options.h"
51 mtd_ioctl(struct tcb *tcp, const unsigned int code, long arg)
53 struct mtd_info_user minfo;
54 struct erase_info_user einfo;
55 struct erase_info_user64 einfo64;
56 struct mtd_oob_buf mbuf;
57 struct mtd_oob_buf64 mbuf64;
58 struct region_info_user rinfo;
59 struct otp_info oinfo;
60 struct mtd_ecc_stats estat;
61 struct mtd_write_req mreq;
62 struct nand_oobinfo ninfo;
63 struct nand_ecclayout_user nlay;
72 if (!verbose(tcp) || umove(tcp, arg, &minfo) < 0)
76 printxval(mtd_type_options, minfo.type, "MTD_???");
78 printflags(mtd_flags_options, minfo.flags, "MTD_???");
79 tprintf(", size=%#" PRIx32 ", erasesize=%#" PRIx32,
80 minfo.size, minfo.erasesize);
81 tprintf(", writesize=%#" PRIx32 ", oobsize=%#" PRIx32,
82 minfo.writesize, minfo.oobsize);
83 tprintf(", padding=%#" PRIx64 "}",
84 (uint64_t) minfo.padding);
91 if (!verbose(tcp) || umove(tcp, arg, &einfo) < 0)
94 tprintf(", {start=%#" PRIx32 ", length=%#" PRIx32 "}",
95 einfo.start, einfo.length);
99 if (!verbose(tcp) || umove(tcp, arg, &einfo64) < 0)
102 tprintf(", {start=%#" PRIx64 ", length=%#" PRIx64 "}",
103 (uint64_t) einfo64.start, (uint64_t) einfo64.length);
108 if (!verbose(tcp) || umove(tcp, arg, &mbuf) < 0)
111 tprintf(", {start=%#" PRIx32 ", length=%#" PRIx32 ", ptr=...}",
112 mbuf.start, mbuf.length);
117 if (!verbose(tcp) || umove(tcp, arg, &mbuf64) < 0)
120 tprintf(", {start=%#" PRIx64 ", length=%#" PRIx64 ", ptr=...}",
121 (uint64_t) mbuf64.start, (uint64_t) mbuf64.length);
124 case MEMGETREGIONINFO:
125 if (!verbose(tcp) || umove(tcp, arg, &rinfo) < 0)
128 tprintf(", {offset=%#" PRIx32 ", erasesize=%#" PRIx32,
129 rinfo.offset, rinfo.erasesize);
130 tprintf(", numblocks=%#" PRIx32 ", regionindex=%#" PRIx32 "}",
131 rinfo.numblocks, rinfo.regionindex);
135 if (!verbose(tcp) || umove(tcp, arg, &ninfo) < 0)
138 tprints(", {useecc=");
139 printxval(mtd_nandecc_options, ninfo.useecc, "MTD_NANDECC_???");
140 tprintf(", eccbytes=%#" PRIx32, ninfo.eccbytes);
142 tprints(", oobfree={");
143 for (i = 0; i < ARRAY_SIZE(ninfo.oobfree); ++i) {
147 for (j = 0; j < ARRAY_SIZE(ninfo.oobfree[0]); ++j) {
150 tprintf("%#" PRIx32, ninfo.oobfree[i][j]);
154 tprints("}}, eccpos={");
155 for (i = 0; i < ARRAY_SIZE(ninfo.eccpos); ++i) {
158 tprintf("%#" PRIx32, ninfo.eccpos[i]);
164 case OTPGETREGIONINFO:
166 if (!verbose(tcp) || umove(tcp, arg, &oinfo) < 0)
169 tprintf(", {start=%#" PRIx32 ", length=%#" PRIx32 ", locked=%" PRIu32 "}",
170 oinfo.start, oinfo.length, oinfo.locked);
174 if (!verbose(tcp) || umove(tcp, arg, &nlay) < 0)
177 tprintf(", {eccbytes=%#" PRIx32 ", eccpos={", nlay.eccbytes);
178 for (i = 0; i < ARRAY_SIZE(nlay.eccpos); ++i) {
181 tprintf("%#" PRIx32, nlay.eccpos[i]);
183 tprintf("}, oobavail=%#" PRIx32 ", oobfree={", nlay.oobavail);
184 for (i = 0; i < ARRAY_SIZE(nlay.oobfree); ++i) {
187 tprintf("{offset=%#" PRIx32 ", length=%#" PRIx32 "}",
188 nlay.oobfree[i].offset, nlay.oobfree[i].length);
194 if (!verbose(tcp) || umove(tcp, arg, &estat) < 0)
197 tprintf(", {corrected=%#" PRIx32 ", failed=%#" PRIx32,
198 estat.corrected, estat.failed);
199 tprintf(", badblocks=%#" PRIx32 ", bbtblocks=%#" PRIx32 "}",
200 estat.badblocks, estat.bbtblocks);
204 if (!verbose(tcp) || umove(tcp, arg, &mreq) < 0)
207 tprintf(", {start=%#" PRIx64 ", len=%#" PRIx64,
208 (uint64_t) mreq.start, (uint64_t) mreq.len);
209 tprintf(", ooblen=%#" PRIx64 ", usr_data=%#" PRIx64,
210 (uint64_t) mreq.ooblen, (uint64_t) mreq.usr_data);
211 tprintf(", usr_oob=%#" PRIx64 ", mode=",
212 (uint64_t) mreq.usr_oob);
213 printxval(mtd_mode_options, mreq.mode, "MTD_OPS_???");
214 tprints(", padding=...}");
218 if (!verbose(tcp) || umove(tcp, arg, &i) < 0)
222 printxval(mtd_otp_options, i, "MTD_OTP_???");
232 print_loff_t(tcp, arg);
235 case OTPGETREGIONCOUNT:
236 if (!verbose(tcp) || umove(tcp, arg, &i) < 0)
239 tprintf(", [%u]", i);
243 /* XXX: process return value as enum mtd_file_modes */
245 case MEMGETREGIONCOUNT:
246 /* These ones take simple args, so let default printer handle it */
253 #include "xlat/ubi_volume_types.h"
254 #include "xlat/ubi_volume_props.h"
257 ubi_ioctl(struct tcb *tcp, const unsigned int code, long arg)
259 struct ubi_mkvol_req mkvol;
260 struct ubi_rsvol_req rsvol;
261 struct ubi_rnvol_req rnvol;
262 struct ubi_attach_req attach;
263 struct ubi_map_req map;
264 struct ubi_set_vol_prop_req prop;
271 if (!verbose(tcp) || umove(tcp, arg, &mkvol) < 0)
274 tprintf(", {vol_id=%" PRIi32 ", alignment=%" PRIi32
275 ", bytes=%" PRIi64 ", vol_type=", mkvol.vol_id,
276 mkvol.alignment, (int64_t)mkvol.bytes);
277 printxval(ubi_volume_types, mkvol.vol_type, "UBI_???_VOLUME");
278 tprintf(", name_len=%" PRIi16 ", name=", mkvol.name_len);
279 if (print_quoted_string(mkvol.name,
280 CLAMP(mkvol.name_len, 0, UBI_MAX_VOLUME_NAME),
281 QUOTE_0_TERMINATED) > 0) {
288 if (!verbose(tcp) || umove(tcp, arg, &rsvol) < 0)
291 tprintf(", {vol_id=%" PRIi32 ", bytes=%" PRIi64 "}",
292 rsvol.vol_id, (int64_t)rsvol.bytes);
298 if (!verbose(tcp) || umove(tcp, arg, &rnvol) < 0)
301 tprintf(", {count=%" PRIi32 ", ents=[", rnvol.count);
302 for (c = 0; c < CLAMP(rnvol.count, 0, UBI_MAX_RNVOL); ++c) {
305 tprintf("{vol_id=%" PRIi32 ", name_len=%" PRIi16
306 ", name=", rnvol.ents[c].vol_id,
307 rnvol.ents[c].name_len);
308 if (print_quoted_string(rnvol.ents[c].name,
309 CLAMP(rnvol.ents[c].name_len, 0, UBI_MAX_VOLUME_NAME),
310 QUOTE_0_TERMINATED) > 0) {
322 if (!verbose(tcp) || umove(tcp, arg, &bytes) < 0)
325 tprintf(", %" PRIi64, (int64_t)bytes);
330 if (!verbose(tcp) || umove(tcp, arg, &attach) < 0)
333 tprintf(", {ubi_num=%" PRIi32 ", mtd_num=%" PRIi32
334 ", vid_hdr_offset=%" PRIi32
335 ", max_beb_per1024=%" PRIi16 "}",
336 attach.ubi_num, attach.mtd_num,
337 attach.vid_hdr_offset, attach.max_beb_per1024);
341 if (!verbose(tcp) || umove(tcp, arg, &map) < 0)
344 tprintf(", {lnum=%" PRIi32 ", dtype=%" PRIi8 "}",
345 map.lnum, map.dtype);
348 case UBI_IOCSETVOLPROP:
349 if (!verbose(tcp) || umove(tcp, arg, &prop) < 0)
352 tprints(", {property=");
353 printxval(ubi_volume_props, prop.property, "UBI_VOL_PROP_???");
354 tprintf(", value=%#" PRIx64 "}", (uint64_t)prop.value);
363 /* These ones take simple args, so let default printer handle it */