dnw for linux: Ubuntu下可用,无需编译驱动,mini2440可用
2013-09-18 22:37
405 查看
1.安装所需库文件sudoapt-getinstalllibusb-dev
2.源代码如下
2.源代码如下
/*dnw2linuxmainfile.Thisdependsonlibusb. * *Author:Fox<hulifox008@163.com> *License:GPL * */ #include<stdio.h> #include<usb.h> #include<errno.h> #include<sys/stat.h> #include<fcntl.h> #include<unistd.h> #defineQQ2440_SECBULK_IDVENDOR 0x5345 #defineQQ2440_SECBULK_IDPRODUCT 0x1234 structusb_dev_handle*open_port(){ structusb_bus*busses,*bus; usb_init(); usb_find_busses(); usb_find_devices(); busses=usb_get_busses(); for(bus=busses;bus;bus=bus->next){ structusb_device*dev; for(dev=bus->devices;dev;dev=dev->next){ printf("idVendor:0x%x\t,ipProduct:0x%x\n", dev->descriptor.idVendor,dev->descriptor.idProduct); if(QQ2440_SECBULK_IDVENDOR==dev->descriptor.idVendor &&QQ2440_SECBULK_IDPRODUCT==dev->descriptor.idProduct){ printf("Targetusbdevicefound!\n"); structusb_dev_handle*hdev=usb_open(dev); if(!hdev){ perror("Cannotopendevice"); }else{ if(0!=usb_claim_interface(hdev,0)){ perror("Cannotclaiminterface"); usb_close(hdev); hdev=NULL; } } returnhdev; } } } printf("Targetusbdevicenotfound!\n"); returnNULL; } voidusage(){ printf("Usage:dnw2<file>\n\n"); } unsignedchar*prepare_write_buf(char*filename,unsignedint*len){ unsignedchar*write_buf=NULL; structstatfs; intfd=open(filename,O_RDONLY); if(-1==fd){ perror("Cannotopenfile"); returnNULL; } if(-1==fstat(fd,&fs)){ perror("Cannotgetfilesize"); gotoerror; } write_buf=(unsignedchar*)malloc(fs.st_size+10); if(NULL==write_buf){ perror("mallocfailed"); gotoerror; } if(fs.st_size!=read(fd,write_buf+8,fs.st_size)){ perror("Readingfilefailed"); gotoerror; } printf("Filename:%s\n",filename); printf("Filesize:%dbytes\n",fs.st_size); *((u_int32_t*)write_buf)=0x30000000;//downloadaddress *((u_int32_t*)write_buf+1)=fs.st_size+10;//downloadsize; *len=fs.st_size+10; returnwrite_buf; error:if(fd!=-1) close(fd); if(NULL!=write_buf) free(write_buf); fs.st_size=0; returnNULL; } intmain(intargc,char*argv[]){ if(2!=argc){ usage(); return1; } structusb_dev_handle*hdev=open_port(); if(!hdev){ return1; } unsignedintlen=0; unsignedchar*write_buf=prepare_write_buf(argv[1],&len); if(NULL==write_buf) return1; unsignedintremain=len; unsignedinttowrite; printf("Writingdata...\n"); while(remain){ towrite=remain>512?512:remain; if(towrite!=usb_bulk_write(hdev,0x03,write_buf+(len-remain), towrite,3000)){ perror("usb_bulk_writefailed"); break; } remain-=towrite; printf("\r%d%\t%dbytes",(len-remain)*100/len,len -remain); fflush(stdout); } if(0==remain) printf("Done!\n"); return0; }
3.gccdnw.c-odnw-lusb
相关文章推荐
- Linux-4.9.2内核在mini2440上的移植(一)——Ubuntu编译环境搭建(上)
- linux驱动学习(1)-ubuntu 内核源码下载及编译
- Linux驱动开发系列之一:Ubuntu 8.10下编译Linux kernel 2.6.32.1
- Linux驱动开发之环境搭建----Ubuntu 12.4 编译内核
- linux里面编译安装显卡驱动失败:ERROR:Unable to find the kernel source tree for the currently running kernel.
- ubuntu14.04 编译安装highpoint rocketraid 2720驱动 分类: arm-linux-Ubuntu 2015-01-22 17:18 321人阅读 评论(0) 收藏
- 快速编译Linux2.6.33.3 for mini2440
- dnw for linux ( ubuntu opensuse federa 测试通过)
- Linux驱动开发之ubuntu下的驱动编译
- Linux 有问必答:如何在Ubuntu或者Debian中编译安装ixgbe驱动
- ubuntu系统下linux驱动编译常见错误
- Linux-4.9.2内核在mini2440上的移植(二)——Ubuntu编译环境搭建(下)
- Linux驱动开发之环境搭建----Ubuntu 12.4 编译内核
- dnw for linux(ubuntu)
- Linux for Ubuntu Eclipse配置OpenGL编译命令
- linux下驱动模块化编译,动态加载以及卸载 分类: arm-linux-Ubuntu 2015-05-30 16:24 172人阅读 评论(0) 收藏
- dnw for linux(ubuntu)
- boost and boost::regex for linux(Ubuntu) 编译and安装_二少_新浪博客
- 交叉编译环境搭建:系统: Ubuntu8..1 内核: linux2.6平台:2410
- 如何在linux(Ubuntu)下编译和安装lzop压缩工具源码