All of lore.kernel.org
 help / color / mirror / Atom feed
* User error with fw_printenv - I hope
@ 2012-03-30 20:54 Bishop, Mark
  2012-03-30 22:30 ` Mike Frysinger
  0 siblings, 1 reply; 9+ messages in thread
From: Bishop, Mark @ 2012-03-30 20:54 UTC (permalink / raw)
  To: linux-mtd

I am trying to read my uboot environment from userspace.  Not too successful.

root:/> cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00080000 00020000 "bootloader(nand)"
mtd1: 00800000 00020000 "linux kernel(nand)"
mtd2: 06400000 00020000 "file system(nand)"
mtd3: 09380000 00020000 "file system(ubifs)"

>From my uboot config:
#define CONFIG_ENV_OFFSET       0x60000
#define CONFIG_ENV_SIZE         0x20000

Try #1
root:/> cat /etc/fw_env.config
/dev/mtd0               0x60000         0x20000         0x20000         1

root:/> ./fw_printenv
Cannot read bad block mark: Invalid argument

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: User error with fw_printenv - I hope
  2012-03-30 20:54 User error with fw_printenv - I hope Bishop, Mark
@ 2012-03-30 22:30 ` Mike Frysinger
  2012-04-02 17:37   ` Bishop, Mark
  0 siblings, 1 reply; 9+ messages in thread
From: Mike Frysinger @ 2012-03-30 22:30 UTC (permalink / raw)
  To: Bishop, Mark; +Cc: linux-mtd

On Fri, Mar 30, 2012 at 16:54, Bishop, Mark wrote:
> I am trying to read my uboot environment from userspace.  Not too successful.
>
> root:/> cat /proc/mtd
> dev:    size   erasesize  name
> mtd0: 00080000 00020000 "bootloader(nand)"
> mtd1: 00800000 00020000 "linux kernel(nand)"
> mtd2: 06400000 00020000 "file system(nand)"
> mtd3: 09380000 00020000 "file system(ubifs)"
>
> From my uboot config:
> #define CONFIG_ENV_OFFSET       0x60000
> #define CONFIG_ENV_SIZE         0x20000
>
> Try #1
> root:/> cat /etc/fw_env.config
> /dev/mtd0               0x60000         0x20000         0x20000         1
>
> root:/> ./fw_printenv
> Cannot read bad block mark: Invalid argument

strace it to see what is actually complaining
-mike

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: User error with fw_printenv - I hope
  2012-03-30 22:30 ` Mike Frysinger
@ 2012-04-02 17:37   ` Bishop, Mark
  2012-04-03  6:26     ` Mike Frysinger
  0 siblings, 1 reply; 9+ messages in thread
From: Bishop, Mark @ 2012-04-02 17:37 UTC (permalink / raw)
  To: linux-mtd



> -----Original Message-----
> From: Mike Frysinger [mailto:vapier.adi@gmail.com]
> Sent: Friday, March 30, 2012 6:30 PM
> To: Bishop, Mark
> Cc: linux-mtd@lists.infradead.org
> Subject: Re: User error with fw_printenv - I hope
> 
> On Fri, Mar 30, 2012 at 16:54, Bishop, Mark wrote:
> > I am trying to read my uboot environment from userspace.  Not too
> successful.
> >
> > root:/> cat /proc/mtd
> > dev:    size   erasesize  name
> > mtd0: 00080000 00020000 "bootloader(nand)"
> > mtd1: 00800000 00020000 "linux kernel(nand)"
> > mtd2: 06400000 00020000 "file system(nand)"
> > mtd3: 09380000 00020000 "file system(ubifs)"
> >
> > From my uboot config:
> > #define CONFIG_ENV_OFFSET       0x60000
> > #define CONFIG_ENV_SIZE         0x20000
> >
> > Try #1
> > root:/> cat /etc/fw_env.config
> > /dev/mtd0               0x60000         0x20000
> 0x20000         1
> >
> > root:/> ./fw_printenv
> > Cannot read bad block mark: Invalid argument
> 
> strace it to see what is actually complaining
> -mike

