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. Cxf soap协议改成1.2

    在和.net做联调的时候,报错: A SOAP 1.2 message is not valid when sent to a SOAP 1.1 only endpoint. 看来是soap协议不匹配 ...

  2. astyle代码格式化

    Artistic Style 1.24 A Free, Fast and Small Automatic Formatterfor C, C++, C#, and Java Source Code 项 ...

  3. VM Depot 镜像新增系列II – 学习管理系统,内容管理系统以及平台管理工具

     发布于 2014-06-23 作者 刘 天栋 继上周企业管理软件和电子商务镜像的加盟之后,我们看到又有一批内容管理解决方案(CMS),学习管理解决方案(LMS)以及平台管理工具 (如 Open ...

  4. Azure SQL 数据库的灵活缩放预览版简介

    Eron Kelly SQL Server 产品管理部门产品市场营销总经理 几天前,我们宣布了发布 Azure SQL 数据库的灵活缩放公共预览版.新增的灵活缩放功能通过简化开发和管理,简化了扩展和缩 ...

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

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

  6. Extjs4开发中的一些问题

    1.  子frame刷新的问题 一般在jsp里面,要实现界面跳转,有很多方法,最典型的就是window.location.href="href",但是在嵌套有iframe框架的页面 ...

  7. ORACLE软件下载地址

    Oracle Database 11g Release 2 Standard Edition and Enterprise Edition Software Downloads Oracle 数据库 ...

  8. dotfuscator使用方法

    dotfuscator如何对.net程序进行混淆保护对于程序代码的保护,网上有很多资料,有的说混淆,有的说加密,我比较支持混淆的方法,这样可以让反编译劳工,头晕一阵子,哈哈开玩笑.对于加密如果不是不得 ...

  9. [转]关于strtok和strtok_r函数的深度研究

    在linux环境下,字符串分割的函数中,大家比较常用的是strtok函数,这个函数用处很大,但也有一些问题,以下将深度挖掘一下这个函数的用法,原理,实现,其次,该函数是不可再入函数,但是在linux ...

  10. linux驱动开发之GCC问题

    最近正在学习驱动开发,进展到字符设备驱动开发阶段. 先不多说,首先把刚看的一篇学习驱动步骤的帖子记录如下: 1. 学会写简单的makefile 2. 编一应用程序,可以用makefile跑起来 3. ...