All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory
@ 2010-07-08  0:30 Kevin Cernekee
  2010-07-08  0:30 ` [PATCHv2 2/5] mtd-utils: update Makefiles, source files to use common libmtd.a Kevin Cernekee
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Kevin Cernekee @ 2010-07-08  0:30 UTC (permalink / raw)
  To: dedekind1, saeed.bishara, jwboyer, vapier.adi; +Cc: linux-mtd

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.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
 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

diff --git a/crc32.h b/crc32.h
deleted file mode 100644
index ee3145b..0000000
--- a/crc32.h
+++ /dev/null
@@ -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
diff --git a/ubi-utils/src/common.h b/include/common.h
similarity index 100%
rename from ubi-utils/src/common.h
rename to include/common.h
diff --git a/mkfs.ubifs/crc32.h b/include/crc32.h
similarity index 100%
rename from mkfs.ubifs/crc32.h
rename to include/crc32.h
diff --git a/ubi-utils/include/libmtd.h b/include/libmtd.h
similarity index 100%
rename from ubi-utils/include/libmtd.h
rename to include/libmtd.h
diff --git a/crc32.c b/lib/crc32.c
similarity index 100%
rename from crc32.c
rename to lib/crc32.c
diff --git a/fec.c b/lib/fec.c
similarity index 100%
rename from fec.c
rename to lib/fec.c
diff --git a/ubi-utils/src/libmtd.c b/lib/libmtd.c
similarity index 100%
rename from ubi-utils/src/libmtd.c
rename to lib/libmtd.c
diff --git a/ubi-utils/src/libmtd_int.h b/lib/libmtd_int.h
similarity index 100%
rename from ubi-utils/src/libmtd_int.h
rename to lib/libmtd_int.h
diff --git a/ubi-utils/src/libmtd_legacy.c b/lib/libmtd_legacy.c
similarity index 100%
rename from ubi-utils/src/libmtd_legacy.c
rename to lib/libmtd_legacy.c
diff --git a/mkfs.ubifs/crc32.c b/mkfs.ubifs/crc32.c
deleted file mode 100644
index 6b1e50c..0000000
--- a/mkfs.ubifs/crc32.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
- *  code or tables extracted from it, as desired without restriction.
- *
- *  First, the polynomial itself and its table of feedback terms.  The
- *  polynomial is
- *  X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
- *
- *  Note that we take it "backwards" and put the highest-order term in
- *  the lowest-order bit.  The X^32 term is "implied"; the LSB is the
- *  X^31 term, etc.  The X^0 term (usually shown as "+1") results in
- *  the MSB being 1
- *
- *  Note that the usual hardware shift register implementation, which
- *  is what we're using (we're merely optimizing it by doing eight-bit
- *  chunks at a time) shifts bits into the lowest-order term.  In our
- *  implementation, that means shifting towards the right.  Why do we
- *  do it this way?  Because the calculated CRC must be transmitted in
- *  order from highest-order term to lowest-order term.  UARTs transmit
- *  characters in order from LSB to MSB.  By storing the CRC this way
- *  we hand it to the UART in the order low-byte to high-byte; the UART
- *  sends each low-bit to hight-bit; and the result is transmission bit
- *  by bit from highest- to lowest-order term without requiring any bit
- *  shuffling on our part.  Reception works similarly
- *
- *  The feedback terms table consists of 256, 32-bit entries.  Notes
- *
- *      The table can be generated at runtime if desired; code to do so
- *      is shown later.  It might not be obvious, but the feedback
- *      terms simply represent the results of eight shift/xor opera
- *      tions for all combinations of data and CRC register values
- *
- *      The values must be right-shifted by eight bits by the "updcrc
- *      logic; the shift must be unsigned (bring in zeroes).  On some
- *      hardware you could probably optimize the shift in assembler by
- *      using byte-swap instructions
- *      polynomial $edb88320
- */
-
-#include <stdint.h>
-
-const uint32_t crc32_table[256] = {
-	0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
-	0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
-	0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
-	0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
-	0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
-	0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
-	0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
-	0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
-	0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
-	0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
-	0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
-	0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
-	0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
-	0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
-	0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
-	0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
-	0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
-	0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
-	0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
-	0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
-	0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
-	0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
-	0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
-	0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
-	0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
-	0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
-	0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
-	0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
-	0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
-	0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
-	0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
-	0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
-	0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
-	0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
-	0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
-	0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
-	0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
-	0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
-	0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
-	0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
-	0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
-	0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
-	0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
-	0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
-	0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
-	0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
-	0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
-	0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
-	0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
-	0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
-	0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
-	0x2d02ef8dL
-};
diff --git a/ubi-utils/src/crc32.c b/ubi-utils/src/crc32.c
deleted file mode 100644
index 6b1e50c..0000000
--- a/ubi-utils/src/crc32.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- *  COPYRIGHT (C) 1986 Gary S. Brown.  You may use this program, or
- *  code or tables extracted from it, as desired without restriction.
- *
- *  First, the polynomial itself and its table of feedback terms.  The
- *  polynomial is
- *  X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
- *
- *  Note that we take it "backwards" and put the highest-order term in
- *  the lowest-order bit.  The X^32 term is "implied"; the LSB is the
- *  X^31 term, etc.  The X^0 term (usually shown as "+1") results in
- *  the MSB being 1
- *
- *  Note that the usual hardware shift register implementation, which
- *  is what we're using (we're merely optimizing it by doing eight-bit
- *  chunks at a time) shifts bits into the lowest-order term.  In our
- *  implementation, that means shifting towards the right.  Why do we
- *  do it this way?  Because the calculated CRC must be transmitted in
- *  order from highest-order term to lowest-order term.  UARTs transmit
- *  characters in order from LSB to MSB.  By storing the CRC this way
- *  we hand it to the UART in the order low-byte to high-byte; the UART
- *  sends each low-bit to hight-bit; and the result is transmission bit
- *  by bit from highest- to lowest-order term without requiring any bit
- *  shuffling on our part.  Reception works similarly
- *
- *  The feedback terms table consists of 256, 32-bit entries.  Notes
- *
- *      The table can be generated at runtime if desired; code to do so
- *      is shown later.  It might not be obvious, but the feedback
- *      terms simply represent the results of eight shift/xor opera
- *      tions for all combinations of data and CRC register values
- *
- *      The values must be right-shifted by eight bits by the "updcrc
- *      logic; the shift must be unsigned (bring in zeroes).  On some
- *      hardware you could probably optimize the shift in assembler by
- *      using byte-swap instructions
- *      polynomial $edb88320
- */
-
-#include <stdint.h>
-
-const uint32_t crc32_table[256] = {
-	0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
-	0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
-	0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
-	0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
-	0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
-	0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
-	0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
-	0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
-	0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
-	0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
-	0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
-	0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
-	0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
-	0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
-	0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
-	0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
-	0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
-	0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
-	0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
-	0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
-	0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
-	0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
-	0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
-	0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
-	0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
-	0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
-	0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
-	0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
-	0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
-	0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
-	0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
-	0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
-	0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
-	0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
-	0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
-	0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
-	0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
-	0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
-	0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
-	0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
-	0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
-	0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
-	0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
-	0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
-	0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
-	0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
-	0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
-	0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
-	0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
-	0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
-	0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
-	0x2d02ef8dL
-};
diff --git a/ubi-utils/src/crc32.h b/ubi-utils/src/crc32.h
deleted file mode 100644
index c001fcf..0000000
--- a/ubi-utils/src/crc32.h
+++ /dev/null
@@ -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
-- 
1.7.0.4

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

* [PATCHv2 2/5] mtd-utils: update Makefiles, source files to use common libmtd.a
  2010-07-08  0:30 [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory Kevin Cernekee
@ 2010-07-08  0:30 ` Kevin Cernekee
  2010-07-08  0:30 ` [PATCHv2 3/5] mtd-utils: update to latest mtd-abi.h from kernel.org Kevin Cernekee
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 18+ messages in thread
From: Kevin Cernekee @ 2010-07-08  0:30 UTC (permalink / raw)
  To: dedekind1, saeed.bishara, jwboyer, vapier.adi; +Cc: linux-mtd

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.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
 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

diff --git a/Makefile b/Makefile
index 577634f..b558705 100644
--- a/Makefile
+++ b/Makefile
@@ -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}
diff --git a/common.mk b/common.mk
index d704b44..be785b4 100644
--- a/common.mk
+++ b/common.mk
@@ -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:
diff --git a/fectest.c b/fectest.c
index d5893b9..c1fbd52 100644
--- a/fectest.c
+++ b/fectest.c
@@ -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
diff --git a/flash_eraseall.c b/flash_eraseall.c
index a22fc49..e6f8d50 100644
--- a/flash_eraseall.c
+++ b/flash_eraseall.c
@@ -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>
diff --git a/include/crc32.h b/include/crc32.h
index 86fc841..4b51177 100644
--- a/include/crc32.h
+++ b/include/crc32.h
@@ -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;
 
diff --git a/jffs2dump.c b/jffs2dump.c
index 2802682..cd8b6fa 100644
--- a/jffs2dump.c
+++ b/jffs2dump.c
@@ -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"
diff --git a/lib/Makefile b/lib/Makefile
new file mode 100644
index 0000000..91507f3
--- /dev/null
+++ b/lib/Makefile
@@ -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:
diff --git a/mkfs.jffs2.c b/mkfs.jffs2.c
index 64cafb6..2c78fd5 100644
--- a/mkfs.jffs2.c
+++ b/mkfs.jffs2.c
@@ -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 */
diff --git a/mkfs.ubifs/Makefile b/mkfs.ubifs/Makefile
index 61d0e20..ba21a8c 100644
--- a/mkfs.ubifs/Makefile
+++ b/mkfs.ubifs/Makefile
@@ -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::
diff --git a/mkfs.ubifs/compr.c b/mkfs.ubifs/compr.c
index e378c5d..7f084c5 100644
--- a/mkfs.ubifs/compr.c
+++ b/mkfs.ubifs/compr.c
@@ -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"
diff --git a/mkfs.ubifs/mkfs.ubifs.c b/mkfs.ubifs/mkfs.ubifs.c
index e4b4e3c..95b20b0 100644
--- a/mkfs.ubifs/mkfs.ubifs.c
+++ b/mkfs.ubifs/mkfs.ubifs.c
@@ -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);
 
diff --git a/mkfs.ubifs/mkfs.ubifs.h b/mkfs.ubifs/mkfs.ubifs.h
index 16b34c7..c00dce0 100644
--- a/mkfs.ubifs/mkfs.ubifs.h
+++ b/mkfs.ubifs/mkfs.ubifs.h
@@ -49,7 +49,6 @@
 #include <sys/file.h>
 
 #include "libubi.h"
-#include "crc32.h"
 #include "defs.h"
 #include "crc16.h"
 #include "ubifs-media.h"
diff --git a/recv_image.c b/recv_image.c
index d65aa2a..2be511a 100644
--- a/recv_image.c
+++ b/recv_image.c
@@ -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"
 
diff --git a/serve_image.c b/serve_image.c
index adb4869..5aafa35 100644
--- a/serve_image.c
+++ b/serve_image.c
@@ -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;
diff --git a/sumtool.c b/sumtool.c
index 6bb7168..966e110 100644
--- a/sumtool.c
+++ b/sumtool.c
@@ -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)
diff --git a/ubi-utils/Makefile b/ubi-utils/Makefile
index e736a09..327d2d7 100644
--- a/ubi-utils/Makefile
+++ b/ubi-utils/Makefile
@@ -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))
diff --git a/ubi-utils/src/libscan.c b/ubi-utils/src/libscan.c
index 5a2ea78..85f3d7f 100644
--- a/ubi-utils/src/libscan.c
+++ b/ubi-utils/src/libscan.c
@@ -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"
 
diff --git a/ubi-utils/src/libubigen.c b/ubi-utils/src/libubigen.c
index 8f060da..62792d0 100644
--- a/ubi-utils/src/libubigen.c
+++ b/ubi-utils/src/libubigen.c
@@ -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"
diff --git a/ubi-utils/src/ubicrc32.c b/ubi-utils/src/ubicrc32.c
index d39af10..2dd69e1 100644
--- a/ubi-utils/src/ubicrc32.c
+++ b/ubi-utils/src/ubicrc32.c
@@ -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
diff --git a/ubi-utils/src/ubiformat.c b/ubi-utils/src/ubiformat.c
index 8487fd5..f0a87c4 100644
--- a/ubi-utils/src/ubiformat.c
+++ b/ubi-utils/src/ubiformat.c
@@ -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"
-- 
1.7.0.4

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

* [PATCHv2 3/5] mtd-utils: update to latest mtd-abi.h from kernel.org
  2010-07-08  0:30 [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory Kevin Cernekee
  2010-07-08  0:30 ` [PATCHv2 2/5] mtd-utils: update Makefiles, source files to use common libmtd.a Kevin Cernekee
