Porting MTD-utils toolkit-tutorial
For MTD-utils transplantation, cross-compilation is performed on the Ubuntu server 10.04 platform and transplanted to embedded Linux. The correct steps for cross-compilation are as follows, it is not guaranteed to run properly in other environments. The following is the compiling environment:
Build: Ubuntu server 10.04
HOST: Linux version 2.6.32.15-15-sigma
Cross Compiler: MIPS-Linux-GNU-GCC version: 4.3.2
CPU: MIPS
Cross-compile MTD-utils, dependency (zlib, lzo );
Download open sources:
Mtd-utils-1.0.0.tar.gz (Address: ftp://ftp.infradead.org/pub/mtd-utils)
Zlib-1.2.3.tar.gz
Lzo-2.03.tar.gz
Building zlib-1.2.3.tar.gz:
Tar zxvf zlib-1.2.3.tar.gz
CD zlib-1.2.3/
Cc = "MIPS-Linux-GNU-gcc-El"./configure -- shared -- prefix =/home/gzshun/zlib/(dynamic library *. So)
Cc = "MIPS-Linux-GNU-gcc-El"./configure -- prefix =/home/gzshun/zlib/(static library *.)
Make
Make install
Building lzo-2.03.tar.gz:
Tar zxvf lzo-2.03.tar.gz
CD lzo-2.03/
./Configure -- Host = MIPS-Linux-GNU cc = "MIPS-Linux-GNU-gcc-El" -- prefix =/home/gzshun/lzo/
Make
Make install
Copy the header files in the installation directory include of the above two open-source packages to the corresponding include directory of the MIPs cross compiler.
My environment: CP-A/home/gzshun/zlib/include/*/home/gzshun/lzo/include/*/usr/local/src/mips-4.3/MIPS-Linux-GNU/libc/ usr/include/
Building mtd-utils-1.0.0.tar.gz:
Tar zxvf mtd-utils-1.0.0.tar.gz
CD mtd-utils-1.0.0/
Dynamic Compilation:
VI makefile
The modification content is as follows:
9 cross = MIPS-Linux-GNU-
10 cc: = $ (Cross) GCC-El
42 mkfs. jffs2: crc32.o compr_rtime.o mkfs. jffs2.o compr_zlib.o compr. o
43 $ (CC) $ (ldflags)-o $ @ $ ^/home/gzshun/zlib/lib/libz. So #-LZ
48 jffs2reader: jffs2reader. o
49 $ (CC) $ (ldflags)-o $ @ $ ^/home/gzshun/zlib/lib/libz. So #-LZ
57 install_dir =/home/gzshun/MTD-utils
58
59 install: $ {targets}
60 mkdir-p $ {install_dir}/sbin
61 install-m0755 $ {targets }$ {install_dir}/sbin
62 mkdir-p ${install_dir}/man/Man1
63 gzip-C mkfs. jffs2.1 >$ {install_dir}/man/Man1/mkfs.jffs2.1.gz
Save and exit
Static Compilation:
VI makefile
The modification content is as follows:
9 cross = MIPS-Linux-GNU-
10 cc: = $ (Cross) GCC-El
12 ldflags: =-static
25 $ (CC) $ (ldflags)-g-o $ @ $ ^
43 mkfs. jffs2: crc32.o compr_rtime.o mkfs. jffs2.o compr_zlib.o compr. o
44 $ (CC) $ (ldflags)-o $ @ $ ^/home/gzshun/zlib/lib/libz. A #-LZ
45
46 flash_eraseall: crc32.o flash_eraseall.o
47 $ (CC) $ (ldflags)-o $ @ $ ^
48
49 jffs2reader: jffs2reader. o
50 $ (CC) $ (ldflags)-o $ @ $ ^/home/gzshun/zlib/lib/libz. A #-LZ
58 install_dir =/home/gzshun/Others/MTD-utils
59
60 install :$ {targets}
61 mkdir-p $ {install_dir}/sbin
62 install-m0755 $ {targets }$ {install_dir}/sbin
63 mkdir-p ${install_dir}/man/Man1
64 gzip-C mkfs. jffs2.1 >$ {install_dir}/man/Man1/mkfs.jffs2.1.gz
Save and exit
Make
Make install
Install the MTD-utils command in the/home/gzshun/MTD-utils/sbin/directory.
Because cross-Compilation of open-source software packages does not involve specific difficulties, it is not explained one by one. Only the compilation steps are provided.
========================================================
The following article is reproduced on the Internet. If you have any questions about copyright infringement, please notify me. Delete now
Use of MTD-utils Toolkit (reproduced ):
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/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 ).