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.

Using the NXP i.MX RT1170 EVK board, you connect to the target serial console on LPUART1 available on the J45 and J46(refer to Connecting Serial Console to the NXP i.MX RT1170 EVK for details. Assuming you connect to a Linux PC host, on the Linux host the i.MX RT1170 serial console will be visible as a /dev/ttyUSBx 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 NXP i.MX RT1170 EVK loadaddr is set as follows, placing the download buffer into SDRAM:

=> print loadaddr

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 NXP i.MX RT1170 EVK).

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-imxrt1170.script

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

echo {loading uImage}

OUTPUT loadb ${loadaddr} 115200\{13}
send rootfs.uImage
INPUT 180 {\{13}\{10}=> }

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

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-imxrt1170.script $ ./uartboot-imxrt1170.script C-Kermit 9.0.305 OPEN SOURCE: Alpha.07, 24 Jan 2022, Ubuntu-22.04.2.myguest.virt ualbox.org [] Current Directory: /home/sasha Communication Device: /dev/ttyUSB0 Communication Speed: 115200 Parity: none RTT/Timeout: 01 / 03 SENDING: rootfs.uImage => ROOTFS.UIMAGE File Type: BINARY File Size: 5423698 Percent Done: 30 /////////////// ...10...20...30...40...50...60...70...80...90..100 Estimated Time Left: 00:07:26 Transfer Rate, CPS: 8405 Window Slots: 1 of 1 Packet Type: D Packet Count: 253 Packet Length: 9033 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 15+ long minutes to download the image at 115.2Kps but finally it will get to the target and Linux will boot from it:

## Total Size = 0x00764002 = 7749634 Bytes ## Start Addr = 0x80007FC0 => running kernel Connecting to /dev/ttyUSB0, 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 80007fc0 ... Image Name: Linux-4.5.0 Image Type: ARM Linux Multi-File Image (uncompressed) Data Size: 5423634 Bytes = 5.2 MiB Load Address: 80008000 Entry Point: 80008001 Contents: Image 0: 5416512 Bytes = 5.2 MiB Image 1: 7110 Bytes = 6.9 KiB Verifying Checksum ... OK ## Flattened Device Tree from multi component Image at 80007FC0 Booting using the fdt at 0x8053264c Loading Multi-File Image ... OK Loading Device Tree to 83e68000, end 83e6cbc5 ... OK Starting kernel ... Booting Linux on physical CPU 0x0 Linux version 4.5.0 (sasha@workbench.emcraft.com) (gcc version 4.7.4 20130508 (prerelease) (20161027-112109- build on iron.emcraft.com by sergmir) ) #1 Wed Apr 19 12:20:52 +0400 2023 CPU: ARMv7-M [411fc272] revision 2 (ARMv7M), cr=00000000 CPU: WBA data cache, WBA instruction cache Machine model: NXP IMXRT1170 EVK board