@ 2010-07-08  0:30 ` Kevin Cernekee
  2010-07-13 10:38   ` Artem Bityutskiy
  2010-07-08  0:30 ` [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB Kevin Cernekee
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: Kevin Cernekee @ 2010-07-08  0:30 UTC (permalink / raw)
  To: dedekind1, saeed.bishara, jwboyer, vapier.adi; +Cc: linux-mtd

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
 include/mtd/mtd-abi.h |   89 ++++++++++++++++++++++++++++--------------------
 mtd_debug.c           |    2 +-
 2 files changed, 53 insertions(+), 38 deletions(-)

diff --git a/include/mtd/mtd-abi.h b/include/mtd/mtd-abi.h
index 86defe1..c6954ed 100644
--- a/include/mtd/mtd-abi.h
+++ b/include/mtd/mtd-abi.h
@@ -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;
 };
 
 /*
diff --git a/mtd_debug.c b/mtd_debug.c
index 49a4567..4934699 100644
--- a/mtd_debug.c
+++ b/mtd_debug.c
@@ -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++)
-- 
1.7.0.4

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

* [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-08  0:30 [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory Kevin Cernekee
  2010-07-08  0:30 ` [PATCHv2 2/5] mtd-utils: update Makefiles, source files to use common libmtd.a Kevin Cernekee
  2010-07-08  0:30 ` [PATCHv2 3/5] mtd-utils: update to latest mtd-abi.h from kernel.org Kevin Cernekee
@ 2010-07-08  0:30 ` Kevin Cernekee
  2010-07-13 10:49   ` Artem Bityutskiy
                     ` (2 more replies)
  2010-07-08  0:30 ` [PATCHv2 5/5] mtd-utils: change flash_eraseall to use libmtd-wrapped ioctls Kevin Cernekee
  2010-07-13 10:35 ` [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory Artem Bityutskiy
  4 siblings, 3 replies; 18+ messages in thread
From: Kevin Cernekee @ 2010-07-08  0:30 UTC (permalink / raw)
  To: dedekind1, saeed.bishara, jwboyer, vapier.adi; +Cc: linux-mtd

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.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
 include/libmtd.h |   36 ++++++++++++++++++++++-
 lib/libmtd.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 111 insertions(+), 7 deletions(-)

diff --git a/include/libmtd.h b/include/libmtd.h
index 0aea966..292d8c3 100644
--- a/include/libmtd.h
+++ b/include/libmtd.h
@@ -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.
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 3ff031c..66e794a 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -32,6 +32,7 @@
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <mtd/mtd-user.h>
+#include <mtd/mtd-abi.h>
 
 #include <libmtd.h>
 #include "libmtd_int.h"
@@ -789,13 +790,84 @@ int mtd_get_dev_info(libmtd_t desc, const char *node, struct mtd_dev_info *mtd)
 	return mtd_get_dev_info1(desc, mtd_num, mtd);
 }
 
