MTD Utilities

转载:http://blog.csdn.net/neiloid/article/details/7614576


http://processors.wiki.ti.com/index.php/MTD_Utilities
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 character devices - usually referred to as /dev/mtd0, /dev/mtd1, and so on. These character devices provide I/O access to the raw flash. They support a number of ioctl calls for erasing eraseblocks, marking them as bad or checking if an eraseblock is bad, getting information about MTD devices, etc.
  • The sysfs interface is relatively newer and it provides full information about each MTD device in the system. This interface is easily extensible and developers are encouraged to use the sysfs interface instead of older ioctl or /proc/mtd interfaces, when possible.
  • The /proc/mtd proc file system file provides general MTD information. This is a legacy interface and the sysfs interface provides more information.

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.infradead.org/doc/general.html>

MTD-Utils User-space tools

The MTD Utilities are a collection of tools that allow the user to interact with theMTD subsystem in the kernel to perform operations on Flash devices. The most commonly used utilities are:

  • flash_erase - Erases an erase block of flash
  • flash_eraseall - Erases the entire flash device
  • flashcp - Copies data into NOR flash
  • flash_info - Displays information about Flash devices
  • flash_lock - Lock flash pages to prevent writing
  • flash_unlock - Unlock flash pages to allow writing
  • mkfs.jffs2 - Create a JFFS2 file system image from an existing file system
  • nandwrite - Write an input file (i.e. JFFS2 or YAFFS2 image) to the NAND Flash device

These utilities are often used to write file system images to the Flash device on an embedded system.

MTD-Utils Compilation

Source and dependencies

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.

  1. zlib
  2. lzo
  3. e2fsprogs


Sources

zlib
Download zlib from http://zlib.net/. As of writing this wiki, zlib version is 1.2.5. Download fromhttp://zlib.net/zlib-1.2.5.tar.gz


lzo
Download from http://www.oberhumer.com/opensource/lzo/download/ . As of writing this wiki, lzo version is 2.0.6. Download fromhttp://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz


e2fsprogs
Download e2fsprogs from http://e2fsprogs.sourceforge.net/ . As of writing this wiki, e2fsprogs version is 1.42. Download fromhttp://sourceforge.net/projects/e2fsprogs/files/e2fsprogs/1.42/e2fsprogs-1.42.tar.gz/download


MTD-Utils
MTD utils are available from http://git.infradead.org/mtd-utils.git. You can get them by

  • using gitweb "snapshot" feature (use "snapshot" link at latest commit at the right side)
  • using http://git.or.cz/
    • git pull git://git.infradead.org/mtd-utils.git mtd-utils

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.infradead.org/mtd-utils.git/snapshot/d37fcc0afd0d4a14c56812847e8e4257d0a99e3b.tar.gz (--> mtd-utils-d37fcc0.tar.gz)


Setup 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 sub-directory:
> mkdir install
should result in /home/user/mtd/install (replace this with your real path below).


Host

This section describes how to compile the MTD utilities for the Linux development host.


zlib

    host$ tar xvf zlib-1.2.5.tar.gz
    host$ cd zlib-1.2.5/
    host$ ./configure --prefix=/home/user/mtd/install
    host$ make
    host$ make install
    host$ cd ..

Result should be zlib.a in /home/user/mtd/install/lib directory and zlib's headers in /home/user/mtd/install/include.


lzo

    host$ tar xvf lzo-2.06.tar.gz
    host$ cd lzo-2.06/
    host$ ./configure --build=i686-pc-linux --prefix=/home/user/mtd/install
    host$ make
    host$ make install
    host$ cd ..

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


e2fsprogs

    host$ tar xvf e2fsprogs-1.42.tar.gz
    host$ cd e2fsprogs-1.42/
    host$ ./configure --build=i686-pc-linux --prefix=/home/user/mtd/install 
    host$ make
    host$ make install
    host$ cd lib/uuid/
    host$ make install
    host$ cd ../../../

Result should be libuuid.a in /home/user/mtd/install/lib directory and uuid's headers in /home/user/mtd/install/include/uuid.


mtd-utils

    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 = /home/user/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=/home/user/mtd/install
    host$ cd ..

Directory /home/user/mtd/install/sbin/ should now contain compiled MTD utils you can use on Linux host.


Target

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


zlib

    host$ tar xvf zlib-1.2.5.tar.gz
    host$ cd zlib-1.2.5/
    host$ ./configure --prefix=/home/user/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 /home/user/mtd/install/lib directory and zlib's headers in /home/user/mtd/install/include.


lzo

    host$ tar xvf lzo-2.06.tar.gz
    host$ cd lzo-2.06/
    host$ ./configure --build=i686-pc-linux --prefix=/home/user/mtd/install --host=arm-arago-linux-gnueabi

    host$ make
    host$ make install
    host$ cd ..

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


e2fsprogs

    host$ tar xvf e2fsprogs-1.42.tar.gz
    host$ cd e2fsprogs-1.42/
    host$ ./configure --build=i686-pc-linux --prefix=/home/user/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 /home/user/mtd/install/lib directory and uuid's headers in /home/user/mtd/install/include/uuid.


mtd-utils

    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 = /home/user/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=/home/user/mtd/install
    host$ cd ..

Directory/home/user/mtd/install/sbin/ should now contain cross compiled MTD utils that can be used on target.

