CompilingMTDUtils

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://git.infradead.org/mtd-utils.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


 * zlib-1.2.3.tar.bz2
 * lzo-2.03.tar.gz
 * git clone git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
 * mtd-utils.git-snapshot-20081004.tar.gz

=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.

Preparation
In this example, we use

/home/user/mtd

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)

zlib
> 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

lzo
> 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.

e2fsprogs
> git clone git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.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.

mtd-utils
> 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

PREFIX=/home/user/mtd/install ... ZLIBCPPFLAGS=-I$(PREFIX)/include LZOCPPFLAGS=-I$(PREFIX)/include/lzo ZLIBLDFLAGS=-L$(PREFIX)/lib LZOLDFLAGS=-L$(PREFIX)/lib CROSS=arm-none-linux-gnueabi- ... CFLAGS ?= -O2 -g $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) ...

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 PREFIX=/usr in common.mk to and run:
 * 1) PREFIX=/usr

WITHOUT_XATTR=1 make install