-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)
 {
-	struct erase_info_user ei;
+	int ret;
+	struct erase_info_user64 ei;
 
-	ei.start = eb * mtd->eb_size;;
+	ei.start = (__u64)eb * mtd->eb_size;
 	ei.length = mtd->eb_size;
-	return ioctl(fd, MEMERASE, &ei);
+
+	if (!mtd->legacy_ioctls) {
+		ret = ioctl(fd, MEMERASE64, &ei);
+		if (ret < 0 && errno == ENOTTY)
+			mtd->legacy_ioctls = 1;
+	}
+
+	if (mtd->legacy_ioctls) {
+		struct erase_info_user ei_old;
+
+		ei_old.start = ei.start;
+		ei_old.length = ei.length;
+
+		if (ei_old.start != ei.start) {
+			errno = EOVERFLOW;
+			return -1;
+		}
+
+		ret = ioctl(fd, MEMERASE, &ei_old);
+	}
+
+	return ret;
+}
+
+static int mtd_oob_op(int cmd, int cmd_old, struct mtd_dev_info *mtd, int fd,
+	uint64_t start, uint64_t length, void *data)
+{
+	int ret;
+	struct mtd_oob_buf64 oob;
+
+	oob.start = start;
+	oob.length = length;
+	oob.usr_ptr = (__u64)(unsigned long)data;
+
+	if (!mtd->legacy_ioctls) {
+		ret = ioctl(fd, cmd, &oob);
+		if (ret < 0 && errno == ENOTTY)
+			mtd->legacy_ioctls = 1;
+	}
+
+	if (mtd->legacy_ioctls) {
+		struct mtd_oob_buf oob_old;
+
+		oob_old.start = oob.start;
+		oob_old.length = oob.length;
+		oob_old.ptr = data;
+
+		if (oob_old.start != oob.start ||
+				oob_old.length != oob.length) {
+			errno = EOVERFLOW;
+			return -1;
+		}
+
+		ret = ioctl(fd, cmd_old, &oob_old);
+	}
+
+	return ret;
+}
+
+int mtd_read_oob(struct mtd_dev_info *mtd, int fd, uint64_t start,
+	uint64_t length, void *data)
+{
+	return mtd_oob_op(MEMREADOOB64, MEMREADOOB, mtd, fd, start, length,
+		data);
+}
+
+int mtd_write_oob(struct mtd_dev_info *mtd, int fd, uint64_t start,
+	uint64_t length, void *data)
+{
+	return mtd_oob_op(MEMWRITEOOB64, MEMWRITEOOB, mtd, fd, start, length,
+		data);
 }
 
 /* Patterns to write to a physical eraseblock when torturing it */
