aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docfdisk.c22
-rw-r--r--include/mtd_swab.h33
-rw-r--r--mkfs.jffs.c26
-rw-r--r--nftl_format.c22
-rw-r--r--nftldump.c17
-rw-r--r--rfddump.c6
6 files changed, 40 insertions, 86 deletions
diff --git a/docfdisk.c b/docfdisk.c
index 4d82bde..b275df9 100644
--- a/docfdisk.c
+++ b/docfdisk.c
@@ -34,27 +34,7 @@
#include <asm/types.h>
#include <mtd/mtd-user.h>
#include <mtd/inftl-user.h>
-
-#define swab16(x) \
- ((__u16)( \
- (((__u16)(x) & (__u16)0x00ffU) << 8) | \
- (((__u16)(x) & (__u16)0xff00U) >> 8) ))
-#define swab32(x) \
- ((__u32)( \
- (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
- (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
- (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
- (((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define cpu_to_le16(x) ({ __u16 _x = x; swab16(_x); })
-#define cpu_to_le32(x) ({ __u32 _x = x; swab32(_x); })
-#else
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#endif
-#define le32_to_cpu(x) cpu_to_le32(x)
-#define le16_to_cpu(x) cpu_to_le16(x)
+#include <mtd_swab.h>
unsigned char *buf;
diff --git a/include/mtd_swab.h b/include/mtd_swab.h
new file mode 100644
index 0000000..05732a9
--- /dev/null
+++ b/include/mtd_swab.h
@@ -0,0 +1,33 @@
+#ifndef MTD_SWAB_H
+#define MTD_SWAB_H
+
+#include <endian.h>
+
+#define swab16(x) \
+ ((__u16)( \
+ (((__u16)(x) & (__u16)0x00ffU) << 8) | \
+ (((__u16)(x) & (__u16)0xff00U) >> 8) ))
+#define swab32(x) \
+ ((__u32)( \
+ (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
+ (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
+ (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
+ (((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cpu_to_le16(x) ({ __u16 _x = x; swab16(_x); })
+#define cpu_to_le32(x) ({ __u32 _x = x; swab32(_x); })
+#define cpu_to_be16(x) (x)
+#define cpu_to_be32(x) (x)
+#else
+#define cpu_to_le16(x) (x)
+#define cpu_to_le32(x) (x)
+#define cpu_to_be16(x) ({ __u16 _x = x; swab16(_x); })
+#define cpu_to_be32(x) ({ __u32 _x = x; swab32(_x); })
+#endif
+#define le16_to_cpu(x) cpu_to_le16(x)
+#define be16_to_cpu(x) cpu_to_be16(x)
+#define le32_to_cpu(x) cpu_to_le32(x)
+#define be32_to_cpu(x) cpu_to_be32(x)
+
+#endif
diff --git a/mkfs.jffs.c b/mkfs.jffs.c
index 942a093..7e8de96 100644
--- a/mkfs.jffs.c
+++ b/mkfs.jffs.c
@@ -17,33 +17,9 @@
#include <dirent.h>
#include <unistd.h>
#include <linux/types.h>
-#include <asm/byteorder.h>
+#include <mtd_swab.h>
#include <ctype.h>
-#define swab16(x) \
- ((__u16)( \
- (((__u16)(x) & (__u16)0x00ffU) << 8) | \
- (((__u16)(x) & (__u16)0xff00U) >> 8) ))
-#define swab32(x) \
- ((__u32)( \
- (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
- (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
- (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
- (((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define cpu_to_le16(x) ({ __u16 _x = x; swab16(_x); })
-#define cpu_to_le32(x) ({ __u32 _x = x; swab32(_x); })
-#define cpu_to_be16(x) (x)
-#define cpu_to_be32(x) (x)
-#else
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#define cpu_to_be16(x) ({ __u16 _x = x; swab16(_x); })
-#define cpu_to_be32(x) ({ __u32 _x = x; swab32(_x); })
-#endif
-#define le32_to_cpu(x) cpu_to_le32(x)
-#define be32_to_cpu(x) cpu_to_be32(x)
#define BLOCK_SIZE 1024
#define JFFS_MAGIC 0x34383931 /* "1984" */
diff --git a/nftl_format.c b/nftl_format.c
index a04411a..b0a80cf 100644
--- a/nftl_format.c
+++ b/nftl_format.c
@@ -39,27 +39,7 @@
#include <mtd/mtd-user.h>
#include <mtd/nftl-user.h>
#include <mtd/inftl-user.h>
-
-#define swab16(x) \
- ((__u16)( \
- (((__u16)(x) & (__u16)0x00ffU) << 8) | \
- (((__u16)(x) & (__u16)0xff00U) >> 8) ))
-#define swab32(x) \
- ((__u32)( \
- (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
- (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
- (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
- (((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define cpu_to_le16(x) ({ __u16 _x = x; swab16(_x); })
-#define cpu_to_le32(x) ({ __u32 _x = x; swab32(_x); })
-#else
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
-#endif
-#define le32_to_cpu(x) cpu_to_le32(x)
-#define le16_to_cpu(x) cpu_to_le16(x)
+#include <mtd_swab.h>
unsigned char BadUnitTable[MAX_ERASE_ZONES];
unsigned char *readbuf;
diff --git a/nftldump.c b/nftldump.c
index fc97b58..59aa7d7 100644
--- a/nftldump.c
+++ b/nftldump.c
@@ -38,6 +38,7 @@
#include <asm/types.h>
#include <mtd/mtd-user.h>
#include <mtd/nftl-user.h>
+#include <mtd_swab.h>
static struct NFTLMediaHeader MedHead[2];
static mtd_info_t meminfo;
@@ -50,26 +51,10 @@ static int NumMedHeads;
static unsigned char BadUnitTable[MAX_ERASE_ZONES];
-/* some byte swabbing stuff from include/linux/byteorder/ */
-#define swab16(x) \
- ((__u16)( \
- (((__u16)(x) & (__u16)0x00ffU) << 8) | \
- (((__u16)(x) & (__u16)0xff00U) >> 8) ))
-#define swab32(x) \
- ((__u32)( \
- (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
- (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
- (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
- (((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
-
#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define cpu_to_le16(x) (x)
-#define cpu_to_le32(x) (x)
#define SWAP16(x) do { ; } while(0)
#define SWAP32(x) do { ; } while(0)
#else
-#define cpu_to_le16(x) swab16(x)
-#define cpu_to_le32(x) swab32(x)
#define SWAP16(x) do { x = swab16(x); } while(0)
#define SWAP32(x) do { x = swab32(x); } while(0)
#endif
diff --git a/rfddump.c b/rfddump.c
index 268e610..f5884ab 100644
--- a/rfddump.c
+++ b/rfddump.c
@@ -25,7 +25,7 @@
#include <mtd/mtd-user.h>
#include <linux/types.h>
-#include <asm/byteorder.h>
+#include <mtd_swab.h>
/* next is an array of mapping for each corresponding sector */
#define RFD_MAGIC 0x9193
@@ -137,7 +137,7 @@ int build_block_map(struct rfd *rfd, int fd, int block)
return -1;
}
- if (__le16_to_cpu(rfd->header[0]) != RFD_MAGIC) {
+ if (le16_to_cpu(rfd->header[0]) != RFD_MAGIC) {
if (rfd->verbose)
printf("Block #%02d: Magic missing\n", block);
@@ -146,7 +146,7 @@ int build_block_map(struct rfd *rfd, int fd, int block)
sectors = 0;
for (i=0; i<rfd->data_sectors; i++) {
- __u16 entry = __le16_to_cpu(rfd->header[i + HEADER_MAP_OFFSET]);
+ __u16 entry = le16_to_cpu(rfd->header[i + HEADER_MAP_OFFSET]);
if (entry == SECTOR_FREE || entry == SECTOR_DELETED)
continue;