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 <linux/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_file_mode_options.h"
46 #include "xlat/mtd_type_options.h"
47 #include "xlat/mtd_flags_options.h"
48 #include "xlat/mtd_otp_options.h"
49 #include "xlat/mtd_nandecc_options.h"
52 mtd_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
62 struct erase_info_user einfo;
65 if (umove_or_printaddr(tcp, arg, &einfo))
68 tprintf("{start=%#" PRIx32 ", length=%#" PRIx32 "}",
69 einfo.start, einfo.length);
74 struct erase_info_user64 einfo64;
77 if (umove_or_printaddr(tcp, arg, &einfo64))
80 tprintf("{start=%#" PRIx64 ", length=%#" PRIx64 "}",
81 (uint64_t) einfo64.start, (uint64_t) einfo64.length);
87 struct mtd_oob_buf mbuf;
90 if (umove_or_printaddr(tcp, arg, &mbuf))
93 tprintf("{start=%#" PRIx32 ", length=%#" PRIx32 ", ptr=...}",
94 mbuf.start, mbuf.length);
100 struct mtd_oob_buf64 mbuf64;
103 if (umove_or_printaddr(tcp, arg, &mbuf64))
106 tprintf("{start=%#" PRIx64 ", length=%#" PRIx64 ", ptr=...}",
107 (uint64_t) mbuf64.start, (uint64_t) mbuf64.length);
111 case MEMGETREGIONINFO: {
112 struct region_info_user rinfo;
116 if (umove_or_printaddr(tcp, arg, &rinfo))
118 tprintf("{regionindex=%#x", rinfo.regionindex);
125 if (umove(tcp, arg, &rinfo) < 0) {
129 tprintf(", offset=%#x, erasesize=%#x, numblocks=%#x}",
130 rinfo.offset, rinfo.erasesize, rinfo.numblocks);
136 struct otp_info oinfo;
139 if (umove_or_printaddr(tcp, arg, &oinfo))
142 tprintf("{start=%#" PRIx32 ", length=%#" PRIx32 ", locked=%" PRIu32 "}",
143 oinfo.start, oinfo.length, oinfo.locked);
148 struct mtd_write_req mreq;
151 if (umove_or_printaddr(tcp, arg, &mreq))
154 tprintf("{start=%#" PRIx64 ", len=%#" PRIx64,
155 (uint64_t) mreq.start, (uint64_t) mreq.len);
156 tprintf(", ooblen=%#" PRIx64 ", usr_data=%#" PRIx64,
157 (uint64_t) mreq.ooblen, (uint64_t) mreq.usr_data);
158 tprintf(", usr_oob=%#" PRIx64 ", mode=",
159 (uint64_t) mreq.usr_oob);
160 printxval(mtd_mode_options, mreq.mode, "MTD_OPS_???");
161 tprints(", padding=...}");
169 if (umove_or_printaddr(tcp, arg, &i))
173 printxval(mtd_otp_options, i, "MTD_OTP_???");
180 printxval(mtd_file_mode_options, arg, "MTD_FILE_MODE_???");
186 printnum_int64(tcp, arg, "%" PRIu64);
190 struct mtd_info_user minfo;
196 if (umove_or_printaddr(tcp, arg, &minfo))
200 printxval(mtd_type_options, minfo.type, "MTD_???");
202 printflags(mtd_flags_options, minfo.flags, "MTD_???");
203 tprintf(", size=%#" PRIx32 ", erasesize=%#" PRIx32,
204 minfo.size, minfo.erasesize);
205 tprintf(", writesize=%#" PRIx32 ", oobsize=%#" PRIx32,
206 minfo.writesize, minfo.oobsize);
207 tprintf(", padding=%#" PRIx64 "}",
208 (uint64_t) minfo.padding);
213 struct nand_oobinfo ninfo;
220 if (umove_or_printaddr(tcp, arg, &ninfo))
224 printxval(mtd_nandecc_options, ninfo.useecc, "MTD_NANDECC_???");
225 tprintf(", eccbytes=%#" PRIx32, ninfo.eccbytes);
227 tprints(", oobfree={");
228 for (i = 0; i < ARRAY_SIZE(ninfo.oobfree); ++i) {
234 for (j = 0; j < ARRAY_SIZE(ninfo.oobfree[0]); ++j) {
237 tprintf("%#" PRIx32, ninfo.oobfree[i][j]);
241 tprints("}}, eccpos={");
242 for (i = 0; i < ARRAY_SIZE(ninfo.eccpos); ++i) {
245 tprintf("%#" PRIx32, ninfo.eccpos[i]);
252 case OTPGETREGIONINFO: {
253 struct otp_info oinfo;
259 if (umove_or_printaddr(tcp, arg, &oinfo))
262 tprintf("{start=%#" PRIx32 ", length=%#" PRIx32 ", locked=%" PRIu32 "}",
263 oinfo.start, oinfo.length, oinfo.locked);
268 struct nand_ecclayout_user nlay;
275 if (umove_or_printaddr(tcp, arg, &nlay))
278 tprintf("{eccbytes=%#" PRIx32 ", eccpos={", nlay.eccbytes);
279 for (i = 0; i < ARRAY_SIZE(nlay.eccpos); ++i) {
282 tprintf("%#" PRIx32, nlay.eccpos[i]);
284 tprintf("}, oobavail=%#" PRIx32 ", oobfree={", nlay.oobavail);
285 for (i = 0; i < ARRAY_SIZE(nlay.oobfree); ++i) {
288 tprintf("{offset=%#" PRIx32 ", length=%#" PRIx32 "}",
289 nlay.oobfree[i].offset, nlay.oobfree[i].length);
296 struct mtd_ecc_stats estat;
302 if (umove_or_printaddr(tcp, arg, &estat))
305 tprintf("{corrected=%#" PRIx32 ", failed=%#" PRIx32,
306 estat.corrected, estat.failed);
307 tprintf(", badblocks=%#" PRIx32 ", bbtblocks=%#" PRIx32 "}",
308 estat.badblocks, estat.bbtblocks);
312 case OTPGETREGIONCOUNT:
317 printnum_int(tcp, arg, "%u");
320 case MEMGETREGIONCOUNT:
325 printnum_int(tcp, arg, "%d");
332 return RVAL_DECODED | 1;
335 #include "xlat/ubi_volume_types.h"
336 #include "xlat/ubi_volume_props.h"
339 ubi_ioctl(struct tcb *tcp, const unsigned int code, const long arg)
347 struct ubi_mkvol_req mkvol;
350 if (umove_or_printaddr(tcp, arg, &mkvol))
353 tprintf("{vol_id=%" PRIi32 ", alignment=%" PRIi32
354 ", bytes=%" PRIi64 ", vol_type=", mkvol.vol_id,
355 mkvol.alignment, (int64_t)mkvol.bytes);
356 printxval(ubi_volume_types, mkvol.vol_type, "UBI_???_VOLUME");
357 tprintf(", name_len=%" PRIi16 ", name=", mkvol.name_len);
358 if (print_quoted_string(mkvol.name,
359 CLAMP(mkvol.name_len, 0, UBI_MAX_VOLUME_NAME),
360 QUOTE_0_TERMINATED) > 0) {
366 if (!syserror(tcp)) {
368 printnum_int(tcp, arg, "%d");
373 struct ubi_rsvol_req rsvol;
376 if (umove_or_printaddr(tcp, arg, &rsvol))
379 tprintf("{vol_id=%" PRIi32 ", bytes=%" PRIi64 "}",
380 rsvol.vol_id, (int64_t)rsvol.bytes);
385 struct ubi_rnvol_req rnvol;
389 if (umove_or_printaddr(tcp, arg, &rnvol))
392 tprintf("{count=%" PRIi32 ", ents=[", rnvol.count);
393 for (c = 0; c < CLAMP(rnvol.count, 0, UBI_MAX_RNVOL); ++c) {
396 tprintf("{vol_id=%" PRIi32 ", name_len=%" PRIi16
397 ", name=", rnvol.ents[c].vol_id,
398 rnvol.ents[c].name_len);
399 if (print_quoted_string(rnvol.ents[c].name,
400 CLAMP(rnvol.ents[c].name_len, 0, UBI_MAX_VOLUME_NAME),
401 QUOTE_0_TERMINATED) > 0) {
411 struct ubi_leb_change_req leb;
414 if (umove_or_printaddr(tcp, arg, &leb))
417 tprintf("{lnum=%d, bytes=%d}", leb.lnum, leb.bytes);
423 struct ubi_attach_req attach;
426 if (umove_or_printaddr(tcp, arg, &attach))
429 tprintf("{ubi_num=%" PRIi32 ", mtd_num=%" PRIi32
430 ", vid_hdr_offset=%" PRIi32
431 ", max_beb_per1024=%" PRIi16 "}",
432 attach.ubi_num, attach.mtd_num,
433 attach.vid_hdr_offset, attach.max_beb_per1024);
436 if (!syserror(tcp)) {
438 printnum_int(tcp, arg, "%d");
443 struct ubi_map_req map;
446 if (umove_or_printaddr(tcp, arg, &map))
449 tprintf("{lnum=%" PRIi32 ", dtype=%" PRIi8 "}",
450 map.lnum, map.dtype);
454 case UBI_IOCSETVOLPROP: {
455 struct ubi_set_vol_prop_req prop;
458 if (umove_or_printaddr(tcp, arg, &prop))
461 tprints("{property=");
462 printxval(ubi_volume_props, prop.property, "UBI_VOL_PROP_???");
463 tprintf(", value=%#" PRIx64 "}", (uint64_t)prop.value);
470 printnum_int64(tcp, arg, "%" PRIi64);
479 printnum_int(tcp, arg, "%d");
482 #ifdef UBI_IOCVOLCRBLK
483 case UBI_IOCVOLCRBLK:
485 #ifdef UBI_IOCVOLRMBLK
486 case UBI_IOCVOLRMBLK:
495 return RVAL_DECODED | 1;