@@ -820,7 +892,7 @@ static int check_pattern(const void *buf, uint8_t patt, int size)
 	return 1;
 }
 
-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)
 {
 	int err, i, patt_count;
 	void *buf;
-- 
1.7.0.4

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

* [PATCHv2 5/5] mtd-utils: change flash_eraseall to use libmtd-wrapped ioctls
  2010-07-08  0:30 [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory Kevin Cernekee
                   ` (2 preceding siblings ...)
  2010-07-08  0:30 ` [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB Kevin Cernekee
@ 2010-07-08  0:30 ` Kevin Cernekee
  2010-07-13 10:35 ` [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory Artem Bityutskiy
  4 siblings, 0 replies; 18+ messages in thread
From: Kevin Cernekee @ 2010-07-08  0:30 UTC (permalink / raw)
  To: dedekind1, saeed.bishara, jwboyer, vapier.adi; +Cc: linux-mtd

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
 flash_eraseall.c |   58 +++++++++++++++++++++++++++--------------------------
 1 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/flash_eraseall.c b/flash_eraseall.c
index e6f8d50..916a75a 100644
--- a/flash_eraseall.c
+++ b/flash_eraseall.c
@@ -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);
 }
 
-- 
1.7.0.4

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

* Re: [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory
  2010-07-08  0:30 [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory Kevin Cernekee
                   ` (3 preceding siblings ...)
  2010-07-08  0:30 ` [PATCHv2 5/5] mtd-utils: change flash_eraseall to use libmtd-wrapped ioctls Kevin Cernekee
@ 2010-07-13 10:35 ` Artem Bityutskiy
  4 siblings, 0 replies; 18+ messages in thread
From: Artem Bityutskiy @ 2010-07-13 10:35 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Wed, 2010-07-07 at 17:30 -0700, Kevin Cernekee wrote:
> 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.
> 
> Signed-off-by: Kevin Cernekee <cernekee@gmail.com>

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.

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

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

* Re: [PATCHv2 3/5] mtd-utils: update to latest mtd-abi.h from kernel.org
  2010-07-08  0:30 ` [PATCHv2 3/5] mtd-utils: update to latest mtd-abi.h from kernel.org Kevin Cernekee
@ 2010-07-13 10:38   ` Artem Bityutskiy
  0 siblings, 0 replies; 18+ messages in thread
From: Artem Bityutskiy @ 2010-07-13 10:38 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Wed, 2010-07-07 at 17:30 -0700, Kevin Cernekee wrote:
> Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
> ---
>  include/mtd/mtd-abi.h |   89 ++++++++++++++++++++++++++++--------------------
>  mtd_debug.c           |    2 +-
>  2 files changed, 53 insertions(+), 38 deletions(-)

Pushed this patch as well.

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

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-08  0:30 ` [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB Kevin Cernekee
@ 2010-07-13 10:49   ` Artem Bityutskiy
  2010-07-14  0:09     ` Kevin Cernekee
  2010-07-17  7:35     ` Artem Bityutskiy
  2010-07-13 10:50   ` Artem Bityutskiy
  2010-07-17 17:08   ` Artem Bityutskiy
  2 siblings, 2 replies; 18+ messages in thread
From: Artem Bityutskiy @ 2010-07-13 10:49 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Wed, 2010-07-07 at 17:30 -0700, Kevin Cernekee wrote:
> 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.
> 
> Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
> ---
>  include/libmtd.h |   36 ++++++++++++++++++++++-
>  lib/libmtd.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
>  2 files changed, 111 insertions(+), 7 deletions(-)
> 
> diff --git a/include/libmtd.h b/include/libmtd.h
> index 0aea966..292d8c3 100644
> --- a/include/libmtd.h
> +++ b/include/libmtd.h
> @@ -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;
>  };

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.

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

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-08  0:30 ` [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB Kevin Cernekee
  2010-07-13 10:49   ` Artem Bityutskiy
@ 2010-07-13 10:50   ` Artem Bityutskiy
  2010-07-17 17:08   ` Artem Bityutskiy
  2 siblings, 0 replies; 18+ messages in thread
From: Artem Bityutskiy @ 2010-07-13 10:50 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Wed, 2010-07-07 at 17:30 -0700, Kevin Cernekee wrote:
> 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.
> 
> Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
> ---
>  include/libmtd.h |   36 ++++++++++++++++++++++-
>  lib/libmtd.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
>  2 files changed, 111 insertions(+), 7 deletions(-)
> 
> diff --git a/include/libmtd.h b/include/libmtd.h
> index 0aea966..292d8c3 100644
> --- a/include/libmtd.h
> +++ b/include/libmtd.h
> @@ -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);

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.

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

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-13 10:49   ` Artem Bityutskiy
@ 2010-07-14  0:09     ` Kevin Cernekee
  2010-07-14  2:51       ` Artem Bityutskiy
  2010-07-17  7:35     ` Artem Bityutskiy
  1 sibling, 1 reply; 18+ messages in thread
From: Kevin Cernekee @ 2010-07-14  0:09 UTC (permalink / raw)
  To: dedekind1; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Tue, Jul 13, 2010 at 3:49 AM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> 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.

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-14  0:09     ` Kevin Cernekee
@ 2010-07-14  2:51       ` Artem Bityutskiy
  0 siblings, 0 replies; 18+ messages in thread
From: Artem Bityutskiy @ 2010-07-14  2:51 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Tue, 2010-07-13 at 17:09 -0700, Kevin Cernekee wrote:
> On Tue, Jul 13, 2010 at 3:49 AM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> > 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.

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

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-13 10:49   ` Artem Bityutskiy
  2010-07-14  0:09     ` Kevin Cernekee
@ 2010-07-17  7:35     ` Artem Bityutskiy
  1 sibling, 0 replies; 18+ messages in thread
From: Artem Bityutskiy @ 2010-07-17  7:35 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Tue, 2010-07-13 at 13:49 +0300, Artem Bityutskiy wrote:
> On Wed, 2010-07-07 at 17:30 -0700, Kevin Cernekee wrote:
> > 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.
> > 
> > Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
> > ---
> >  include/libmtd.h |   36 ++++++++++++++++++++++-
> >  lib/libmtd.c     |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
> >  2 files changed, 111 insertions(+), 7 deletions(-)
> > 
> > diff --git a/include/libmtd.h b/include/libmtd.h
> > index 0aea966..292d8c3 100644
> > --- a/include/libmtd.h
> > +++ b/include/libmtd.h
> > @@ -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;
> >  };
> 
> 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.

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.

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

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-08  0:30 ` [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB Kevin Cernekee
  2010-07-13 10:49   ` Artem Bityutskiy
  2010-07-13 10:50   ` Artem Bityutskiy
@ 2010-07-17 17:08   ` Artem Bityutskiy
  2010-07-18  4:26     ` Artem Bityutskiy
  2010-07-24  2:43     ` Kevin Cernekee
  2 siblings, 2 replies; 18+ messages in thread
From: Artem Bityutskiy @ 2010-07-17 17:08 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Wed, 2010-07-07 at 17:30 -0700, Kevin Cernekee wrote:
> 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.
> 
> Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
> ---
>  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.



>From 02dc72bbc78c79f34b92fccc0fdce43f6af0af49 Mon Sep 17 00:00:00 2001
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
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.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 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(-)

diff --git a/include/libmtd.h b/include/libmtd.h
index 0aea966..2bf9859 100644
--- a/include/libmtd.h
+++ b/include/libmtd.h
@@ -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.
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 3ff031c..4fe19db 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -560,6 +560,8 @@ libmtd_t libmtd_open(void)
 	if (!lib)
 		return NULL;
 
+	lib->offs64_ioctls = OFFS64_IOCTLS_UNKNOWN;
+
 	lib->sysfs_mtd = mkpath("/sys", SYSFS_MTD);
 	if (!lib->sysfs_mtd)
 		goto out_error;
@@ -789,13 +791,57 @@ int mtd_get_dev_info(libmtd_t desc, const char *node, struct mtd_dev_info *mtd)
 	return mtd_get_dev_info1(desc, mtd_num, mtd);
 }
 
-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)
 {
+	int ret;
+	struct libmtd *lib = (struct libmtd *)desc;
+	struct erase_info_user64 ei64;
 	struct erase_info_user ei;
 
-	ei.start = eb * mtd->eb_size;;
-	ei.length = mtd->eb_size;
-	return ioctl(fd, MEMERASE, &ei);
+	if (eb < 0 || eb >= mtd->eb_cnt) {
+		errmsg("bad eraseblock number %d, mtd%d has %d eraseblocks",
+		       eb, mtd->mtd_num, mtd->eb_cnt);
+		errno = EINVAL;
+		return -1;
+	}
+
+	ei64.start = (__u64)eb * mtd->eb_size;
+	ei64.length = mtd->eb_size;
+
+	if (lib->offs64_ioctls == OFFS64_IOCTLS_SUPPORTED ||
+	    lib->offs64_ioctls == OFFS64_IOCTLS_UNKNOWN) {
+		ret = ioctl(fd, MEMERASE64, &ei64);
+		if (ret == 0)
+			return ret;
+
+		if (errno != ENOTTY ||
+		    lib->offs64_ioctls != OFFS64_IOCTLS_UNKNOWN)
+			return sys_errmsg("MEMERASE64 ioctl failed for "
+					  "eraseblock %d (mtd%d)",
+					  eb, mtd->mtd_num);
+
+		/*
+		 * MEMERASE64 support was added in kernel version 2.6.30, so
+		 * probably we are working with older kernel and this ioctl is
+		 * not supported.
+		 */
+		lib->offs64_ioctls = OFFS64_IOCTLS_NOT_SUPPORTED;
+	}
+
+	if (ei64.start + ei64.length > 0xFFFFFFFF) {
+		errmsg("this system can address only %u eraseblocks",
+		       0xFFFFFFFFU / mtd->eb_size);
+		errno = EINVAL;
+		return -1;
+	}
+
+	ei.start = ei64.start;
+	ei.length = ei64.length;
+	ret = ioctl(fd, MEMERASE, &ei);
+	if (ret < 0)
+		return sys_errmsg("MEMERASE ioctl failed for eraseblock %d "
+				  "(mtd%d)", eb, mtd->mtd_num);
+	return 0;
 }
 
 /* Patterns to write to a physical eraseblock when torturing it */
@@ -820,7 +866,7 @@ static int check_pattern(const void *buf, uint8_t patt, int size)
 	return 1;
 }
 
-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)
 {
 	int err, i, patt_count;
 	void *buf;
@@ -835,7 +881,7 @@ int mtd_torture(const struct mtd_dev_info *mtd, int fd, int eb)
 	}
 
 	for (i = 0; i < patt_count; i++) {
-		err = mtd_erase(mtd, fd, eb);
+		err = mtd_erase(desc, mtd, fd, eb);
 		if (err)
 			goto out;
 
diff --git a/lib/libmtd_int.h b/lib/libmtd_int.h
index 7de4b42..bb48d35 100644
--- a/lib/libmtd_int.h
+++ b/lib/libmtd_int.h
@@ -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);
diff --git a/ubi-utils/src/ubiformat.c b/ubi-utils/src/ubiformat.c
index 6052a35..4e27e4f 100644
--- a/ubi-utils/src/ubiformat.c
+++ b/ubi-utils/src/ubiformat.c
@@ -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;
 	}
