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 designs that do not provide an Ethernet port it may be the only reasonable development and software manufacturing option using U-Boot and uClinux.

UUsing the STM32H753i-EVAL board, you connect to the target serial console available on the CN23 Micro-USB connector on the baseboard. Assuming you connect to a Linux PC host, on the Linux host the STM32H753i-EVAL serial console will be visible as a/dev/ttyACMx device. The U-Boot and Linux software configures the console for 115.2 Kps operation.

There are various serial communication tools available for Linux, the most popular perhaps being kermit. kermit is a very powerful tool that can be run in interactive mode or controlled by a script. There is abundant documentation on kermit available in the Internet, if you require details.

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 STM32H753i-EVAL loadaddr is set as follows, placing the download buffer into SDRAM:

STM32H7-EVAL U-Boot > print loadaddr
loadaddr=0xD0C00000

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 STM32H753i-EVAL).

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, on-module Flash), display the memory, etc.

To automate the download procedure, you might want to put a desired sequence of interactive steps involving interactions 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 (rootfs.uImage) to SDRAM and boot Linux from it:

$ vi uartboot.script
#!/usr/bin/kermit

set port /dev/ttyACM0
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 rootfs.uImage
INPUT 180 {\{13}\{10}STM32H7-EVAL U-Boot > }
IF FAIL STOP 1 INPUT timeout

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

Copy the sample Linux image (rootfs.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:

  $ chmod a+x uartboot.script $ ./uartboot.script C-Kermit 9.0.305 OPEN SOURCE: Alpha.07, 24 Jan 2022, Ubuntu-22.04.2.myguest.virt ualbox.org [10.0.2.15] Current Directory: /tmp Communication Device: /dev/ttyACM0 Communication Speed: 115200 Parity: none RTT/Timeout: 01 / 03 SENDING: rootfs.uImage => ROOTFS.UIMAGE File Type: BINARY File Size: 6456331 Percent Done: 56 //////////////////////////// ...10...20...30...40...50...60...70...80...90..100 Estimated Time Left: 00:05:32 Transfer Rate, CPS: 8430 Window Slots: 1 of 1 Packet Type: D Packet Count: 554 Packet Length: 9033 Error Count: 0 Last Error: Last Message: X to cancel file, Z to cancel group, <CR> to resend last packet, E to send Error packet, ^C to quit immediately, ^L to refresh screen.

It will take 15+ long minutes to download the image at 115.2Kps but finally it will get to the target and Linux will boot from it:

loading uImage ## Total Size = 0x007d03e7 = 8192999 Bytes ## Start Addr = 0xD0C00000 STM32H7-EVAL U-Boot > running kernel Connecting to /dev/ttyACM0, 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 d0c00000 ... Image Name: Linux-6.1.28 Image Type: ARM Linux Multi-File Image (uncompressed) Data Size: 8192935 Bytes = 7.8 MiB Load Address: d0008000 Entry Point: d0008001 Contents: Image 0: 8176896 Bytes = 7.8 MiB Image 1: 16027 Bytes = 15.7 KiB Verifying Checksum ... OK ## Loading init Ramdisk from multi component Legacy Image at d0c00000 ... ## Flattened Device Tree from multi component Image at D0C00000 Booting using the fdt at 0xd13cc54c Loading Multi-File Image ... OK Loading Ramdisk to d1a7f000, end d1a82e9b ... OK ERROR: reserving fdt memory region failed (addr=d1c00000 size=300000) ERROR: reserving fdt memory region failed (addr=d1f00000 size=100000) Loading Device Tree to d1a78000, end d1a7ee9a ... OK Starting kernel ... [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 6.1.28 (sasha@workbench.emcraft.com) (arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10) 10.3.1 20210824 (release), GNU ld (GNU Arm Embedded Toolchain 10.3-2021.10) 2.36.1.20210621) #18 PREEMPT Thu Aug 10 04:55:43 UTC 2023 [ 0.000000] CPU: ARMv7-M [411fc271] revision 1 (ARMv7M), cr=00000000 ... [ 2.439499] ip=172.17.0.166:172.17.0.1::::eth0:off init started: BusyBox v1.24.2 (2023-08-08 13:33:53 UTC) [43] Jan 01 00:00:02 Running in background / # / # ls bin etc httpd lib proc sbin tmp var dev hello.ko init mnt root sys usr / #