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 #ifdef HAVE_STRUCT_MTD_WRITE_REQ
32 # include DEF_MPERS_TYPE(struct_mtd_oob_buf)
34 # include <linux/ioctl.h>
35 # include <mtd/mtd-abi.h>
37 typedef struct mtd_oob_buf struct_mtd_oob_buf;
39 #endif /* HAVE_STRUCT_MTD_WRITE_REQ */
43 #ifdef HAVE_STRUCT_MTD_WRITE_REQ
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 *const tcp, const kernel_ulong_t 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 *const tcp, const kernel_ulong_t 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 *const tcp, const kernel_ulong_t addr)
80 struct_mtd_oob_buf mbuf;
83 if (umove_or_printaddr(tcp, addr, &mbuf))
86 tprintf("{start=%#x, length=%#x, ptr=", mbuf.start, mbuf.length);
87 printaddr(ptr_to_kulong(mbuf.ptr));
92 decode_mtd_oob_buf64(struct tcb *const tcp, const kernel_ulong_t addr)
94 struct mtd_oob_buf64 mbuf64;
97 if (umove_or_printaddr(tcp, addr, &mbuf64))
100 tprintf("{start=%#" PRIx64 ", length=%#x, usr_ptr=%#" PRIx64 "}",
101 (uint64_t) mbuf64.start, mbuf64.length,
102 (uint64_t) mbuf64.usr_ptr);
106 decode_otp_info(struct tcb *const tcp, const kernel_ulong_t addr)
108 struct otp_info oinfo;
111 if (umove_or_printaddr(tcp, addr, &oinfo))
114 tprintf("{start=%#x, length=%#x, locked=%u}",
115 oinfo.start, oinfo.length, oinfo.locked);
119 decode_otp_select(struct tcb *const tcp, const kernel_ulong_t addr)
124 if (umove_or_printaddr(tcp, addr, &i))
128 printxval(mtd_otp_options, i, "MTD_OTP_???");
133 decode_mtd_write_req(struct tcb *const tcp, const kernel_ulong_t addr)
135 struct mtd_write_req mreq;
138 if (umove_or_printaddr(tcp, addr, &mreq))
141 tprintf("{start=%#" PRIx64 ", len=%#" PRIx64
142 ", ooblen=%#" PRIx64 ", usr_data=%#" PRIx64
143 ", usr_oob=%#" PRIx64 ", mode=",
144 (uint64_t) mreq.start, (uint64_t) mreq.len,
145 (uint64_t) mreq.ooblen, (uint64_t) mreq.usr_data,
146 (uint64_t) mreq.usr_oob);
147 printxval(mtd_mode_options, mreq.mode, "MTD_OPS_???");
152 decode_mtd_info_user(struct tcb *const tcp, const kernel_ulong_t addr)
154 struct mtd_info_user minfo;
157 if (umove_or_printaddr(tcp, addr, &minfo))
161 printxval(mtd_type_options, minfo.type, "MTD_???");
163 printflags(mtd_flags_options, minfo.flags, "MTD_???");
164 tprintf(", size=%#x, erasesize=%#x, writesize=%#x, oobsize=%#x"
165 ", padding=%#" PRIx64 "}",
166 minfo.size, minfo.erasesize, minfo.writesize, minfo.oobsize,
167 (uint64_t) minfo.padding);
171 decode_nand_oobinfo(struct tcb *const tcp, const kernel_ulong_t addr)
173 struct nand_oobinfo ninfo;
177 if (umove_or_printaddr(tcp, addr, &ninfo))
181 printxval(mtd_nandecc_options, ninfo.useecc, "MTD_NANDECC_???");
182 tprintf(", eccbytes=%#x", ninfo.eccbytes);
184 tprints(", oobfree={");
185 for (i = 0; i < ARRAY_SIZE(ninfo.oobfree); ++i) {
189 for (j = 0; j < ARRAY_SIZE(ninfo.oobfree[0]); ++j) {
192 tprintf("%#x", ninfo.oobfree[i][j]);
196 tprints("}}, eccpos={");
197 for (i = 0; i < ARRAY_SIZE(ninfo.eccpos); ++i) {
200 tprintf("%#x", ninfo.eccpos[i]);
207 decode_nand_ecclayout_user(struct tcb *const tcp, const kernel_ulong_t addr)
209 struct nand_ecclayout_user nlay;
213 if (umove_or_printaddr(tcp, addr, &nlay))
216 tprintf("{eccbytes=%#x, eccpos={", nlay.eccbytes);
217 for (i = 0; i < ARRAY_SIZE(nlay.eccpos); ++i) {
220 tprintf("%#x", nlay.eccpos[i]);
222 tprintf("}, oobavail=%#x, oobfree={", nlay.oobavail);
223 for (i = 0; i < ARRAY_SIZE(nlay.oobfree); ++i) {
226 tprintf("{offset=%#x, length=%#x}",
227 nlay.oobfree[i].offset, nlay.oobfree[i].length);
233 decode_mtd_ecc_stats(struct tcb *const tcp, const kernel_ulong_t addr)
235 struct mtd_ecc_stats es;
238 if (umove_or_printaddr(tcp, addr, &es))
241 tprintf("{corrected=%#x, failed=%#x, badblocks=%#x, bbtblocks=%#x}",
242 es.corrected, es.failed, es.badblocks, es.bbtblocks);
245 MPERS_PRINTER_DECL(int, mtd_ioctl, struct tcb *const tcp,
246 const unsigned int code, const kernel_ulong_t arg)
253 decode_erase_info_user(tcp, arg);
257 decode_erase_info_user64(tcp, arg);
262 decode_mtd_oob_buf(tcp, arg);
267 decode_mtd_oob_buf64(tcp, arg);
271 decode_mtd_write_req(tcp, arg);
274 case OTPGETREGIONINFO:
277 ATTRIBUTE_FALLTHROUGH;
279 decode_otp_info(tcp, arg);
283 decode_otp_select(tcp, arg);
288 printxval64(mtd_file_mode_options, arg, "MTD_FILE_MODE_???");
294 printnum_int64(tcp, arg, "%" PRIu64);
300 decode_mtd_info_user(tcp, arg);
306 decode_nand_oobinfo(tcp, arg);
312 decode_nand_ecclayout_user(tcp, arg);
318 decode_mtd_ecc_stats(tcp, arg);
321 case OTPGETREGIONCOUNT:
325 printnum_int(tcp, arg, "%u");
328 case MEMGETREGIONCOUNT:
332 printnum_int(tcp, arg, "%d");
335 case MEMGETREGIONINFO:
337 struct region_info_user rinfo;
340 if (umove_or_printaddr(tcp, arg, &rinfo))
342 tprintf("{regionindex=%#x", rinfo.regionindex);
345 struct region_info_user rinfo;
347 if (!syserror(tcp) && !umove(tcp, arg, &rinfo))
348 tprintf(", offset=%#x"
362 return RVAL_IOCTL_DECODED;
365 #endif /* HAVE_STRUCT_MTD_WRITE_REQ */