Skip to contentSkip to conversation

mtd-utils: move libmtd source files to lib/ subdirectory

PATCH In review Kevin Cernekee 2 participants 18 messages Jul 8, 2010 – Jul 26, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/5 mtd-utils: move libmtd source files to lib/ subdirectory

Source files for libmtd, crc32, and fec are scattered throughout the tree. Move them to a central location so they can be built into a common "libmtd.a" library used by all mtd-utils programs.

This patch only renames/deletes files and does not change the content.

---
 crc32.h                                 |   19 ------
 {ubi-utils/src => include}/common.h     |    0
 {mkfs.ubifs => include}/crc32.h         |    0
 {ubi-utils/include => include}/libmtd.h |    0
 crc32.c => lib/crc32.c                  |    0
 fec.c => lib/fec.c                      |    0
 {ubi-utils/src => lib}/libmtd.c         |    0
 {ubi-utils/src => lib}/libmtd_int.h     |    0
 {ubi-utils/src => lib}/libmtd_legacy.c  |    0
 mkfs.ubifs/crc32.c                      |   95 -------------------------------
 ubi-utils/src/crc32.c                   |   95 -------------------------------
 ubi-utils/src/crc32.h                   |   17 ------
 12 files changed, 0 insertions(+), 226 deletions(-)
 delete mode 100644 crc32.h
 rename {ubi-utils/src => include}/common.h (100%)
 rename {mkfs.ubifs => include}/crc32.h (100%)
 rename {ubi-utils/include => include}/libmtd.h (100%)
 rename crc32.c => lib/crc32.c (100%)
 rename fec.c => lib/fec.c (100%)
 rename {ubi-utils/src => lib}/libmtd.c (100%)
 rename {ubi-utils/src => lib}/libmtd_int.h (100%)
 rename {ubi-utils/src => lib}/libmtd_legacy.c (100%)
 delete mode 100644 mkfs.ubifs/crc32.c
 delete mode 100644 ubi-utils/src/crc32.c
 delete mode 100644 ubi-utils/src/crc32.h
crc32.h deleted +0 -19
deleted file mode 100644
index ee3145b..0000000
@@ -1,19 +0,0 @@
-#ifndef CRC32_H
-#define CRC32_H
-
-#include <stdint.h>
-
-extern const uint32_t crc32_table[256];
-
-/* Return a 32-bit CRC of the contents of the buffer. */
-
-	static inline uint32_t
-crc32(uint32_t val, const void *ss, int len)
-{
-	const unsigned char *s = ss;
-	while (--len >= 0)
-		val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
-	return val;
-}
-
-#endif
include/common.h renamed from ubi-utils/src/common.h +0 -0
similarity index 100%
rename from ubi-utils/src/common.h
rename to include/common.h
include/crc32.h renamed from mkfs.ubifs/crc32.h +0 -0
similarity index 100%
rename from mkfs.ubifs/crc32.h
rename to include/crc32.h
include/libmtd.h renamed from ubi-utils/include/libmtd.h +0 -0
similarity index 100%
rename from ubi-utils/include/libmtd.h
rename to include/libmtd.h
lib/crc32.c renamed from crc32.c +0 -0
similarity index 100%
rename from crc32.c
rename to lib/crc32.c
lib/fec.c renamed from fec.c +0 -0
similarity index 100%
rename from fec.c
rename to lib/fec.c
lib/libmtd.c renamed from ubi-utils/src/libmtd.c +0 -0
similarity index 100%
rename from ubi-utils/src/libmtd.c
rename to lib/libmtd.c
lib/libmtd_int.h renamed from ubi-utils/src/libmtd_int.h +0 -0
similarity index 100%
rename from ubi-utils/src/libmtd_int.h
rename to lib/libmtd_int.h
lib/libmtd_legacy.c renamed from ubi-utils/src/libmtd_legacy.c +0 -0
similarity index 100%
rename from ubi-utils/src/libmtd_legacy.c
rename to lib/libmtd_legacy.c
mkfs.ubifs/crc32.c deleted +0 -95

95 lines not on this page · raw message

ubi-utils/src/crc32.c deleted +0 -95

95 lines not on this page · raw message

ubi-utils/src/crc32.h deleted +0 -17
deleted file mode 100644
index c001fcf..0000000
@@ -1,17 +0,0 @@
-#ifndef __CRC32_H__
-#define __CRC32_H__
-
-#include <stdint.h>
-
-extern const uint32_t crc32_table[256];
-
-/* Returns a 32-bit CRC of the contents of the buffer */
-static inline uint32_t crc32(uint32_t val, const void *ss, int len)
-{
-	const unsigned char *s = ss;
-	while (--len >= 0)
-		val = crc32_table[(val ^ *s++) & 0xff] ^ (val >> 8);
-	return val;
-}
-
-#endif
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH v2 2/5 mtd-utils: update Makefiles, source files to use common libmtd.a

Modify the build system and source code so that libmtd.a can be built from a "common" location (lib/). Statically link all utilities at the top level with libmtd.a . Minor changes to mkfs.ubifs to allow using the common crc32 implementation.

---
 Makefile                  |   21 ++++++---------------
 common.mk                 |    2 +-
 fectest.c                 |    2 +-
 flash_eraseall.c          |    2 +-
 include/crc32.h           |    2 +-
 jffs2dump.c               |    2 +-
 lib/Makefile              |   22 ++++++++++++++++++++++
 mkfs.jffs2.c              |    4 ++--
 mkfs.ubifs/Makefile       |    3 ++-
 mkfs.ubifs/compr.c        |    4 +++-
 mkfs.ubifs/mkfs.ubifs.c   |    5 +++--
 mkfs.ubifs/mkfs.ubifs.h   |    1 -
 recv_image.c              |    2 +-
 serve_image.c             |    2 +-
 sumtool.c                 |    2 +-
 ubi-utils/Makefile        |   15 +++++++--------
 ubi-utils/src/libscan.c   |    2 +-
 ubi-utils/src/libubigen.c |    2 +-
 ubi-utils/src/ubicrc32.c  |    2 +-
 ubi-utils/src/ubiformat.c |    2 +-
 20 files changed, 57 insertions(+), 42 deletions(-)
 create mode 100644 lib/Makefile
Makefile +6 -15
index 577634f..b558705 100644
@@ -7,7 +7,7 @@ ifeq ($(WITHOUT_XATTR), 1)
   CPPFLAGS += -DWITHOUT_XATTR
 endif
 
-SUBDIRS = ubi-utils mkfs.ubifs
+SUBDIRS = lib ubi-utils mkfs.ubifs
 
 TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
 	ftl_check mkfs.jffs2 flash_lock flash_unlock flash_info \
@@ -20,6 +20,9 @@ TARGETS = ftl_format flash_erase flash_eraseall nanddump doc_loadbios \
 
 SYMLINKS =
 
+LDLIBS = -L$(BUILDDIR)/lib -lmtd
+LDDEPS = $(BUILDDIR)/lib/libmtd.a
+
 include common.mk
 
 clean::
@@ -36,28 +39,16 @@ $(SYMLINKS):
 	ln -sf ../fs/jffs2/$@ $@
 
 $(BUILDDIR)/mkfs.jffs2: $(addprefix $(BUILDDIR)/,\
-	crc32.o compr_rtime.o mkfs.jffs2.o compr_zlib.o compr_lzo.o \
+	compr_rtime.o mkfs.jffs2.o compr_zlib.o compr_lzo.o \
 	compr.o rbtree.o)
 LDFLAGS_mkfs.jffs2 = $(ZLIBLDFLAGS) $(LZOLDFLAGS)
 LDLIBS_mkfs.jffs2  = -lz -llzo2
 