http://processors.wiki.ti.com/index.php/MTD_Utilities



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 character devices - usually referred to as /dev/mtd0, /dev/mtd1, and so on. These character devices provide I/O access to the raw flash. They support a number of ioctl calls for erasing eraseblocks, marking them as bad or checking if an eraseblock is bad, getting information about MTD devices, etc.
  • The sysfs interface is relatively newer and it provides full information about each MTD device in the system. This interface is easily extensible and developers are encouraged to use the sysfs interface instead of older ioctl or /proc/mtd interfaces, when possible.
  • The /proc/mtd proc file system file provides general MTD information. This is a legacy interface and the sysfs interface provides more information.

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.infradead.org/doc/general.html>

MTD-Utils User-space tools

The MTD Utilities are a collection of tools that allow the user to interact with theMTD subsystem in the kernel to perform operations on Flash devices. The most commonly used utilities are:

  • flash_erase - Erases an erase block of flash
  • flash_eraseall - Erases the entire flash device
  • flashcp - Copies data into NOR flash
  • flash_info - Displays information about Flash devices
  • flash_lock - Lock flash pages to prevent writing
  • flash_unlock - Unlock flash pages to allow writing
  • mkfs.jffs2 - Create a JFFS2 file system image from an existing file system
  • nandwrite - Write an input file (i.e. JFFS2 or YAFFS2 image) to the NAND Flash device

These utilities are often used to write file system images to the Flash device on an embedded system.

MTD-Utils Compilation

Source and dependencies

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.

  1. zlib
  2. lzo
  3. e2fsprogs


Sources

zlib
Download zlib from http://zlib.net/. As of writing this wiki, zlib version is 1.2.5. Download fromhttp://zlib.net/zlib-1.2.5.tar.gz


lzo
Download from http://www.oberhumer.com/opensource/lzo/download/ . As of writing this wiki, lzo version is 2.0.6. Download fromhttp://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz


e2fsprogs
Download e2fsprogs from http://e2fsprogs.sourceforge.net/ . As of writing this wiki, e2fsprogs version is 1.42. Download fromhttp://sourceforge.net/projects/e2fsprogs/files/e2fsprogs/1.42/e2fsprogs-1.42.tar.gz/download


MTD-Utils
MTD utils are available from http://git.infradead.org/mtd-utils.git. You can get them by

  • using gitweb "snapshot" feature (use "snapshot" link at latest commit at the right side)
  • using http://git.or.cz/
    • git pull git://git.infradead.org/mtd-utils.git mtd-utils

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.infradead.org/mtd-utils.git/snapshot/d37fcc0afd0d4a14c56812847e8e4257d0a99e3b.tar.gz (--> mtd-utils-d37fcc0.tar.gz)


Setup 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 sub-directory:
> mkdir install
should result in /home/user/mtd/install (replace this with your real path below).


Host

This section describes how to compile the MTD utilities for the Linux development host.


zlib

    host$ tar xvf zlib-1.2.5.tar.gz
    host$ cd zlib-1.2.5/
    host$ ./configure --prefix=/home/user/mtd/install
    host$ make
    host$ make install
    host$ cd ..

Result should be zlib.a in /home/user/mtd/install/lib directory and zlib's headers in /home/user/mtd/install/include.


lzo

    host$ tar xvf lzo-2.06.tar.gz
    host$ cd lzo-2.06/
    host$ ./configure --build=i686-pc-linux --prefix=/home/user/mtd/install
    host$ make
    host$ make install
    host$ cd ..

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


e2fsprogs

    host$ tar xvf e2fsprogs-1.42.tar.gz
    host$ cd e2fsprogs-1.42/
    host$ ./configure --build=i686-pc-linux --prefix=/home/user/mtd/install 
    host$ make
    host$ make install
    host$ cd lib/uuid/
    host$ make install
    host$ cd ../../../

Result should be libuuid.a in /home/user/mtd/install/lib directory and uuid's headers in /home/user/mtd/install/include/uuid.


mtd-utils

    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 = /home/user/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=/home/user/mtd/install
    host$ cd ..

Directory /home/user/mtd/install/sbin/ should now contain compiled MTD utils you can use on Linux host.


Target

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


zlib

    host$ tar xvf zlib-1.2.5.tar.gz
    host$ cd zlib-1.2.5/
    host$ ./configure --prefix=/home/user/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 /home/user/mtd/install/lib directory and zlib's headers in /home/user/mtd/install/include.


lzo

    host$ tar xvf lzo-2.06.tar.gz
    host$ cd lzo-2.06/
    host$ ./configure --build=i686-pc-linux --prefix=/home/user/mtd/install --host=arm-arago-linux-gnueabi

    host$ make
    host$ make install
    host$ cd ..

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


e2fsprogs

    host$ tar xvf e2fsprogs-1.42.tar.gz
    host$ cd e2fsprogs-1.42/
    host$ ./configure --build=i686-pc-linux --prefix=/home/user/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 /home/user/mtd/install/lib directory and uuid's headers in /home/user/mtd/install/include/uuid.


mtd-utils

    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 = /home/user/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=/home/user/mtd/install
    host$ cd ..

Directory/home/user/mtd/install/sbin/ should now contain cross compiled MTD utils that can be used on target.

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(71) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值