Jump to: navigation, search

This article is about (cross-) compiling MTD-Utils. MTD-Utils(MTD == memory technology device) are user space tools to work with MTD kernel subsystem. As these tools are often necessary to write embedded file system to MTD (NOR/NAND) devices and there are some dependencies, we briefly describe here how to cross compile them.

Source and dependencies

MTD utils are available from MTD utils git. You can get them by

  • using gitweb "snapshot" feature (use "snapshot" link at latest commit at the right side)
  • using git
git pull git:// mtd-utils

Compiling MTD utils depend on zlib, LZO and e2fsprogs for uuid. Download latest archives using the given links. For this example we use

Cross compile

As example for cross compilation, we use CodeSourcery ARM tool chain as popular for BeagleBoard.

Note: If you use other cross compiler, replace tool chain prefix arm-none-linux-gnueabi- below by prefix of your (cross-) toolchain.


In this example, we use


as base directory. This example assumes you are in this directory and the above three source .tar.gz files are located here, too.

To not pollute the host file system, we install build results in local subdirectory:

> mkdir install

should result in /home/user/mtd/install (replace this with your real path below)


> tar xfj zlib-1.2.3.tar.bz2
> cd zlib-1.2.3/
zlib-1.2.3 > ./configure --prefix=/home/user/mtd/install

Edit resulting Makefile, e.g.

zlib-1.2.3 > emacs Makefile

and add toolchain prefix arm-none-linux-gnueabi- to gcc, ar and ranlib. Then you should be ready to compile:

zlib-1.2.3 > make
zlib-1.2.3 > make install
zlib-1.2.3 > cd ..

Result should be zlib.a in install/lib directory and zlib's headers in install/include. If this was successful, remove build directory:

> rm -rf zlib-1.2.3


> tar xfz lzo-2.03.tar.gz
> cd lzo-2.03/
lzo-2.03 > ./configure --host=arm-none-linux-gnueabi --prefix=/home/user/mtd/install
lzo-2.03 > make
lzo-2.03 > make install
lzo-2.03 > cd ..
> rm -rf lzo-2.03

Result should be liblzo2.a in install/lib directory and lzo's headers in install/include/lzo.


> git clone git://

Export the path for your toolchain binaries.

> export PATH=~/path_to_your_toolchain_bin/bin:$PATH

Create Makefile using configure command

> cd e2fsprogs
e2fsprogs> ./configure --prefix=/home/user/mtd/install --host=arm-none-linux-gnueabi

Adding "--host=" in configure command will update the toolchain used for cross-compiling e2fsprogs.

e2fsprogs> make
e2fsprogs> make install
e2fsprogs> make install-libs

"make install" will just install the binary programs.

"make install-libs" installs the actual libraries and header files to given install directory.


> tar xfz mtd-utils.git-snapshot-20081004.tar.gz
> cd mtd-utils/

MTD-Utils don't have a configure script, so we have to edit Makefile again. Depending on the version of MTD Utils, make sure head of top level Makefile has:

mtd-utils > emacs Makefile



Then, you should be able to cross compile MTD Utils setting variable WITHOUT_XATTR:

mtd-utils > WITHOUT_XATTR=1 make
mtd-utils > make install
mtd-utils > cd ..
> rm -rf mtd-utils
> cd install/sbin/
install/sbin > arm-none-linux-gnueabi-strip *

Directory install/sbin/ should now contain cross compiled MTD utils you can use at your target.

If make reports:

CROSS COMPILE Badness: /usr/include in INCLUDEPATH: /usr/include

you will need to change the line


in to


and run:

WITHOUT_XATTR=1 make install