Ubuntu下搭建TQ2440的程序下载dnw环境
来源:互联网 发布:js获取div属性 编辑:程序博客网 时间:2024/05/22 01:28
首先要安装libusb-dev这个库,
sudo apt-get install libusb-dev
/* dnw2 linux main file. This depends on libusb.** 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>#define QQ2440_SECBULK_IDVENDOR 0x5345#define QQ2440_SECBULK_IDPRODUCT 0x1234struct usb_dev_handle * open_port(){ struct usb_bus *busses, *bus; usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for(bus=busses;bus;bus=bus->next) { struct usb_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("Target usb device found!\n"); struct usb_dev_handle *hdev = usb_open(dev); if(!hdev) { perror("Cannot open device"); } else { if(0!=usb_claim_interface(hdev, 0)) { perror("Cannot claim interface"); usb_close(hdev); hdev = NULL; } } return hdev; } } } printf("Target usb device not found!\n"); return NULL;}void usage(){ printf("Usage: dnw2 <file>\n\n");}unsigned char* prepare_write_buf(char *filename, unsigned int *len){ unsigned char *write_buf = NULL; struct stat fs; int fd = open(filename, O_RDONLY); if(-1==fd) { perror("Cannot open file"); return NULL; } if(-1==fstat(fd, &fs)) { perror("Cannot get file size"); goto error; } write_buf = (unsigned char*)malloc(fs.st_size+10); if(NULL==write_buf) { perror("malloc failed"); goto error; } if(fs.st_size != read(fd, write_buf+8, fs.st_size)) { perror("Reading file failed"); goto error; } printf("Filename : %s\n", filename); printf("Filesize : %d bytes\n", fs.st_size); *((u_int32_t*)write_buf) = 0x30000000; //download address *((u_int32_t*)write_buf+1) = fs.st_size + 10; //download size; *len = fs.st_size + 10; return write_buf;error: if(fd!=-1) close(fd); if(NULL!=write_buf) free(write_buf); fs.st_size = 0; return NULL; }int main(int argc, char *argv[]){ if(2!=argc) { usage(); return 1; } struct usb_dev_handle *hdev = open_port(); if(!hdev) { return 1; } unsigned int len = 0; unsigned char* write_buf = prepare_write_buf(argv[1], &len); if(NULL==write_buf) return 1; unsigned int remain = len; unsigned int towrite; printf("Writing data ...\n"); while(remain) { towrite = remain>512 ? 512 : remain; if(towrite != usb_bulk_write(hdev, 0x03, write_buf+(len-remain), towrite, 3000)) { perror("usb_bulk_write failed"); break; } remain-=towrite; printf("\r%d%\t %d bytes ", (len-remain)*100/len, len-remain); fflush(stdout); } if(0==remain) printf("Done!\n"); return 0;}
把它保存为文件如:dnw2.c
接着编译: gcc dnw2.c -o dnw2 -lusb
编译完得到的dnw2就是usb下载的PC端了。
0 0
- Ubuntu下搭建TQ2440的程序下载dnw环境
- Ubuntu下用minicom搭建TQ2440的程序下载dnw环境
- Ubuntu下搭建TQ2440的程序下载环境
- Ubuntu下搭建TQ2440的程序下载环境
- Ubuntu下搭建TQ2440的程序下载环境
- Ubuntu下搭建TQ2440的程序下载环境
- Ubuntu下搭建TQ2440的程序下载环境
- linux虚拟机环境下配置dnw下载程序到TQ2440
- linux 下DNW 下载环境搭建
- linux下使用DNW下载镜像-TQ2440
- 基于Ubuntu系统的Tiny4412使用dnw下载程序
- 在Ubuntu下,建立下载image文件到Mini2440或者TQ2440开发板的环境
- ubuntu 下的 dnw 下载安装和使用
- ubuntu 下的 dnw 下载安装和使用
- ubuntu系统使用dnw下载程序
- Ubuntu-ARM FL2440 交叉编译及dnw下载环境搭建成功
- 64位Windows7下TQ2440开发板的环境搭建
- ubuntu 8.04搭建TQ2440开发环境
- [leetcode]Rotate Array
- jQuery.each方法,内部使用代码
- 吸烟是一种心理疾病
- 编写的windows程序,崩溃时产生crash dump文件的办法
- 线段树引篇
- Ubuntu下搭建TQ2440的程序下载dnw环境
- 路由宝421之后版本开启telnet
- POJ 3984 迷宫问题
- oracle 函数
- iOS开发keychain的使用
- Java 排序 - 冒泡排序
- 镜面反射与Phong模型
- Spring简介,搭建Spring环境——轻量级容器框架(一)
- submit在第一次点击按钮后且页面没有得到响应前,多次点击向后台发送数据情况说明