root:/> strace fw_printenv
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x886000
stat("/etc/ld.so.cache", {st_mode=S_IFREG|0644, st_size=1108, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY)      = 3
mmap2(NULL, 1108, PROT_READ, MAP_PRIVATE, 3, 0) = 0x89f000
close(3)                                = 0
open("/lib/libgcc_s.so.1", O_RDONLY)    = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=62416, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x890000
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0j\0\1\0\0\0\324#\0\0004\0\0\0"..., 4096) = 4096
mmap2(NULL, 57256, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE|MAP_EXECUTABLE, 3, 0) = 0x270000
mmap2(NULL, 8184, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x892000
pread(3, "\17d\325/\0h\5h;/\353\2708\242\202\316\6\302\322\270\0\0\377\343\35\372\216/8\256\302\254"..., 8024, 53248) = 8024
close(3)                                = 0
munmap(0x890000, 4096)                  = 0
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=252236, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x890000
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0j\0\1\0\0\0\f\313\0\0004\0\0\0"..., 4096) = 4096
mmap2(NULL, 243908, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE|MAP_EXECUTABLE, 3, 0) = 0x800000
mmap2(NULL, 17920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x888000
pread(3, "__get_myaddress: socket\0__get_my"..., 8840, 241664) = 8840
close(3)                                = 0
munmap(0x890000, 4096)                  = 0
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=252236, ...}) = 0
close(3)                                = 0
munmap(0x89f000, 1108)                  = 0
stat("/lib/ld-uClibc.so.0", {st_mode=S_IFREG|0755, st_size=20348, ...}) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B57600 opost isig icanon echo ...}) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B57600 opost isig icanon echo ...}) = 0
open("/etc/fw_env.config", O_RDONLY)    = 3
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x2dffb78) = -1 ENOTTY (Inappropriate ioctl for device)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS|0x4000000, 0, 0) = 0x89f000
read(3, "/dev/mtd0               0x60000 "..., 256) = 74
read(3, "", 256)                        = 0
close(3)                                = 0
stat("/dev/mtd0", {st_mode=S_IFCHR|0660, st_rdev=makedev(90, 0), ...}) = 0
mmap2(NULL, 135168, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS|0x4000000, 0, 0) = 0x840000
open("/dev/mtd0", O_RDONLY)             = 3
ioctl(3, MEMGETINFO or MFB_SET_CHROMA_KEY, 0x2dffc20) = 0
ioctl(3, MEMGETBADBLOCK, 0x2dffb9c)     = 1
ioctl(3, MEMGETBADBLOCK, 0x2dffb9c)     = -1 EINVAL (Invalid argument)
write(2, "Cannot read bad block mark", 26Cannot read bad block mark) = 26
write(2, ": ", 2: )                       = 2
write(2, "Invalid argument", 16Invalid argument)        = 16
write(2, "\n", 1
)                       = 1
close(3)                                = 0
_exit(1)                                = ?
root:/>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: User error with fw_printenv - I hope
  2012-04-02 17:37   ` Bishop, Mark
@ 2012-04-03  6:26     ` Mike Frysinger
  2012-04-03 15:59       ` Bishop, Mark
  0 siblings, 1 reply; 9+ messages in thread
From: Mike Frysinger @ 2012-04-03  6:26 UTC (permalink / raw)
  To: Bishop, Mark; +Cc: linux-mtd

[-- Attachment #1: Type: text/plain, Size: 296 bytes --]

On Mon, Apr 2, 2012 at 13:37, Bishop, Mark wrote:
> ioctl(3, MEMGETBADBLOCK, 0x2dffb9c)     = 1
> ioctl(3, MEMGETBADBLOCK, 0x2dffb9c)     = -1 EINVAL (Invalid argument)

be nice to see what's actually in those pointers.  update your strace
with the attached patch and try again.
-mike

[-- Attachment #2: 0001-decode-mtd-ioctls.patch --]
[-- Type: application/octet-stream, Size: 11260 bytes --]

From 6e2b60b895a11aab43e82b123cd33b7388a33bfa Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@gentoo.org>
Date: Tue, 3 Apr 2012 02:11:18 -0400
Subject: [PATCH v2] decode mtd ioctls

I got tired of figuring out mtd structures (which show up a lot
in the embedded space), so add decoders for those ioctls.

* defs.h (mtd_ioctl): New prototype.
(print_loff_t): Likewise.
* io.c (print_loff_t): Delete static keyword
* ioctl.c (ioctl_decode): Call mtd_ioctl when code is 'M'.
* Makefile.am (strace_SOURCES): Add mtd.c.
* mtd.c: New file.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
v2
	- seems mtd-user.h lies and most ioctls take pointers to ints/off_ts
	  rather than inlining them as the argument.  my simple dummy test
	  code seems ok, but i'll try and boot this up on hardware to verify.

 Makefile.am |    2 +-
 defs.h      |    2 +
 io.c        |    2 +-
 ioctl.c     |    2 +
 mtd.c       |  275 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 281 insertions(+), 2 deletions(-)
 create mode 100644 mtd.c

diff --git a/Makefile.am b/Makefile.am
index c775801..b7e8460 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,7 +17,7 @@ AM_CPPFLAGS = -I$(srcdir)/$(OS)/$(ARCH) -I$(srcdir)/$(OS) -I$(builddir)/$(OS)
 strace_SOURCES = strace.c syscall.c count.c util.c desc.c file.c ipc.c \
 		 io.c ioctl.c mem.c net.c process.c bjm.c quota.c \
 		 resource.c signal.c sock.c system.c term.c time.c \
-		 scsi.c stream.c block.c pathtrace.c
+		 scsi.c stream.c block.c pathtrace.c mtd.c
 noinst_HEADERS = defs.h
 
 EXTRA_DIST = $(man_MANS) errnoent.sh signalent.sh syscallent.sh ioctlsort.c \
diff --git a/defs.h b/defs.h
index 3348400..1ebbd29 100644
--- a/defs.h
+++ b/defs.h
@@ -545,6 +545,7 @@ extern void printsignal(int);
 extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov);
 extern void tprint_open_modes(mode_t);
 extern const char *sprint_open_modes(mode_t);
+extern void print_loff_t(struct tcb *, long);
 
 extern const struct ioctlent *ioctl_lookup(long);
 extern const struct ioctlent *ioctl_next_match(const struct ioctlent *);
@@ -555,6 +556,7 @@ extern int proc_ioctl(struct tcb *, int, int);
 extern int rtc_ioctl(struct tcb *, long, long);
 extern int scsi_ioctl(struct tcb *, long, long);
 extern int block_ioctl(struct tcb *, long, long);
+extern int mtd_ioctl(struct tcb *, long, long);
 
 extern int tv_nz(struct timeval *);
 extern int tv_cmp(struct timeval *, struct timeval *);
diff --git a/io.c b/io.c
index a7f6c29..5e697ec 100644
--- a/io.c
+++ b/io.c
@@ -261,7 +261,7 @@ sys_sendfile(struct tcb *tcp)
 	return 0;
 }
 
-static void
+void
 print_loff_t(struct tcb *tcp, long addr)
 {
 	loff_t offset;
diff --git a/ioctl.c b/ioctl.c
index a8055d5..8744b41 100644
--- a/ioctl.c
+++ b/ioctl.c
@@ -88,6 +88,8 @@ ioctl_decode(struct tcb *tcp, long code, long arg)
 		return block_ioctl(tcp, code, arg);
 	case 0x22:
 		return scsi_ioctl(tcp, code, arg);
+	case 'M':
+		return mtd_ioctl(tcp, code, arg);
 	default:
 		break;
 	}
diff --git a/mtd.c b/mtd.c
new file mode 100644
index 0000000..61092d8
--- /dev/null
+++ b/mtd.c
@@ -0,0 +1,275 @@
+/*
+ * Copyright (c) 2012 Mike Frysinger <vapier@gentoo.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "defs.h"
+
+#include <sys/ioctl.h>
+#include <mtd/mtd-user.h>
+
+static const struct xlat mtd_mode_options[] = {
+	{ MTD_OPS_PLACE_OOB,	"MTD_OPS_PLACE_OOB"	},
+	{ MTD_OPS_AUTO_OOB,	"MTD_OPS_AUTO_OOB"	},
+	{ MTD_OPS_RAW,		"MTD_OPS_RAW"		},
+	{ 0,			NULL			},
+};
+
+static const struct xlat mtd_type_options[] = {
+	{ MTD_ABSENT,		"MTD_ABSENT"		},
+	{ MTD_RAM,		"MTD_RAM"		},
+	{ MTD_ROM,		"MTD_ROM"		},
+	{ MTD_NORFLASH,		"MTD_NORFLASH"		},
+	{ MTD_NANDFLASH,	"MTD_NANDFLASH"		},
+	{ MTD_DATAFLASH,	"MTD_DATAFLASH"		},
+	{ MTD_UBIVOLUME,	"MTD_UBIVOLUME"		},
+	{ MTD_MLCNANDFLASH,	"MTD_MLCNANDFLASH"	},
+	{ 0,			NULL			},
+};
+
+static const struct xlat mtd_flags_options[] = {
+	{ MTD_WRITEABLE,	"MTD_WRITEABLE"		},
+	{ MTD_BIT_WRITEABLE,	"MTD_BIT_WRITEABLE"	},
+	{ MTD_NO_ERASE,		"MTD_NO_ERASE"		},
+	{ MTD_POWERUP_LOCK,	"MTD_POWERUP_LOCK"	},
+	{ 0,			NULL			},
+};
+
+static const struct xlat mtd_otp_options[] = {
+	{ MTD_OTP_OFF,		"MTD_OTP_OFF"		},
+	{ MTD_OTP_FACTORY,	"MTD_OTP_FACTORY"	},
+	{ MTD_OTP_USER,		"MTD_OTP_USER"		},
+	{ 0,			NULL			},
+};
+
+static const struct xlat mtd_nandecc_options[] = {
+	{ MTD_NANDECC_OFF,		"MTD_NANDECC_OFF"		},
+	{ MTD_NANDECC_PLACE,		"MTD_NANDECC_PLACE"		},
+	{ MTD_NANDECC_AUTOPLACE,	"MTD_NANDECC_AUTOPLACE"		},
+	{ MTD_NANDECC_PLACEONLY,	"MTD_NANDECC_PLACEONLY"		},
+	{ MTD_NANDECC_AUTOPL_USR,	"MTD_NANDECC_AUTOPL_USR"	},
+	{ 0,				NULL				},
+};
+
+int mtd_ioctl(struct tcb *tcp, long code, long arg)
+{
+	struct mtd_info_user minfo;
+	struct erase_info_user einfo;
+	struct erase_info_user64 einfo64;
+	struct mtd_oob_buf mbuf;
+	struct mtd_oob_buf64 mbuf64;
+	struct region_info_user rinfo;
+	struct otp_info oinfo;
+	struct mtd_ecc_stats estat;
+	struct mtd_write_req mreq;
+	struct nand_oobinfo ninfo;
+	struct nand_ecclayout_user nlay;
+	int i, j;
+
+	if (entering(tcp))
+		return 0;
+
+	switch (code) {
+
+	case MEMGETINFO:
+		if (!verbose(tcp) || umove(tcp, arg, &minfo) < 0)
+			return 0;
+
+		tprints(", {type=");
+		printxval(mtd_type_options, minfo.type, "MTD_???");
+		tprints(", flags=");
+		printflags(mtd_flags_options, minfo.flags, "MTD_???");
+		tprintf(", size=%#" PRIx32 ", erasesize=%#" PRIx32,
+			minfo.size, minfo.erasesize);
+		tprintf(", writesize=%#" PRIx32 ", oobsize=%#" PRIx32,
+			minfo.writesize, minfo.oobsize);
+		tprintf(", padding=%#" PRIx64 "}",
+			(uint64_t) minfo.padding);
+		return 1;
+
+	case MEMERASE:
+	case MEMLOCK:
+	case MEMUNLOCK:
+	case MEMISLOCKED:
+		if (!verbose(tcp) || umove(tcp, arg, &einfo) < 0)
+			return 0;
+
+		tprintf(", {start=%#" PRIx32 ", length=%#" PRIx32 "}",
+			einfo.start, einfo.length);
+		return 1;
+
+	case MEMERASE64:
+		if (!verbose(tcp) || umove(tcp, arg, &einfo64) < 0)
+			return 0;
+
+		tprintf(", {start=%#" PRIx64 ", length=%#" PRIx64 "}",
+			(uint64_t) einfo64.start, (uint64_t) einfo64.length);
+		return 1;
+
+	case MEMWRITEOOB:
+	case MEMREADOOB:
+		if (!verbose(tcp) || umove(tcp, arg, &mbuf) < 0)
+			return 0;
+
+		tprintf(", {start=%#" PRIx32 ", length=%#" PRIx32 ", ptr=...}",
+			mbuf.start, mbuf.length);
+		return 1;
+
+	case MEMWRITEOOB64:
+	case MEMREADOOB64:
+		if (!verbose(tcp) || umove(tcp, arg, &mbuf64) < 0)
+			return 0;
+
+		tprintf(", {start=%#" PRIx64 ", length=%#" PRIx64 ", ptr=...}",
+			(uint64_t) mbuf64.start, (uint64_t) mbuf64.length);
+		return 1;
+
+	case MEMGETREGIONINFO:
+		if (!verbose(tcp) || umove(tcp, arg, &rinfo) < 0)
+			return 0;
+
+		tprintf(", {offset=%#" PRIx32 ", erasesize=%#" PRIx32,
+			rinfo.offset, rinfo.erasesize);
+		tprintf(", numblocks=%#" PRIx32 ", regionindex=%#" PRIx32 "}",
+			rinfo.numblocks, rinfo.regionindex);
+		return 1;
+
+	case MEMGETOOBSEL:
+		if (!verbose(tcp) || umove(tcp, arg, &ninfo) < 0)
+			return 0;
+
+		tprints(", {useecc=");
+		printxval(mtd_nandecc_options, ninfo.useecc, "MTD_NANDECC_???");
+		tprintf(", eccbytes=%#" PRIx32, ninfo.eccbytes);
+
+		tprints(", oobfree={");
+		for (i = 0; i < ARRAY_SIZE(ninfo.oobfree); ++i) {
+			if (i)
+				tprints("}, ");
+			tprints("{");
+			for (j = 0; j < ARRAY_SIZE(ninfo.oobfree[0]); ++j) {
+				if (j)
+					tprints(", ");
+				tprintf("%#" PRIx32, ninfo.oobfree[i][j]);
+			}
+		}
+
+		tprints("}}, eccpos={");
+		for (i = 0; i < ARRAY_SIZE(ninfo.eccpos); ++i) {
+			if (i)
+				tprints(", ");
+			tprintf("%#" PRIx32, ninfo.eccpos[i]);
+		}
+
+		tprints("}");
+		return 1;
+
+	case OTPGETREGIONINFO:
+	case OTPLOCK:
+		if (!verbose(tcp) || umove(tcp, arg, &oinfo) < 0)
+			return 0;
+
+		tprintf(", {start=%#" PRIx32 ", length=%#" PRIx32 ", locked=%" PRIu32 "}",
+			oinfo.start, oinfo.length, oinfo.locked);
+		return 1;
+
+	case ECCGETLAYOUT:
+		if (!verbose(tcp) || umove(tcp, arg, &nlay) < 0)
+			return 0;
+
+		tprintf(", {eccbytes=%#" PRIx32 ", eccpos={", nlay.eccbytes);
+		for (i = 0; i < ARRAY_SIZE(nlay.eccpos); ++i) {
+			if (i)
+				tprints(", ");
+			tprintf("%#" PRIx32, nlay.eccpos[i]);
+		}
+		tprintf("}, oobavail=%#" PRIx32 ", oobfree={", nlay.oobavail);
+		for (i = 0; i < ARRAY_SIZE(nlay.oobfree); ++i) {
+			if (i)
+				tprints(", ");
+			tprintf("{offset=%#" PRIx32 ", length=%#" PRIx32 "}",
+				nlay.oobfree[i].offset, nlay.oobfree[i].length);
+		}
+		tprints("}");
+		return 1;
+
+	case ECCGETSTATS:
+		if (!verbose(tcp) || umove(tcp, arg, &estat) < 0)
+			return 0;
+
+		tprintf(", {corrected=%#" PRIx32 ", failed=%#" PRIx32,
+			estat.corrected, estat.failed);
+		tprintf(", badblocks=%#" PRIx32 ", bbtblocks=%#" PRIx32 "}",
+			estat.badblocks, estat.bbtblocks);
+		return 1;
+
+	case MEMWRITE:
+		if (!verbose(tcp) || umove(tcp, arg, &mreq) < 0)
+			return 0;
+
+		tprintf(", {start=%#" PRIx64 ", len=%#" PRIx64,
+			(uint64_t) mreq.start, (uint64_t) mreq.len);
+		tprintf(", ooblen=%#" PRIx64 ", usr_data=%#" PRIx64,
+			(uint64_t) mreq.ooblen, (uint64_t) mreq.usr_data);
+		tprintf(", usr_oob=%#" PRIx64 ", mode=",
+			(uint64_t) mreq.usr_oob);
+		printxval(mtd_mode_options, mreq.mode, "MTD_OPS_???");
+		tprints(", padding=...}");
+		return 1;
+
+	case OTPSELECT:
+		if (!verbose(tcp) || umove(tcp, arg, &i) < 0)
+			return 0;
+
+		tprints(", [");
+		printxval(mtd_otp_options, i, "MTD_OTP_???");
+		tprints("]");
+		return 1;
+
+	case MEMGETBADBLOCK:
+	case MEMSETBADBLOCK:
+		if (!verbose(tcp))
+			return 0;
+
+		tprints(", ");
+		print_loff_t(tcp, arg);
+		return 1;
+
+	case OTPGETREGIONCOUNT:
+		if (!verbose(tcp) || umove(tcp, arg, &i) < 0)
+			return 0;
+
+		tprintf(", [%i]", i);
+		return 1;
+
+	case MTDFILEMODE:
+		/* XXX: process return value as enum mtd_file_modes */
+
+	case MEMGETREGIONCOUNT:
+		/* These ones take simple args, so let default printer handle it */
+
+	default:
+		return 0;
+	}
+}
-- 
1.7.8.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* RE: User error with fw_printenv - I hope
  2012-04-03  6:26     ` Mike Frysinger
