diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-27 13:26:17 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-27 13:26:17 +0100 |
commit | 86cfb70ca5f2bde11f2d071bc59db75291d8552f (patch) | |
tree | 8f26107f9c1394a0e87609eb5c29e58cecd166b6 | |
parent | 160b9ca7318fb63e9432c1028f52373aea6166f9 (diff) | |
download | busybox-w32-86cfb70ca5f2bde11f2d071bc59db75291d8552f.tar.gz busybox-w32-86cfb70ca5f2bde11f2d071bc59db75291d8552f.tar.bz2 busybox-w32-86cfb70ca5f2bde11f2d071bc59db75291d8552f.zip |
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>
-rw-r--r-- | 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 ba0a6b515..ca00a130e 100644 --- a/miscutils/flash_eraseall.c +++ b/miscutils/flash_eraseall.c | |||
@@ -12,22 +12,35 @@ | |||
12 | 12 | ||
13 | #include "libbb.h" | 13 | #include "libbb.h" |
14 | #include <mtd/mtd-user.h> | 14 | #include <mtd/mtd-user.h> |
15 | #include <mtd/jffs2-user.h> | 15 | #include <linux/jffs2.h> |
16 | 16 | ||
17 | #define OPTION_J (1 << 0) | 17 | #define OPTION_J (1 << 0) |
18 | #define OPTION_Q (1 << 1) | 18 | #define OPTION_Q (1 << 1) |
19 | #define IS_NAND (1 << 2) | 19 | #define IS_NAND (1 << 2) |
20 | #define BBTEST (1 << 3) | 20 | #define BBTEST (1 << 3) |
21 | 21 | ||
22 | struct globals { | 22 | /* mtd/jffs2-user.h used to have this atrocity: |
23 | /* This is used in the cpu_to_je/je_to_cpu macros in jffs2_user.h */ | 23 | extern int target_endian; |
24 | int tgt_endian; | 24 | |
25 | }; | 25 | #define t16(x) ({ __u16 __b = (x); (target_endian==__BYTE_ORDER)?__b:bswap_16(__b); }) |
26 | #define G (*(struct globals*)&bb_common_bufsiz1) | 26 | #define t32(x) ({ __u32 __b = (x); (target_endian==__BYTE_ORDER)?__b:bswap_32(__b); }) |
27 | #define target_endian (G.tgt_endian) | 27 | |
28 | #define INIT_G() do { \ | 28 | #define cpu_to_je16(x) ((jint16_t){t16(x)}) |
29 | target_endian = __BYTE_ORDER; \ | 29 | #define cpu_to_je32(x) ((jint32_t){t32(x)}) |
30 | } while (0) | 30 | #define cpu_to_jemode(x) ((jmode_t){t32(x)}) |
31 | |||
32 | #define je16_to_cpu(x) (t16((x).v16)) | ||
33 | #define je32_to_cpu(x) (t32((x).v32)) | ||
34 | #define jemode_to_cpu(x) (t32((x).m)) | ||
35 | |||
36 | but mtd/jffs2-user.h is gone now (at least 2.6.31.6 does not have it anymore) | ||
37 | */ | ||
38 | |||
39 | /* We always use native endianness */ | ||
40 | #undef cpu_to_je16 | ||
41 | #undef cpu_to_je32 | ||
42 | #define cpu_to_je16(v) ((jint16_t){(v)}) | ||
43 | #define cpu_to_je32(v) ((jint32_t){(v)}) | ||
31 | 44 | ||
32 | static uint32_t crc32(uint32_t val, const void *ss, int len, | 45 | static uint32_t crc32(uint32_t val, const void *ss, int len, |
33 | uint32_t *crc32_table) | 46 | uint32_t *crc32_table) |
@@ -40,9 +53,11 @@ static uint32_t crc32(uint32_t val, const void *ss, int len, | |||
40 | 53 | ||
41 | static void show_progress(mtd_info_t *meminfo, erase_info_t *erase) | 54 | static void show_progress(mtd_info_t *meminfo, erase_info_t *erase) |
42 | { | 55 | { |
43 | printf("\rErasing %d Kibyte @ %x -- %2llu %% complete.", | 56 | printf("\rErasing %u Kibyte @ %x - %2u%% complete.", |
44 | (unsigned)meminfo->erasesize / 1024, erase->start, | 57 | (unsigned)meminfo->erasesize / 1024, |
45 | (unsigned long long) erase->start * 100 / meminfo->size); | 58 | erase->start, |
59 | (unsigned) ((unsigned long long) erase->start * 100 / meminfo->size) | ||
60 | ); | ||
46 | fflush_all(); | 61 | fflush_all(); |
47 | } | 62 | } |
48 | 63 | ||
@@ -57,17 +72,15 @@ int flash_eraseall_main(int argc UNUSED_PARAM, char **argv) | |||
57 | unsigned int flags; | 72 | unsigned int flags; |
58 | char *mtd_name; | 73 | char *mtd_name; |
59 | 74 | ||
60 | INIT_G(); | ||
61 | opt_complementary = "=1"; | 75 | opt_complementary = "=1"; |
62 | flags = BBTEST | getopt32(argv, "jq"); | 76 | flags = BBTEST | getopt32(argv, "jq"); |
63 | 77 | ||
64 | mtd_name = argv[optind]; | 78 | mtd_name = argv[optind]; |
65 | xstat(mtd_name, &st); | 79 | fd = xopen(mtd_name, O_RDWR); |
80 | fstat(fd, &st); | ||
66 | if (!S_ISCHR(st.st_mode)) | 81 | if (!S_ISCHR(st.st_mode)) |
67 | bb_error_msg_and_die("%s: not a char device", mtd_name); | 82 | bb_error_msg_and_die("%s: not a char device", mtd_name); |
68 | 83 | ||
69 | fd = xopen(mtd_name, O_RDWR); | ||
70 | |||
71 | xioctl(fd, MEMGETINFO, &meminfo); | 84 | xioctl(fd, MEMGETINFO, &meminfo); |
72 | erase.length = meminfo.erasesize; | 85 | erase.length = meminfo.erasesize; |
73 | if (meminfo.type == MTD_NANDFLASH) | 86 | if (meminfo.type == MTD_NANDFLASH) |