最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【转】使用脚本与RedBoot协作

工作和技术 crifan 1742浏览 0评论

【转】使用脚本与RedBoot协作

搞嵌入式系统,用惯了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 &lt; 2} {<br /> puts &quot;Not enough arguments.&quot;<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 &quot;telnet timed out&quot;; exit<br /> }<br /> &quot;CATCenter&gt;&quot; {<br />  set telnet_id $spawn_id<br /> }<br />}<br /><br />#<br /># Redboot flashen<br />#<br />send &quot;res haltr&quot;<br />expect {<br /> timeout {<br />  puts &quot;telnet timed out&quot;; exit<br /> }<br /> &quot;CATCenter&gt;&quot; {<br />  set telnet_id $spawn_id<br /> }<br />}<br /><br />send &quot;erase 0x1000000 chipr&quot;<br />set timeout 60<br />expect {<br /> timeout {<br />  puts &quot;Flash erase timed out&quot;; exit<br /> }<br /> &quot;Erasing flash passed&quot;<br />}<br /><br />send &quot;prog 0x1000000 images/redboot_110.bin binr&quot;<br />set timeout 10<br />expect {<br /> timeout {<br />  puts &quot;Flash programming timed out&quot;; exit<br /> }<br /> &quot;Programming flash passed&quot;<br />}<br /><br />send &quot;res runr&quot;<br />expect {<br /> timeout {<br />  puts &quot;CPU reset timed out&quot;; exit<br /> }<br /> &quot;processing target startup passed&quot;<br />}<br /><br />#<br /># Kermit oeffnen und mit CATCenter verbinden<br />#<br />spawn kermit<br />expect {<br /> timeout {<br />  puts &quot;kermit timed out&quot;; exit<br /> }<br /> &quot;C-Kermit&gt;&quot; {<br />  set kermit_id $spawn_id<br /> }<br />}<br /><br />send &quot;set line $catc_ttyn&quot;<br />send &quot;set speed 38400n&quot;<br />expect {<br /> timeout {<br />  puts &quot;kermit timed out&quot;; exit<br /> }<br /> &quot;38400 bps&quot;<br />}<br />send &quot;set flow nonen&quot;<br />send &quot;set carrier-watch offn&quot;<br />send &quot;cn&quot;<br />expect {<br /> timeout {<br />  puts &quot;Kermit timed out&quot;; exit<br /> }<br /> &quot;n-------*n&quot;<br />}<br /><br />send &quot;n&quot;<br />send &quot;n&quot;<br />expect {<br /> timeout {<br />  puts &quot;Redboot timed out&quot;; exit<br /> }<br /> &quot;enter ^C to abort&quot; {<br />  send x03<br />  expect {<br />   timeout {<br />    puts &quot;Redboot timed out&quot;; exit<br />   }<br />                        &quot;RedBoot&gt; &quot;<br />  }<br /> }<br /> &quot;RedBoot&gt; &quot;<br />}<br /><br />#<br /># Redboot Erstkonfiguration<br />#<br />send &quot;fconfig -ir&quot;<br />set timeout 10<br />expect {<br /> timeout {<br />  puts &quot;init timed out&quot;; exit<br /> }<br /> &quot;Initialize non-volatile configuration - continue (y/n)?&quot;<br />}<br /><br />send &quot;yr&quot;<br />set timeout 10<br />expect {<br /> timeout {<br />  puts &quot;init timed out&quot;; exit<br /> }<br /> &quot;Run script at boot: false&quot;<br />}<br /><br />set send_slow {1 .005}<br />send -s &quot;x8x8x8x8x8&quot;<br />send -s &quot;truer&quot;<br />expect {<br /> timeout {<br />  puts &quot;load timed out&quot;; exit<br /> }<br /> &quot;&gt;&gt;&quot;<br />}<br /><br />send -s &quot;fis load BIN_INTr&quot;<br />send -s &quot;gor&quot;<br />send &quot;r&quot;<br />expect {<br /> timeout {<br />  puts &quot;init timed out&quot;; exit<br /> }<br /> &quot;Boot script timeout (1000ms resolution):&quot;<br />}<br /><br />send &quot;3r&quot;<br />expect {<br /> timeout {<br />  puts &quot;init timed out&quot;; exit<br /> }<br /> &quot;Console baud rate:&quot;<br />}<br /><br /><br />send &quot;r&quot;<br />expect {<br /> timeout {<br />  puts &quot;init timed out&quot;; exit<br /> }<br /> &quot;Update RedBoot non-volatile configuration - continue (y/n)?&quot;<br />}<br /><br />send &quot;yr&quot;<br />expect {<br /> timeout {<br />  puts &quot;init timed out&quot;; exit<br /> }<br /> &quot;RedBoot&gt;&quot;<br />}<br /><br />send &quot;fis initr&quot;<br />expect {<br /> timeout {<br />  puts &quot;init timed out&quot;; exit<br /> }<br /> &quot;FLASH image system - continue (y/n)?&quot;<br />}<br /><br />send &quot;yr&quot;<br />expect {<br /> timeout {<br />  puts &quot;init timed out&quot;; exit<br /> }<br /> &quot;RedBoot&gt;&quot;<br />}<br /><br />#<br /># Firmware fuer Adresse 0xc000 laden<br />#<br />set spawn_id $telnet_id<br /><br />send &quot;haltr&quot;<br />send &quot;load 0x400000 images/de/matrix2_CATCENTER_c000.bin binr&quot;<br />set timeout 30<br />expect {<br /> timeout {<br />  puts &quot;load timed out&quot;; exit<br /> }<br /> &quot;Loading program file passed&quot;<br />}<br />send &quot;gor&quot;<br />sleep 1<br /><br />set spawn_id $kermit_id<br /><br />send &quot;fis delete BIN_INTr&quot;<br />set timeout 30<br />expect {<br /> timeout {<br />  puts &quot;delete timed out&quot;; exit<br /> }<br /> &quot;continue (y/n)?&quot; {<br />  send &quot;yr&quot;<br />  expect {<br />   timeout {<br />    puts &quot;delete timed out&quot;; exit<br />   }<br />   &quot;RedBoot&gt; &quot;<br />  } <br /> }<br /> &quot;RedBoot&gt; &quot;<br />}<br /><br />send -- &quot;fis create -b 0x400000 -l 0x20000 -s 0x20000&quot;<br />send -- &quot; -f 0x1700000 -r 0xc000 BIN_INTr&quot;<br />set timeout 40<br />expect {<br /> timeout {<br />  puts &quot;flash timed out&quot;; exit<br /> }<br /> &quot;RedBoot&gt; &quot;<br />}<br /><br />#<br /># ROMFS laden<br />#<br />set spawn_id $telnet_id<br /><br />send &quot;haltr&quot;<br />send &quot;load 0x400000 images/de/romfs.img BINr&quot;<br />set timeout 30<br />expect {<br /> timeout {<br />  puts &quot;load timed out&quot;; exit<br /> }<br /> &quot;Loading program file passed&quot;<br />}<br />send &quot;gor&quot;<br />sleep 1<br /><br />set spawn_id $kermit_id<br /><br />send &quot;fis delete ROMFSr&quot;<br />set timeout 30<br />expect {<br /> timeout {<br />  puts &quot;delete timed out&quot;; exit<br /> }<br /> &quot;continue (y/n)?&quot; {<br />  send &quot;yr&quot;<br />  expect {<br />   timeout {<br />    puts &quot;delete timed out&quot;; exit<br />   }<br />   &quot;RedBoot&gt; &quot;<br />  } <br /> }<br /> &quot;RedBoot&gt; &quot;<br />}<br /><br />send -- &quot;fis create -b 0x400000 -l 0xD0000 -s 0xD0000&quot;<br />send -- &quot; -f 0x1020000 ROMFSr&quot;<br />set timeout 40<br />expect {<br /> timeout {<br />  puts &quot;flash timed out&quot;; exit<br /> }<br /> &quot;RedBoot&gt; &quot;<br />}<br /><br />#<br /># JFFS2 laden<br />#<br />set spawn_id $telnet_id<br /><br />send &quot;haltr&quot;<br />send &quot;load 0x400000 images/jffs2.img binr&quot;<br />set timeout 30<br />expect {<br /> timeout {<br />  puts &quot;load timed out&quot;; exit<br /> }<br /> &quot;Loading program file passed&quot;<br />}<br />send &quot;gor&quot;<br />sleep 1<br /><br />set spawn_id $kermit_id<br /><br />send &quot;fis delete JFFS2r&quot;<br />set timeout 30 <br />expect {<br /> timeout {<br />   puts &quot;delete timed out&quot;; exit<br /> }<br /> &quot;continue (y/n)?&quot; { <br />  send &quot;yr&quot; <br />  expect {<br />   timeout { <br />    puts &quot;delete timed out&quot;; exit<br />   }<br />   &quot;RedBoot&gt; &quot;<br />  } <br /> }<br /> &quot;RedBoot&gt; &quot;<br />}<br /><br />send -- &quot;fis create -b 0x400000 -l 0x400000 -s 0x164&quot; <br />send -- &quot; -f 0x1300000 JFFS2r&quot; <br />set timeout 40 <br />expect {<br /> timeout { <br />  puts &quot;flash timed out&quot;; exit<br /> }<br /> &quot;RedBoot&gt; &quot;<br />}<br /><br />#<br /># Geraet starten<br />#<br />set spawn_id $telnet_id<br /><br />send &quot;res runr&quot;<br /><br />set spawn_id $kermit_id<br />set timeout 40<br />expect {<br /> timeout {<br />   puts &quot;startup timed out&quot;; exit<br /> }<br /><br /> &quot;Here we go&quot;<br />}<br /><br />puts &quot;succes!!!n&quot;

转载请注明:在路上 » 【转】使用脚本与RedBoot协作

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
79 queries in 0.199 seconds, using 22.15MB memory