@ 2012-04-03 15:59       ` Bishop, Mark
  2012-04-03 19:22         ` Mike Frysinger
  0 siblings, 1 reply; 9+ messages in thread
From: Bishop, Mark @ 2012-04-03 15:59 UTC (permalink / raw)
  To: linux-mtd

I don't have a print_loff_t().  I have a ioctl_decode() instead and I am trying to cram your patch into it.

I'll get back to you when I get something that works.

> -----Original Message-----
> From: Mike Frysinger [mailto:vapier.adi@gmail.com]
> Sent: Tuesday, April 03, 2012 2:26 AM
> To: Bishop, Mark
> Cc: linux-mtd@lists.infradead.org
> Subject: Re: User error with fw_printenv - I hope
> 
> On Mon, Apr 2, 2012 at 13:37, Bishop, Mark wrote:
> > ioctl(3, MEMGETBADBLOCK, 0x2dffb9c)     = 1 ioctl(3, MEMGETBADBLOCK,
> > 0x2dffb9c)     = -1 EINVAL (Invalid argument)
> 
> be nice to see what's actually in those pointers.  update your strace
> with the attached patch and try again.
> -mike

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: User error with fw_printenv - I hope
  2012-04-03 15:59       ` Bishop, Mark
@ 2012-04-03 19:22         ` Mike Frysinger
  2012-04-03 21:46           ` Bishop, Mark
  2012-04-03 23:09           ` Bishop, Mark
  0 siblings, 2 replies; 9+ messages in thread
