使用 ubi 文件系統掛載 mtd 分區用於做 Flash 的讀寫測試
ubifs
掛載命令
以 mtd8 爲例:
$ flash_eraseall /dev/mtd8 # 也可能你的命令是 `flash_erase /dev/mtd8`
$ ubiattach /dev/ubi_ctrl -m 8 # 和mt8 關聯
####
#### 注意輸出的 log
####
$ ubimkvol /dev/ubi<X> -N <name> -s 100MiB
####
#### 注意 size (應該)小於 mtd 的 size
#### 可以從上面的輸出的 log 看到 available 的 size
#### ubi<X> 從 ubiattach 的輸出確認是 ubi0, 或 ubi1 或 ubi2 ...
####
$ mkdir /mnt/ubi
$ mount -t ubifs ubi<X>_0 /mnt/ubi
####
#### 或 mount -t ubifs ubi<X>:<name> /mnt/ubi
####
$ ###### finish ###########
測試 Flash 腳本示例
#parameter 1 is test type, 1=USB, 2= nand flash
#parameter 2 is write times
#parameter 3 is the directory name of USB, exp: sda1, only used when type is USB.
#
###
### Notes:
### - hard-code:
### 1. 1M of file size used to test
### 2. 12M of Flash size be mounted
### 3. test nand flash: the "ubi1" in "ubimkvol ubi1 ..." command which is the empiric value.
### - require:
### flash_eraseall (Base system > busybox > Miscellaneous Utilities)
###
#!/bin/sh
cd /tmp
rm -rf test.file
umount /tmp/nand/ >/dev/null 2>&1
rm -rf /tmp/nand/
echo "Create 1M file tmp/test.file"
dd if=/dev/zero of=test.file bs=1M count=1 >/dev/null 2>&1
mkdir /tmp/nand
if [ $1 == 1 ];
then
str="/dev/$3"
echo "Mounting..."
mount $str /tmp/nand/ >/dev/null 2>&1
echo y
sleep 3
elif [ $1 == 2 ];
then
flash_eraseall /dev/mtd8
ubiattach /dev/ubi_ctrl -m 8
ubimkvol /dev/ubi1 -N testflash -s 12MiB
echo "Mounting..."
mount -t ubifs ubi1_0 /tmp/nand/
fi
cd /tmp/nand
i=0;
while [ $i -lt $2 ];
do
if [ $1 == 1 ];
then
echo Copy test.file to USB
elif [ $1 == 2 ];
then
echo Copy test.file to Nand Flash
fi
start=`date +%s`
cp /tmp/test.file test.file
end=`date +%s`
echo ` ls -l test.file | awk '{print $5}'` bytes copied using $(($end-$start)) seconds
echo Sleep 2 seconds
sleep 2
echo Delete /tmp/test.file
rm /tmp/test.file
if [ $1 == 1 ];
then
echo Copy test.file from USB
elif [ $1 == 2 ];
then
echo Copy test.file from Nand Flash
fi
cp test.file /tmp/test.file
echo Compute md5sum value for /tmp/test.file
md5sum /tmp/test.file
let i+=1
done
rm test.file
cd /tmp
umount /tmp/nand/
rm -rf /tmp/nand/
rm -rf test.file
測試腳本使用 example:
# TestFlash.sh 2 10
####
#### 測試 Flash(mtd8)10 次讀寫,用眼檢查輸出的 checksum 是否相同。
####
以 jffs2 文件系統掛載
問題
提示擦除塊相關錯誤的
經過上一步之後還是遇到點問題, 錯誤可能如下:
# mount -t jffs2 /dev/mtdblock7 /var/dr_bin/
jffs2: Too few erase blocks (1)
mount: mounting /dev/mtdblock7 on /var/dr_bin/ failed: Invalid argument
也可能如下:
# mount -t jffs2 /dev/mtdblock5 /var/dr_bin/
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00000000: 0xe58c instead
...
jffs2: jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at
這是由於該分區塊上以前有殘留數據,不是全0xFF導致,需要手動擦除該塊。
解決辦法:
dd命令生成一個全FF的文件,大小和分區大小一致,然後tftp到板子,再cat這個文件重定向到該分區即可。
例如 cat 512KFF > /dev/mtdblock5
Reference: 掛載jffs2文件系統遇到的問題
未測試是否有效。