linux下擦除 寫入flash的簡單程式設計參考

2021-06-09 11:27:33 字數 2158 閱讀 7139

linux下對dataflash裝置操作(擦除、寫入檔案)的應用程式,注意,所有的操作必須要使用mtdx的字元裝置。

mtdchar的字元裝置驅動程式設計參考!

來自:#include

#include

#include

#include

#include

#include

#include

#include

#include

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)

cmd=argv[1];

if (argc > 3)

// open and size the device

if ((fd = open(argv[2],o_rdwr)) < 0)

else

if (ioctl(fd,memgetregioncount,®count) == 0)

/*erase the device*/

if (strcmp(cmd, "erase") == 0)

printf("erase!/n");

}/*write file to this device*/

if (strcmp(cmd, "write") == 0)

else

readlen=info.writesize;

write_buf=malloc(readlen);

if(write_buf==null)

else

printf("write buf is ok!/n");

imglen1=imglen;

while(imglen)

}if((write_cnt=write(fd,write_buf,readlen))!=readlen)

else

printf("/rwrite mtd device ok!startaddr=%d",(imglen1-imglen));

imglen-=cnt;

}printf("/n");

return 0;

}if (strcmp(cmd, "read") == 0)

return 1;

}命令格式:

擦除命令:

dataflash_ioctl erase /dev/mtd6 

info.size=1968384

info.erasesize=528

info.writesize=528

info.oobsize=0                         

regcount=0

performing flash erase of length 528 at offset 0x1e06f0 done

erase!

寫入檔案命令:

dataflash_ioctl write /dev/mtd6 /modules/uimage2.6.21 

info.size=1968384

info.erasesize=528

info.writesize=528

info.oobsize=0                         

regcount=0

write!

the input file image len is 1406740!

write buf is ok!

write mtd device ok!startaddr=1406064the file is write ok!

write mtd device ok!startaddr=1406592

修改u-boot的啟動引數

cp.b d023f700 20400000 158000

其中d023f700是mtd6在flash中,u-boot識別的位址,20400000是記憶體位址,0x158000是長度!

flash的讀寫擦除

flash快閃儲存器是非易失儲存器,可以對稱為塊的儲存器單元塊進行擦寫和再程式設計。任何 flash 器件的寫入操作只能在空或已擦除的單元內進行,所以大多數情況下,在進行寫入操作之前必須先執行擦除。nand 器件執行擦除 操作是十分簡單的,而 nor則要求在進行擦除前 先要將目標塊內所有的位都寫為1...

flash as打造FLASH向量線條擦除

flash向量線條擦除 向量線條的擦除在塗鴉板也許用處不是很大 寫的不到位,還望高手指點 原理很簡單,用橡皮來檢測與陣列中的點相碰 刪除碰撞點 重新繪製線條 放在第一幀就可以執行 var startx number 起始點 var starty number var path movieclip t...

MicroBlaze程式寫入Flash

1.在 settings bitstream 中選中 bin file 2.在約束檔案中新增 set property bitstream.general.compress true current design set property bitstream.config.configrate 33...