
In one of my
previous posts I talked about using zmodem as a backup/emergency method to transfer files onto an embedded device using the serial console. This technique requires you to have the
lrz binary on the target to initiate the transfer. But what happens if you have no way of getting
lrz onto the target in the first place? In this post I show you a method of serial transfer requiring no binaries to be on the target, and absolutely no setup on the target-side.
First, check that you have a
Python 2.x version installed. If you don't,
apt-get or
yum install it onto your host OS. Check the version with
python --version.
Now get the utility, which is called '
serio'. Get it with
hg clone https://code.google.com/p/serio/. Before you go ahead, there are two patches you need to apply (by hand):
Patch 1:
Insert
self.last_size = 0 at the location shown, highlighted in green:
if callable(fp.read) and callable(fp.write) and callable(fp.readline) and callable (fp.readlines):
self.fp = fp
self.current = 0
self.showprogress = progress
self.last_size = 0
Patch 2:
Get rid of this line, on
line 19:
self.s.open()
and insert these lines instead:
already_open = self.s.isOpen()
if not already_open:
self.s.open()
Update (14 June 2015): I tried this again recently. It seems you may need to use
self.serial.isOpen() and
self.serial.open() instead.
That patch above is for people who get the
"Port is already open" error. Now you can run the utility:
sudo ./serio -s lrz -d lrz -p /dev/ttyS0
where
-s is the source file,
-d is the destination, and
-p is the serial (console) port. You'll get a nice progress bar.
I recommend putting
lrz onto your target (as per my example) so you can do zmodem transfers from here on in.
Help! It transfers, but the executable doesn't work!
- Check that the echo command on your target supports the "-n" and "-e" options (that's all you need).
- Try cross-compiling a minimal "hello world" program with your toolchain and try transferring that, as a test. Run it, and if you see "hello world" your settings are probably OK. See the next point...
- Open the source code and modify the parameter IO_TIME = .1 to be something greater than .1 (try .3 or .5).
- In addition to the previous step, try using your toolchain's strip command to reduce the size of the binary.