Use of mtd-utils Tools

Source: Internet
Author: User
Tags bz2 diff gz file uuid git clone

Cross-compile compilation mtd-utils on Ubuntu 10.04

=====================================================================================

Before writing an article, about two days to find mtd-utils data, often found are outdated, or the version is very low, or need to change a pile of makefile, can not change the makefile and use the latest version of the mtd-utils it.

This is my completion of Mt-utils cross compilation after writing the starting point of this article, I hope more people less take detours. The following is the step, my personal test is completely no problem, if there are errors please email me: szricky@gmail.com

This time is May 24, 2010, the compilation platform is Ubuntu 10.04, the cross-compilation tool is Arm-none-linux-gnueabi, the version is 2010q1. are currently the highest version.

Tool Chain installation package is: ARM-2010Q1-202-ARM-NONE-LINUX-GNUEABI-I686-PC-LINUX-GNU.TAR.BZ2, if not found on Google. Put it in the/home/szricky/after decompression The toolchains/directory.

The essence of cross-compile is that you can add your own compiled library and header files to the tool chain. Take Mtd-utils as an example, you need to compile zlib, Lzo, and E2fsprogs. It is a good idea to install these three libraries into the tool chain. Then there is no need to change the makefile of every project.

-------------------------the legendary dividing line------------------------------

A.) Export path= $PATH:/home/szricky/toolchains/arm-2010q1/bin, add a valid path to the tool chain to ensure that the folder exists, if different, you have to make the appropriate changes.

B.) use Git to download the latest E2fsprogs:git clone git://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git

C.) Configuration: E2fsprogs
./configure--host=i686-linux--target=arm-linux CC=ARM-NONE-LINUX-GNUEABI-GCC--prefix=/home/szricky/toolchains/ Arm-2010q1/arm-none-linux-gnueabi

D.) Compiling:
Make

E.) Installation: Because we only need a UUID library, we do not need a full installation to view the makefile file, so only:
Make Install-libs

F.) Check: Can be seen in the tool chain directory, uuid/uuid.h file has been installed. LIBUUID.A has been installed.

-------------------------the legendary dividing line------------------------------

The latest lzo is lzo-2.03.tar.gz, download and unzip.

Configuration:
./configure--host=i686-linux--target=arm-linux CC=ARM-NONE-LINUX-GNUEABI-GCC--prefix=/home/szricky/toolchains/ Arm-2010q1/arm-none-linux-gnueabi

Compile:
Make

Installation:
Make install

Check: liblzo2.a has been copied to the Lib directory of the tool chain.

Zlib is currently the latest zlib-1.2.5.tar.gz, download and extract.

Configuration:
CC=ARM-NONE-LINUX-GNUEABI-GCC./configure--prefix=/home/szricky/toolchains/arm-2010q1/arm-none-linux-gnueabi

Compile:
Make

Installation:
Make install

Check: Zconf.h and LIBZ.A are installed in the tool chain directory.

-------------------------the legendary dividing line------------------------------

Mtd-utils is different from the library above, the library file is to be installed in the tool chain, and the application (mtd-utils) should be installed in the file system.
So specify--prefix=/home/szricky/work/install, and create the empty folder manually.

Specify compilation parameters:
Export cross=arm-none-linux-gnueabi-
Export Destdir=/home/szricky/work/install

Make error, sys/acl.h file not found. Check the source code and Google to determine the parameters that need to be added to the without_xattr=1

So add:
Export Without_xattr=1

Direct compilation:
Make

Installation:
Make install

Check that 1:/home/szricky/work/install/usr/sbin has copied all the Mtd-utils tools.

Check 2:file Flash_eraseall
Flash_eraseall:elf 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for Gnu/linux 2.6 . Not stripped

There are two points that do not meet the requirements, the first is to use dynamic library, the second is no strip.

View makefile and Common.mk files and find cflags? =-o2-g compilation options,

So add one more option:
Export cflags= "-static-o2-g"

Rerun Make & make install

Remove debug information, run Arm-none-linux-gnueabi-strip in/home/szricky/work/install/usr/sbin *

