安裝mtd相關命令
手動安裝mtd-utils,根據系統自行選擇
mtd交叉編譯
:
系統flash操作命令
# cat /proc/mtd
dev: size erasesize name
mtd0: 00080000 00020000 "boot"
mtd1: 00100000 00020000 "kernel"
mtd2: 00580000 00020000 "roofs"
# flash_erase device [start] [cnt]
# flash_erase /dev/mtd0 0×40000 5
start:起始位置。必須為0x20000(128k)的整數倍
cnt:塊數
# flash_eraseall [option] device
# flash_eraseall -j /dev/mtd0
-j,jffs2:jffs2格式化分割槽
-q,quiet:不顯示列印資訊
# flash_eraseall -j -q /dev/mtd0 = flash_erase /dev/mtd0 0 0
新版擦除整個裝置,已建議使用flash_erase
# mount -t jffs2 /dev/mtdblock0 /mnt
掛載mtd裝置。mtdblock只用於掛載,/dev/mtd操作實際就是操作/dev/mtdblock
# flashcp # flashcp fs.jffs2 /dev/mtd0
# mtd_debug info # mtd_debug info /dev/mtd0
mtd.type = mtd_norflash
mtd.flags =
mtd.size = 12582912 (12m)
mtd.erasesize = 131072 (128k)
mtd.oobblock = 1
mtd.oobsize = 0
mtd.ecctype = (unknown ecc type - new mtd api maybe?)
regions = 0
# mtd_debug read /dev/mtd2 0 100 file.dest
uboot flash操作
對nand flash對應mtd分割槽擦除時。擦除要擦除整個裝置大小;寫要寫jffs2檔案系統大小。不然資料可能會有問題,可能原因是jffs2格式寫入位置
# nand erase 0x4100000 0x200000 //擦除整個mtd分割槽2m
# nand write 0x6000000 0x4100000 0x20000 //寫入128k
uboot flash按分割槽操作
> mtd
device nand0 , # parts = 4
#: name size offset mask_flags
0: bootloader 0x00040000 0x00000000 0
1: params 0x00020000 0x00040000 0
2: kernel 0x00200000 0x00060000 0
3: root 0x0fda0000 0x00260000 0
> nand erase root
nand erase: device 0 offset 0x260000, size 0xfda0000
erasing at 0xffe0000 -- 100% complete.
ok> nand write.jffs2 0x3000000 root
nand write: device 0 offset 0x260000, size 0xfda0000
0xfda0000 bytes written: ok
filesize檔案大小
> nand write.jffs2 0x3000000 0x260000 $(filesize)
nand write: device 0 offset 0x260000, size 0x15787a8
writing data at 0x17f8000 -- 100% complete.
22513576 bytes written: ok
舉例
#include #include #include #include "mtd-user.h"
int non_region_erase(int fd, int start, int count, int unlock)
}if(ioctl(fd, memerase, &erase) != 0)
erase.start += meminfo.erasesize;
}printf("done!\n");
}return 0;
}int main(int argc, char *argv)
else
struct stat st;
//check is a char device
ret = fstat(fd, &st);
if(ret < 0)
if(!s_ischr(st.st_mode))
#if 0
ret = non_region_erase(fd, 0, 1, 0);
if(ret < 0)
#endif
char *preadbuf;
int nreadbytes;
nreadbytes = info.erasesize;
preadbuf = malloc(nreadbytes);
memset(preadbuf, 0, nreadbytes);
ret = read(fd, preadbuf, 256);
printf("%s--read %d bytes from mtd\n", __func__, ret);
for(i = 0; i < ret; i++)
printf("\n");
free(preadbuf);
}
詳細操作,參考mtd原始碼mtd_debug.c
jffs2映象製作及掛載
一 用mkfs.jffs2 命令製作jffs2映象檔案 或者使用命令 apt get install mtd utils 命令使用例項 mkfs.jffs2 s 0x1000 e 0x40000 p 0x500000 d rootfs o jffs2.img 說明 頁大小0x1000 4k 塊大小0...
jffs2映象製作和掛載
用mkfs.jffs2 命令製作jffs2映象檔案 或者使用命令 apt get install mtd utils 命令使用例項 mkfs.jffs2 s 0x1000 e 0x40000 p 0x500000 d rootfs o jffs2.img 說明 頁大小0x1000 4k 塊大小0x4...
普通分割槽jffs2掛載
dmesg grep mtdblock kernel command line console tty0 console ttys0,115200 root dev mtdblock2 rootfstype jffs2 init linuxrc mem 64m rwnoinitrd loglevel...