-$(BUILDDIR)/flash_eraseall: $(BUILDDIR)/crc32.o $(BUILDDIR)/flash_eraseall.o
-
 $(BUILDDIR)/jffs2reader: $(BUILDDIR)/jffs2reader.o
 LDFLAGS_jffs2reader = $(ZLIBLDFLAGS) $(LZOLDFLAGS)
 LDLIBS_jffs2reader  = -lz -llzo2
 
-$(BUILDDIR)/jffs2dump: $(BUILDDIR)/jffs2dump.o $(BUILDDIR)/crc32.o
-
-$(BUILDDIR)/sumtool: $(BUILDDIR)/sumtool.o $(BUILDDIR)/crc32.o
-
-$(BUILDDIR)/serve_image: $(BUILDDIR)/serve_image.o $(BUILDDIR)/crc32.o $(BUILDDIR)/fec.o
-
-$(BUILDDIR)/recv_image: $(BUILDDIR)/recv_image.o $(BUILDDIR)/crc32.o $(BUILDDIR)/fec.o
-
-$(BUILDDIR)/fectest: $(BUILDDIR)/fectest.o $(BUILDDIR)/crc32.o $(BUILDDIR)/fec.o
-
-
+$(BUILDDIR)/lib/libmtd.a: subdirs_lib_all ;
 
 install:: ${TARGETS}
 	mkdir -p ${DESTDIR}/${SBINDIR}
common.mk +1 -1
index d704b44..be785b4 100644
@@ -47,7 +47,7 @@ clean:: $(SUBDIRS_CLEAN)
 
 install:: $(TARGETS) $(SUBDIRS_INSTALL)
 
-%: %.o
+%: %.o $(LDDEPS) $(LDDEPS_$(notdir $@))
 	$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_$(notdir $@)) -g -o $@ $^ $(LDLIBS) $(LDLIBS_$(notdir $@))
 
 $(BUILDDIR)/%.a:
fectest.c +1 -1
index d5893b9..c1fbd52 100644
@@ -8,7 +8,7 @@
 #include <sys/stat.h>
 
 #include "mcast_image.h"
-#include "crc32.h"
+#include <crc32.h>
 
 #define ERASE_SIZE 131072
 //#define PKT_SIZE 1400
flash_eraseall.c +1 -1
index a22fc49..e6f8d50 100644
@@ -35,7 +35,7 @@
 #include <getopt.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
-#include "crc32.h"
+#include <crc32.h>
 
 #include <mtd/mtd-user.h>
 #include <mtd/jffs2-user.h>
include/crc32.h +1 -1
index 86fc841..4b51177 100644
@@ -10,7 +10,7 @@
 extern const uint32_t crc32_table[256];
 
 /* Return a 32-bit CRC of the contents of the buffer. */
-static inline uint32_t ubifs_crc32(uint32_t val, const void *ss, int len)
+static inline uint32_t crc32(uint32_t val, const void *ss, int len)
 {
 	const unsigned char *s = ss;
 
jffs2dump.c +1 -1
index 2802682..cd8b6fa 100644
@@ -31,7 +31,7 @@
 #include <endian.h>
 #include <byteswap.h>
 #include <getopt.h>
-#include "crc32.h"
+#include <crc32.h>
 #include "summary.h"
 
 #define PROGRAM "jffs2dump"
lib/Makefile new file +22 -0
new file mode 100644
index 0000000..91507f3
@@ -0,0 +1,22 @@
+#
+# Makefile for libmtd
+#
+
+SUBDIRS =
+
+# CFLAGS += -Werror
+CPPFLAGS += -I../include
+LIBS = libmtd
+TARGETS = libmtd.a
+
+include ../common.mk
+
+$(BUILDDIR)/libmtd.a: $(addprefix $(BUILDDIR)/,\
+	libmtd.o libmtd_legacy.o crc32.o fec.o)
+
+clean::
+	rm -f $(addsuffix .a, $(LIBS))
+
+install::
+
+uninstall:
mkfs.jffs2.c +2 -2
index 64cafb6..2c78fd5 100644
@@ -69,10 +69,10 @@
 #include <sys/acl.h>
 #endif
 #include <byteswap.h>
-#define crc32 __complete_crap
+#define crc32 __zlib_crc32
 #include <zlib.h>
 #undef crc32
-#include "crc32.h"
+#include <crc32.h>
 #include "rbtree.h"
 
 /* Do not use the weird XPG version of basename */
mkfs.ubifs/Makefile +2 -1
index 61d0e20..ba21a8c 100644
@@ -7,12 +7,13 @@ ALL_SOURCES=*.[ch] hashtable/*.[ch]
 TARGETS = mkfs.ubifs
 
 LDLIBS_mkfs.ubifs = -lz -llzo2 -lm -luuid -L$(BUILDDIR)/../ubi-utils/ -lubi
+LDLIBS_mkfs.ubifs += -L$(BUILDDIR)/../lib -lmtd
 LDLIBS_mkfs.ubifs += $(ZLIBLDFLAGS) $(LZOLDFLAGS)
 
 include ../common.mk
 
 $(BUILDDIR)/mkfs.ubifs: $(addprefix $(BUILDDIR)/,\
-	crc16.o crc32.o lpt.o compr.o devtable.o \
+	crc16.o lpt.o compr.o devtable.o \
 	hashtable/hashtable.o hashtable/hashtable_itr.o)
 
 clean::
mkfs.ubifs/compr.c +3 -1
index e378c5d..7f084c5 100644
@@ -24,10 +24,12 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <string.h>
-#include <zlib.h>
 #include <lzo/lzo1x.h>
 #include <linux/types.h>
 
+#define crc32 __zlib_crc32
+#include <zlib.h>
+
 #include "compr.h"
 #include "ubifs-media.h"
 #include "mkfs.ubifs.h"
mkfs.ubifs/mkfs.ubifs.c +3 -2
index e4b4e3c..95b20b0 100644
@@ -21,6 +21,7 @@
  */
 
 #include "mkfs.ubifs.h"
+#include <crc32.h>
 
 #define PROGRAM_VERSION "1.3"
 
@@ -752,7 +753,7 @@ static void prepare_node(void *node, int len)
 	ch->group_type = UBIFS_NO_NODE_GROUP;
 	ch->sqnum = cpu_to_le64(++c->max_sqnum);
 	ch->padding[0] = ch->padding[1] = 0;
-	crc = ubifs_crc32(UBIFS_CRC32_INIT, node + 8, len - 8);
+	crc = crc32(UBIFS_CRC32_INIT, node + 8, len - 8);
 	ch->crc = cpu_to_le32(crc);
 }
 
@@ -822,7 +823,7 @@ static int do_pad(void *buf, int len)
 		pad_len -= UBIFS_PAD_NODE_SZ;
 		pad_node->pad_len = cpu_to_le32(pad_len);
 
