Loading Application Files via UART
This note explains how to transfer files, such as application binaries, to a target running Linux over the serial console. This is a useful procedure for those targets that do not provide an Ethernet link and have the serial console as the only communication channel.
On the host, activate the Cortex-M cross-development environment:
[host] $ . ./ACTIVATE.shCreate a simple "Hello, world" C application:
[host] $ cd /tmp [host] $ vi test.c #include <stdio.h> int main(int argc, char *argv[]) { printf("Hello, i.MX RTxxxx\n"); return 0; }Build the application for the Cortex-M target:
[host] $ ${CROSS_COMPILE_APPS}gcc -o test test.cIf you have no
uuencodeinstalled in your system, then install it:[host] $ sudo apt-get install sharutilsEncode the application binary into an ASCII-only presentation so that the file can be transmitted over a serial line:
[host] $ uuencode test < test > test.encodedThe
uudecodeapplication on the target (in order to convert the ASCII-only file back into the application binary) is provided withbusyboxby default in therootfsproject.If you have no
picocominstalled in your system, the install it:[host] $ sudo apt-get install picocomStart the target console:
[host] $ picocom -b 115200 /dev/ttyACM0From the target, run the following to read a file from the serial console:
/ # cat > /test.encoded < /dev/ttyLP0On the host, exit the target console (Ctrl-A and then Ctrl-X in
picocom).On the host, configure the serial port for raw 115200 bps operation, so that the terminal line discipline passes the encoded file through unmodified:
[host] $ stty -F /dev/ttyACM0 115200 raw -echo -echoe -echoctl -echokOn the host, send the encoded ASCII file to the serial port used for the target console:
[host] $ cat /tmp/test.encoded > /dev/ttyACM0When the transfer command finishes, enter the target console again:
[host] $ picocom -b 115200 /dev/ttyACM0Type Ctrl-C to interrupt the
catcommand:^C / #Run uudecode to convert the ASCII file back to the binary file:
/ # uudecode /test.encoded -o /testChange mode to allow running the application binary:
/ # chmod a+x /testFinally, run the application:
/ # /test Hello, i.MX RTxxxx / #