Check again: File Flash_eraseall
Flash_eraseall:elf 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for Gnu/linux 2.6.16, stripped

Completed, compiled tools such as: Flash_eraseall, Ubimkvol, Ubiattach can run independently on the Android platform.
compilation and use of Mtd-utils tools


Compilation and use of Mtd-utils tools
First, download the source package and decompression
root@:/home/# wget ftp://ftp.infradead.org/pub/mtd-utils/mtd-utils-1.0.0.tar.bz2
root@:/home/# wget http://www.zlib.net/zlib-1.2.3.tar.gz
root@:/home/# wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.03.tar.gz
root@:/home/# Tar zxvf zlib-1.2.3.tar.gz
root@:/home/# Tar zxvf lzo-2.03.tar.gz
root@:/home/# Tar zxvf mtd-utils-1.0.0.tar.bz2
Ii. Compiling and installing zlib
1)
root@:/home/# CD zlib-1.2.3
./configure--prefix=/home/local/mips/zlib/--shared
(Note: Here the/home/local/mips/zlib/is the zlib library to install a large directory you can set yourself to want a large directory.) Remember this directory oh, or you will not be able to find the zlib library. )
2)
Modify the following entries for the generated makefile file:
cc=/cross/target/local/bin/mipsel-linux-gcc
Ar=/cross/target/local/bin/mipsel-linux-ar RC
Ranlib=/cross/target/local/bin/mipsel-linux-ranlib
(Note: My large cross compilation tool chain path is/cross/target/local/bin/, and you also want to replace your cross compilation Tool path.) )
3)
Make
Make install
4)
After the installation is complete, three directories are generated in the/home/local/mips/zlib/directory: Include, LIB, share.
Check the directory/home/local/mips/zlib/after installation
If there is no zlib.h such as the header file, Lib, there is no libz.so.1.2.3, then manually copy to these directories, remember the handcuffs when all the *.h need to handcuff the past, in the copy of the library with Cp-ca libz.*/..../lib On the line, use the-CA option.
Iii. Compiling and installing Lzo
1)
root@:/home/# CD lzo-2.03/
root@:/home/lzo-2.03# cc=mipsel-linux-gcc./configure--host=mipsel-linux--prefix=/home/local/mips/zlib/
2)
root@:/home/lzo-2.03# make
root@:/home/lzo-2.03# make Install
root@:/home/lzo-2.03# CD ...
Iv. Cross-compiling mtd-utils
1)
Modify Makefile
cross=mipsel-linux-
2)
Make
3)
See if the next mtd-utils-1.0.0 directory generates the big tools we need (Flashcp,nandwrite ...). , etc.).
There are tools generated, OK, cross compilation succeeded.
4)
Copy the build large tool to the file system Development Board root file system, in either/bin or/sbin. Then compile the kernel and OK pull.
V. Supplementary
If the cross compiler is above 4.3.x, compilation does not pass, please refer to
Http://www.mail-archive.com/ptxdist@pengutronix.de/msg01067.html
http://patchwork.ozlabs.org/patch/12689/
To play Patches
Vi. Use of mtd-utils tool commands
1)
Check the Mtdchar character device with CAT/PROC/MTD before using the command, or use ls-l/dev/mtd*
#cat/PROC/MTD
Dev:size erasesize Name
mtd0:00c00000 00020000 "Rootfs"
mtd1:00200000 00020000 "BOOTLOADER"
mtd2:00200000 00020000 "KERNEL"
mtd3:03200000 00020000 "NAND rootfs Partition"
mtd4:04b00000 00020000 "NAND datafs Partition"
To learn more about zoning information with the Mtd_debug command
#mtd_debug INFO/DEV/MTDX (Cannot use Mtdblockx, Mtdblockx is only available for mount)
Mtd.type = Mtd_norflash
Mtd.flags =
Mtd.size = 12582912 (12M)
Mtd.erasesize = 131072 (128K)
Mtd.oobblock = 1
Mtd.oobsize = 0
Mtd.ecctype = (Unknown ECC type-new MTD API maybe?)
Regions = 0