-- 
1.6.2.5

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

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-17 17:08   ` Artem Bityutskiy
@ 2010-07-18  4:26     ` Artem Bityutskiy
  2010-07-24  1:07       ` Kevin Cernekee
  2010-07-24  2:43     ` Kevin Cernekee
  1 sibling, 1 reply; 18+ messages in thread
From: Artem Bityutskiy @ 2010-07-18  4:26 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Sat, 2010-07-17 at 20:08 +0300, Artem Bityutskiy wrote:
> On Wed, 2010-07-07 at 17:30 -0700, Kevin Cernekee wrote:
> > 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.
> > 
> > Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
> > ---
> >  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()'.

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.

>From 4b3a46c1464b4b7bcc1c7983b66eb3e13f3dee5e Mon Sep 17 00:00:00 2001
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
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.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 include/libmtd.h |   36 ++++++++++++++++++++-
 lib/libmtd.c     |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+), 1 deletions(-)

diff --git a/include/libmtd.h b/include/libmtd.h
index 2bf9859..afaba42 100644
--- a/include/libmtd.h
+++ b/include/libmtd.h
@@ -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);
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 3b4544e..1f2a6ea 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -1054,6 +1054,100 @@ int mtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
 	return 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)
+{
+	int ret;
+	struct mtd_oob_buf64 oob64;
+	struct mtd_oob_buf oob;
+	unsigned long long max_offs;
+	const char *cmd64_str, *cmd_str;
+	struct libmtd *lib = (struct libmtd *)desc;
+
+	if (cmd64 ==  MEMREADOOB64) {
+		cmd64_str = "MEMREADOOB64";
+		cmd_str   = "MEMREADOOB";
+	} else {
+		cmd64_str = "MEMWRITEOOB64";
+		cmd_str   = "MEMWRITEOOB";
+	}
+
+	max_offs = (unsigned long long)mtd->eb_cnt * mtd->eb_size;
+	if (start >= max_offs) {
+		errmsg("bad page address %llu, mtd%d has %d eraseblocks "
+		       "(%llu bytes)", (unsigned long long) start, mtd->mtd_num,
+		       mtd->eb_cnt, max_offs);
+		errno = EINVAL;
+		return -1;
+	}
+	if (start % mtd->min_io_size) {
+		errmsg("unaligned address %llu, mtd%d page size is %d",
+		       (unsigned long long)start, mtd->mtd_num,
+		       mtd->min_io_size);
+		errno = EINVAL;
+		return -1;
+	}
+
+	oob64.start = start;
+	oob64.length = length;
+	oob64.usr_ptr = (uint64_t)(unsigned long)data;
+
+	if (lib->offs64_ioctls == OFFS64_IOCTLS_SUPPORTED ||
+	    lib->offs64_ioctls == OFFS64_IOCTLS_UNKNOWN) {
+		ret = ioctl(fd, cmd64, &oob64);
+		if (ret == 0)
+			return ret;
+
+		if (errno != ENOTTY ||
+		    lib->offs64_ioctls != OFFS64_IOCTLS_UNKNOWN) {
+			sys_errmsg("%s ioctl failed for mtd%d, offset %llu "
+				   "(eraseblock %llu)", cmd64_str, mtd->mtd_num,
+				   (unsigned long long)start,
+				   (unsigned long long)start / mtd->eb_size);
+		}
+
+		/*
+		 * 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.
+		 */
+		lib->offs64_ioctls = OFFS64_IOCTLS_NOT_SUPPORTED;
+	}
+
+	if (oob64.start > 0xFFFFFFFFULL) {
+		errmsg("this system can address only up to address %lu",
+		       0xFFFFFFFFUL);
+		errno = EINVAL;
+		return -1;
+	}
+
+	oob.start = oob64.start;
+	oob.length = oob64.length;
+	oob.ptr = data;
+
+	ret = ioctl(fd, cmd, &oob);
+	if (ret < 0)
+		sys_errmsg("%s ioctl failed for mtd%d, offset %llu "
+			   "(eraseblock %llu)", cmd_str, mtd->mtd_num,
+			   (unsigned long long)start,
+			   (unsigned long long)start / mtd->eb_size);
+	return ret;
+}
+
+int mtd_read_oob(libmtd_t desc, const struct mtd_dev_info *mtd, int fd,
+		 uint64_t start, uint64_t length, void *data)
+{
+	return do_oob_op(desc, mtd, fd, start, length, data,
+			 MEMREADOOB64, MEMREADOOB);
+}
+
+int mtd_write_oob(libmtd_t desc, const struct mtd_dev_info *mtd, int fd,
+		  uint64_t start, uint64_t length, void *data)
+{
+	return do_oob_op(desc, mtd, fd, start, length, data,
+			 MEMWRITEOOB64, MEMWRITEOOB);
+}
+
 int mtd_write_img(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
 		  const char *img_name)
 {
-- 
1.6.2.5

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

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-18  4:26     ` Artem Bityutskiy
@ 2010-07-24  1:07       ` Kevin Cernekee
  2010-07-26  5:57         ` Artem Bityutskiy
  0 siblings, 1 reply; 18+ messages in thread
From: Kevin Cernekee @ 2010-07-24  1:07 UTC (permalink / raw)
  To: dedekind1; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Sat, Jul 17, 2010 at 9:26 PM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> +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."

> +       if (cmd64 ==  MEMREADOOB64) {

Extra space after ==

> +               /*
> +                * 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).

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-17 17:08   ` Artem Bityutskiy
  2010-07-18  4:26     ` Artem Bityutskiy
@ 2010-07-24  2:43     ` Kevin Cernekee
  2010-07-26  5:36       ` Artem Bityutskiy
  1 sibling, 1 reply; 18+ messages in thread
From: Kevin Cernekee @ 2010-07-24  2:43 UTC (permalink / raw)
  To: dedekind1; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Sat, Jul 17, 2010 at 10:08 AM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> +               /*
> +                * 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.

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-24  2:43     ` Kevin Cernekee
@ 2010-07-26  5:36       ` Artem Bityutskiy
  0 siblings, 0 replies; 18+ messages in thread
From: Artem Bityutskiy @ 2010-07-26  5:36 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Fri, 2010-07-23 at 19:43 -0700, Kevin Cernekee wrote:
> On Sat, Jul 17, 2010 at 10:08 AM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> > +               /*
> > +                * 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.

Amended and pushed.

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

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

* Re: [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB
  2010-07-24  1:07       ` Kevin Cernekee
@ 2010-07-26  5:57         ` Artem Bityutskiy
  0 siblings, 0 replies; 18+ messages in thread
From: Artem Bityutskiy @ 2010-07-26  5:57 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: linux-mtd, jwboyer, saeed.bishara, vapier.adi

On Fri, 2010-07-23 at 18:07 -0700, Kevin Cernekee wrote:
> On Sat, Jul 17, 2010 at 9:26 PM, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> > +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."
> 
> > +       if (cmd64 ==  MEMREADOOB64) {
> 
> Extra space after ==
> 
> > +               /*
> > +                * 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.

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

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

end of thread, other threads:[~2010-07-26  5:58 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-08  0:30 [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory Kevin Cernekee
2010-07-08  0:30 ` [PATCHv2 2/5] mtd-utils: update Makefiles, source files to use common libmtd.a Kevin Cernekee
2010-07-08  0:30 ` [PATCHv2 3/5] mtd-utils: update to latest mtd-abi.h from kernel.org Kevin Cernekee
2010-07-13 10:38   ` Artem Bityutskiy
2010-07-08  0:30 ` [PATCHv2 4/5] libmtd: add support for 64-bit offsets, OOB Kevin Cernekee
2010-07-13 10:49   ` Artem Bityutskiy
2010-07-14  0:09     ` Kevin Cernekee
2010-07-14  2:51       ` Artem Bityutskiy
2010-07-17  7:35     ` Artem Bityutskiy
2010-07-13 10:50   ` Artem Bityutskiy
2010-07-17 17:08   ` Artem Bityutskiy
2010-07-18  4:26     ` Artem Bityutskiy
2010-07-24  1:07       ` Kevin Cernekee
2010-07-26  5:57         ` Artem Bityutskiy
2010-07-24  2:43     ` Kevin Cernekee
2010-07-26  5:36       ` Artem Bityutskiy
2010-07-08  0:30 ` [PATCHv2 5/5] mtd-utils: change flash_eraseall to use libmtd-wrapped ioctls Kevin Cernekee
2010-07-13 10:35 ` [PATCHv2 1/5] mtd-utils: move libmtd source files to lib/ subdirectory Artem Bityutskiy

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.