Ubuntu下用minicom搭建TQ2440的程序下载dnw环境
来源:互联网 发布:带英语的网络流行语 编辑:程序博客网 时间:2024/05/22 10:22
在之前就已经做了一半的工作了,也就是把minicom安装好了,而之后也不知道是为什么就不了了之了,很可能是因为dnw for linux的不成功。
今天想起上次跟哥说起为什么要在虚拟机开发而不直接在Linux系统下开发呢?同时今天也想要在ubuntu下学习,所以就索性在linux环境下开发的工作先搞定!
首先要多谢这位网友的文章,很不错很详细的:http://www.linuxidc.com/Linux/2011-03/32869.htm Ubuntu下搭建TQ2440的程序下载环境
我这里是用ubuntu 10.10的,也差不多的。
安装minicom:sudo apt-get install minicom (这里也有网友说安装putty,有空试下http://linux.net527.cn/Ubuntu/Ubuntuanzhuangyuyingyong/140.html)
sudo minicom -s 这里是用管理员身份打开,也只能用管理员身份打开
之后检查/dev下有没有ttyUSB0驱动(这里是用串口转USB的),如果没有,就自行创建一个吧:sudo mknod /dev/ttyUSB0 c 188 0。在这里我是直接把USB口插进去自动生成,这个有关问题之后还要去探索的。
进入minicom进行配置:sudo minicom -s
在serial port setup中的A配置为/dev/ttyUSB0
再save setup as dfl,这是为了下次不用再配置
然后插上USB,重启minicom就可看到信息
Welcome to minicom 2.4
OPTIONS: I18n
Compiled on Jun 3 2010, 13:48:00.
Port /dev/ttyUSB0
Press CTRL-A Z for help on special keys
开发板在nor flash启动,插上USB host,按下选项即可出现USB host is connected. Waiting a download. 在这里一定是要先启动开发板之后再插上USB host才能检测到。
接下来是dnw for linux的问题了。
我们先新建一个名为dnw.c的文件,往里面复制以下代码:
/* 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;
}
保存之后就进行编译,这里要注意前面的信息,也就是关于usb.h的,在这里也纠结了一会,要在你的ubuntu系统中有安装libusb-dev才能认得了usb.h:sudo apt-get install libusb-dev这样在/usr/include下就有usb.h,而不要误认为/usr/include/linux下的usb.h就是你要的而把usb.h复制到对应的目录下
之后编译:gcc dnw.c -o dnw -lusb 即可生成dnw可执行文件
把dnw复制到工具目录下:sudo cp dnw /usr/local/bin
现在就可以使用dnw工具啦!
体验ubuntu环境下的下载程序:
1.连接好开发板,先连接USB转串口;
2.打开终端,在管理员身份下输入minicom,看到连接成功的提示;
3.从Nor Flash启动开发板,从minicom上看到u-boot的提示,再连接USB host,按1可看到USB host is connected. Waiting a download.的提示信息(这个是烧写u-boot程序到Nand Flash下);
4.在另一终端下运行dnw程序,并烧写u-boot.bin:sudo ./dnw u-boot.bin
到这里就烧写成功来,不过还是相对有点慢的,呵呵,没关系。好好体验下吧!
今天想起上次跟哥说起为什么要在虚拟机开发而不直接在Linux系统下开发呢?同时今天也想要在ubuntu下学习,所以就索性在linux环境下开发的工作先搞定!
首先要多谢这位网友的文章,很不错很详细的:http://www.linuxidc.com/Linux/2011-03/32869.htm Ubuntu下搭建TQ2440的程序下载环境
我这里是用ubuntu 10.10的,也差不多的。
安装minicom:sudo apt-get install minicom (这里也有网友说安装putty,有空试下http://linux.net527.cn/Ubuntu/Ubuntuanzhuangyuyingyong/140.html)
sudo minicom -s 这里是用管理员身份打开,也只能用管理员身份打开
之后检查/dev下有没有ttyUSB0驱动(这里是用串口转USB的),如果没有,就自行创建一个吧:sudo mknod /dev/ttyUSB0 c 188 0。在这里我是直接把USB口插进去自动生成,这个有关问题之后还要去探索的。
进入minicom进行配置:sudo minicom -s
在serial port setup中的A配置为/dev/ttyUSB0
再save setup as dfl,这是为了下次不用再配置
然后插上USB,重启minicom就可看到信息
Welcome to minicom 2.4
OPTIONS: I18n
Compiled on Jun 3 2010, 13:48:00.
Port /dev/ttyUSB0
Press CTRL-A Z for help on special keys
开发板在nor flash启动,插上USB host,按下选项即可出现USB host is connected. Waiting a download. 在这里一定是要先启动开发板之后再插上USB host才能检测到。
接下来是dnw for linux的问题了。
我们先新建一个名为dnw.c的文件,往里面复制以下代码:
/* 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;
}
保存之后就进行编译,这里要注意前面的信息,也就是关于usb.h的,在这里也纠结了一会,要在你的ubuntu系统中有安装libusb-dev才能认得了usb.h:sudo apt-get install libusb-dev这样在/usr/include下就有usb.h,而不要误认为/usr/include/linux下的usb.h就是你要的而把usb.h复制到对应的目录下
之后编译:gcc dnw.c -o dnw -lusb 即可生成dnw可执行文件
把dnw复制到工具目录下:sudo cp dnw /usr/local/bin
现在就可以使用dnw工具啦!
体验ubuntu环境下的下载程序:
1.连接好开发板,先连接USB转串口;
2.打开终端,在管理员身份下输入minicom,看到连接成功的提示;
3.从Nor Flash启动开发板,从minicom上看到u-boot的提示,再连接USB host,按1可看到USB host is connected. Waiting a download.的提示信息(这个是烧写u-boot程序到Nand Flash下);
4.在另一终端下运行dnw程序,并烧写u-boot.bin:sudo ./dnw u-boot.bin
到这里就烧写成功来,不过还是相对有点慢的,呵呵,没关系。好好体验下吧!
- Ubuntu下用minicom搭建TQ2440的程序下载dnw环境
- Ubuntu下搭建TQ2440的程序下载dnw环境
- Ubuntu下搭建TQ2440的程序下载环境
- Ubuntu下搭建TQ2440的程序下载环境
- Ubuntu下搭建TQ2440的程序下载环境
- Ubuntu下搭建TQ2440的程序下载环境
- Ubuntu下搭建TQ2440的程序下载环境
- linux虚拟机环境下配置dnw下载程序到TQ2440
- linux 下DNW 下载环境搭建
- xp 虚拟机用minicom 连接tq2440与ubuntu下串口连接tq2440
- Linux下的minicom和dnw
- linux下使用DNW下载镜像-TQ2440
- 基于Ubuntu系统的Tiny4412使用dnw下载程序
- 在Ubuntu下,建立下载image文件到Mini2440或者TQ2440开发板的环境
- linux下程序烧写(dnw+minicom)
- ubuntu 下的 dnw 下载安装和使用
- ubuntu 下的 dnw 下载安装和使用
- Ubuntu下用dnw下载到OK6410开发板
- 深入学习main()返回值问题
- 如何让cmd全屏显示?
- 线程同步
- asp.net常用函数表
- 家庭和睦、人生平淡也是一种成功
- Ubuntu下用minicom搭建TQ2440的程序下载dnw环境
- 再谈Oracle like优化
- 在PHP语言中使用JSON
- uboot源码阅读(八)江湖人物go
- task_struct /inlcude/linux/sched.h
- Linux学习心得:细细品味shell脚本中的细节与用户体验 ^_^
- js 字符串转日期并比较大小(附其它操作)
- 程序人员新手心得
- JDeveloper 11g 中配置 MySQL