搞嵌入式系统,用惯了Windows下的超级终端调试ARM程序,每次都要键入一大堆的字符,重复,重复,再重复。
为了减少无用的工作,开始寻找一种能自动与RedBoot交互的方法。
其实,可以有两种思路,一是自己实现类似超级终端的程序,支持XModem协议,这样交互过程就可以通过程序来控制。二是使用类似Expect的思路,使用其他的程序控制已有的通信程序。第一种方法工作量较大,而且很多时候是在reinvent the wheel,不可取;第二种方法应该是研究的重点。
SecureCRT正好提供了类似Expect的功能,它支持脚本来操作与通信的另一方的交互的能力,从而实现交互的自动化。SecureCRT支持三种脚本:vbscript, javascript和perl。前两种只要安装了IE4以上的浏览器的操作系统就支持,最后一种perl需要安装perl解释器,windows下最好的选择就是ActivePerl了。
下面是一段perl脚本来完成自动下载可执行文件demo.bin到目标板上并运行的例子:
# $language = "PerlScript"
# $interface = "1.0"
use Win32::OLE;
Win32::OLE->Option(Warn => 3);
$true = 1;
$false = 0;
$crt->Screen->{‘Synchronous’} = $true;
$crt->Screen->Send("n");
$crt->Screen->WaitForString("RedBoot> ");
$crt->Screen->{‘Synchronous’} = $false;
$crt->Screen->Send("load -m xmodem -c 0 -b 0x00600000 -rn");
$crt->FileTransfer->SendXmodem("demo.bin");
$crt->Screen->WaitForString("RedBoot> ");
$crt->Screen->Send("gon");
$crt->Screen->WaitForString("(y/n)");
$crt->Screen->Send("nn");
在这个脚本基础上可以很容易的增加GUI功能,让文件可以由用户自己选择。
使用Expect进行下装的脚本如下:(以下代码来自于eCos mail archive)
(Since the list doesn't like my attachment, I insert the script here)<br /><br />#!/usr/bin/expect --<br /><br />#<br /># Konstanten definieren<br />#<br />if {$argc < 2} {<br /> puts "Not enough arguments."<br /> exit<br />}<br /><br />set catc_tty [lindex $argv 0]<br /><br />set bdi_ip [lindex $argv 1]<br /><br />#<br /># Sleep-Befehl<br />#<br />proc sleep {timeout} {<br /> expect<br />}<br /><br />#<br /># Telnet-Sitzung zum BDI oeffnen<br />#<br />spawn telnet $bdi_ip<br />expect {<br /> timeout {<br /> puts "telnet timed out"; exit<br /> }<br /> "CATCenter>" {<br /> set telnet_id $spawn_id<br /> }<br />}<br /><br />#<br /># Redboot flashen<br />#<br />send "res haltr"<br />expect {<br /> timeout {<br /> puts "telnet timed out"; exit<br /> }<br /> "CATCenter>" {<br /> set telnet_id $spawn_id<br /> }<br />}<br /><br />send "erase 0x1000000 chipr"<br />set timeout 60<br />expect {<br /> timeout {<br /> puts "Flash erase timed out"; exit<br /> }<br /> "Erasing flash passed"<br />}<br /><br />send "prog 0x1000000 images/redboot_110.bin binr"<br />set timeout 10<br />expect {<br /> timeout {<br /> puts "Flash programming timed out"; exit<br /> }<br /> "Programming flash passed"<br />}<br /><br />send "res runr"<br />expect {<br /> timeout {<br /> puts "CPU reset timed out"; exit<br /> }<br /> "processing target startup passed"<br />}<br /><br />#<br /># Kermit oeffnen und mit CATCenter verbinden<br />#<br />spawn kermit<br />expect {<br /> timeout {<br /> puts "kermit timed out"; exit<br /> }<br /> "C-Kermit>" {<br /> set kermit_id $spawn_id<br /> }<br />}<br /><br />send "set line $catc_ttyn"<br />send "set speed 38400n"<br />expect {<br /> timeout {<br /> puts "kermit timed out"; exit<br /> }<br /> "38400 bps"<br />}<br />send "set flow nonen"<br />send "set carrier-watch offn"<br />send "cn"<br />expect {<br /> timeout {<br /> puts "Kermit timed out"; exit<br /> }<br /> "n-------*n"<br />}<br /><br />send "n"<br />send "n"<br />expect {<br /> timeout {<br /> puts "Redboot timed out"; exit<br /> }<br /> "enter ^C to abort" {<br /> send x03<br /> expect {<br /> timeout {<br /> puts "Redboot timed out"; exit<br /> }<br /> "RedBoot> "<br /> }<br /> }<br /> "RedBoot> "<br />}<br /><br />#<br /># Redboot Erstkonfiguration<br />#<br />send "fconfig -ir"<br />set timeout 10<br />expect {<br /> timeout {<br /> puts "init timed out"; exit<br /> }<br /> "Initialize non-volatile configuration - continue (y/n)?"<br />}<br /><br />send "yr"<br />set timeout 10<br />expect {<br /> timeout {<br /> puts "init timed out"; exit<br /> }<br /> "Run script at boot: false"<br />}<br /><br />set send_slow {1 .005}<br />send -s "x8x8x8x8x8"<br />send -s "truer"<br />expect {<br /> timeout {<br /> puts "load timed out"; exit<br /> }<br /> ">>"<br />}<br /><br />send -s "fis load BIN_INTr"<br />send -s "gor"<br />send "r"<br />expect {<br /> timeout {<br /> puts "init timed out"; exit<br /> }<br /> "Boot script timeout (1000ms resolution):"<br />}<br /><br />send "3r"<br />expect {<br /> timeout {<br /> puts "init timed out"; exit<br /> }<br /> "Console baud rate:"<br />}<br /><br /><br />send "r"<br />expect {<br /> timeout {<br /> puts "init timed out"; exit<br /> }<br /> "Update RedBoot non-volatile configuration - continue (y/n)?"<br />}<br /><br />send "yr"<br />expect {<br /> timeout {<br /> puts "init timed out"; exit<br /> }<br /> "RedBoot>"<br />}<br /><br />send "fis initr"<br />expect {<br /> timeout {<br /> puts "init timed out"; exit<br /> }<br /> "FLASH image system - continue (y/n)?"<br />}<br /><br />send "yr"<br />expect {<br /> timeout {<br /> puts "init timed out"; exit<br /> }<br /> "RedBoot>"<br />}<br /><br />#<br /># Firmware fuer Adresse 0xc000 laden<br />#<br />set spawn_id $telnet_id<br /><br />send "haltr"<br />send "load 0x400000 images/de/matrix2_CATCENTER_c000.bin binr"<br />set timeout 30<br />expect {<br /> timeout {<br /> puts "load timed out"; exit<br /> }<br /> "Loading program file passed"<br />}<br />send "gor"<br />sleep 1<br /><br />set spawn_id $kermit_id<br /><br />send "fis delete BIN_INTr"<br />set timeout 30<br />expect {<br /> timeout {<br /> puts "delete timed out"; exit<br /> }<br /> "continue (y/n)?" {<br /> send "yr"<br /> expect {<br /> timeout {<br /> puts "delete timed out"; exit<br /> }<br /> "RedBoot> "<br /> } <br /> }<br /> "RedBoot> "<br />}<br /><br />send -- "fis create -b 0x400000 -l 0x20000 -s 0x20000"<br />send -- " -f 0x1700000 -r 0xc000 BIN_INTr"<br />set timeout 40<br />expect {<br /> timeout {<br /> puts "flash timed out"; exit<br /> }<br /> "RedBoot> "<br />}<br /><br />#<br /># ROMFS laden<br />#<br />set spawn_id $telnet_id<br /><br />send "haltr"<br />send "load 0x400000 images/de/romfs.img BINr"<br />set timeout 30<br />expect {<br /> timeout {<br /> puts "load timed out"; exit<br /> }<br /> "Loading program file passed"<br />}<br />send "gor"<br />sleep 1<br /><br />set spawn_id $kermit_id<br /><br />send "fis delete ROMFSr"<br />set timeout 30<br />expect {<br /> timeout {<br /> puts "delete timed out"; exit<br /> }<br /> "continue (y/n)?" {<br /> send "yr"<br /> expect {<br /> timeout {<br /> puts "delete timed out"; exit<br /> }<br /> "RedBoot> "<br /> } <br /> }<br /> "RedBoot> "<br />}<br /><br />send -- "fis create -b 0x400000 -l 0xD0000 -s 0xD0000"<br />send -- " -f 0x1020000 ROMFSr"<br />set timeout 40<br />expect {<br /> timeout {<br /> puts "flash timed out"; exit<br /> }<br /> "RedBoot> "<br />}<br /><br />#<br /># JFFS2 laden<br />#<br />set spawn_id $telnet_id<br /><br />send "haltr"<br />send "load 0x400000 images/jffs2.img binr"<br />set timeout 30<br />expect {<br /> timeout {<br /> puts "load timed out"; exit<br /> }<br /> "Loading program file passed"<br />}<br />send "gor"<br />sleep 1<br /><br />set spawn_id $kermit_id<br /><br />send "fis delete JFFS2r"<br />set timeout 30 <br />expect {<br /> timeout {<br /> puts "delete timed out"; exit<br /> }<br /> "continue (y/n)?" { <br /> send "yr" <br /> expect {<br /> timeout { <br /> puts "delete timed out"; exit<br /> }<br /> "RedBoot> "<br /> } <br /> }<br /> "RedBoot> "<br />}<br /><br />send -- "fis create -b 0x400000 -l 0x400000 -s 0x164" <br />send -- " -f 0x1300000 JFFS2r" <br />set timeout 40 <br />expect {<br /> timeout { <br /> puts "flash timed out"; exit<br /> }<br /> "RedBoot> "<br />}<br /><br />#<br /># Geraet starten<br />#<br />set spawn_id $telnet_id<br /><br />send "res runr"<br /><br />set spawn_id $kermit_id<br />set timeout 40<br />expect {<br /> timeout {<br /> puts "startup timed out"; exit<br /> }<br /><br /> "Here we go"<br />}<br /><br />puts "succes!!!n"
转载请注明:在路上 » 【转】使用脚本与RedBoot协作