主机渠道:Gentoo Linux 11.2 with linux kernel 3.0.6
硬件渠道:FL2440(S3C2440)with linux kernel 2.6.35
原创著作,转载请标明出处http://blog.csdn.net/yming0221/article/details/7211396
1、首要下载DNW for linuxhttp://download.csdn.net/source/1011140
2、解压文件
、
3、编译主机的USB驱动
- make-C/lib/modules/`uname-r`/buildM=`pwd`modules
然后insmod装置驱动并dmesg检查如下
4、修正dnw.c文件并编译
我们FL2440烧写内核需求设置初始地址为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-%s\n”,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:%s\n”,argv[1]);
- printf(“filesize:%dbytes\n”,file_stat.st_size);
- intfd_dev=open(dev,O_WRONLY);
- if(-1==fd_dev)
- {
- printf(“Cannotopen%s\n”,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(“OK\n”);
- return0;
- error:
- if(-1!=fd_dev)close(fd_dev);
- if(fd!=-1)close(fd);
- if(NULL!=file_buffer)
- free(file_buffer);
- return-1;
- }
最终烧写内核