1,源码下载
git clone https://gitee.com/mirrors/mtd-utils.git
代码链接:
https://git.infradead.org/mtd-utils.git,
2, 功能移植:
(1)下载安装前提,安装
test@test-virtual-machine:~$ sudo apt-get install build-essential libacl1-dev liblzo2-dev uuid-dev
test@test-virtual-machine:~/mtd-utils$ sudo apt install autoconf
test@test-virtual-machine:~/mtd-utils$ sudo apt install pkg-config
test@test-virtual-machine:~$ sudo apt-get update
test@test-virtual-machine:~$ sudo apt-get upgrade
(2)代码下载安装
test@test-virtual-machine:~$ git clone git://git.infradead.org/mtd-utils.git
安装流程,查看readme.txt
How to build
mtd-utils uses an autotools based build system. If you are building the git
tree, you first need to run `./autogen.sh`. This sets up the build system
and requires autoconf, automake and possibly other autotools to be installed.
After unpacking a tarball (or running autogen.sh) simply run:
$ ./configure
$ make
to build the package. This does not require autotools to be installed, but
does need pkg-config, make, etc...
There are a number of configure switches to tune the build.
Run `./configure --help` to get an overview.
For compiling mtd-utils, you need development packages for the following
dependency libraries:
zlib (optional dependency for mkfs.ubifs, mkfs.jffs2)
lzo2 (optional dependency for mkfs.ubifs, mkfs.jffs2)
zstd (optional dependency for mkfs.ubifs)
libuuid* (required by mkfs.ubifs)
libselinux (optional dependency for mkfs.ubifs)
openssl (optional dependency for mkfs.ubifs)
(1) ./autogen.sh
test@test-virtual-machine:~/mtd-utils$ ./autogen.sh
configure.ac:17: installing './compile'
configure.ac:172: installing './config.guess'
configure.ac:172: installing './config.sub'
configure.ac:15: installing './install-sh'
configure.ac:15: installing './missing'
Makefile.am: installing './depcomp'
parallel-tests: installing './test-driver'
(2)./configure
test@test-virtual-machine:~/mtd-utils$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
。。。
onfig.status: creating tests/ubifs_tools-tests/mkfs_tests/build_fs_from_dir.sh
config.status: creating Makefile
config.status: creating include/config.h
config.status: executing depfiles commands
mtd-utils 2.3.0
prefix: /usr/local
exec prefix: ${prefix}
runstatedir: ${localstatedir}/run
bindir: ${exec_prefix}/bin
sbindir: ${exec_prefix}/sbin
libdir: ${exec_prefix}/lib
includedir: ${prefix}/include
compiler: gcc
cflags: -g -O2
ldflags:
asan debug: no
lzo support: yes
zlib support: no
zstd support: no
xattr/acl support: yes
SELinux support: no
fscrypt support: no
Test programs: yes
Unit tests: no
ubihealthd: yes
lsmtd: yes
jffs2 utils: yes
ubifs utils: yes
warnings:
-Wall -Wextra -Wunused -Wmissing-prototypes -Wmissing-declarations -Wwrite-strings -Wjump-misses-init -Wuninitialized -Winit-self -Wlogical-op -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-parameter -Wunused-result -Wunused-variable -Wduplicated-cond -Wduplicated-branches -Wrestrict -Wnull-dereference -Wno-shadow -Wno-sign-compare
Type 'make' or 'make <utilname>' to compile.
(3)make
test@test-virtual-machine:~/mtd-utils$ make
CC lib/libmtd.o
CC lib/libfec.o
CC lib/common.o
CC lib/list_sort.o
CC lib/rbtree.o
CC lib/libcrc32.o
CC lib/libmtd_legacy.o
AR libmtd.a
CC tests/mtd-tests/nandbiterrs-nandbiterrs.o
CCLD nandbiterrs
CC tests/mtd-tests/flash_readtest-flash_readtest.o
CCLD flash_readtest
CC tests/mtd-tests/nandpagetest-nandpagetest.o
CCLD nandpagetest
CC tests/mtd-tests/nandsubpagetest-nandsubpagetest.o
CCLD nandsubpagetest
编译后生成的工具
test@test-virtual-machine:~/mtd-utils$ ls
aclocal.m4 configure.ac flash_otp_lock ftrunc jffs2reader make_a_release.sh mtd0_dump_nanddump.bin nandwrite rfdformat test_2 ubinize
autogen.sh COPYING flash_otp_write fwrite00 jffsX-utils Makefile mtd_debug nftldump rmdir00 test-driver ubirename
autom4te.cache depcomp flash_readtest gcd_hupper JitterTest Makefile.am mtdinfo nftl_format rndrm00 tests ubirmvol
cat.bin docfdisk flash_speed include lib Makefile.in mtdpart nor-utils rndrm99 ubiattach ubirsvol
CHANGELOG.md doc_loadbios flash_stress install-sh libiniparser.a makefiles nandbiterrs orph rndwrite00 ubiblock ubiscan
checkfs fectest flash_torture integ libmissing.a misc-utils nanddump pdfrun rsvol ubicrc32 ubiupdatevol
compile flashcp flash_unlock integck libmtd.a missing nanddump.bin perf serve_image ubidetach ubi-utils
config.guess flash_erase free_space io_basic libscan.a mkfs.jffs2 nandflipbits plotJittervsFill stress_1 ubiformat volrefcnt
config.log flash_lock fsck.ubifs io_paral libubi.a mkfs.ubifs nandpagetest read_data.bin stress_2 ubifs-utils
config.status flash_otp_dump fstest_monitor io_read libubigen.a mkvol_bad nandsubpagetest README.txt stress_3 ubihealthd
config.sub flash_otp_erase ftl_check io_update lsmtd mkvol_basic nandtest recv_image sumtool ubimkvol
configure flash_otp_info ftl_format jffs2dump m4 mkvol_paral nand-utils rfddump test_1 ubinfo
(4)sudo make install
test@test-virtual-machine:~/mtd-utils$ sudo make install
make[1]: 进入目录"/home/tt/mtd-utils"
/bin/mkdir -p '/usr/local/sbin'
/usr/bin/install -c ubifs-utils/mount.ubifs '/usr/local/sbin'
/bin/mkdir -p '/usr/local/sbin'
/usr/bin/install -c ubiupdatevol ubimkvol ubirmvol ubicrc32 ubinfo ubiattach ubidetach ubinize ubiformat ubirename mtdinfo ubirsvol ubiblock ubiscan ubihealthd ftl_format doc_loadbios ftl_check mtd_debug docfdisk serve_image recv_image fectest flash_erase flash_lock flash_unlock flash_otp_info flash_otp_dump flash_otp_lock flash_otp_erase flash_otp_write flashcp mtdpart lsmtd nanddump nandwrite nandtest nftldump nftl_format nandflipbits rfddump rfdformat mkfs.ubifs fsck.ubifs mkfs.jffs2 jffs2dump jffs2reader sumtool '/usr/local/sbin'
/bin/mkdir -p '/usr/local/sbin'
/bin/mkdir -p '/usr/local/libexec/mtd-utils'
/usr/bin/install -c io_basic io_update io_paral io_read volrefcnt integ mkvol_basic mkvol_bad mkvol_paral rsvol JitterTest plotJittervsFill makefiles checkfs integck test_1 test_2 ftrunc perf orph stress_1 stress_2 stress_3 pdfrun gcd_hupper rndwrite00 fwrite00 rmdir00 rndrm00 rndrm99 fstest_monitor free_space flash_torture flash_stress flash_speed nandbiterrs flash_readtest nandpagetest nandsubpagetest '/usr/local/libexec/mtd-utils'
/bin/mkdir -p '/usr/local/libexec/mtd-utils'
/usr/bin/install -c nand-utils/load_nandsim.sh tests/ubi-tests/runubitests.sh tests/ubi-tests/ubi-stress-test.sh tests/jittertest/filljffs2.sh tests/fs-tests/fs_help_all.sh tests/fs-tests/fs_run_all.sh tests/fs-tests/stress/fs_stress00.sh tests/fs-tests/stress/fs_stress01.sh tests/ubifs_tools-tests/lib/common.sh tests/ubifs_tools-tests/ubifs_tools_run_all.sh tests/ubifs_tools-tests/fsck_tests/authentication_refuse.sh tests/ubifs_tools-tests/fsck_tests/cycle_mount_fsck_check.sh tests/ubifs_tools-tests/fsck_tests/powercut_fsck_mount.sh tests/ubifs_tools-tests/fsck_tests/cycle_corrupted_fsck_fault_inject.sh tests/ubifs_tools-tests/fsck_tests/cycle_powercut_mount_fsck.sh tests/ubifs_tools-tests/fsck_tests/random_corrupted_fsck.sh tests/ubifs_tools-tests/fsck_tests/fsck_bad_image.sh tests/ubifs_tools-tests/mkfs_tests/build_fs_from_dir.sh '/usr/local/libexec/mtd-utils'
make[1]: 离开目录"/home/tt/mtd-utils"
测试mtd是否可以正常使用。
test@test-virtual-machine:~/mtd-utils$ mtdinfo
mtdinfo: error!: MTD is not present in the systemtt@tt-virtual-machine:~/mtd-utils$ mtd
mtd_debug mtdinfo mtdpart
tt@tt-virtual-machine:~/mtd-utils$ mtd_debug
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>
手动添加分区测试
test@testvirtual-machine:~/mtd-utils sudo modprobe mtdram total_size=16384 erase_size=2048 test@test-virtual-machine:\~/mtd-utils mtdinfo /dev/mtd0
mtd0
Name: mtdram test device
Type: ram
Eraseblock size: 2097152 bytes, 2.0 MiB
Amount of eraseblocks: 8 (16777216 bytes, 16.0 MiB)
Minimum input/output unit size: 1 byte
Sub-page size: 1 byte
Character device major/minor: 90:0
Bad blocks are allowed: false
Device is writable: true
(1)测试 mtd_debug
test@test-virtual-machine:~/mtd-utils sudo mtd_debug read /dev/mtd0 0 16384 read_data.bin test@test-virtual-machine:\~/mtd-utils sudo nanddump /dev/mtd0 --forcebinary > nanddump.bin
test@test-virtual-machine:~/mtd-utils$ sudo cat/dev/mtd0 > cat.bintest@test-virtual-machine:~/mtd-utils$ diff nanddump.bin cat.bin
上面的bin文件是一样的。
(2)flashcp
tt@tt-virtual-machine:~/mtd-utils$ flash
flashcp flash_lock flash_otp_info flash_unlock
flash_erase flash_otp_dump flash_otp_lock
flash_eraseall flash_otp_erase flash_otp_write
tt@tt-virtual-machine:~/mtd-utils$ flashcp -v
Flash Copy - Written by Abraham van der Merwe <abraham@2d3d.co.za>
usage: flashcp [ -v | --verbose | -A | --erase-all ] <filename> <device>
flashcp -h | --help
flashcp -V | --version
-h | --help Show this help message
-v | --verbose Show progress reports
-p | --partition Only copy different block from file to device
-A | --erase-all Erases the whole device regardless of the image size
-l | --wr-last=bytes Write the first [bytes] last
-V | --version Show version information and exit
<filename> File which you want to copy to flash
<device> Flash device node or 'mtd:<name>' to write to (e.g. /dev/mtd0, /dev/mtd1, mtd:data, etc.)
(3)jffs2测试
tt@tt-virtual-machine:~/mtd-utils$ jffs2dump
Usage: jffs2dump [OPTION]... INPUTFILE
Dump the contents of a binary JFFS2 image.
-h, --help display this help and exit
-V, --version display version information and exit
-b, --bigendian image is big endian
-l, --littleendian image is little endian
-c, --content dump image contents
-e, --endianconvert=FNAME convert image endianness, output to file fname
-r, --recalccrc recalc name and data crc on endian conversion
-d, --datsize=LEN size of data chunks, when oob data in binary image (NAND only)
-o, --oobsize=LEN size of oob data chunk in binary image (NAND only)
-v, --verbose verbose output
(4)ubi测试
tt@tt-virtual-machine:~/mtd-utils$ mkfs.ubifs -h
Usage: mkfs.ubifs [OPTIONS] target
Make a UBIFS file system image from an existing directory tree
Examples:
Build file system from directory /opt/img, writing the result in the ubifs.img file
mkfs.ubifs -m 512 -e 128KiB -c 100 -r /opt/img ubifs.img
The same, but writing directly to an UBI volume
mkfs.ubifs -r /opt/img /dev/ubi0_0
Creating an empty UBIFS filesystem on an UBI volume
mkfs.ubifs /dev/ubi0_0
(5) mkfis
test@test-virtual-machine:~/mtd-utils$ mkfs
mkfs mkfs.bfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.fat mkfs.jffs2 mkfs.minix mkfs.msdos mkfs.ntfs mkfs.ubifs mkfs.vfat
(6) dd 指令写数据到文件的分区测试。