-		crc = ubifs_crc32(UBIFS_CRC32_INIT, buf + 8,
+		crc = crc32(UBIFS_CRC32_INIT, buf + 8,
 				  UBIFS_PAD_NODE_SZ - 8);
 		ch->crc = cpu_to_le32(crc);
 
mkfs.ubifs/mkfs.ubifs.h +0 -1
index 16b34c7..c00dce0 100644
@@ -49,7 +49,6 @@
 #include <sys/file.h>
 
 #include "libubi.h"
-#include "crc32.h"
 #include "defs.h"
 #include "crc16.h"
 #include "ubifs-media.h"
recv_image.c +1 -1
index d65aa2a..2be511a 100644
@@ -16,7 +16,7 @@
 #include <netinet/in.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
-#include "crc32.h"
+#include <crc32.h>
 #include "mtd/mtd-user.h"
 #include "mcast_image.h"
 
serve_image.c +1 -1
index adb4869..5aafa35 100644
@@ -16,7 +16,7 @@
 #include <sys/mman.h>
 #include <netinet/in.h>
 #include <sys/time.h>
-#include "crc32.h"
+#include <crc32.h>
 #include "mcast_image.h"
 
 int tx_rate = 80000;
sumtool.c +1 -1
index 6bb7168..966e110 100644
@@ -44,7 +44,7 @@
 #include <endian.h>
 #include <byteswap.h>
 #include <getopt.h>
-#include "crc32.h"
+#include <crc32.h>
 #include "summary.h"
 
 #define PAD(x) (((x)+3)&~3)
ubi-utils/Makefile +7 -8
index e736a09..327d2d7 100644
@@ -9,11 +9,12 @@ SUBDIRS = old-utils
 # CFLAGS += -Werror
 CPPFLAGS += -Iinclude -Isrc -I$(KERNELHDR)
 
-LIBS = libubi libmtd libubigen libiniparser libscan
+LIBS = libubi libubigen libiniparser libscan
 TARGETS = ubiupdatevol ubimkvol ubirmvol ubicrc32 ubinfo ubiattach \
           ubidetach ubinize ubiformat ubirename mtdinfo ubirsvol
 
 VPATH = src
+LDLIBS = -L$(BUILDDIR)/../lib -lmtd
 
 include ../common.mk
 
@@ -23,32 +24,30 @@ $(TARGETS): $(addprefix $(BUILDDIR)/,\
 #	$(CC) $(CFLAGS) $(filter %.o, $^) -L. -lubi -o $@
 
 $(BUILDDIR)/ubicrc32: $(addprefix $(BUILDDIR)/,\
-	ubicrc32.o crc32.o)
+	ubicrc32.o)
 #	$(CC) $(CFLAGS) -o $@ $^
 
 $(BUILDDIR)/ubinize: $(addprefix $(BUILDDIR)/,\
-	ubinize.o common.o crc32.o libiniparser.a libubigen.a)
+	ubinize.o common.o libiniparser.a libubigen.a)
 #	$(CC) $(CFLAGS) $(filter %.o, $^) -L. -liniparser -lubigen -o $@
 
 $(BUILDDIR)/mtdinfo: $(addprefix $(BUILDDIR)/,\
-	libmtd.a libubigen.a crc32.o common.o)
+	libubigen.a common.o)
 #	$(CC) $(CFLAGS) $(filter %.o, $^) -L. -lmtd -lubigen -o $@
 
 $(BUILDDIR)/ubiformat: $(addprefix $(BUILDDIR)/,\
-	ubiformat.o common.o crc32.o libmtd.a libscan.a libubi.a libubigen.a)
+	ubiformat.o common.o libscan.a libubi.a libubigen.a)
 #	$(CC) $(CFLAGS) $(filter %.o, $^) -L. -lmtd -lscan -lubi -lubigen -o $@
 
 $(BUILDDIR)/libubi.a: $(BUILDDIR)/libubi.o
 
-$(BUILDDIR)/libmtd.a: $(BUILDDIR)/libmtd.o $(BUILDDIR)/libmtd_legacy.o
-
 $(BUILDDIR)/libubigen.a: $(BUILDDIR)/libubigen.o
 
 $(BUILDDIR)/libiniparser.a: $(addprefix $(BUILDDIR)/,\
 	libiniparser.o dictionary.o)
 
 $(BUILDDIR)/libscan.a: $(addprefix $(BUILDDIR)/,\
-	libscan.o crc32.o)
+	libscan.o)
 
 clean::
 	rm -f $(addsuffix .a, $(LIBS))
ubi-utils/src/libscan.c +1 -1
index 5a2ea78..85f3d7f 100644
@@ -32,8 +32,8 @@
 #include <mtd/mtd-user.h>
 #include <libmtd.h>
 #include <libscan.h>
+#include <crc32.h>
 #include "common.h"
-#include "crc32.h"
 
 #define PROGRAM_NAME "libscan"
 
ubi-utils/src/libubigen.c +1 -1
index 8f060da..62792d0 100644
@@ -32,7 +32,7 @@
 #include <mtd/ubi-media.h>
 #include <mtd_swab.h>
 #include <libubigen.h>
-#include "crc32.h"
+#include <crc32.h>
 #include "common.h"
 
 #define PROGRAM_NAME "libubigen"
ubi-utils/src/ubicrc32.c +1 -1
index d39af10..2dd69e1 100644
@@ -28,8 +28,8 @@
 #include <getopt.h>
 #include <unistd.h>
 #include <mtd/ubi-media.h>
+#include <crc32.h>
 
-#include "crc32.h"
 #include "common.h"
 
 #define BUFSIZE 4096
ubi-utils/src/ubiformat.c +1 -1
index 8487fd5..f0a87c4 100644
@@ -41,7 +41,7 @@
 #include <libscan.h>
 #include <libubigen.h>
 #include <mtd_swab.h>
-#include "crc32.h"
+#include <crc32.h>
 #include "common.h"
 
 #define PROGRAM_VERSION "1.5"
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v2 3/5 mtd-utils: update to latest mtd-abi.h from kernel.org

In reply to Kevin Cernekee
---
 include/mtd/mtd-abi.h |   89 ++++++++++++++++++++++++++++--------------------
 mtd_debug.c           |    2 +-
 2 files changed, 53 insertions(+), 38 deletions(-)
include/mtd/mtd-abi.h +52 -37
index 86defe1..c6954ed 100644
@@ -1,23 +1,35 @@
 /*
- * $Id: mtd-abi.h,v 1.13 2005/11/07 11:14:56 gleixner Exp $
- *
  * Portions of MTD ABI definition which are shared by kernel and user space
  */
 
 #ifndef __MTD_ABI_H__
 #define __MTD_ABI_H__
 
+#include <linux/types.h>
+
 struct erase_info_user {
-	uint32_t start;
-	uint32_t length;
+	__u32 start;
+	__u32 length;
+};
+
+struct erase_info_user64 {
+	__u64 start;
+	__u64 length;
 };
 
 struct mtd_oob_buf {
-	uint32_t start;
-	uint32_t length;
+	__u32 start;
+	__u32 length;
 	unsigned char *ptr;
 };
 
+struct mtd_oob_buf64 {
+	__u64 start;
+	__u32 pad;
+	__u32 length;
+	__u64 usr_ptr;
+};
+
 #define MTD_ABSENT		0
 #define MTD_RAM			1
 #define MTD_ROM			2
