2018年12月3日 星期一

使用linux的MTD tests support測試flash性能

Source  https://blog.csdn.net/gp_scoprius/article/details/53257056


在嵌入式linux開發過程中,經常會使用到nor flashnand flash等存放裝置,由於flash的晶片型號和介面類別型較多,性能不一,我們需要對系統中使用的flash性能進行分析,並對設備工作的穩定性進行測試。
flash設備在嵌入式系統中,會被驅動為MTD分區,在linux kernel中,提供了針對MTD的測試模組,方面開發人員對flash的功能,性能,穩定性等進行測試。
使用make ARCH=arm  menuconfig打開kernel配置介面,配置 "Device Drivers" -> "Memory Technology Device (MTD) support" -> "MTD tests support",該選項只可以配置為按模組編譯,保存配置後退出。
使用make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules編譯代碼,生成測試工具模組,存儲在目錄drivers/mtd/tests中,包括以下內容:
mtd_nandecctest.konand flashECC校驗測試
mtd_pagetest.konand flashpage讀寫測試
mtd_speedtest.koMTD分區的讀寫速度測試
mtd_subpagetest.konand flashsub-page介面測試
mtd_oobtest.konand falshOOB區域讀寫測試
mtd_readtest.ko:讀取整個MTD分區
mtd_stresstest.ko:隨機讀寫,擦除操作測試
mtd_torturetest.ko:該功能可用於做穩定性或者壽命測試,隨機操作直到發生錯誤

在即時ko檔進行測試時,可以通過dev=n指定要測試的MTD分區,示例如下:
insmod mtd_stresstest.ko dev=9 count=1000
[ 3289.273771] =================================================
[ 3289.279826] mtd_stresstest: MTD device: 9
[ 3289.284079] mtd_stresstest: MTD device size 268435456, eraseblock size 131072, page size 2048, count of eraseblocks 2048, pages per eraseblock 64, OOB size 64
[ 3289.303250] mtd_stresstest: scanning for bad eraseblocks
[ 3289.420267] mtd_stresstest: scanned 2048 eraseblocks, 0 are bad
[ 3289.426534] mtd_stresstest: doing operations
[ 3289.431031] mtd_stresstest: 0 operations done
[ 3339.606972] mtd_stresstest: finished, 1000 operations done
[ 3339.612992] =================================================
mtd_stresstest測試發生操作錯誤時,會退出並答應錯誤資訊,示例如下:
[root@AT8XXX ~]# dmesg |grep mtd_stresstest
[591404.676252] mtd_stresstest: MTD device: 9
[591404.680577] mtd_stresstest: MTD device size 268435456, eraseblock size 131072, page size 2048, count of eraseblocks 2048, pages per eraseblock 64, OOB size 64
[591404.699798] mtd_stresstest: scanning for bad eraseblocks
[591404.715081] mtd_stresstest: block 78 is bad
[591404.723850] mtd_stresstest: block 159 is bad
[591404.812382] mtd_stresstest: block 1752 is bad
[591404.832925] mtd_stresstest: scanned 2048 eraseblocks, 3 are bad
[591404.839259] mtd_stresstest: doing operations
[591404.843859] mtd_stresstest: 0 operations done
[591459.037353] mtd_stresstest: 1024 operations done
[591510.529876] mtd_stresstest: 2048 operations done

[594847.430017] mtd_stresstest: error: write failed at 0xf964000
[594847.436350] mtd_stresstest: error -5 occurred


Source https://www.crifan.com/the_new_linux_kernel_of_the_mtd_test_into_the_old_kernel_in/

將新的Linux kernel中的MTD test加入到舊的kernel中


Linux Kernel自從2.6.29之後,就加入了MTD test模組,即幾個測試模組,用於測試你的mtd的特性。

分別是:
mtd_oobtest.c //測試oob資料讀寫是否正常
mtd_pagetest.c //測試page讀寫
mtd_readtest.c //測試讀功能
mtd_speedtest.c //測試mtd的速度
mtd_stresstest.c //壓力測試
mtd_subpagetest.c //子頁面(如果支援的話,此處我的是MLC,不支援sub page
mtd_torturetest.c //扭曲測試? 反正就是對mtd“嚴刑拷打”,看看其能經受多少讀寫,直至掛掉。。,所以,作者說了,除非你知道自己在幹啥,否則不要隨意進行這個測試。
其中,最有用的就是speed test了,方便了開發者用來測試你的mtd(我的此處是nand flash)的讀//擦除塊的速度。
我當前用的Linux kernel2.6.28.4,沒有加入MTD test,所以自己加入:
1)下載mtd tests源碼,並加入到自己的內核中,編譯成.ko模組用於後期動態載入:
我這裡是從最新內核linux-2.6.32.8
中的/drivers/mtd/test裡面抽取的,然後放到自己的kernel源碼中:
/drivers/mtd/test,再把
config MTD_TESTS
tristate "MTD tests support"
depends on m
help
This option includes various MTD tests into compilation. The tests
should normally be compiled as kernel modules. The modules perform
various checks and verifications when loaded.
加入到Kconfig中,把
obj-y   += tests/
加入到Makefile中。然後make ARCH=arm menuconfig,去把mtd test選上:
Device Drivers >
<*> Memory Technology Device (MTD) support >
   MTD tests support
