Welcome 微信登录

首页 / 操作系统 / Linux / TQ2440在Ubuntu如何使用DNW

注意此方法我在TQ2440开发板测试成功,其他开发板请在王路上查找相应的代码!!!经历了多方周折,终于看到程序下载到了目标板上下面是具体步骤:),首先要安装libusb-dev这个库。我是在Ubuntu 下做的。那么就:sudo apt-get install libusb-dev装完之后就编译一个下载工具,网上有个牛人提供了一个。代码如下:
#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;
}2),把它保存为文件如:dnw2.c
接着编译: gcc dnw2.c -o dnw2 -lusb
3) 移动dnw2可执行文件到 /usr/bin下sudo mv . / dnw2 / usr/ bin4)sudo dnw2 path/your_filename Ubuntu 11.10下安装NS2.35Ubuntu 11.10下ibus输入法的图标经常消失解决办法相关资讯      TQ2440  Ubuntu安装教程 
  • 平板电脑安装Ubuntu教程  (今 08:25)
  • u-boot-2014.04移植手册(TQ2440)   (02/05/2015 19:06:22)
  • TQ2440四线电阻式触摸屏驱动程序的  (10/13/2014 09:45:53)
  • u-boot-2015.01在TQ2440上移植过程  (02/05/2015 19:30:05)
  • TQ2440按键点亮LED驱动程序  (10/13/2014 09:50:43)
  • TQ2440触摸屏驱动程序的移植  (10/13/2014 09:14:27)
本文评论 查看全部评论 (1)
表情: 姓名: 字数


评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论