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
總結
以上是生活随笔為你收集整理的Ubuntu10.04系统调试TQ2440开发板之一《Ubuntu下搭建TQ2440的程序下载环境》的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Kali Linux渗透测试实战 2.2
- 下一篇: Android中利用HttpClient