博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ubuntu下dnw2工具的使用
阅读量:6172 次
发布时间:2019-06-21

本文共 2759 字,大约阅读时间需要 9 分钟。

hot3.png

  1. 安装libusb-dev库
$sudo apt-get install libusb-dev
  1. dnw2源码
/* dnw2 linux main file. This depends on libusb. * * Author: Fox * License: GPL * */#include 
#include
#include
#include
#include
#include
#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) { 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 \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;}
  1. 编译
gcc dnw2.c -o dnw2 -lusb4. 移动dnw2可执行文件到 /usr/bin下sudo mv ./dnw2 /usr/bin
  1. 使用 当开发板和PC机用usb连接线(B型,一头是方口,一头是标准usb口)后,使用命令
sudo dnw2 your_file

转载于:https://my.oschina.net/Czl6BQ6SEmYt/blog/485197

你可能感兴趣的文章
《动手玩转Arduino》——11.2 众多的Arduino板
查看>>
IBM Watson 进入癌症基因组分析市场
查看>>
在 Linux 中查看你的时区
查看>>
Linux集群和自动化维1.6 小结
查看>>
《OpenACC并行编程实战》—— 第1章 并行编程概览 1.1 加速器产品
查看>>
C语言OJ项目参考(2417) 字符串长度
查看>>
ajax的手写、封装和自定义设置
查看>>
class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist
查看>>
android自定义属性
查看>>
ERROR 1114 (HY000): The table 'table1' is full
查看>>
知乎网友神回复:哪怕是平时聊天吹牛的也没见程序员晒,这是为什么呢?
查看>>
Android实训案例(三)——实现时间轴效果的ListView,加入本地存储,实现恋爱日记的效果!...
查看>>
phalapi-进阶篇2(DI依赖注入和单例模式)
查看>>
MySQL 5.7.5 : GTID_EXECUTED系统表
查看>>
Hybrid框架UI重构之路:四、分而治之
查看>>
【原创】Valgrind 基础
查看>>
Es6系列之destructuring assignments
查看>>
CSS ID选择器与CLASS选择器
查看>>
mysql 索引B-Tree类型对索引使用的生效和失效情况详解
查看>>
指针的看法
查看>>