交叉编译e2fsprogs For android

因为须要使用dumpe2fs debugfs工具,所以交叉编译了e2fsprogs的源码。html

本人在ubuntu 14.04下操做的
linux


1. 下载e2fsprogs的源码android

版本是1.42.6   c++


2.  下载NDKshell

https://developer.android.com/ndk/downloads/index.html
bootstrap


3. 生成standalone toolchain (斜体为具体路径)ubuntu

cd $NDK_PATHapp

cd build/toolsionic

./make_standalone_toolchain.sh --install-dir=$TOOLCHAIN_PATHide

成功则在$TOOLCHAIN_PATH下生成交叉编译所需的工具


4. 测试是否成功

cd $TOOL_CHAIN/bin

./arm-linux-androideabi-gcc -v

zombie@zombie-OptiPlex-3010:~/Software/NDK/tool-chain/bin$ ./arm-linux-androideabi-gcc -v
Using built-in specs.
COLLECT_GCC=./arm-linux-androideabi-gcc
COLLECT_LTO_WRAPPER=/home/zombie/Software/NDK/tool-chain/bin/../libexec/gcc/arm-linux-androideabi/4.9.x/lto-wrapper
Target: arm-linux-androideabi
Configured with: /usr/local/google/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/configure --prefix=/tmp/59719db9ae19ff43aef46bbcb79596b6 --target=arm-linux-androideabi --host=x86_64-linux-gnu --build=x86_64-linux-gnu --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/buildbot/tmp/build/toolchain/temp-install --with-mpfr=/buildbot/tmp/build/toolchain/temp-install --with-mpc=/buildbot/tmp/build/toolchain/temp-install --with-cloog=/buildbot/tmp/build/toolchain/temp-install --with-isl=/buildbot/tmp/build/toolchain/temp-install --with-ppl=/buildbot/tmp/build/toolchain/temp-install --disable-ppl-version-check --disable-cloog-version-check --disable-isl-version-check --enable-cloog-backend=isl --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --disable-libitm --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --enable-bionic-libs --enable-libatomic-ifuncs=no --enable-initfini-array --disable-nls --prefix=/tmp/59719db9ae19ff43aef46bbcb79596b6 --with-sysroot=/tmp/59719db9ae19ff43aef46bbcb79596b6/sysroot --with-binutils-version=2.25 --with-mpfr-version=3.1.1 --with-mpc-version=1.0.1 --with-gmp-version=5.0.5 --with-gcc-version=4.9 --with-gdb-version=none --with-gxx-include-dir=/tmp/59719db9ae19ff43aef46bbcb79596b6/include/c++/4.9.x --with-bugurl=http://source.android.com/source/report-bugs.html --enable-languages=c,c++ --disable-bootstrap --enable-plugins --enable-libgomp --enable-gnu-indirect-function --disable-libsanitizer --enable-gold --enable-threads --enable-eh-frame-hdr-for-static --enable-graphite=yes --with-isl-version=0.11.1 --with-cloog-version=0.18.0 --with-arch=armv5te --program-transform-name='s&^&arm-linux-androideabi-&' --enable-gold=default
Thread model: posix
gcc version 4.9.x 20150123 (prerelease) (GCC)


加入PATH中

export PATH=$PATH:/$TOOL_CHAIN/bin

5. 编译e2fsprogs

cd $e2fsprogs_PATH

export CFLAGS="-static -O2 -fpie -pie"

export LDFLAGS="-staitc -pie"

./configure --host=arm-linux -target=arm-linux CC=arm-linux-androideabi-gcc --prefix=$OUT_DIR

make (-j8)

make install


6. 成功编译后会在$OUT_DIR/sbin下生成可执行文件

zombie@zombie-OptiPlex-3010:~/e2fsprogs/out/sbin$ ls
badblocks   e2fsck    filefrag   fsck.ext4     mkfs.ext3     tune2fs
blkid       e2image   findfs     fsck.ext4dev  mkfs.ext4     uuidd
debugfs     e2label   fsck       logsave       mkfs.ext4dev
dumpe2fs    e2undo    fsck.ext2  mke2fs        mklost+found
e2freefrag  e4defrag  fsck.ext3  mkfs.ext2     resize2fs


7.  剔除可执行文件符号表信息

cd $OUT_DIR 

arm-linux-androideabi-strip *


8. 查看可执行文件信息(关键是statically linked 和 stripped)

file *

zombie@zombie-OptiPlex-3010:~/e2fsprogs/out/sbin$ file *
badblocks:    ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
blkid:        ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
debugfs:      ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
dumpe2fs:     ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
e2freefrag:   ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
e2fsck:       ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
e2image:      ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
e2label:      ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
e2undo:       ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
e4defrag:     ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
filefrag:     ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
findfs:       ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
fsck:         ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
fsck.ext2:    ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
fsck.ext3:    ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
fsck.ext4:    ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
fsck.ext4dev: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
logsave:      ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
mke2fs:       ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
mkfs.ext2:    ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
mkfs.ext3:    ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
mkfs.ext4:    ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
mkfs.ext4dev: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
mklost+found: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
resize2fs:    ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
tune2fs:      ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
uuidd:        ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped



9. 将可执行文件放入手机

adb push debugfs /data/local/tmp



10. 在手机中运行

adb shell

cd /data/local/tmp

./debugfs