Revision as of 16:25, 4 December 2015 by Sachinpandhare (talk | contribs) (added a section for e2fsprogs dependency compilation)
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.



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

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-uitls > emacs Makefile



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

mtd-uitls > WITHOUT_XATTR=1 make
mtd-uitls > make install
mtd-uitls > 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 PREFIX=/usr in to #PREFIX=/usr and run:

WITHOUT_XATTR=1 make install