From: Mike Frysinger @ 2012-04-03 19:22 UTC (permalink / raw)
  To: Bishop, Mark; +Cc: linux-mtd

On Tue, Apr 3, 2012 at 08:59, Bishop, Mark wrote:
> I don't have a print_loff_t().  I have a ioctl_decode() instead and I am trying to cram your patch into it.

all the print_loff_t does is process a pointer to an int.  you could
probably do the same thing by changing the mtd.c file to process the
int directly (look at the other ioctls that do umove() with &i).
-mike

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: User error with fw_printenv - I hope
  2012-04-03 19:22         ` Mike Frysinger
@ 2012-04-03 21:46           ` Bishop, Mark
  2012-04-03 23:09           ` Bishop, Mark
  1 sibling, 0 replies; 9+ messages in thread
From: Bishop, Mark @ 2012-04-03 21:46 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: linux-mtd



> -----Original Message-----
> From: Mike Frysinger [mailto:vapier.adi@gmail.com]
> Sent: Tuesday, April 03, 2012 3:22 PM
> To: Bishop, Mark
> Cc: linux-mtd@lists.infradead.org
> Subject: Re: User error with fw_printenv - I hope
> 
> On Tue, Apr 3, 2012 at 08:59, Bishop, Mark wrote:
> > I don't have a print_loff_t().  I have a ioctl_decode() instead and I
> am trying to cram your patch into it.
> 
> all the print_loff_t does is process a pointer to an int.  you could
> probably do the same thing by changing the mtd.c file to process the
> int directly (look at the other ioctls that do umove() with &i).
> -mike

Any idea what is causing this:

/home/mark/new_image/uclinux-dist/user/strace/strace-4.6/mtd.c: In function ‘mtd_ioctl’:
/home/mark/new_image/uclinux-dist/user/strace/strace-4.6/mtd.c:102: warning: implicit declaration of function ‘tprints’
/home/mark/new_image/uclinux-dist/user/strace/strace-4.6/mtd.c:106: error: expected ‘)’ before ‘PRIx32’
/home/mark/new_image/uclinux-dist/user/strace/strace-4.6/mtd.c:107: warning: conversion lacks type at end of format
/home/mark/new_image/uclinux-dist/user/strace/strace-4.6/mtd.c:108: error: expected ‘)’ before ‘PRIx32’
.....


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: User error with fw_printenv - I hope
  2012-04-03 19:22         ` Mike Frysinger
  2012-04-03 21:46           ` Bishop, Mark
@ 2012-04-03 23:09           ` Bishop, Mark
  2012-04-04  2:16             ` Mike Frysinger
  1 sibling, 1 reply; 9+ messages in thread
From: Bishop, Mark @ 2012-04-03 23:09 UTC (permalink / raw)
  To: linux-mtd



> -----Original Message-----
> From: Mike Frysinger [mailto:vapier.adi@gmail.com]
> Sent: Tuesday, April 03, 2012 3:22 PM
> To: Bishop, Mark
> Cc: linux-mtd@lists.infradead.org
> Subject: Re: User error with fw_printenv - I hope
> 
> On Tue, Apr 3, 2012 at 08:59, Bishop, Mark wrote:
> > I don't have a print_loff_t().  I have a ioctl_decode() instead and I
> am trying to cram your patch into it.
> 
> all the print_loff_t does is process a pointer to an int.  you could
> probably do the same thing by changing the mtd.c file to process the
> int directly (look at the other ioctls that do umove() with &i).
> -mike

Thanks Mike.  Hopefully you can tell me what I need to do here:

root:/> strace fw_printenv
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x2950000
stat("/etc/ld.so.cache", {st_mode=S_IFREG|0644, st_size=1108, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY)      = 3
mmap2(NULL, 1108, PROT_READ, MAP_PRIVATE, 3, 0) = 0x2d18000
close(3)                                = 0
open("/lib/libgcc_s.so.1", O_RDONLY)    = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=62416, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x2d19000
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0j\0\1\0\0\0\324#\0\0004\0\0\0"..., 4096) = 4096
mmap2(NULL, 57256, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE|MAP_EXECUTABLE, 3, 0) = 0x2d90000
mmap2(NULL, 8184, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2d50000
pread(3, "\17d\325/\0h\5h;/\353\2708\242\202\316\6\302\322\270\0\0\377\343\35\372\216/8\256\302\254"..., 8024, 53248) = 8024
close(3)                                = 0
munmap(0x2d19000, 4096)                 = 0
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=252236, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x2d19000
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0j\0\1\0\0\0\f\313\0\0004\0\0\0"..., 4096) = 4096
mmap2(NULL, 243908, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE|MAP_EXECUTABLE, 3, 0) = 0x2e40000
mmap2(NULL, 17920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2d48000
pread(3, "__get_myaddress: socket\0__get_my"..., 8840, 241664) = 8840
close(3)                                = 0
munmap(0x2d19000, 4096)                 = 0
open("/lib/libc.so.0", O_RDONLY)        = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=252236, ...}) = 0
close(3)                                = 0
munmap(0x2d18000, 1108)                 = 0
stat("/lib/ld-uClibc.so.0", {st_mode=S_IFREG|0755, st_size=20348, ...}) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B57600 opost isig icanon echo ...}) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B57600 opost isig icanon echo ...}) = 0
open("/etc/fw_env.config", O_RDONLY)    = 3
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x2e1fb78) = -1 ENOTTY (Inappropriate ioctl for device)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS|0x4000000, 0, 0) = 0x2d18000
read(3, "# Configuration file for fw_(pri"..., 256) = 256
read(3, "Flash sector size\tNumber of sect"..., 256) = 163
read(3, "", 256)                        = 0
close(3)                                = 0
stat("/dev/mtd0", {st_mode=S_IFCHR|0660, st_rdev=makedev(90, 0), ...}) = 0
mmap2(NULL, 135168, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS|0x4000000, 0, 0) = 0x2e80000
open("/dev/mtd0", O_RDONLY)             = 3
ioctl(3, MEMGETINFO or MFB_SET_CHROMA_KEY, {type=MTD_NANDFLASH, flags=MTD_WRITEABLE, size=0x80000, erasesize=0x20000, writesize=0x800, oobsize=0x40, padding=0xffffffff}) = 0
ioctl(3, MEMGETBADBLOCK, [393216])      = 1
ioctl(3, MEMGETBADBLOCK, [524288])      = -1 EINVAL (Invalid argument)
write(2, "Cannot read bad block mark", 26Cannot read bad block mark) = 26
write(2, ": ", 2: )                       = 2
write(2, "Invalid argument", 16Invalid argument)        = 16
write(2, "\n", 1
)                       = 1
close(3)                                = 0
_exit(1)                                = ?
root:/>


root:/> cat /etc/fw_env.config
# Configuration file for fw_(printenv/saveenv) utility.
# Up to two entries are valid, in this case the redundant
# environment sector is assumed present.
# Notice, that the "Number of sectors" is ignored on NOR.

# MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
#/dev/mtd1              0x0000          0x4000          0x4000
#/dev/mtd2              0x0000          0x4000          0x4000

# NAND example
/dev/mtd0               0x60000         0x20000         0x20000                 1
root:/>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: User error with fw_printenv - I hope
  2012-04-03 23:09           ` Bishop, Mark
