title: Sending file through serial port using expect and ymodem on Linux?
body: <p>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 <code>ymodem &lt;address&gt;</code> and seeing the <code>C</code> character: </p>
  
  <pre><code>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
  </code></pre>
  
  <p>Tera Term also support Macro to automate the process, which works fine. Now I want to use <code>screen</code>+<code>expect</code>+<code>sz</code> under Linux to do the same...But so far I am not successful.</p>
  
  <p>I am currently testing with the following code:</p>
  
  <pre><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"
  </code></pre>
  
  <p>It seems <code>sz</code> repeately sending the file, but there is no feedback from the remote side:</p>
  
  <pre><code>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 &lt;C&gt;
  spawn id exp8 sent &lt;\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&gt;
  
  spawn id exp8 sent &lt;\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&gt;
  </code></pre>
  
  <p>What's missing from the script above? </p>
  
  <p>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 <code>45123 Bytes</code>. How <code>expect</code> watch this msg now? My understanding is that these two spawned processes (<code>screen</code> and <code>sz</code>) talks directly, bypassing <code>expect</code>, no?</p>