1.安装所需库文件 sudo apt-get install libusb-dev

2.源代码如下

/* 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 0x1234 struct 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;
}
 
 
3.gcc dnw.c -o dnw -lusb
 

dnw for linux: Ubuntu下可用,无需编译驱动,mini2440可用的更多相关文章

  1. 开源播放器 ijkplayer (五) :Linux/Ubuntu 下编译ijkplayer

    一.安装Git与yasm sudo apt-get install git sudo apt-get install yasm 二.下载和配置 SDK.NDK SDK一般开发时肯定都有的,NDK一般是 ...

  2. 在Linux(Ubuntu)下搭建ASP.NET Core环境并运行 继续跨平台

    最新教程:http://www.cnblogs.com/linezero/p/aspnetcoreubuntu.html 无需安装mono,在Linux(Ubuntu)下搭建ASP.NET Core环 ...

  3. ubuntu下使用反编译apk,工具dex2jar和jd-gui

    ubuntu下使用反编译apk, 工具 1:通过apk-tool反编译出资源文件: http://code.google.com/p/android-apktool/ 2.首先使用dex2jar反编译 ...

  4. lampp 在linux ubuntu下自动开机启动

    lampp 在linux ubuntu下自动开机启动 lampp在linux下是不会自动启动的.需要手工处理.如下: 假如,你的lampp安装在 /opt/lampp 目录下,那么可以如下处理: 1. ...

  5. Linux(Ubuntu)下MySQL的安装与配置

    转自:http://www.2cto.com/database/201401/273423.html 在Linux下MySQL的安装,我一直觉得挺麻烦的,因为之前安装时就是由于复杂的配置导致有点晕.今 ...

  6. Linux(Ubuntu) 下自然码加辅助码双拼输入的解决方案

    Linux(Ubuntu) 下自然码加辅助码双拼输入的解决方案 环境: Ubuntu 14.04 LTS 解决方案是 ibus-Rime 输入法, 再加上搭配自然码的配置表 (1) ibus 首先安装 ...

  7. Ubuntu下使用gcc编译c文件,未识别cos,sin

    Ubuntu下使用gcc编译c文件,虽然我调用了math.h的头文件,但是未识别cos,sin 报错:( fft.c ) /tmp/ccwXjD8C.o: In function `fft': fft ...

  8. Linux环境下使用VSCode编译makefile文件的注意事项

    Linux环境下使用VSCode编译makefile文件的注意事项 首先安装C/C++的两个依赖 在debug,launch会自动的生成下方的launch.json launch.json { // ...

  9. Ubuntu下安装nvidia显卡驱动

    layout: post title: Ubuntu下安装nvidia显卡驱动 date: 2015-10-02 17:19:06 categories: 常用命令 tags: 显卡 驱动 最近一直在 ...

随机推荐

  1. Semaphore的介绍和使用

    转自:http://www.itzhai.com/the-introduction-and-use-of-semaphore.html 相关介绍 public class Semaphore exte ...

  2. 孤陋寡闻又一遭:ReportEvent API函数(有微软Service官方例子为例)

    API 详解: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363679(v=vs.85).aspx 使用例子: https: ...

  3. HBase学习笔记之HFile格式

    主要看Roger的文档,这里作为文档的补充 HFile的格式-HFile的基本结构 Trailer通过指针找到Meta index.Data index.File info. Meta index保存 ...

  4. Linux Shell编程(10)——引用变量

    当要引用一个变量的值时,一般推荐使用双引号.使用双引号除了变量名前缀($).后引符(`)和转义符(\)外,会使shell不再解释引号中其它所有的特殊字符.用双引号时$仍被当成特殊字符,允许引用一个被双 ...

  5. 【转】iOS开发入门:Xcode常用快捷键

    原文网址:http://www.3g-edu.org/ios_free/3G-89.htm Xcode有许多快捷键,这些快捷键在Xcode的工具栏里都有标注,学会使用这些快捷键可以大大的提高你的编程效 ...

  6. (转载)[MySQL技巧]INSERT INTO… ON DUPLICATE KEY UPDATE

    (转载)http://blog.zol.com.cn/2299/article_2298921.html MySQL 自4.1版以后开始支持INSERT … ON DUPLICATE KEY UPDA ...

  7. HDU-1527 取石子游戏

    http://acm.hdu.edu.cn/showproblem.php?pid=1527 交换  :可实现. if( n < m ) { n^=m; m^=n; n^=m; } (三)尼姆博 ...

  8. 定时器NSTimer的用法

        //时间间隔     NSTimeInterval activeTimeInterval = NETWORK_SEND_ACTIVE_TIME;     NSTimeInterval othe ...

  9. cas 单点登录配置

    服务端配置 cas是个好东西,很灵活很好用,但是配置起来很麻烦 cas官方网站 http://downloads.jasig.org/ 下载服务端 CAS Server 3.3.3 Final 1.将 ...

  10. hdoj 1950 Bridging signals【二分求最大上升子序列长度】【LIS】

    Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...