@@ -29,7 +41,7 @@ struct mtd_oob_buf {
 #define MTD_WRITEABLE		0x400	/* Device is writeable */
 #define MTD_BIT_WRITEABLE	0x800	/* Single bits can be flipped */
 #define MTD_NO_ERASE		0x1000	/* No erase necessary */
-#define MTD_STUPID_LOCK		0x2000	/* Always locked after reset */
+#define MTD_POWERUP_LOCK	0x2000	/* Always locked after reset */
 
 // Some common devices / combinations of capabilities
 #define MTD_CAP_ROM		0
@@ -50,30 +62,30 @@ struct mtd_oob_buf {
 #define MTD_OTP_USER		2
 
 struct mtd_info_user {
-	uint8_t type;
-	uint32_t flags;
-	uint32_t size;	 // Total size of the MTD
-	uint32_t erasesize;
-	uint32_t writesize;
-	uint32_t oobsize;   // Amount of OOB data per block (e.g. 16)
+	__u8 type;
+	__u32 flags;
+	__u32 size;	 // Total size of the MTD
+	__u32 erasesize;
+	__u32 writesize;
+	__u32 oobsize;   // Amount of OOB data per block (e.g. 16)
 	/* The below two fields are obsolete and broken, do not use them
 	 * (TODO: remove at some point) */
-	uint32_t ecctype;
-	uint32_t eccsize;
+	__u32 ecctype;
+	__u32 eccsize;
 };
 
 struct region_info_user {
-	uint32_t offset;		/* At which this region starts,
+	__u32 offset;		/* At which this region starts,
 					 * from the beginning of the MTD */
-	uint32_t erasesize;		/* For this region */
-	uint32_t numblocks;		/* Number of blocks in this region */
-	uint32_t regionindex;
+	__u32 erasesize;		/* For this region */
+	__u32 numblocks;		/* Number of blocks in this region */
+	__u32 regionindex;
 };
 
 struct otp_info {
-	uint32_t start;
-	uint32_t length;
-	uint32_t locked;
+	__u32 start;
+	__u32 length;
+	__u32 locked;
 };
 
 #define MEMGETINFO		_IOR('M', 1, struct mtd_info_user)
@@ -86,8 +98,8 @@ struct otp_info {
 #define MEMGETREGIONINFO	_IOWR('M', 8, struct region_info_user)
 #define MEMSETOOBSEL		_IOW('M', 9, struct nand_oobinfo)
 #define MEMGETOOBSEL		_IOR('M', 10, struct nand_oobinfo)
-#define MEMGETBADBLOCK		_IOW('M', 11, loff_t)
-#define MEMSETBADBLOCK		_IOW('M', 12, loff_t)
+#define MEMGETBADBLOCK		_IOW('M', 11, __kernel_loff_t)
+#define MEMSETBADBLOCK		_IOW('M', 12, __kernel_loff_t)
 #define OTPSELECT		_IOR('M', 13, int)
 #define OTPGETREGIONCOUNT	_IOW('M', 14, int)
 #define OTPGETREGIONINFO	_IOW('M', 15, struct otp_info)
@@ -95,21 +107,24 @@ struct otp_info {
 #define ECCGETLAYOUT		_IOR('M', 17, struct nand_ecclayout)
 #define ECCGETSTATS		_IOR('M', 18, struct mtd_ecc_stats)
 #define MTDFILEMODE		_IO('M', 19)
+#define MEMERASE64		_IOW('M', 20, struct erase_info_user64)
+#define MEMWRITEOOB64		_IOWR('M', 21, struct mtd_oob_buf64)
+#define MEMREADOOB64		_IOWR('M', 22, struct mtd_oob_buf64)
 
 /*
  * Obsolete legacy interface. Keep it in order not to break userspace
  * interfaces
  */
 struct nand_oobinfo {
-	uint32_t useecc;
-	uint32_t eccbytes;
-	uint32_t oobfree[8][2];
-	uint32_t eccpos[32];
+	__u32 useecc;
+	__u32 eccbytes;
+	__u32 oobfree[8][2];
+	__u32 eccpos[32];
 };
 
 struct nand_oobfree {
-	uint32_t offset;
-	uint32_t length;
+	__u32 offset;
+	__u32 length;
 };
 
 #define MTD_MAX_OOBFREE_ENTRIES	8
@@ -118,9 +133,9 @@ struct nand_oobfree {
  * diagnosis and to allow creation of raw images
  */
 struct nand_ecclayout {
-	uint32_t eccbytes;
-	uint32_t eccpos[64];
-	uint32_t oobavail;
+	__u32 eccbytes;
+	__u32 eccpos[64];
+	__u32 oobavail;
 	struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
 };
 
@@ -133,10 +148,10 @@ struct nand_ecclayout {
  * @bbtblocks:	number of blocks reserved for bad block tables
  */
 struct mtd_ecc_stats {
-	uint32_t corrected;
-	uint32_t failed;
-	uint32_t badblocks;
-	uint32_t bbtblocks;
+	__u32 corrected;
+	__u32 failed;
+	__u32 badblocks;
+	__u32 bbtblocks;
 };
 
 /*
mtd_debug.c +1 -1
index 49a4567..4934699 100644
@@ -301,7 +301,7 @@ int showinfo (int fd)
 			{ "MTD_WRITEABLE", MTD_WRITEABLE },
 			{ "MTD_BIT_WRITEABLE", MTD_BIT_WRITEABLE },
 			{ "MTD_NO_ERASE", MTD_NO_ERASE },
-			{ "MTD_STUPID_LOCK", MTD_STUPID_LOCK },
+			{ "MTD_POWERUP_LOCK", MTD_POWERUP_LOCK },
 			{ NULL, -1 }
 		};
 		for (i = 0; flags[i].name != NULL; i++)
Signature · 1 line
1.7.0.4
#3 lore raw

Re: [PATCHv2 3/5] mtd-utils: update to latest mtd-abi.h from kernel.org

Quoted 5 lines · Kevin Cernekee
---
 include/mtd/mtd-abi.h |   89 ++++++++++++++++++++++++++++--------------------
 mtd_debug.c           |    2 +-
 2 files changed, 53 insertions(+), 38 deletions(-)

Pushed this patch as well.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#4 lore raw

PATCH v2 4/5 libmtd: add support for 64-bit offsets, OOB

In reply to Kevin Cernekee

Change mtd_erase() so that it attempts to use MEMERASE64 first, then falls back to the old <2.6.31 MEMERASE if MEMERASE64 is unsupported.

Add mtd_read_oob(), mtd_write_oob() functions to wrap the OOB ioctls. Similar ioctl fallback logic is used in these functions as well.

---
 include/libmtd.h |   36 ++++++++++++++++++++++-
 lib/libmtd.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 111 insertions(+), 7 deletions(-)
include/libmtd.h +34 -2
index 0aea966..292d8c3 100644
@@ -66,6 +66,7 @@ struct mtd_info
  * @region_cnt: count of additional erase regions
  * @writable: zero if the device is read-only
  * @bb_allowed: non-zero if the MTD device may have bad eraseblocks
+ * @legacy_ioctls: non-zero if the kernel lacks MEMERASE64, MEM*OOB64
  */
 struct mtd_dev_info
 {
@@ -84,6 +85,7 @@ struct mtd_dev_info
 	int region_cnt;
 	unsigned int writable:1;
 	unsigned int bb_allowed:1;
+	unsigned int legacy_ioctls:1;
 };
 
 /**
@@ -146,7 +148,37 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd);
  * This function erases eraseblock @eb of MTD device described by @fd. Returns
  * %0 in case of success and %-1 in case of failure.
  */
-int mtd_erase(const struct mtd_dev_info *mtd, int fd, int eb);
+int mtd_erase(struct mtd_dev_info *mtd, int fd, int eb);
+
+/**
+ * mtd_read_oob - read OOB bytes
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @start: page-aligned start address
+ * @length: number of OOB bytes to read
+ * @data: read buffer
+ *
+ * This function reads @length OOB bytes starting from address @start on
+ * MTD device described by @fd. Returns %0 in case of success and %-1 in
+ * case of failure.
+ */
+int mtd_read_oob(struct mtd_dev_info *mtd, int fd, uint64_t start,
+	uint64_t length, void *data);
+
+/**
+ * mtd_write_oob - write OOB bytes
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @start: page-aligned start address
+ * @length: number of OOB bytes to write
+ * @data: write buffer
+ *
+ * This function writes @length OOB bytes starting from address @start on
+ * MTD device described by @fd. Returns %0 in case of success and %-1 in
+ * case of failure.
+ */
+int mtd_write_oob(struct mtd_dev_info *mtd, int fd, uint64_t start,
+	uint64_t length, void *data);
 
 /**
  * mtd_torture - torture an eraseblock.
@@ -157,7 +189,7 @@ int mtd_erase(const struct mtd_dev_info *mtd, int fd, int eb);
  * This function tortures eraseblock @eb. Returns %0 in case of success and %-1
  * in case of failure.
  */
-int mtd_torture(const struct mtd_dev_info *mtd, int fd, int eb);
+int mtd_torture(struct mtd_dev_info *mtd, int fd, int eb);
 
 /**
  * mtd_is_bad - check if eraseblock is bad.
lib/libmtd.c +77 -5

103 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#5 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

Quoted 25 lines · Kevin Cernekee

Change mtd_erase() so that it attempts to use MEMERASE64 first, then falls back to the old <2.6.31 MEMERASE if MEMERASE64 is unsupported.

Add mtd_read_oob(), mtd_write_oob() functions to wrap the OOB ioctls. Similar ioctl fallback logic is used in these functions as well.

---
 include/libmtd.h |   36 ++++++++++++++++++++++-
 lib/libmtd.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 111 insertions(+), 7 deletions(-)
include/libmtd.h +1 -0
index 0aea966..292d8c3 100644
@@ -66,6 +66,7 @@ struct mtd_info
  * @region_cnt: count of additional erase regions
  * @writable: zero if the device is read-only
  * @bb_allowed: non-zero if the MTD device may have bad eraseblocks
+ * @legacy_ioctls: non-zero if the kernel lacks MEMERASE64, MEM*OOB64
  */
 struct mtd_dev_info
 {

include/libmtd.h struct mtd_dev_info · line 89

Quoted 5 lines
include/libmtd.h +1 -0
@@ -84,6 +85,7 @@ struct mtd_dev_info
 	int region_cnt;
 	unsigned int writable:1;
 	unsigned int bb_allowed:1;
+	unsigned int legacy_ioctls:1;
 };

Kevin, I'm sorry, but thinking about this some more, this is not a property of mtd device, this is a property of whole mtd subsystem. So this flag should live in 'struct mtd_info', just like the 'unsigned int sysfs_supported:1;' field.

You should find out whether the new ioctl's are supported in 'libmtd_open()'. This also means that all libmtd calls which need this flag will need a 'libmtd_t desc' parameter.

Also, is it possible to have 2 separate patches - 1st adds support for 64-bit offest, second adds OOB calls.

Is this doable? I think this should not be too difficult to change.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#6 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

Quoted 3 lines · Artem Bityutskiy

You should find out whether the new ioctl's are supported in 'libmtd_open()'. This also means that all libmtd calls which need this flag will need a 'libmtd_t desc' parameter.

Typically I just try the new ioctl first, then fall back to the old one if it returned -ENOTTY. Could you recommend a way to detect the presence of the new ioctls from libmtd_open()?

Thanks.

#7 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

Quoted 8 lines · Kevin Cernekee
Quoted 3 lines · Artem Bityutskiy

You should find out whether the new ioctl's are supported in 'libmtd_open()'. This also means that all libmtd calls which need this flag will need a 'libmtd_t desc' parameter.

Typically I just try the new ioctl first, then fall back to the old one if it returned -ENOTTY. Could you recommend a way to detect the presence of the new ioctls from libmtd_open()?

Hmm, how about MEMERASE64 with start = length = -1? You can distinguish between -ENOTTY and other error codes.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#8 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

In reply to Artem Bityutskiy
Quoted 37 lines · Artem Bityutskiy
Quoted 25 lines · Kevin Cernekee

Change mtd_erase() so that it attempts to use MEMERASE64 first, then falls back to the old <2.6.31 MEMERASE if MEMERASE64 is unsupported.

Add mtd_read_oob(), mtd_write_oob() functions to wrap the OOB ioctls. Similar ioctl fallback logic is used in these functions as well.

---
 include/libmtd.h |   36 ++++++++++++++++++++++-
 lib/libmtd.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 111 insertions(+), 7 deletions(-)
include/libmtd.h +1 -0
index 0aea966..292d8c3 100644
@@ -66,6 +66,7 @@ struct mtd_info
  * @region_cnt: count of additional erase regions
  * @writable: zero if the device is read-only
  * @bb_allowed: non-zero if the MTD device may have bad eraseblocks
+ * @legacy_ioctls: non-zero if the kernel lacks MEMERASE64, MEM*OOB64
  */
 struct mtd_dev_info
 {

include/libmtd.h struct mtd_dev_info · line 89

Quoted 5 lines
include/libmtd.h +1 -0
@@ -84,6 +85,7 @@ struct mtd_dev_info
 	int region_cnt;
 	unsigned int writable:1;
 	unsigned int bb_allowed:1;
+	unsigned int legacy_ioctls:1;
 };

Kevin, I'm sorry, but thinking about this some more, this is not a property of mtd device, this is a property of whole mtd subsystem. So this flag should live in 'struct mtd_info', just like the 'unsigned int sysfs_supported:1;' field.

Quoted 8 lines

You should find out whether the new ioctl's are supported in 'libmtd_open()'. This also means that all libmtd calls which need this flag will need a 'libmtd_t desc' parameter.

Also, is it possible to have 2 separate patches - 1st adds support for 64-bit offest, second adds OOB calls.

Is this doable? I think this should not be too difficult to change.

I thought some more, and no, this is not doable because you need a device node, which you do not have when the library is being initialized. I'll take a look at these patches once again.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#9 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

In reply to Kevin Cernekee
Quoted 43 lines · Kevin Cernekee

Change mtd_erase() so that it attempts to use MEMERASE64 first, then falls back to the old <2.6.31 MEMERASE if MEMERASE64 is unsupported.

Add mtd_read_oob(), mtd_write_oob() functions to wrap the OOB ioctls. Similar ioctl fallback logic is used in these functions as well.

---
 include/libmtd.h |   36 ++++++++++++++++++++++-
 lib/libmtd.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 111 insertions(+), 7 deletions(-)
include/libmtd.h +8 -1
index 0aea966..292d8c3 100644
@@ -66,6 +66,7 @@ struct mtd_info
  * @region_cnt: count of additional erase regions
  * @writable: zero if the device is read-only
  * @bb_allowed: non-zero if the MTD device may have bad eraseblocks
+ * @legacy_ioctls: non-zero if the kernel lacks MEMERASE64, MEM*OOB64
  */
 struct mtd_dev_info
 {
@@ -84,6 +85,7 @@ struct mtd_dev_info
 	int region_cnt;
 	unsigned int writable:1;
 	unsigned int bb_allowed:1;
+	unsigned int legacy_ioctls:1;
 };
 
 /**
@@ -146,7 +148,37 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd);
  * This function erases eraseblock @eb of MTD device described by @fd. Returns
  * %0 in case of success and %-1 in case of failure.
  */
-int mtd_erase(const struct mtd_dev_info *mtd, int fd, int eb);
+int mtd_erase(struct mtd_dev_info *mtd, int fd, int eb);
+
+/**
+ * mtd_read_oob - read OOB bytes
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor

include/libmtd.h int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd); · line 166

Quoted 10 lines
include/libmtd.h +10 -0
+ * @start: page-aligned start address
+ * @length: number of OOB bytes to read
+ * @data: read buffer
+ *
+ * This function reads @length OOB bytes starting from address @start on
+ * MTD device described by @fd. Returns %0 in case of success and %-1 in
+ * case of failure.
+ */
+int mtd_read_oob(struct mtd_dev_info *mtd, int fd, uint64_t start,
+	uint64_t length, void *data);

Minor, but for consistency, please, use the same indentation style as the rest of the code. Namely, aline the second line:

int mtd_read_oob(struct mtd_dev_info *mtd, int fd, uint64_t start,

		 uint64_t length, void *data);

Use tabs, but then adjust by adding spaces.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#10 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

In reply to Kevin Cernekee
Quoted 11 lines · Kevin Cernekee

Change mtd_erase() so that it attempts to use MEMERASE64 first, then falls back to the old <2.6.31 MEMERASE if MEMERASE64 is unsupported.

Add mtd_read_oob(), mtd_write_oob() functions to wrap the OOB ioctls. Similar ioctl fallback logic is used in these functions as well.

---
 include/libmtd.h |   36 ++++++++++++++++++++++-
 lib/libmtd.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 111 insertions(+), 7 deletions(-)

Kevin, here is a patch which adds MEMERASE64 support. I did not want to add the flag to 'struct mtd_dev_info', because I do not think it should be visible to users. So I put it to libmtd descriptor, but this means that now we have to pass it to 'mtd_erase()'.

I also added error messages to 'mtd_erase()', to be consistent with other functions. I did not add OOB functions. If this patch is OK, I can push it.

Quoted 1 line

From 02dc72bbc78c79f34b92fccc0fdce43f6af0af49 Mon Sep 17 00:00:00 2001

From: Artem Bityutskiy <[email protected]>
Date: Sat, 17 Jul 2010 19:48:13 +0300
Subject: [PATCH] libmtd: support MEMERASE64

This patch is base on Kevin Cernekee's patch posted to the MTD mailing list. It adds MEMERASE64 support to the 'mtd_erase()' call. Now it first tries to use MEMERASE64, and if that is not supported, falls back to the old MEMERASE ioctl.

This patch also introduces an 'offs64_ioctl' flag to the libmtd descriptor. However, we cannot initialize it in 'libmtd_open()', because we need an MTD device node, which we do not have in 'libmtd_open()'. Thus, we firs mark this flag as "uninitialized", and at the first invocation of 'mtd_erase()' we initialize it.

This also means that we have to pass the limbtd descriptor to 'mtd_erase()', to save the flag value. This, in turn, requires tweaking 'mtd_erase()' users.

This is not very nice, but good enough so far.

---
 include/libmtd.h          |    6 +++-
 lib/libmtd.c              |   58 ++++++++++++++++++++++++++++++++++++++++----
 lib/libmtd_int.h          |   18 ++++++++++++++
 ubi-utils/src/ubiformat.c |   23 +++++++++--------
 4 files changed, 86 insertions(+), 19 deletions(-)
include/libmtd.h +4 -2
index 0aea966..2bf9859 100644
@@ -139,6 +139,7 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd);
 
 /**
  * mtd_erase - erase an eraseblock.
+ * @desc: MTD library descriptor
  * @mtd: MTD device description object
  * @fd: MTD device node file descriptor
  * @eb: eraseblock to erase
@@ -146,10 +147,11 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd);
  * This function erases eraseblock @eb of MTD device described by @fd. Returns
  * %0 in case of success and %-1 in case of failure.
  */
-int mtd_erase(const struct mtd_dev_info *mtd, int fd, int eb);
+int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb);
 
 /**
  * mtd_torture - torture an eraseblock.
+ * @desc: MTD library descriptor
  * @mtd: MTD device description object
  * @fd: MTD device node file descriptor
  * @eb: eraseblock to torture
@@ -157,7 +159,7 @@ int mtd_erase(const struct mtd_dev_info *mtd, int fd, int eb);
  * This function tortures eraseblock @eb. Returns %0 in case of success and %-1
  * in case of failure.
  */
-int mtd_torture(const struct mtd_dev_info *mtd, int fd, int eb);
+int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb);
 
 /**
  * mtd_is_bad - check if eraseblock is bad.
lib/libmtd.c +52 -6

85 lines not on this page · raw message

lib/libmtd_int.h +18 -0
index 7de4b42..bb48d35 100644
@@ -43,6 +43,10 @@ extern "C" {
 #define MTD_REGION_CNT   "numeraseregions"
 #define MTD_FLAGS        "flags"
 
+#define OFFS64_IOCTLS_UNKNOWN       0
+#define OFFS64_IOCTLS_NOT_SUPPORTED 1
+#define OFFS64_IOCTLS_SUPPORTED     2
+
 /**
  * libmtd - MTD library description data structure.
  * @sysfs_mtd: MTD directory in sysfs
@@ -58,6 +62,19 @@ extern "C" {
  * @mtd_region_cnt: count of additional erase regions file pattern
  * @mtd_flags: MTD device flags file pattern
  * @sysfs_supported: non-zero if sysfs is supported by MTD
+ * @offs64_ioctls: %OFFS64_IOCTLS_SUPPORTED if 64-bit %MEMERASE64,
+ *                 %MEMREADOOB64, %MEMWRITEOOB64 MTD device ioctls are
+ *                 supported, %OFFS64_IOCTLS_NOT_SUPPORTED if not, and
+ *                 %OFFS64_IOCTLS_UNKNOWN if it is not known yet;
+ *
+ *  Note, we cannot find out whether 64-bit ioctls are supported by MTD when we
+ *  are initializing the library, because this requires an MTD device node.
+ *  Indeed, we have to actually call the ioctl and check for %ENOTTY to find
+ *  out whether it is supported or not.
+ *
+ *  Thus, we leave %offs64_ioctls uninitialized in 'libmtd_open()', and
+ *  initialize it later, when corresponding libmtd function is used, and when
+ *  we actually have a device node and can invoke an ioctl command on it.
  */
 struct libmtd
 {
@@ -74,6 +91,7 @@ struct libmtd
 	char *mtd_region_cnt;
 	char *mtd_flags;
 	unsigned int sysfs_supported:1;
+	unsigned int offs64_ioctls:2;
 };
 
 int legacy_libmtd_open(void);
ubi-utils/src/ubiformat.c +12 -11
index 6052a35..4e27e4f 100644
@@ -441,8 +441,8 @@ static int mark_bad(const struct mtd_dev_info *mtd, struct ubi_scan_info *si, in
 	return consecutive_bad_check(eb);
 }
 
-static int flash_image(const struct mtd_dev_info *mtd, const struct ubigen_info *ui,
-		       struct ubi_scan_info *si)
+static int flash_image(libmtd_t libmtd, const struct mtd_dev_info *mtd,
+		       const struct ubigen_info *ui, struct ubi_scan_info *si)
 {
 	int fd, img_ebs, eb, written_ebs = 0, divisor;
 	off_t st_size;
@@ -488,7 +488,7 @@ static int flash_image(const struct mtd_dev_info *mtd, const struct ubigen_info
 			fflush(stdout);
 		}
 
-		err = mtd_erase(mtd, args.node_fd, eb);
+		err = mtd_erase(libmtd, mtd, args.node_fd, eb);
 		if (err) {
 			if (!args.quiet)
 				printf("\n");
@@ -543,7 +543,7 @@ static int flash_image(const struct mtd_dev_info *mtd, const struct ubigen_info
 			if (errno != EIO)
 				goto out_close;
 
-			err = mtd_torture(mtd, args.node_fd, eb);
+			err = mtd_torture(libmtd, mtd, args.node_fd, eb);
 			if (err) {
 				if (mark_bad(mtd, si, eb))
 					goto out_close;
@@ -564,8 +564,9 @@ out_close:
 	return -1;
 }
 
-static int format(const struct mtd_dev_info *mtd, const struct ubigen_info *ui,
-		  struct ubi_scan_info *si, int start_eb, int novtbl)
+static int format(libmtd_t libmtd, const struct mtd_dev_info *mtd,
+		  const struct ubigen_info *ui, struct ubi_scan_info *si,
+		  int start_eb, int novtbl)
 {
 	int eb, err, write_size;
 	struct ubi_ec_hdr *hdr;
@@ -606,7 +607,7 @@ static int format(const struct mtd_dev_info *mtd, const struct ubigen_info *ui,
 			fflush(stdout);
 		}
 
-		err = mtd_erase(mtd, args.node_fd, eb);
+		err = mtd_erase(libmtd, mtd, args.node_fd, eb);
 		if (err) {
 			if (!args.quiet)
 				printf("\n");
@@ -652,7 +653,7 @@ static int format(const struct mtd_dev_info *mtd, const struct ubigen_info *ui,
 				goto out_free;
 			}
 
-			err = mtd_torture(mtd, args.node_fd, eb);
+			err = mtd_torture(libmtd, mtd, args.node_fd, eb);
 			if (err) {
 				if (mark_bad(mtd, si, eb))
 					goto out_free;
@@ -922,15 +923,15 @@ int main(int argc, char * const argv[])
 	}
 
 	if (args.image) {
-		err = flash_image(&mtd, &ui, si);
+		err = flash_image(libmtd, &mtd, &ui, si);
 		if (err < 0)
 			goto out_free;
 
-		err = format(&mtd, &ui, si, err, 1);
+		err = format(libmtd, &mtd, &ui, si, err, 1);
 		if (err)
 			goto out_free;
 	} else {
-		err = format(&mtd, &ui, si, 0, args.novtbl);
+		err = format(libmtd, &mtd, &ui, si, 0, args.novtbl);
 		if (err)
 			goto out_free;
 	}
Signature · 5 lines
1.6.2.5

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#11 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

Quoted 13 lines · Artem Bityutskiy
Quoted 11 lines · Kevin Cernekee

Change mtd_erase() so that it attempts to use MEMERASE64 first, then falls back to the old <2.6.31 MEMERASE if MEMERASE64 is unsupported.

Add mtd_read_oob(), mtd_write_oob() functions to wrap the OOB ioctls. Similar ioctl fallback logic is used in these functions as well.

---
 include/libmtd.h |   36 ++++++++++++++++++++++-
 lib/libmtd.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 111 insertions(+), 7 deletions(-)
Quoted 4 lines

Kevin, here is a patch which adds MEMERASE64 support. I did not want to add the flag to 'struct mtd_dev_info', because I do not think it should be visible to users. So I put it to libmtd descriptor, but this means that now we have to pass it to 'mtd_erase()'.

And then on top of this I've created another patch which adds mtd_read_oob() and mtd_write_oob(). And your patch 5/5 then can be applied on top.

Please, take a look at my patches and try them - they are only compile tested. Would be great to try on both pre-offs64_ioctls kernel and new kernels. If the patches are OK for you and work, I can push them.

Quoted 1 line

From 4b3a46c1464b4b7bcc1c7983b66eb3e13f3dee5e Mon Sep 17 00:00:00 2001

From: Artem Bityutskiy <[email protected]>
Date: Sun, 18 Jul 2010 07:14:29 +0300
Subject: [PATCH] libmtd: add OOB read and write interfaces

This patch is based on Kevin Cernekee's patch posted to the MTD mailing list. It adds 'mtd_read_oob()' and 'mtd_write_oob()' interfaces support.

The interfaces use MEMREADOOB64/MEMWRITEOOB64 MTD ioctls if possible, and fall-back to MEMREADOOB/MEMWRITEOOB if the 64-bit versions are not supported. The information about ioctls support is then cashed in 'offs64_ioctls' libmtd flag.

---
 include/libmtd.h |   36 ++++++++++++++++++++-
 lib/libmtd.c     |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+), 1 deletions(-)
include/libmtd.h +35 -1
index 2bf9859..afaba42 100644
@@ -216,6 +216,40 @@ int mtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
 	      void *buf, int len);
 
 /**
+ * mtd_read_oob - read out-of-band area.
+ * @desc: MTD library descriptor
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @start: page-aligned start address
+ * @length: number of OOB bytes to read
+ * @data: read buffer
+ *
+ * This function reads @length OOB bytes starting from address @start on
+ * MTD device described by @fd. The address is specified as page byte offset
+ * from the beginning of the MTD device. This function returns %0 in case of
+ * success and %-1 in case of failure.
+ */
+int mtd_read_oob(libmtd_t desc, const struct mtd_dev_info *mtd, int fd,
+		 uint64_t start, uint64_t length, void *data);
+
+/**
+ * mtd_write_oob - write out-of-band area.
+ * @desc: MTD library descriptor
+ * @mtd: MTD device description object
+ * @fd: MTD device node file descriptor
+ * @start: page-aligned start address
+ * @length: number of OOB bytes to write
+ * @data: write buffer
+ *
+ * This function writes @length OOB bytes starting from address @start on
+ * MTD device described by @fd. The address is specified as page byte offset
+ * from the beginning of the MTD device. Returns %0 in case of success and %-1
+ * in case of failure.
+ */
+int mtd_write_oob(libmtd_t desc, const struct mtd_dev_info *mtd, int fd,
+		  uint64_t start, uint64_t length, void *data);
+
+/**
  * mtd_write_img - write a file to MTD device.
  * @mtd: MTD device description object
  * @fd: MTD device node file descriptor
@@ -236,7 +270,7 @@ int mtd_write_img(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
  * @node: the node to test
  *
  * This function tests whether @node is an MTD device node and returns %1 if it
- * is, and %-1 if it is not (errno is ENODEV in this case) or if an error
+ * is, and %-1 if it is not (errno is %ENODEV in this case) or if an error
  * occurred.
  */
 int mtd_probe_node(libmtd_t desc, const char *node);
lib/libmtd.c +94 -0

100 lines not on this page · raw message

Signature · 5 lines
1.6.2.5

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#12 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

Quoted 2 lines · Artem Bityutskiy

+int do_oob_op(libmtd_t desc, const struct mtd_dev_info *mtd, int fd,
+             uint64_t start, uint64_t length, void *data, int cmd64, int cmd)

cmd64 should be an unsigned int. When it gets compared to MEMREADOOB64 (0xc0184d16), gcc says "comparison is always false due to limited range of data type."

Quoted 1 line

+       if (cmd64 ==  MEMREADOOB64) {

Extra space after ==

Quoted 5 lines

+               /*
+                * MEMREADOOB64/MEMWRITEOOB64 support was added in kernel
+                * version 2.6.30, so probably we are working with older kernel
+                * and these ioctls are not supported.
+                */

The new sysfs attributes were in 2.6.30, but the new ioctls did not make it in until 2.6.31 (commit 0dc54e).

#13 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

Quoted 12 lines · Kevin Cernekee

lib/libmtd.c int mtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs, · line 1058

Quoted 2 lines · Artem Bityutskiy
lib/libmtd.c +2 -0
+int do_oob_op(libmtd_t desc, const struct mtd_dev_info *mtd, int fd,
+             uint64_t start, uint64_t length, void *data, int cmd64, int cmd)

cmd64 should be an unsigned int. When it gets compared to MEMREADOOB64 (0xc0184d16), gcc says "comparison is always false due to limited range of data type."

Quoted 1 line

+ if (cmd64 == MEMREADOOB64) {

Extra space after ==

Quoted 8 lines

lib/libmtd.c int mtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs, · line 1113

Quoted 5 lines
lib/libmtd.c +5 -0
+               /*
+                * MEMREADOOB64/MEMWRITEOOB64 support was added in kernel
+                * version 2.6.30, so probably we are working with older kernel
+                * and these ioctls are not supported.
+                */

The new sysfs attributes were in 2.6.30, but the new ioctls did not make it in until 2.6.31 (commit 0dc54e).

Amended and pushed, thanks.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#14 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

In reply to Artem Bityutskiy
Quoted 5 lines · Artem Bityutskiy

+               /*
+                * MEMERASE64 support was added in kernel version 2.6.30, so
+                * probably we are working with older kernel and this ioctl is
+                * not supported.
+                */

s/2.6.30/2.6.31/

I applied both of your patches, applied my flash_eraseall v3 patch, then tested erase only (no OOB) on 2.6.18 and 2.6.31. Works fine. I verified with strace that the proper ioctl was being called in each instance.

Thanks.

#15 lore raw

Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB

Quoted 7 lines · Kevin Cernekee

lib/libmtd.c int mtd_get_dev_info(libmtd_t desc, const char *node, struct mtd_dev_info *mtd) · line 827

Quoted 5 lines · Artem Bityutskiy
lib/libmtd.c +5 -0
+               /*
+                * MEMERASE64 support was added in kernel version 2.6.30, so
+                * probably we are working with older kernel and this ioctl is
+                * not supported.
+                */
Quoted 6 lines

s/2.6.30/2.6.31/

I applied both of your patches, applied my flash_eraseall v3 patch, then tested erase only (no OOB) on 2.6.18 and 2.6.31. Works fine. I verified with strace that the proper ioctl was being called in each instance.

Amended and pushed.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#16 lore raw

PATCH v2 5/5 mtd-utils: change flash_eraseall to use libmtd-wrapped ioctls

In reply to Kevin Cernekee
---
 flash_eraseall.c |   58 +++++++++++++++++++++++++++--------------------------
 1 files changed, 30 insertions(+), 28 deletions(-)
flash_eraseall.c +30 -28
index e6f8d50..916a75a 100644
@@ -36,6 +36,7 @@
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 #include <crc32.h>
+#include <libmtd.h>
 
 #include <mtd/mtd-user.h>
 #include <mtd/jffs2-user.h>
@@ -49,7 +50,7 @@ static int quiet;		/* true -- don't output progress */
 static int jffs2;		// format for jffs2 usage
 
 static void process_options (int argc, char *argv[]);
-void show_progress (mtd_info_t *meminfo, erase_info_t *erase);
+void show_progress (struct mtd_dev_info *mtd, uint64_t start);
 static void display_help (void);
 static void display_version (void);
 static struct jffs2_unknown_node cleanmarker;
@@ -57,26 +58,31 @@ int target_endian = __BYTE_ORDER;
 
 int main (int argc, char *argv[])
 {
-	mtd_info_t meminfo;
-	int fd, clmpos = 0, clmlen = 8;
-	erase_info_t erase;
+	libmtd_t mtd_desc;
+	struct mtd_dev_info mtd;
+	int fd, clmpos = 0, clmlen = 8, eb;
 	int isNAND, bbtest = 1;
+	uint64_t offset = 0;
 
 	process_options(argc, argv);
 
+	mtd_desc = libmtd_open();
+	if (mtd_desc == NULL) {
+		fprintf(stderr, "%s: can't initialize libmtd\n", exe_name);
+		return 1;
+	}
+
 	if ((fd = open(mtd_device, O_RDWR)) < 0) {
 		fprintf(stderr, "%s: %s: %s\n", exe_name, mtd_device, strerror(errno));
 		return 1;
 	}
 
-
-	if (ioctl(fd, MEMGETINFO, &meminfo) != 0) {
-		fprintf(stderr, "%s: %s: unable to get MTD device info\n", exe_name, mtd_device);
+	if (mtd_get_dev_info(mtd_desc, mtd_device, &mtd) < 0) {
+		fprintf(stderr, "%s: mtd_get_dev_info failed\n", exe_name);
 		return 1;
 	}
 
-	erase.length = meminfo.erasesize;
-	isNAND = meminfo.type == MTD_NANDFLASH ? 1 : 0;
+	isNAND = mtd.type == MTD_NANDFLASH ? 1 : 0;
 
 	if (jffs2) {
 		cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
@@ -104,7 +110,7 @@ int main (int argc, char *argv[])
 					clmlen = 8;
 			} else {
 				/* Legacy mode */
-				switch (meminfo.oobsize) {
+				switch (mtd.oob_size) {
 					case 8:
 						clmpos = 6;
 						clmlen = 2;
@@ -124,13 +130,13 @@ int main (int argc, char *argv[])
 		cleanmarker.hdr_crc =  cpu_to_je32 (crc32 (0, &cleanmarker,  sizeof (struct jffs2_unknown_node) - 4));
 	}
 
-	for (erase.start = 0; erase.start < meminfo.size; erase.start += meminfo.erasesize) {
+	for (eb = 0; eb < (mtd.size / mtd.eb_size); eb++) {
+		offset = eb * mtd.eb_size;
 		if (bbtest) {
-			loff_t offset = erase.start;
-			int ret = ioctl(fd, MEMGETBADBLOCK, &offset);
+			int ret = mtd_is_bad(&mtd, fd, eb);
 			if (ret > 0) {
 				if (!quiet)
-					printf ("\nSkipping bad block at 0x%08x\n", erase.start);
+					printf ("\nSkipping bad block at 0x%08llx\n", (unsigned long long)offset);
 				continue;
 			} else if (ret < 0) {
 				if (errno == EOPNOTSUPP) {
@@ -147,9 +153,9 @@ int main (int argc, char *argv[])
 		}
 
 		if (!quiet)
-			show_progress(&meminfo, &erase);
+			show_progress(&mtd, offset);
 
-		if (ioctl(fd, MEMERASE, &erase) != 0) {
+		if (mtd_erase(&mtd, fd, eb) != 0) {
 			fprintf(stderr, "\n%s: %s: MTD Erase failure: %s\n", exe_name, mtd_device, strerror(errno));
 			continue;
 		}
@@ -160,16 +166,12 @@ int main (int argc, char *argv[])
 
 		/* write cleanmarker */
 		if (isNAND) {
-			struct mtd_oob_buf oob;
-			oob.ptr = (unsigned char *) &cleanmarker;
-			oob.start = erase.start + clmpos;
-			oob.length = clmlen;
-			if (ioctl (fd, MEMWRITEOOB, &oob) != 0) {
+			if (mtd_write_oob(&mtd, fd, offset + clmpos, clmlen, &cleanmarker) != 0) {
 				fprintf(stderr, "\n%s: %s: MTD writeoob failure: %s\n", exe_name, mtd_device, strerror(errno));
 				continue;
 			}
 		} else {
-			if (lseek (fd, erase.start, SEEK_SET) < 0) {
+			if (lseek (fd, (loff_t)offset, SEEK_SET) < 0) {
 				fprintf(stderr, "\n%s: %s: MTD lseek failure: %s\n", exe_name, mtd_device, strerror(errno));
 				continue;
 			}
@@ -179,10 +181,10 @@ int main (int argc, char *argv[])
 			}
 		}
 		if (!quiet)
-			printf (" Cleanmarker written at %x.", erase.start);
+			printf (" Cleanmarker written at %llx.", (unsigned long long)offset);
 	}
 	if (!quiet) {
-		show_progress(&meminfo, &erase);
+		show_progress(&mtd, offset);
 		printf("\n");
 	}
 
@@ -250,11 +252,11 @@ void process_options (int argc, char *argv[])
 	mtd_device = argv[optind];
 }
 
-void show_progress (mtd_info_t *meminfo, erase_info_t *erase)
+void show_progress (struct mtd_dev_info *mtd, uint64_t start)
 {
-	printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.",
-		meminfo->erasesize / 1024, erase->start,
-		(unsigned long long) erase->start * 100 / meminfo->size);
+	printf("\rErasing %d Kibyte @ %llx -- %2llu %% complete.",
+		mtd->eb_size / 1024, (unsigned long long)start,
+		(unsigned long long) start * 100 / mtd->size);
 	fflush(stdout);
 }
 
Signature · 1 line
1.7.0.4
#17 lore raw
In reply to Kevin Cernekee
Quoted 7 lines · Kevin Cernekee

Source files for libmtd, crc32, and fec are scattered throughout the tree. Move them to a central location so they can be built into a common "libmtd.a" library used by all mtd-utils programs.

This patch only renames/deletes files and does not change the content.

Let's try to keep the tree always compilable. This patch alone breaks compilation, so I merged it with the second patch and pushed to the mtd-utils tree.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)