@ 2012-04-04  2:16             ` Mike Frysinger
  0 siblings, 0 replies; 9+ messages in thread
From: Mike Frysinger @ 2012-04-04  2:16 UTC (permalink / raw)
  To: Bishop, Mark; +Cc: linux-mtd

On Tue, Apr 3, 2012 at 19:09, Bishop, Mark
<Mark.Bishop@cooperindustries.com> wrote:
> ioctl(3, MEMGETINFO or MFB_SET_CHROMA_KEY, {type=MTD_NANDFLASH, flags=MTD_WRITEABLE, size=0x80000, erasesize=0x20000, writesize=0x800, oobsize=0x40, padding=0xffffffff}) = 0
> ioctl(3, MEMGETBADBLOCK, [393216])      = 1
> ioctl(3, MEMGETBADBLOCK, [524288])      = -1 EINVAL (Invalid argument)
> write(2, "Cannot read bad block mark", 26Cannot read bad block mark) = 26

thanks, this shows the issue.  looks like a bug in u-boot's
fw_printenv code.  it first tests block 0x60000 to see if it's bad,
then tries 0x80000.

> root:/> cat /etc/fw_env.config
> /dev/mtd0               0x60000         0x20000         0x20000                 1

your config though says you only have 1 block starting at 0x60000 with
a length of 0x20000.  so there's no reason it should be testing
0x80000 -- after all, you only care about bytes 0x60000 - 0x7ffff.

i guess time to raise the issue on the u-boot mailing list.  i'm
guessing you aren't running the latest mainline code, but in looking
at the git history, there doesn't seem to be many changes recently let
alone relevant ones.  wouldn't hurt to test though and should be easy
to try:
$ make env HOSTCC=bfin-uclinux-gcc
-mike

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-04-04  2:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-30 20:54 User error with fw_printenv - I hope Bishop, Mark
2012-03-30 22:30 ` Mike Frysinger
2012-04-02 17:37   ` Bishop, Mark
2012-04-03  6:26     ` Mike Frysinger
2012-04-03 15:59       ` Bishop, Mark
2012-04-03 19:22         ` Mike Frysinger
2012-04-03 21:46           ` Bishop, Mark
2012-04-03 23:09           ` Bishop, Mark
2012-04-04  2:16             ` Mike Frysinger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.