Ubuntu10.04系统调试TQ2440开发板之一《Ubuntu下搭建TQ2440的程序下载环境》

环境搭建主要是装两个工具:串口工具和下载软件(在这里所有指令都是在Ubuntu系统终端Root权限下运行)

1)安装串口工具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        |

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

接着配置串口,运行指令: sudo mknod /dev/ttyUSB0 c 188 0

然后我们重新进入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

   如果你要进入下载模式,那就从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:

2)安装下载软件

我们先新建一个名为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
到这里就烧写成功来,不过还是相对有点慢的,呵呵,没关系。好好体验下吧!

转载于:https://www.cnblogs.com/qingfengshuimu/p/3494897.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值