2)
Command: Flash_erase
Role: Erase the specified range of Flash content, if not specified, the default wipe out the first position, so that the corresponding flash into a total of 1
Usage:
Flash_erase Mtd-device [start] [CNT (# Erase blocks)] [lock]
Mtd-device: A partition to be erased, such as a/dev/mtd0
Start: Start position setting, which must be set to Integer times 0x20000 (128K)
CNT: Counting the number of blocks to erase from start
Lock: Write protection
Eg:./flash_erase/dev/mtd0 0x40000 5//Erase 5 pieces of data from 0x40000 on mtd0 partition, 128k/block

Command: Flash_eraseall
Function: Erase the entire partition's data, but also make bad block detection
Usage:
Flash_eraseall [OPTION] Mtd_device
-Q,--quiet does not display print information
-j,--JFFS2 a JFFS2 format partition
Eg:./flash_eraseall-j/dev/mtd0

Command: FLASHCP
Function: Copy data to Flash
Usage:
usage:flashcp [v |--verbose]
flashcp-h | --help
FileName: Data to be written
Device: A written partition, such as/dev/mtd0
eg
FileName production: mkfs.jffs2-e 0x20000-d cq8401-o cq8401.img-n//Here the-e 0x20000 must be more your chip erasesize equal

./flashcp cq8401.img/dev/mtd0//Copy cq8401.img file system to/DEV/MTD0 partition
Of course, the function of this command is similar to that of DD If=/tmp/fs.img of=/dev/mtd0

Command: Nandwrite
Function: Write data to NAND flash
Usage:
Nandwrite [OPTION] Mtd_device Inputfile
-A,--autoplace use Auto OOB layout
-j,--JFFS2 force JFFS2 OOB Layout (Legacy support)
-Y,--yaffs force yaffs OOB Layout (Legacy support)
-F,--forcelegacy force legacy support on autoplacement enabled MTD device
-N,--NOECC write without ECC
-O,--oob image contains OOB data
-S addr,--start=addr set start address (default is 0)
-P,--pad pad to page size
-B,--blockalign=1|2|4 set multiple of eraseblocks to align to
-Q,--quiet don ' t display progress messages
--help Display this Help and exit
--version output version information and exit

Eg:./nandwrite-p/dev/mtd0/tmp/rootfs.jffs2

Command: Nanddump
Role: Dump out NAND flash some information, such as: Block Size,erasesize,oobblock size, OOB data, page data and so on;
Usage:
Nanddump [OPTIONS] Mtd-device
--help Display this Help and exit
--version output version information and exit
-F file--file=file dump to File
-I--ignoreerrors ignore errors
-L Length--length=length length
-O--omitoob omit OOB data
-B--omitbad omit bad blocks from the dump
-P--prettyprint Print Nice (hexdump)
-S addr--startaddress=addr start address
Eg:./nanddump-p-F nandinfo.txt/dev/mtd0//dump out NAND flash/dev/mtd0 data and saved to Nandinfo.txt

Commands: Mtd_debug
Role: For MTD Debugging
Usage:
usage:mtd_debug info 
       Mtd_debug READ&NB Sp  &NBSP
       mtd_debug write    
       Mtd_debug E rase   
Eg:
#./mtd_debug info/dev/mtd0  //Some information on the output/dev/mtd0, you must use MTDX
#./mtd_debug Erase/dev/mtd0 0x0 0x40000  //erases 0x0 from    on the/dev/mtd0 partition, 128k*2 size data
#./mtd_debug write/dev/m Tdblock0 ox0 0x360810 cq8401.img//To MTDBLOCK0 partition, write 3.6M file system cq8401.img, preferably with Mtdblockx
#./mtd_debug read & Nbsp;/dev/mtdblock0 ox0 0x360810 read.img  //read 3.6M data from Mtdblock0 save to read.img
# cmp-l cq8401.img read.img   //Verify that the data in both write to Flash and read from Flash is consistent, or you can use the diff command to compare
It is also not good to test the MTD drive against the NAND flash,mtd_debug tool. It might be better to use both Nandwrite and nanddump tools. You can then use the CMP command to compare the Nanddump data with the data written by Nandwrite.

Command: Ftl_format
Explanation: In order to use one of the conventional file systems (EXT2, ext3, XFS, JFS, FAT) over a MTD device, you need a software l Ayer which emulates a blocks device over the MTD device. These layers are often called Flash translation layers (FTLS).

Example one: How to test NOR flash drive
Step1:
#./mtd_debug info/dev/mtd0//Output some information on the/dev/mtd0, which must be used here MTDX
Step2:
#./mtd_debug erase/dev/mtd0 0x0 0x40000//erase/dev/mtd0 size data from 0x0 on 128k*2 partition
Step3:

#./mtd_debug write/dev/mtdblock0 ox0 0x360810 cq8401.img//To MTDBLOCK0 partition, write 3.6M file system cq8401.img, preferably with Mtdblockx

STEP4:
#./mtd_debug read/dev/mtdblock0 ox0 0x360810 read.img read 3.6M data from Mtdblock0 Save to read.img, of course, the length should be equal

STEP5:
# cmp-l Cq8401.img read.img//Verify that the data in write to Flash and read from Flash are consistent, or you can use the diff command to compare

Example two: How to test NAND flash drive

In fact, the NAND flash driver can also test the use case method, but since there are nandwrite,nanddump commands, why not?


Step1:
#./flash_eraseall-j/DEV/MTD1//Format the partition with JFFS2

Step2:
#./nanddump-p/DEV/MTD1//dump out of NAND flash/dev/mtd1 data, you can see that the current data is all FF

Step3:
#./nandwrite-p/DEV/MTD1 cq8401.img//write Cq8401.img file system to MTD0 partition

STEP4:
#./nanddump-p/DEV/MTD1//dump out NAND flash/dev/mtd1 data, you can see that the data is no longer full FF


Example three: How to use the Mtd-util tool to write to NAND Flash file system jffs2.img, and modify the startup parameters, so that the file system from NAND flash start, assuming that the zone, mtd0 for the file system partition

Mode one:
Step1:
NFS Up file system
#./flash_eraseall-j/dev/mtd0//Format the partition with JFFS2

#./nandwrite-j-f-p-q/dev/mtd0 jffs2.img//write Jffs2.img file system to MTD0 partition

Step2:
Then we'll see if we can mount the newly written JFFS2 file system.

#mount-T Jffs2/dev/mtdblock0/mnt
#ls/mnt

SETP3:
Reboot the Development Board and set the startup parameters in the U-boot
#setenv Bootargs ' mem=64m console=ttys0,115200n8 ip=192.168.4.201:::::eth0:off root=/dev/mtdblock0 ROOTFSTYPE=JFFS2 rw
#reset


Mode two:


NAND up the kernel, NAND file system
1. Web File system
Nerase 0 && Nprog 0 192.168.4.200 n-boot.bin.hg && nprog 128 192.168.4.200 zimage-6pci && Reset
2. Access to the Web file system
Cat/proc/mtd

3. Production of jiffs file system
Mkfs.jffs2-e 0x20000-d Root-vw-o Dvr20000.img-n

4.
CP Dvr20000.img/dev/mtdblock1

5. Modify NAND boot start parameter include/cq8401_board.h
Modify NAND BOOT
Setenv Bootargs ' mem=64m console=ttys0,115200n8 ip=192.168.4.201:::::eth0:off root=/dev/mtdblock1 ROOTFSTYPE=JFFS2 rw

6. New Burn Write
Nerase 0 && Nprog 0 192.168.4.200 n-boot.bin.local && nprog 128 192.168.4.200 Zimage-6pci && re Set

Example four:
How to write A. tar.gz file system to nor or NAND flash
target$ Mkdir/mnt/flash
target$ mount-t Jffs2/dev/mtdblock0/mnt/flash (Mtdblockx is only used for mounting)
target$ Cd/mnt/flash
target$ Tar zxvf rootfs.tar.gz


Vii. Reference Articles
Http://blog.csdn.net/yinkaizhong/archive/2008/12/25/3604794.aspx
Http://hi.baidu.com/qwetiop/blog/item/f2acb50f03e800eaab64577a.html
Http://blog.chinaunix.net/u1/53103/showart_1101011.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.