ARM-Linux驅(qū)動(dòng)移植--Linux下燒寫工具DNW和USB驅(qū)動(dòng)安裝
硬件平臺(tái):FL2440(S3C2440)with linux kernel 2.6.35
本文引用地址:http://m.butianyuan.cn/article/201611/319015.htm原創(chuàng)作品,轉(zhuǎn)載請(qǐng)標(biāo)明出處http://blog.csdn.net/yming0221/article/details/7211396
1、首先下載DNW for linuxhttp://download.csdn.net/source/1011140
2、解壓文件
、
3、編譯主機(jī)的USB驅(qū)動(dòng)
- make-C/lib/modules/`uname-r`/buildM=`pwd`modules
然后insmod安裝驅(qū)動(dòng)并dmesg查看如下
4、修改dnw.c文件并編譯
由于FL2440燒寫內(nèi)核需要設(shè)置初始地址為0x30800000,修改后文件如下
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- constchar*dev="/dev/secbulk0";
- intmain(intargc,char*argv[])
- {
- unsignedchar*file_buffer=NULL;
- if(2!=argc)
- {
- printf("Usage:dwn
n"); - return1;
- }
- intfd=open(argv[1],O_RDONLY);
- if(-1==fd)
- {
- printf("Cannotopenfile-%sn",argv[1]);
- return1;
- }
- structstatfile_stat;
- if(-1==fstat(fd,&file_stat))
- {
- printf("Getfilesizefiled!n");
- return1;
- }
- file_buffer=(char*)malloc(file_stat.st_size+10);
- if(NULL==file_buffer)
- {
- printf("mallocfailed!n");
- gotoerror;
- }
- if(file_stat.st_size!=read(fd,file_buffer+8,file_stat.st_size))
- {
- printf("Readfilefailed!n");
- gotoerror;
- }
- printf("filename:%sn",argv[1]);
- printf("filesize:%dbytesn",file_stat.st_size);
- intfd_dev=open(dev,O_WRONLY);
- if(-1==fd_dev)
- {
- printf("Cannotopen%sn",dev);
- gotoerror;
- }
- *((unsignedlong*)file_buffer)=0x30800000;//loadaddress
- *((unsignedlong*)file_buffer+1)=file_stat.st_size+10;//filesize
- unsignedshortsum=0;
- inti;
- for(i=8;i
- {
- sum+=file_buffer[i];
- }
- printf("Writingdata...n");
- size_tremain_size=file_stat.st_size+10;
- //size_tblock_size=remain_size/100;
- size_tblock_size=512;
- size_twrited=0;
- while(remain_size>0)
- {
- size_tto_write=remain_size>block_size?block_size:remain_size;
- if(to_write!=write(fd_dev,file_buffer+writed,to_write))
- {
- printf("failed!n");
- return1;
- }
- remain_size-=to_write;
- writed+=to_write;
- printf("r%d%t%dbytes",writed*100/(file_stat.st_size+10),writed);
- fflush(stdout);
- }
- printf("OKn");
- return0;
- error:
- if(-1!=fd_dev)close(fd_dev);
- if(fd!=-1)close(fd);
- if(NULL!=file_buffer)
- free(file_buffer);
- return-1;
- }
最后燒寫內(nèi)核
評(píng)論