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 and LZO. Download latest archives using the given links. For this example we use


 * zlib-1.2.3.tar.bz2
 * lzo-2.03.tar.gz
 * 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.

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

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