转载
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=
CROSSNE−−enable−static−−disable−sharedCC={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=
INSTALLPATH−−with−crond−dir=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=
INSTALLPATH−−prefix=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=
archopensslno−ideano−mdc2no−rc5no−ssl3−−prefix=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/include−g−O2−static"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,youcanfindalltheexecutablesfrommtd−utilsin‘INSTALL_PATH/sbin’.