1

The ATF (arm trusted firmware, BL1, BL2) command line loop supports ymodem protocol. Under windows, I am using TeraTerm and can use its menu to manually send files to the device, using ymodem protocol, after inputting the command ymodem <address> and seeing the C character:

NOTICE:  Booting Trusted Firmware
NOTICE:  BL1: v1.4(release):58e7395
NOTICE:  BL1: Built : 17:39:25, Jan  2 2018
# ymodem 0x45103000
NOTICE:  ## Ready for binary (ymodem) download to 0x451030000 at 115200 bps...
C

Tera Term also support Macro to automate the process, which works fine. Now I want to use screen+expect+sz under Linux to do the same...But so far I am not successful.

I am currently testing with the following code:

 85 spawn screen /dev/ttyUSB0 115200
 86 set screen $spawn_id
 93 send "ymodem 0x45103000\r"
 94 set timeout 3
 95 expect {
 96         timeout {
 97                 puts "timeout..."
 98                 exit 1
 99         }
100         "115200 bps...\r\nC"
101 }
102 #stty -echo raw
103 spawn sz --ymodem $bl2_burn_path
104 interact -u $screen
105 expect "Bytes"    # can expect see this? 
106 stty echo -raw
107
108 send "\r\r\r"
109 send "exit\r"

It seems sz repeately sending the file, but there is no feedback from the remote side:

expect: does "ymodem 0x45103000\r\n\u001b)0\u001b[?1049h\u001b[4l\u001b[?1h\u001b=\u001b[0m\u001b(B\u001b[1;24r\u001b[H\u001b[J\u001b[H\u001b[Jymodem 0x45103000\r\nNOTICE:  ## Ready for binary (ymodem) download to 0x45103000 at 115200 bps...\r\nC" (spawn_id exp7) match glob pattern "115200 bps...\r\nC"? yes
expect: set expect_out(0,string) "115200 bps...\r\nC"
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "ymodem 0x45103000\r\n\u001b)0\u001b[?1049h\u001b[4l\u001b[?1h\u001b=\u001b[0m\u001b(B\u001b[1;24r\u001b[H\u001b[J\u001b[H\u001b[Jymodem 0x45103000\r\nNOTICE:  ## Ready for binary (ymodem) download to 0x45103000 at 115200 bps...\r\nC"
spawn sz --ymodem /home/bruin/work/f5/bsp/bl2-burn.bin
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {31117}
spawn id exp7 sent <C>
spawn id exp8 sent <\u0001\u0000\u00ffbl2-burn.bin\u000045352 13335245531 100700 0 1 45352\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001c\u0013\u00a4>

spawn id exp8 sent <\u0001\u0000\u00ffbl2-burn.bin\u000045352 13335245531 100700 0 1 45352\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001c\u0013\u00a4>

What's missing from the script above?

I have another question about how to determine the file transfer is complete. Normally (on windows as I observed), once the file tranfer completes, among other things, ATF will print the size of the data transfered, such as 45123 Bytes. How expect watch this msg now? My understanding is that these two spawned processes (screen and sz) talks directly, bypassing expect, no?

bruin
  • 979
  • 1
  • 10
  • 30

1 Answers1

0

You should not be doing a second spawn to run sz. You have launched screen to use the tty device, so now you must ask it to run sz for you, connecting any output from that command to the tty, and passing any output from the tty as input back to that command. You do this by sending an exec command to the screen process, followed by the sz command to execute. You also need to add the 2 indicators !! to connect stdin and stdout of the command to the tty. And you need to send the usual control-a : prefix and colon to make screen take your input as a command.

So replace the spawn sz --ymodem $bl2_burn_path line by something like

send "\001:exec !! spawn sz --ymodem $bl2_burn_path\r"
meuh
  • 11,500
  • 2
  • 29
  • 45
  • Thanks for your answer. I don't have the device at home, will try it later. Btw, can you elaborate a bit on "You have launched screen to use the tty device, so now you must ask it to run sz for you"? My thinking was that the spawned `sz` process is connected to `screen` process (using `interact -u $screen` command), which will in turn connected to tty device, no? I was not aware of `exec` and `!!` of `screen`, I was relying on `expect` to connect two processes (sz and screen) together, and assuming that `screen` will connect `sz`'s output to the tty device... – bruin Sep 15 '18 at 15:35
  • Actually, you are probably right. I didnt read carefully enough to see your use of `interact` to connect the 2 processes together. I wonder why it didnt work; perhaps screen is seeing control-A and interpreting this as a command. Note you can give patterns to look for to the interact command, something like `interact -u $screen "Bytes" return` – meuh Sep 15 '18 at 15:57