2021-11-15

转载
Cross compile mtd-utils 2.1.3
For arm and arm64
Posted on August 5, 2020
Install required tools

$ sudo apt install build-essential gcc-arm-linux-gnueabihf git git-email autoconf libtool pkg-config uuid-dev zlib1g-dev liblzo2-dev libzstd-dev
Cross compilation of mtd-utils involve cross-compliling dependencies too.

For clean build create a build directory.

$ mkdir mtdutils_build
$ cd mtdutils_build
$ BUILD_DIR=pwd
Download latest mtd-utils.

$ git clone -b v2.1.3 git://git.infradead.org/mtd-utils.git
or

$ wget ftp://ftp.infradead.org/pub/mtd-utils/mtd-utils-2.1.2.tar.bz2
$ tar -xjf mtd-utils-2.1.3.tar.bz2
$ mv mtd-utils-2.1.3 mtd-utils
Download zilb.

$ wget http://www.zlib.net/zlib-1.2.11.tar.gz
$ tar -xzf zlib-1.2.11.tar.gz
Download lzo.

$ wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.10.tar.gz
$ tar -xzf lzo-2.10.tar.gz
Download e2fsprogs.

$ git clone -b v1.45.6 https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
or

$ wget https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/snapshot/e2fsprogs-1.45.6.tar.gz
$ tar -xzf e2fsprogs-1.45.6.tar.gz
$ mv e2fsprogs-1.45.6 e2fsprogs
Download zstd.

$ git clone --branch v1.4.5 https://github.com/facebook/zstd.git
or

$ wget https://github.com/facebook/zstd/releases/download/v1.4.5/zstd-1.4.5.tar.gz
$ tar -xzf zstd-1.4.5.tar.gz
$ mv zstd-1.4.5 zstd
Download openssl.

$ git clone -b OpenSSL_1_1_1-stable https://github.com/openssl/openssl.git
or

$ wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1-stable.zip
$ unzip OpenSSL_1_1_1-stable.zip
$ mv OpenSSL_1_1_1-stable openssl
Before cross-compiling we need to set some environment variables.

For ARM64:

$ CROSS=/path/to/aarch64-linux-gnu-
$ CROSS_NE=/path/to/aarch64-linux-gnu
For ARM:

$ CROSS=/path/to/arm-linux-gnueabihf-
$ CROSS_NE=/path/to/arm-linux-gnueabihf
Below are for both:

$ export CC=${CROSS}gcc
$ export AR=${CROSS}ar
$ export LD=${CROSS}ld
$ export STRIP=${CROSS}strip
$ export NM=${CROSS}nm
$ export RANLIB=${CROSS}ranlib
$ export OBJDUMP=${CROSS}objdump
Also, we need to specify the install path.

$ mkdir install
$ INSTALL_PATH=$(cd install; pwd)
Cross-compile zlib.

$ cd zlib-1.2.11
$ unset LDFLAGS
$ ./configure --static --prefix=$INSTALL_PATH
$ make
$ make install
$ cd $BUILD_DIR
Cross-compile lzo.

$ cd lzo-2.10
$ unset LDFLAGS
$ ./configure --host= C R O S S N E − − e n a b l e − s t a t i c − − d i s a b l e − s h a r e d C C = CROSS_NE --enable-static --disable-shared CC= CROSSNEenablestaticdisablesharedCC={CROSS}gcc AR= A R L D = {AR} LD= ARLD={LD} NM= N M R A N L I B = {NM} RANLIB= NMRANLIB={RANLIB} STRIP=" S T R I P " O B J D U M P = {STRIP}" OBJDUMP= STRIP"OBJDUMP={OBJDUMP} --prefix=$INSTALL_PATH
$ make
$ make install
$ cd $BUILD_DIR
Cross-compile e2fsprogs.

$ cd e2fsprogs
$ unset LDFLAGS
$ ./configure --host= C R O S S N E C C = CROSS_NE CC= CROSSNECC={CROSS}gcc --with-udev-rules-dir= I N S T A L L P A T H − − w i t h − c r o n d − d i r = INSTALL_PATH --with-crond-dir= INSTALLPATHwithcronddir=INSTALL_PATH --with-systemd-unit-dir= I N S T A L L P A T H − − p r e f i x = INSTALL_PATH --prefix= INSTALLPATHprefix=INSTALL_PATH
$ make
$ make install
$ make install-libs
$ cd lib/uuid/
$ make install
$ cd $BUILD_DIR
Cross-compile zstd.

$ cd zstd
$ make allzstd
$ cp lib/zstd.h $INSTALL_PATH/include/
$ cp lib/deprecated/zbuff.h $INSTALL_PATH/include/
$ cp lib/common/zstd_errors.h $INSTALL_PATH/include/
$ cp lib/dictBuilder/zdict.h $INSTALL_PATH/include/
$ cp lib/libzstd.a $INSTALL_PATH/lib/
$ cp lib/libzstd.pc $INSTALL_PATH/lib/pkgconfig/
$ cp lib/libzstd.so $INSTALL_PATH/lib/
$ cp lib/libzstd.so.1 $INSTALL_PATH/lib/
$ cp lib/libzstd.so.1.4.5 $INSTALL_PATH/lib/
Cross-compile openssl. Set “arch_openssl” as “aarch64” for ARM64. You can get the more info with command “./Configure os/compiler”.

$ cd openssl
$ arch_openssl=armv4
$ ./Configure linux- a r c h o p e n s s l n o − i d e a n o − m d c 2 n o − r c 5 n o − s s l 3 − − p r e f i x = arch_openssl no-idea no-mdc2 no-rc5 no-ssl3 --prefix= archopensslnoideanomdc2norc5nossl3prefix=INSTALL_PATH
$ make depend
$ make
$ make install
$ cd $BUILD_DIR
Cross-compile mtd-utils.

$ cd mtd-utils
$ ./autogen.sh
$ ./configure --host= C R O S S N E C C = CROSS_NE CC= CROSSNECC={CROSS}gcc --prefix= I N S T A L L P A T H L D F L A G S = − L INSTALL_PATH LDFLAGS=-L INSTALLPATHLDFLAGS=L{INSTALL_PATH}/lib CFLAGS="-DWITHOUT_XATTR -I I N S T A L L P A T H / i n c l u d e − g − O 2 − s t a t i c " L Z O C F L A G S = − I {INSTALL_PATH}/include -g -O2 -static" LZO_CFLAGS=-I INSTALLPATH/includegO2static"LZOCFLAGS=I{INSTALL_PATH}/include/lzo/ ZLIB_CFLAGS=-I I N S T A L L P A T H / i n c l u d e Z S T D C F L A G S = − I {INSTALL_PATH}/include ZSTD_CFLAGS=-I INSTALLPATH/includeZSTDCFLAGS=I{INSTALL_PATH}/include --enable-static=yes
$ make
$ make install
$ cd B U I L D D I R F i n a l l y , y o u c a n f i n d a l l t h e e x e c u t a b l e s f r o m m t d − u t i l s i n ‘ BUILD_DIR Finally, you can find all the executables from mtd-utils in ‘ BUILDDIRFinally,youcanfindalltheexecutablesfrommtdutilsinINSTALL_PATH/sbin’.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值