summaryrefslogtreecommitdiffstats
path: root/package/busybox/busybox-1.15.2-flash-eraseall.patch
blob: b37c461f916f96e0b26006c0eeebae02938958d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From 86cfb70ca5f2bde11f2d071bc59db75291d8552f Mon Sep 17 00:00:00 2001
From: Denys Vlasenko <vda.linux@googlemail.com>
Date: Fri, 27 Nov 2009 13:26:17 +0100
Subject: [PATCH] flash_eraseall: stop using obsolete mtd/jffs2-user.h; code shrink

function                                             old     new   delta
show_progress                                         68      67      -1
flash_eraseall_main                                 1007     882    -125
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-126)           Total: -126 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 miscutils/flash_eraseall.c |   47 ++++++++++++++++++++++++++++---------------
 1 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/miscutils/flash_eraseall.c b/miscutils/flash_eraseall.c
index ba0a6b5..ca00a13 100644
--- a/miscutils/flash_eraseall.c
+++ b/miscutils/flash_eraseall.c
@@ -12,22 +12,35 @@
 
 #include "libbb.h"
 #include <mtd/mtd-user.h>
-#include <mtd/jffs2-user.h>
+#include <linux/jffs2.h>
 
 #define OPTION_J	(1 << 0)
 #define OPTION_Q	(1 << 1)
 #define IS_NAND		(1 << 2)
 #define BBTEST		(1 << 3)
 
-struct globals {
-	/* This is used in the cpu_to_je/je_to_cpu macros in jffs2_user.h */
-	int tgt_endian;
-};
-#define G (*(struct globals*)&bb_common_bufsiz1)
-#define target_endian	(G.tgt_endian)
-#define INIT_G() do { \
-	target_endian = __BYTE_ORDER; \
-} while (0)
+/* mtd/jffs2-user.h used to have this atrocity:
+extern int target_endian;
+
+#define t16(x) ({ __u16 __b = (x); (target_endian==__BYTE_ORDER)?__b:bswap_16(__b); })
+#define t32(x) ({ __u32 __b = (x); (target_endian==__BYTE_ORDER)?__b:bswap_32(__b); })
+
+#define cpu_to_je16(x) ((jint16_t){t16(x)})
+#define cpu_to_je32(x) ((jint32_t){t32(x)})
+#define cpu_to_jemode(x) ((jmode_t){t32(x)})
+
+#define je16_to_cpu(x) (t16((x).v16))
+#define je32_to_cpu(x) (t32((x).v32))
+#define jemode_to_cpu(x) (t32((x).m))
+
+but mtd/jffs2-user.h is gone now (at least 2.6.31.6 does not have it anymore)
+*/
+
+/* We always use native endianness */
+#undef cpu_to_je16
+#undef cpu_to_je32
+#define cpu_to_je16(v) ((jint16_t){(v)})
+#define cpu_to_je32(v) ((jint32_t){(v)})
 
 static uint32_t crc32(uint32_t val, const void *ss, int len,
 		uint32_t *crc32_table)
@@ -40,9 +53,11 @@ static uint32_t crc32(uint32_t val, const void *ss, int len,
 
 static void show_progress(mtd_info_t *meminfo, erase_info_t *erase)
 {
-	printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.",
-		(unsigned)meminfo->erasesize / 1024, erase->start,
-		(unsigned long long) erase->start * 100 / meminfo->size);
+	printf("\rErasing %u Kibyte @ %x - %2u%% complete.",
+		(unsigned)meminfo->erasesize / 1024,
+		erase->start,
+		(unsigned) ((unsigned long long) erase->start * 100 / meminfo->size)
+	);
 	fflush(stdout);
 }
 
@@ -57,17 +72,15 @@ int flash_eraseall_main(int argc UNUSED_PARAM, char **argv)
 	unsigned int flags;
 	char *mtd_name;
 
-	INIT_G();
 	opt_complementary = "=1";
 	flags = BBTEST | getopt32(argv, "jq");
 
 	mtd_name = argv[optind];
-	xstat(mtd_name, &st);
+	fd = xopen(mtd_name, O_RDWR);
+	fstat(fd, &st);
 	if (!S_ISCHR(st.st_mode))
 		bb_error_msg_and_die("%s: not a char device", mtd_name);
 
-	fd = xopen(mtd_name, O_RDWR);
-
 	xioctl(fd, MEMGETINFO, &meminfo);
 	erase.length = meminfo.erasesize;
 	if (meminfo.type == MTD_NANDFLASH)
-- 
1.6.5