Loading Linux Images over UART Print

 

This article explains how to load images to the target over UART in U-Boot. Keep in mind that loading via a serial port will take quite a long time (minutes per file!) due to the low speeds (limited to 115.2 Kps). That said, for embedded targets that do not provide an Ethernet port it may be the only reasonable development and software manufacturing option using U-Boot and uClinux.

Please refer to Connecting Serial Console to the STM32F429 Discovery for information on how to connect to the UART console and use kermit for serial line communication to the target.

The download procedure is based on the loadb command provided by the U-Boot command interface. loadb implements a download capability over UART using the kermit protocol and has the following synopsis:

loadb [<load_address> <baud_rate>]

If you do not specify a load address, then the value will be taken from the loadaddr environment variable. On the STM32F429 Discover loadaddr is set as follows, placing the download buffer into SDRAM:

STM32F429-DISCO> print loadaddr
loadaddr=0xD0007FC0

If you do not specify a baud rate, then the speed the console is currently running at will be used (set to a default value of 115200 on the STM32F429 Discovery).

Once the transmission using loadb finishes, the file will be in memory at the specified load address. The loadaddr environment variable will automatically be set to the address the loadb command used. The filesize environment variable will automatically be set to the number of bytes transferred during the load operation.

Then you are free to do whatever you like with the loaded image. You can boot Linux from the image (assuming it is a Linux uImage file), copy it to some other place (for instance, embedded Flash), display the memory, etc.

To automate the download procedure, you might want to put a desired sequence of interactive steps involving intreractions with the U-Boot command interface on the target and kermit on the host into a shell script. For instance, here is a sample script to download a Linux bootable image (uImage) to SDRAM and boot Linux from it:

$ vi uartboot-stm32f429.script
#!/usr/local/bin/kermit

set port /dev/ttyUSB1
set speed 115200
set carrier-watch off
set flow-control none
set prefixing all

echo {loading uImage}
PAUSE 1

OUTPUT loadb ${loadaddr} 115200\{13}
send networking.uImage
INPUT 180 {\{13}\{10}STM32F429-DISCO> }
IF FAIL STOP 1 INPUT timeout

echo {running kernel}
PAUSE 1
OUTPUT run addip; bootm\{13}

c

Change the file mode to make the script an executable file:

$ chmod +x uartboot-stm32f429.script

Copy the sample Linux image (networking.uImage) from the Emcraft software distribution to the host directory you will be running the shell script from.

Then run the script to download the image to the target via UART and boot Linux from it:

[vlad@yota ~]$ ./uartboot-stm32f429.script
loading uImage

C-Kermit 8.0.212 Dev.26, 20 Dec 2006, yota.emcraft.com [172.17.0.138]

Current Directory: /home/vlad
Communication Device: /dev/ttyUSB1
Communication Speed: 115200
Parity: none
RTT/Timeout: 01 / 03
SENDING: networking.uImage => NETWORKING.UIMAGE
File Type: BINARY
File Size: 1592224
Percent Done: 1 -
...10...20...30...40...50...60...70...80...90..100
Estimated Time Left: 00:03:00
Transfer Rate, CPS: 8683
Window Slots: 1 of 1
Packet Type: D
Packet Count: 8
Packet Length: 9024
Error Count: 0
Last Error:
Last Message:

X to cancel file, Z to cancel group, to resend last packet,
E to send Error packet, ^C to quit immediately, ^L to refresh screen.

It will take a 3 long mintues to download the image at 115.2Kps but finally it will get to the target and Linux will boot from it:

## Total Size = 0x00184ba0 = 1592224 Bytes
## Start Addr = 0xD0007FC0
STM32F429-DISCO> running kernel
Connecting to /dev/ttyUSB1, speed 115200
Escape character: Ctrl-\ (ASCII 28, FS): enabled
Type the escape character followed by C to get back,
or followed by ? to see other options.
----------------------------------------------------
run addip; bootm
## Booting kernel from Legacy Image at d0007fc0 ...
Image Name: Linux-2.6.33-arm1
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1592160 Bytes = 1.5 MB
Load Address: d0008000
Entry Point: d0008001
Verifying Checksum ... OK
Loading Kernel Image ... OK
OK

Starting kernel ...

Linux version 2.6.33-arm1 (vlad @ocean.emcraft.com) (gcc version 4.4.1 (Sourcery G++ Lite 2010q1-189) ) #345 Fri Jan 3 12:34:36 +0400 2014
CPU: ARMv7-M Processor [410fc241] revision 1 (ARMv7M)
...
init started: BusyBox v1.17.0 (2014-01-02 18:24:02 +0400)
~ # ls
bin dev etc httpd init mnt proc root sys usr var
~ #

To exit kermit and free up the serial console, type Ctrl-\ and then q.