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 DEF_MPERS_TYPE(struct_mtd_oob_buf)
31 #include <linux/ioctl.h>
33 /* The mtd api changes quickly, so we have to keep a local copy */
34 #include <linux/version.h>
35 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
38 # include <mtd/mtd-abi.h>
41 typedef struct mtd_oob_buf struct_mtd_oob_buf;
45 #include "xlat/mtd_mode_options.h"
46 #include "xlat/mtd_file_mode_options.h"
47 #include "xlat/mtd_type_options.h"
48 #include "xlat/mtd_flags_options.h"
49 #include "xlat/mtd_otp_options.h"
50 #include "xlat/mtd_nandecc_options.h"
53 decode_erase_info_user(struct tcb *tcp, const long addr)
55 struct erase_info_user einfo;
58 if (umove_or_printaddr(tcp, addr, &einfo))
61 tprintf("{start=%#x, length=%#x}", einfo.start, einfo.length);
65 decode_erase_info_user64(struct tcb *tcp, const long addr)
67 struct erase_info_user64 einfo64;
70 if (umove_or_printaddr(tcp, addr, &einfo64))
73 tprintf("{start=%#" PRIx64 ", length=%#" PRIx64 "}",
74 (uint64_t) einfo64.start, (uint64_t) einfo64.length);
78 decode_mtd_oob_buf(struct tcb *tcp, const long addr)
80 struct_mtd_oob_buf mbuf;
83 if (umove_or_printaddr(tcp, addr, &mbuf))
86 tprintf("{start=%#x, length=%#x, ptr=%#lx}",
87 mbuf.start, mbuf.length, (unsigned long) mbuf.ptr);
91 decode_mtd_oob_buf64(struct tcb *tcp, const long addr)
93 struct mtd_oob_buf64 mbuf64;
96 if (umove_or_printaddr(tcp, addr, &mbuf64))
99 tprintf("{start=%#" PRIx64 ", length=%#x, usr_ptr=%#" PRIx64 "}",
100 (uint64_t) mbuf64.start, mbuf64.length,
101 (uint64_t) mbuf64.usr_ptr);
105 decode_otp_info(struct tcb *tcp, const long addr)
107 struct otp_info oinfo;
110 if (umove_or_printaddr(tcp, addr, &oinfo))
113 tprintf("{start=%#x, length=%#x, locked=%u}",
114 oinfo.start, oinfo.length, oinfo.locked);
118 decode_otp_select(struct tcb *tcp, const long addr)
123 if (umove_or_printaddr(tcp, addr, &i))
127 printxval(mtd_otp_options, i, "MTD_OTP_???");
132 decode_mtd_write_req(struct tcb *tcp, const long addr)
134 struct mtd_write_req mreq;
137 if (umove_or_printaddr(tcp, addr, &mreq))
140 tprintf("{start=%#" PRIx64 ", len=%#" PRIx64
141 ", ooblen=%#" PRIx64 ", usr_data=%#" PRIx64
142 ", usr_oob=%#" PRIx64 ", mode=",
143 (uint64_t) mreq.start, (uint64_t) mreq.len,
144 (uint64_t) mreq.ooblen, (uint64_t) mreq.usr_data,
145 (uint64_t) mreq.usr_oob);
146 printxval(mtd_mode_options, mreq.mode, "MTD_OPS_???");
151 decode_mtd_info_user(struct tcb *tcp, const long addr)
153 struct mtd_info_user minfo;
156 if (umove_or_printaddr(tcp, addr, &minfo))
160 printxval(mtd_type_options, minfo.type, "MTD_???");
162 printflags(mtd_flags_options, minfo.flags, "MTD_???");
163 tprintf(", size=%#x, erasesize=%#x, writesize=%#x, oobsize=%#x"
164 ", padding=%#" PRIx64 "}",
165 minfo.size, minfo.erasesize, minfo.writesize, minfo.oobsize,
166 (uint64_t) minfo.padding);
170 decode_nand_oobinfo(struct tcb *tcp, const long addr)
172 struct nand_oobinfo ninfo;
176 if (umove_or_printaddr(tcp, addr, &ninfo))
180 printxval(mtd_nandecc_options, ninfo.useecc, "MTD_NANDECC_???");
181 tprintf(", eccbytes=%#x", ninfo.eccbytes);
183 tprints(", oobfree={");
184 for (i = 0; i < ARRAY_SIZE(ninfo.oobfree); ++i) {
188 for (j = 0; j < ARRAY_SIZE(ninfo.oobfree[0]); ++j) {
191 tprintf("%#x", ninfo.oobfree[i][j]);
195 tprints("}}, eccpos={");
196 for (i = 0; i < ARRAY_SIZE(ninfo.eccpos); ++i) {
199 tprintf("%#x", ninfo.eccpos[i]);
206 decode_nand_ecclayout_user(struct tcb *tcp, const long addr)
208 struct nand_ecclayout_user nlay;
212 if (umove_or_printaddr(tcp, addr, &nlay))
215 tprintf("{eccbytes=%#x, eccpos={", nlay.eccbytes);
216 for (i = 0; i < ARRAY_SIZE(nlay.eccpos); ++i) {
219 tprintf("%#x", nlay.eccpos[i]);
221 tprintf("}, oobavail=%#x, oobfree={", nlay.oobavail);
222 for (i = 0; i < ARRAY_SIZE(nlay.oobfree); ++i) {
225 tprintf("{offset=%#x, length=%#x}",
226 nlay.oobfree[i].offset, nlay.oobfree[i].length);
232 decode_mtd_ecc_stats(struct tcb *tcp, const long addr)
234 struct mtd_ecc_stats es;
237 if (umove_or_printaddr(tcp, addr, &es))
240 tprintf("{corrected=%#x, failed=%#x, badblocks=%#x, bbtblocks=%#x}",
241 es.corrected, es.failed, es.badblocks, es.bbtblocks);
244 MPERS_PRINTER_DECL(int, mtd_ioctl, struct tcb *tcp,
245 const unsigned int code, const long arg)
252 decode_erase_info_user(tcp, arg);
256 decode_erase_info_user64(tcp, arg);
261 decode_mtd_oob_buf(tcp, arg);
266 decode_mtd_oob_buf64(tcp, arg);
270 decode_mtd_write_req(tcp, arg);
273 case OTPGETREGIONINFO:
278 decode_otp_info(tcp, arg);
282 decode_otp_select(tcp, arg);
287 printxval_long(mtd_file_mode_options, arg, "MTD_FILE_MODE_???");
293 printnum_int64(tcp, arg, "%" PRIu64);
299 decode_mtd_info_user(tcp, arg);
305 decode_nand_oobinfo(tcp, arg);
311 decode_nand_ecclayout_user(tcp, arg);
317 decode_mtd_ecc_stats(tcp, arg);
320 case OTPGETREGIONCOUNT:
324 printnum_int(tcp, arg, "%u");
327 case MEMGETREGIONCOUNT:
331 printnum_int(tcp, arg, "%d");
334 case MEMGETREGIONINFO:
336 struct region_info_user rinfo;
339 if (umove_or_printaddr(tcp, arg, &rinfo))
341 tprintf("{regionindex=%#x", rinfo.regionindex);
344 struct region_info_user rinfo;
346 if (!syserror(tcp) && !umove(tcp, arg, &rinfo))
347 tprintf(", offset=%#x"
361 return RVAL_DECODED | 1;