2 * Copyright (c) 2012 Mike Frysinger <vapier@gentoo.org>
3 * Copyright (c) 2012-2017 The strace developers.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include DEF_MPERS_TYPE(struct_mtd_oob_buf)
32 #include <linux/ioctl.h>
34 /* The mtd api changes quickly, so we have to keep a local copy */
35 #include <linux/version.h>
36 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
39 # include <mtd/mtd-abi.h>
42 typedef struct mtd_oob_buf struct_mtd_oob_buf;
46 #include "xlat/mtd_mode_options.h"
47 #include "xlat/mtd_file_mode_options.h"
48 #include "xlat/mtd_type_options.h"
49 #include "xlat/mtd_flags_options.h"
50 #include "xlat/mtd_otp_options.h"
51 #include "xlat/mtd_nandecc_options.h"
54 decode_erase_info_user(struct tcb *const tcp, const kernel_ulong_t addr)
56 struct erase_info_user einfo;
59 if (umove_or_printaddr(tcp, addr, &einfo))
62 tprintf("{start=%#x, length=%#x}", einfo.start, einfo.length);
66 decode_erase_info_user64(struct tcb *const tcp, const kernel_ulong_t addr)
68 struct erase_info_user64 einfo64;
71 if (umove_or_printaddr(tcp, addr, &einfo64))
74 tprintf("{start=%#" PRIx64 ", length=%#" PRIx64 "}",
75 (uint64_t) einfo64.start, (uint64_t) einfo64.length);
79 decode_mtd_oob_buf(struct tcb *const tcp, const kernel_ulong_t addr)
81 struct_mtd_oob_buf mbuf;
84 if (umove_or_printaddr(tcp, addr, &mbuf))
87 tprintf("{start=%#x, length=%#x, ptr=", mbuf.start, mbuf.length);
88 printaddr(ptr_to_kulong(mbuf.ptr));
93 decode_mtd_oob_buf64(struct tcb *const tcp, const kernel_ulong_t addr)
95 struct mtd_oob_buf64 mbuf64;
98 if (umove_or_printaddr(tcp, addr, &mbuf64))
101 tprintf("{start=%#" PRIx64 ", length=%#x, usr_ptr=%#" PRIx64 "}",
102 (uint64_t) mbuf64.start, mbuf64.length,
103 (uint64_t) mbuf64.usr_ptr);
107 decode_otp_info(struct tcb *const tcp, const kernel_ulong_t addr)
109 struct otp_info oinfo;
112 if (umove_or_printaddr(tcp, addr, &oinfo))
115 tprintf("{start=%#x, length=%#x, locked=%u}",
116 oinfo.start, oinfo.length, oinfo.locked);
120 decode_otp_select(struct tcb *const tcp, const kernel_ulong_t addr)
125 if (umove_or_printaddr(tcp, addr, &i))
129 printxval(mtd_otp_options, i, "MTD_OTP_???");
134 decode_mtd_write_req(struct tcb *const tcp, const kernel_ulong_t addr)
136 struct mtd_write_req mreq;
139 if (umove_or_printaddr(tcp, addr, &mreq))
142 tprintf("{start=%#" PRIx64 ", len=%#" PRIx64
143 ", ooblen=%#" PRIx64 ", usr_data=%#" PRIx64
144 ", usr_oob=%#" PRIx64 ", mode=",
145 (uint64_t) mreq.start, (uint64_t) mreq.len,
146 (uint64_t) mreq.ooblen, (uint64_t) mreq.usr_data,
147 (uint64_t) mreq.usr_oob);
148 printxval(mtd_mode_options, mreq.mode, "MTD_OPS_???");
153 decode_mtd_info_user(struct tcb *const tcp, const kernel_ulong_t addr)
155 struct mtd_info_user minfo;
158 if (umove_or_printaddr(tcp, addr, &minfo))
162 printxval(mtd_type_options, minfo.type, "MTD_???");
164 printflags(mtd_flags_options, minfo.flags, "MTD_???");
165 tprintf(", size=%#x, erasesize=%#x, writesize=%#x, oobsize=%#x"
166 ", padding=%#" PRIx64 "}",
167 minfo.size, minfo.erasesize, minfo.writesize, minfo.oobsize,
168 (uint64_t) minfo.padding);
172 decode_nand_oobinfo(struct tcb *const tcp, const kernel_ulong_t addr)
174 struct nand_oobinfo ninfo;
178 if (umove_or_printaddr(tcp, addr, &ninfo))
182 printxval(mtd_nandecc_options, ninfo.useecc, "MTD_NANDECC_???");
183 tprintf(", eccbytes=%#x", ninfo.eccbytes);
185 tprints(", oobfree={");
186 for (i = 0; i < ARRAY_SIZE(ninfo.oobfree); ++i) {
190 for (j = 0; j < ARRAY_SIZE(ninfo.oobfree[0]); ++j) {
193 tprintf("%#x", ninfo.oobfree[i][j]);
197 tprints("}}, eccpos={");
198 for (i = 0; i < ARRAY_SIZE(ninfo.eccpos); ++i) {
201 tprintf("%#x", ninfo.eccpos[i]);
208 decode_nand_ecclayout_user(struct tcb *const tcp, const kernel_ulong_t addr)
210 struct nand_ecclayout_user nlay;
214 if (umove_or_printaddr(tcp, addr, &nlay))
217 tprintf("{eccbytes=%#x, eccpos={", nlay.eccbytes);
218 for (i = 0; i < ARRAY_SIZE(nlay.eccpos); ++i) {
221 tprintf("%#x", nlay.eccpos[i]);
223 tprintf("}, oobavail=%#x, oobfree={", nlay.oobavail);
224 for (i = 0; i < ARRAY_SIZE(nlay.oobfree); ++i) {
227 tprintf("{offset=%#x, length=%#x}",
228 nlay.oobfree[i].offset, nlay.oobfree[i].length);
234 decode_mtd_ecc_stats(struct tcb *const tcp, const kernel_ulong_t addr)
236 struct mtd_ecc_stats es;
239 if (umove_or_printaddr(tcp, addr, &es))
242 tprintf("{corrected=%#x, failed=%#x, badblocks=%#x, bbtblocks=%#x}",
243 es.corrected, es.failed, es.badblocks, es.bbtblocks);
246 MPERS_PRINTER_DECL(int, mtd_ioctl, struct tcb *const tcp,
247 const unsigned int code, const kernel_ulong_t arg)
254 decode_erase_info_user(tcp, arg);
258 decode_erase_info_user64(tcp, arg);
263 decode_mtd_oob_buf(tcp, arg);
268 decode_mtd_oob_buf64(tcp, arg);
272 decode_mtd_write_req(tcp, arg);
275 case OTPGETREGIONINFO:
280 decode_otp_info(tcp, arg);
284 decode_otp_select(tcp, arg);
289 printxval64(mtd_file_mode_options, arg, "MTD_FILE_MODE_???");
295 printnum_int64(tcp, arg, "%" PRIu64);
301 decode_mtd_info_user(tcp, arg);
307 decode_nand_oobinfo(tcp, arg);
313 decode_nand_ecclayout_user(tcp, arg);
319 decode_mtd_ecc_stats(tcp, arg);
322 case OTPGETREGIONCOUNT:
326 printnum_int(tcp, arg, "%u");
329 case MEMGETREGIONCOUNT:
333 printnum_int(tcp, arg, "%d");
336 case MEMGETREGIONINFO:
338 struct region_info_user rinfo;
341 if (umove_or_printaddr(tcp, arg, &rinfo))
343 tprintf("{regionindex=%#x", rinfo.regionindex);
346 struct region_info_user rinfo;
348 if (!syserror(tcp) && !umove(tcp, arg, &rinfo))
349 tprintf(", offset=%#x"
363 return RVAL_DECODED | 1;