Port mtdutils to tx2440

Source: Internet
Author: User

Based on this article, I have successfully transplanted the MTD-utils tool to tx2440, And the cross compiler tool is 4.1.3.

MTD-utils tool compilation and use () classification:
Nand, yaffs2, jffs2, etc.

1. Download and decompress the source code package
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. Compile and install zlib
1)
Root @:/home/# zlib-1.2.3 CD
Cc = mipsel-Linux-GCC./configure -- prefix =/home/local/MIPS/zlib/-- shared

(Note: The/home/local/MIPS/zlib/here is a large directory to be installed in the zlib library. You can set it to a large directory. Remember this directory. Otherwise, you will not be able to find the zlib library .)

2)
Make
Make install

3)
After the installation is complete, three directories are generated under the/home/local/MIPS/zlib/directory: Include, Lib, and share.
Check the directory/home/local/MIPS/zlib/after installation/
If zlib. header files such as H, without libz in Lib. so.1.2.3, copy them to these directories manually, and remember to copy all *. h must be copied. Use CP-Ca libz to copy the database. */.... /Lib. Use the-Ca option.

Iii. Compile and install lzo
1)
Root @:/home/# lzo-2.03/CD/
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-compile MTD-utils
1)
Modify makefile
Cross = mipsel-Linux-

2)
Make

3)
Check whether the mtd-utils-1.0.0 directory has generated the big tools we need (flashcp, nandwrite ).
A tool is generated, OK, and cross-compilation is successful.

4)
Copy the generated Tool to the root file system of the file system development board and store it in/bin or/sbin. Compile the kernel and then pull it.

5. Supplement
If the cross-compiler is 4.3.x or above and the compilation fails, see

Http://www.mail-archive.com/ptxdist@pengutronix.de/msg01067.html

Http://patchwork.ozlabs.org/patch/12689/

Patch

Vi. MTD-utils tool command usage
1)
Run CAT/proc/MTD to check the mtdchar device, or use LS-L/dev/MTD *
# Cat/proc/MTD
Dev: Size erasesize name
Mtd0: 00c0000000020000 "rootfs"
Mtd1: 00200000 00020000 "bootloader"
Mtd2: 00200000 00020000 "kernel"
Mtd3: 03200000 00020000 "NAND rootfs partition"
Mtd4: 04b0000000020000 "NAND datafs partition"

Use mtd_debug command to learn more about partition information
# Mtd_debug info/dev/mtdx (mtdblockx cannot be used, and mtdblockx is only available for mounting)
MTD. type = mtd_norflash
MTD. Flags =
MTD. size = 12582912 (12 m)
MTD. erasesize = 131072 (128 K)
MTD. oobblock = 1
MTD. oobsize = 0
MTD. ecctype = (unknown ECC type-New mtd api maybe ?)
Regions = 0

2)
Command: flash_erase
Purpose: erase the Flash content within the specified range. If not specified, the first block at the starting position is erased by default to make the Flash Content 1
Usage:
Flash_erase MTD-device [start] [CNT (# erase blocks)] [lock]
MTD-device: the partition to be erased, such as/dev/mtd0.
Start: Set the start position, which must be an integer multiple of 0x20000 (128 K ).
CNT: The number of blocks to be erased starting from start.
Lock: Write Protection
Eg:./flash_erase/dev/mtd0 0x40000 5 // erase 5 pieces of data starting from 0x40000 on the mtd0 partition, 128 K/block

Command: flash_eraseall
Purpose: erase the data of the entire partition and perform bad block detection.
Usage:
Flash_eraseall [Option] mtd_device

-Q, -- Quiet does not display printed information
-J, -- jffs2-jffs2 format Partition

Eg:./flash_eraseall-J/dev/mtd0

Command: flashcp
Role: Copy Data to flash
Usage:
Usage: flashcp [-v | -- verbose] <FILENAME> <device>
Flashcp-H | -- Help

Filename: data to be written
Device: Write partition, such as/dev/mtd0

Eg:
Filename: mkfs. jffs2-E 0x20000-D cq8401-O cq8401.img-N // here-E 0x20000 must be equal to the erasesize of your chip
 
./Flashcp cq8401.img/dev/mtd0 // copy cq8401.img File System to/dev/mtd0 Partition
Of course, the function of this command is similar to dd If =/tmp/fs. IMG of =/dev/mtd0.

Command: nandwrite
Purpose: 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 to page size
-B, -- blockalign = 1 | 2 | 4 set multiple of eraseblocks to align
-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
Function: dump out some information about NAND Flash, such as block size, erasesize, oobblock size, OOB data, and page data. It also performs bad block detection.
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 the NAND Flash/dev/mtd0 data and save it to nandinfo.txt

Command: mtd_debug
Role: MTD debugging
Usage:
Usage: mtd_debug info <device>
Mtd_debug read <device> <OFFSET> <Len> <DEST-FILENAME>
Mtd_debug write <device> <OFFSET> <Len> <source-FILENAME>
Mtd_debug erase <device> <OFFSET> <Len>

Eg:
#./Mtd_debug info/dev/mtd0 // output some information on/dev/mtd0. mtdx must be used here
#./Mtd_debug Erase/dev/mtd0 0x0x40000 // erase data of 128 K x 2 size starting from 0x0 on the/dev/mtd0 Partition
#./Mtd_debug write/dev/mtdblock0 ox0 0x360810 cq8401.img // partition mtdblock0 and write a 3.6 m file system cq8401.img. mtdblockx is recommended.
#./Mtd_debug read/dev/mtdblock0 ox0 0x360810 read. IMG // read 3.6 m data from mtdblock0 and save it to read. img
# CMP-l cq8401.img read. IMG // verify whether the data in write to flash and read from flash is consistent. You can also use the diff command to compare

In addition, for NAND Flash, mtd_debug is not a good tool to test the MTD driver. It may be better to use nandwrite and nanddump. Then we can use the CMP command to compare whether the data written by nanddump is consistent with that written by nandwrite.

Command: ftl_format
Explanation: In order to use one of conventional file systems (ext2, ext3, XFS, JFS, fat) over an MTD device, you need a software layer which emulates a block device over the MTD device. these layers are often called Flash Translation layers (FTLs ).

VII. References

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.