再編譯一下:
make ARCH=arm; make ARCH=arm uImage
就可以生成對應的.ko模組檔了。
2.如何使用MTD test
進入Kernel後,使用也很簡單
比如:insmod mtd_speedtest.ko dev=3
:此處的dev指的是你mtd設備number,我這裡的:
# cat /proc/mtd
dev:    size   erasesize name
mtd0: 00100000 00080000 "U-Boot"
mtd1: 00800000 00080000 "Kernel"
mtd2: 0c800000 00080000 "Root filesystem"
mtd3: 04000000 00080000 "Temp"
mtd4: 69000000 00080000 "Data"
dev=3,就是mtd3,就是上面的Temp分區。
3)舉例如何使用:
最後列舉一些測試結果如下:
# ls
mtd_oobtest.ko          mtd_readtest.ko         mtd_subpagetest.ko
mtd_speedtest.ko        mtd_torturetest.ko
mtd_pagetest.ko         mtd_stresstest.ko
# insmod mtd_speedtest.ko dev=3
=================================================
mtd_speedtest: MTD device: 3
mtd_speedtest: MTD device size 67108864, eraseblock size 524288, page size 4096, count of eraseblocks 128, pages per eraseblock 128, OOB size 128
mtd_speedtest: scanning for bad eraseblocks
mtd_speedtest: scanned 128 eraseblocks, 0 are bad
mtd_speedtest: testing eraseblock write speed
mtd_speedtest: eraseblock write speed is 1754 KiB/s
mtd_speedtest: testing eraseblock read speed
mtd_speedtest: eraseblock read speed is 2443 KiB/s
mtd_speedtest: testing page write speed
mtd_speedtest: page write speed is 1748 KiB/s
mtd_speedtest: testing page read speed
mtd_speedtest: page read speed is 2439 KiB/s
mtd_speedtest: testing 2 page write speed
mtd_speedtest: 2 page write speed is 1751 KiB/s
mtd_speedtest: testing 2 page read speed
mtd_speedtest: 2 page read speed is 2440 KiB/s
mtd_speedtest: Testing erase speed
mtd_speedtest: erase speed is 439838 KiB/s
mtd_speedtest: finished
=================================================
# insmod mtd_oobtest.ko dev=3
=================================================
mtd_oobtest: MTD device: 3
mtd_oobtest: MTD device size 67108864, eraseblock size 524288, page size 4096, count of eraseblocks 128, pages per eraseblock 128, OOB size 128
mtd_oobtest: scanning for bad eraseblocks
mtd_oobtest: scanned 128 eraseblocks, 0 are bad
mtd_oobtest: test 1 of 5
mtd_oobtest: erasing whole device
mtd_oobtest: erased 128 eraseblocks
mtd_oobtest: writing OOBs of whole device
mtd_oobtest: written up to eraseblock 0
mtd_oobtest: written 128 eraseblocks
mtd_oobtest: verifying all eraseblocks
mtd_oobtest: verified up to eraseblock 0
mtd_oobtest: verified 128 eraseblocks
mtd_oobtest: test 2 of 5
mtd_oobtest: erasing whole device
mtd_oobtest: erased 128 eraseblocks
mtd_oobtest: writing OOBs of whole device
mtd_oobtest: written up to eraseblock 0
mtd_oobtest: written 128 eraseblocks
mtd_oobtest: verifying all eraseblocks
mtd_oobtest: verified up to eraseblock 0
mtd_oobtest: verified 128 eraseblocks
mtd_oobtest: test 3 of 5
mtd_oobtest: erasing whole device
mtd_oobtest: erased 128 eraseblocks
mtd_oobtest: writing OOBs of whole device
mtd_oobtest: written up to eraseblock 0
mtd_oobtest: written 128 eraseblocks
mtd_oobtest: verifying all eraseblocks
mtd_oobtest: verified up to eraseblock 0
mtd_oobtest: verified 128 eraseblocks
mtd_oobtest: test 4 of 5
mtd_oobtest: erasing whole device
mtd_oobtest: erased 128 eraseblocks
mtd_oobtest: attempting to start write past end of OOB
mtd_oobtest: an error is expected
mtd_oobtest: error occurred as expected
mtd_oobtest: attempting to start read past end of OOB
mtd_oobtest: an error is expected
mtd_oobtest: error occurred as expected
mtd_oobtest: attempting to write past end of device
mtd_oobtest: an error is expected
mtd_oobtest: error occurred as expected
mtd_oobtest: attempting to read past end of device
mtd_oobtest: an error is expected
mtd_oobtest: error: read past end of device
mtd_oobtest: attempting to write past end of device
mtd_oobtest: an error is expected
mtd_oobtest: error occurred as expected
mtd_oobtest: attempting to read past end of device
mtd_oobtest: an error is expected
mtd_oobtest: error: read past end of device
mtd_oobtest: test 5 of 5
mtd_oobtest: erasing whole device
mtd_oobtest: erased 128 eraseblocks
mtd_oobtest: writing OOBs of whole device
mtd_oobtest: written up to eraseblock 0
mtd_oobtest: written up to eraseblock 0
mtd_oobtest: written 127 eraseblocks
mtd_oobtest: verifying all eraseblocks
mtd_oobtest: verified up to eraseblock 0
mtd_oobtest: verified 127 eraseblocks
mtd_oobtest: finished with 2 errors
=================================================
[附錄]
1.MTD tests
http://www.linux-mtd.infradead.org/doc/general.html


沒有留言: