What are the MTD Utilities?MTD subsystem (stands for Memory Technology Devices) provides an abstraction layer for raw flash devices. It makes it possible to use the same API when working with different flash types and technologies, e.g. NAND, OneNAND, NOR, AG-AND, ECC'd NOR, etc. MTD subsystem does not deal with block devices like MMC, eMMC, SD, CompactFlash, etc. These devices are not raw flashes but they have a Flash Translation layer inside, which makes them look like block devices. These devices are the subject of the Linux block subsystem, not MTD. MTD subsystem has the following interfaces.
MTD subsystem supports bare NAND flashes with software and hardware ECC, OneNAND flashes, CFI (Common Flash Interface) NOR flashes, and other flash types. For more information on MTD, refer <http://www.linux-mtd./doc/general.html> MTD-Utils User-space toolsThe MTD Utilities are a collection of tools that allow the user to interact with the MTD subsystem in the kernel to perform operations on Flash devices. The most commonly used utilities are:
These utilities are often used to write file system images to the Flash device on an embedded system. MTD-Utils CompilationSource and dependencies
The 'mtd-utility' requires zlib, lzo and uuid (from e2fsprogs) libraries. The former two are used for compressing the data, and the latter one is used for generating universally unique ID number for the file-system.
zlib
MTD-Utils Version as of writing this wiki is release 1.4.8 Current link for tar archive as of writing this wiki is http://git./mtd-utils.git/snapshot/d37fcc0afd0d4a14c56812847e8e4257d0a99e3b.tar.gz (--> mtd-utils-d37fcc0.tar.gz)
Setup PreparationIn this example, we use
HostThis section describes how to compile mtd-utils for the Linux development host.
host$ tar xvf zlib-1.2.5.tar.gz host$ cd zlib-1.2.5/ host$ ./configure --prefix=~/mtd/install host$ make host$ make install host$ cd .. Result should be libz.a in ~/mtd/install/lib directory and zlib's headers in ~/mtd/install/include.
host$ tar xvf lzo-2.06.tar.gz host$ cd lzo-2.06/ host$ ./configure --build=i686-pc-linux --prefix=~/mtd/install host$ make host$ make install host$ cd .. Result should be liblzo2.a in ~/mtd/install/lib directory and lzo's headers in ~/mtd/install/include/lzo.
host$ tar xvf e2fsprogs-1.42.tar.gz host$ cd e2fsprogs-1.42/ host$ ./configure --build=i686-pc-linux --prefix=~/mtd/install host$ make host$ make install host$ cd lib/uuid/ host$ make install host$ cd ../../../ Result should be libuuid.a in ~/mtd/install/lib directory and uuid's headers in ~/mtd/install/include/uuid.
host$ tar xvf mtd-utils-d37fcc0.tar.gz host$ cd mtd-utils-d37fcc0/ mtd-utils doesn't have a configure script, so we have to edit the Makefile again. Depending on the version of mtd-utils, make sure head of top level Makefile has: host$ vi Makefile PREFIX = ~/mtd/install ZLIBCPPFLAGS = -I$(PREFIX)/include LZOCPPFLAGS = -I$(PREFIX)/include ZLIBLDFLAGS = -L$(PREFIX)/lib LZOLDFLAGS = -L$(PREFIX)/lib LDFLAGS += $(ZLIBLDFLAGS) $(LZOLDFLAGS) CFLAGS ?= -O2 -g $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) Save and close vi editor Edit the common.mk file and comment out the PREFIX=/usr line host$ vi common.mk #PREFIX=/usr Save and close vi editor host$ WITHOUT_XATTR=1 make host$ make install DESTDIR=~/mtd/install host$ cd .. Directory ~/mtd/install/sbin/ should now contain compiled MTD utils you can use on Linux host. The binaries for the tools used to create a UBIFS root file system will be found here: ~/mtd/install/home/<username>/mtd/install/sbin/mkfs.ubifs
TargetThis section describes how to cross compile the MTD utilities on the Linux development host for Linux ARM target. Note :
When using MontaVista toolchain, there is a version of the MTD utilities compiled for the ARM target provided in the MontaVista tool chain. The target file system from MontaVista, located at <MontaVista install dir>/pro/devkit/arm/v5t_le/target, contains these tools for the target.
host$ tar xvf zlib-1.2.5.tar.gz host$ cd zlib-1.2.5/ host$ ./configure --prefix=~/mtd/install Edit resulting Makefile and add toolchain prefix arm-arago-linux-gnueabi- to gcc, ldshared, cpp, ar and ranlib. host$ vi Makefile CC=arm-arago-linux-gnueabi-gcc LDSHARED=arm-arago-linux-gnueabi-gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map CPP=arm-arago-linux-gnueabi-gcc -E AR=arm-arago-linux-gnueabi-ar rc RANLIB=arm-arago-linux-gnueabi-ranlib Save and close vi editor. Then you should be ready to compile. host$ make host$ make install host$ cd .. Result should be zlib.a in ~/mtd/install/lib directory and zlib's headers in ~/mtd/install/include.
host$ tar xvf lzo-2.06.tar.gz host$ cd lzo-2.06/ host$ ./configure --build=i686-pc-linux --prefix=~/mtd/install --host=arm-arago-linux-gnueabi host$ make host$ make install host$ cd .. Result should be liblzo2.a in ~/mtd/install/lib directory and lzo's headers in ~/mtd/install/include/lzo.
host$ tar xvf e2fsprogs-1.42.tar.gz host$ cd e2fsprogs-1.42/ host$ ./configure --build=i686-pc-linux --prefix=~/mtd/install --host=arm-arago-linux-gnueabi host$ make host$ make install host$ cd lib/uuid/ host$ make install host$ cd ../../../ Result should be libuuid.a in ~/mtd/install/lib directory and uuid's headers in ~/mtd/install/include/uuid.
host$ tar xvf mtd-utils-d37fcc0.tar.gz host$ cd mtd-utils-d37fcc0/ 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: host$ vi Makefile PREFIX = ~/mtd/install ZLIBCPPFLAGS = -I$(PREFIX)/include LZOCPPFLAGS = -I$(PREFIX)/include ZLIBLDFLAGS = -L$(PREFIX)/lib LZOLDFLAGS = -L$(PREFIX)/lib LDFLAGS += $(ZLIBLDFLAGS) $(LZOLDFLAGS) CFLAGS ?= -O2 -g $(ZLIBCPPFLAGS) $(LZOCPPFLAGS) CROSS=arm-none-linux-gnueabi- Save and close vi editor. Edit common.mk and comment PREFIX=/usr. host$ vi common.mk # PREFIX=/usr Save and close vi editor. Then you should be ready to compile. host$ WITHOUT_XATTR=1 make host$ make install DESTDIR=~/mtd/install host$ cd .. Directory ~/mtd/install/sbin/ should now contain cross compiled MTD utils that can be used on target. |
|
来自: 望穿墙 > 《linux study way》