我使用的​​Ubuntu​​ 10.04,以下是我搭建实验环境的过程,其他版本的Ubuntu其搭建过程可能会略有不同,请读者自行查阅相关资料解决。

1.必须使用一款类似于windows下SecureCRT的软件:minicom。先下载minicom:

sudo apt-get install minicom

安装完毕之后,使用如下命令行测试一下:

sudo minicom -s

会出现如下结果:

            +-----[configuration]------+

            | Filenames and paths      |

            | File transfer protocols  |

            | Serial port setup        |

            | Modem and dialing        |

            | Screen and keyboard      |

            | Save setup as dfl        |

            | Save setup as..          |

            | Exit                     |

            | Exit from Minicom        |

            +--------------------------+

通过光标可以上下选择相应的配置项,按回车即可确定。

由于我使用的是笔记本电脑,所以便遇到USB转串口的问题。首先我们得先检查ubuntu有无USB转串口的驱动(ubuntu中不用安装什么USB转串口驱动)

我发现在/dev下没有ttyUSB0这个文件,www.linuxidc.com不过可以自行创建一个:

sudo mknod /dev/ttyUSB0 c 188 0

如果使用的是串口线,就设置为/dev/ttyS0

然后我们重新进入minicom进行配置:

sudo minicom -s

选择Serial port setup ,进行如下设置:

    | A -    Serial Device      : /dev/ttyUSB0                              |

    | B - Lockfile Location     : /var/lock                                 |

    | C -   Callin Program      :                                           |

    | D -  Callout Program      :                                           |

    | E -    Bps/Par/Bits       : 115200 8N1                                |

    | F - Hardware Flow Control : No                                        |

    | G - Software Flow Control : No                                        |

设置完成之后,选择Save setup as dfl  ,这样下次就不用重新配置。

接着插上USB转串口线,重启minicom就能看到

Welcome to minicom 2.4

OPTIONS: I18n

Compiled on Jan 25 2010, 06:49:09.

Port /dev/ttyUSB0

Press CTRL-A Z for help on special keys

接着打开TQ2440的电源,就能看到:(此时我是从NAND Flash下启动)

<***************************************>           

               TQ2440 Test Program                  

                www.linuxidc.com

<***************************************>

这就说明你的板子已经跟电脑连接在一起了。

minicom有一个很不好的地方,就是你一拉大或者缩小终端,屏幕就会被清空,这点要注意一下。

如果你要进入下载模式,那就从NOR Flash重新启动开发板,这时候会出现u-boot的信息:

#####    Boot for Nor Flash Main Menu   #####                                  

#####     EmbedSky USB download mode     #####                                 

[1] Download u-boot or STEPLDR.nb1 or other bootloader to Nand Flash           

[2] Download Eboot (eboot.nb0) to Nand Flash                                   

[3] Download Linux Kernel (zImage.bin) to Nand Flash                           

[5] Download CRAMFS image to Nand Flash                                        

[6] Download YAFFS image (root.bin) to Nand Flash                              

[7] Download Program (uCOS-II or TQ2440_Test) to SDRAM and Run it              

[8] Boot the system                                                            

[9] Format the Nand Flash                                                      

[0] Set the boot parameters                                                    

[a] Download User Program (eg: uCOS-II or TQ2440_Test)                         

[b] Download LOGO Picture (.bin) to Nand  Flash                                

[l] Set LCD Parameters                                                         

[n] Enter TFTP download mode menu                                              

[o] Download u-boot to Nor Flash                                               

[r] Reboot u-boot                                                              

[t] Test Linux Image (zImage)                                                  

[q] quit from menu                                                             

Enter your selection:

(如果没有出现的话就按一下复位键)

这时候不要忘了插上USB host,不然在下载的过程就会出现USB host is not connected now的情况。

现在我们需要一个Linux下的类似于DNW的工具,这个工具没有windows下的图形界面,而且代码非常之精简,直接编译之后便可使用:

我们先新建一个名为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;
}

点击保存即可。

接着打开终端编译这个文件:

gcc DNW.c -o dnw -lusb

接着你可以发现当前目录下多了一个dnw的bin文件。我们可以将其复制到用户目录下就可以全局使用这个指令了:

sudo cp dnw /usr/local/bin

现在当你输入dnw命令的时候,会出现

Usage: dnw2 <file>

的用法提示。

我们现在可以测试一下下载过程:

1.连接好开发板(USB转串口线和USB host线);

2.打开终端,输入minicom,看到连接成功的提示;

3.从NOR Flash启动开发板,从minicom上看到u-boot的提示,这里我们按7并回车(该选项可烧写裸机程序);

这时会看到提示waiting download的提示;

4.再打开一个终端,找到所要下载进开发板的bin程序,直接(一定要sudo,不然无法成功)

sudo dnw <file>   (file表示文件的路径)

这时便可看到烧写成功的提示了。