Toradex Luna Unified Flash Image

Toradex Luna uses Synaptics sl1680 that has a pretty unique way to format the eMMC to boot. On this blog post I will show the PhobOS unified flash image that can be used to flash the eMMC on Toradex Luna.


In the previous blog post about the Porting Synaptics Astra SL1680 to run PhobOS I mentioned the weird unique way that the sl1680 eMMC expects to be formatted to be able to boot.

alt text

The Yocto meta-synaptics, that has the vendor specific recipes for create Linux images for the sl1680 SoC, generates then 18 (yeah eighteen!) different .subimg files! One for each of the partitions that the sl1680 expects to be present on the eMMC. Two text files are also generated: emmc_image_list and emmc_part_list that seems to be used by the astra-update tool to match the .subimg files to the partitions.

󱃞 The Problem

Many of the modern OS nowadays has customization and configuration tools that based in a generic image, generates the custom image specific for the application. For example Torizon OS has the TorizonCore Builder and PhobOS has the Opus tool. These tools expects a single raw disk image file that can be then cloned, mounted and modified to apply the customizations.

With the meta-synaptics generating 18 .subimg files, it’s a nightmare for these tools to know how to handle them and generate as output back the 18 .subimg files.

 The Solution

Instead of forcing an edge case onto the customization tool to just handle a single specific SoC format, the smartest solution is to adapt the way that the sl1680 is flashed to instead of use multiple .subimg files, one for each partition, use a single unified raw disk image that contains all the partitions. This way the customization tool will not need to be changed and will work generic enough to handle any SoC that uses a single raw disk image.

 fastboot to the rescue

When the Toradex Luna is put in “flash mode”, usb-boot, the astra-update tool loads and runs an U-boot binary. This USB boot U-boot knows how to read and write the .subimg files to the eMMC. So, the idea was to instead of modify or understand how the Synaptics does the flashing, just use the fastboot directly to flash the unified raw disk image. The image will be formatted in the same way that the meta-synaptics generates the .subimg files, but instead of having 18 files, it will be a single file.

󰔢 Enabling fastboot on USB U-boot

The build of U-boot comes from the same source code that the “normal” U-boot that is flashed to the eMMC. The difference relies on the configuration that is used to build it. You need to enable:

CONFIG_CMD_SYNA_USBLOAD=y

And to have properly fastboot support, the following configuration options are needed:

CONFIG_USB_FUNCTION_FASTBOOT=y
CONFIG_UDP_FUNCTION_FASTBOOT=y
CONFIG_FASTBOOT_BUF_ADDR=0x10000000
CONFIG_FASTBOOT_BUF_SIZE=0x8000000
CONFIG_FASTBOOT_FLASH=y
CONFIG_FASTBOOT_OEM_RUN=y
CONFIG_FASTBOOT_UUU_SUPPORT=y

It’s also important to have:

CONFIG_USE_BOOTCOMMAND=y
CONFIG_BOOTCOMMAND="fastboot usb 0"

This way the U-boot will automatically start the fastboot command when it is loaded by the USB boot. The fastboot command will then wait for a connection from the host computer to send commands and data to flash the eMMC.

 Customizing Synaptics astra-update

The tool that loads the U-boot on the Toradex Luna RAM is the astra-update. It was designed to load the U-boot and also use the SYNA_USBLOAD command to send the .subimg files to be written to the eMMC. Now with our new approach we will continue using the astra-update to load the U-boot anyway, but at end only to load the U-Boot and then we will have to call uuu to then send the unified raw disk image to the eMMC.

To simplify this even more for the end user, I customized the astra-update to have a detection if the $PWD where the user is running the command has a file called uuu.mmc. If this file is present, the astra-update will then hand off to uuu as soon as the U-boot is loaded and ready to receive the fastboot commands.

Here is the commit with these changes: alt text

󰍛 uuu.mmc

So, we have almost everything ready to flash the unified raw disk image to the Toradex Luna eMMC. The only thing missing is a way to tell uuu what to do. The following example is what is being used by PhobOS image:

uuu_version 1.2.39

CFG: FB: -vid 0x18d1 -pid 0x4ee0

FB: ucmd setenv fastboot_dev mmc
FB: ucmd setenv fastboot_partition_alias_all 0.0:0
FB: flash -raw2sparse all PhobOS-luna-emmc-ota-0-2-0.img
FB: done

Simple, right? First it waits for the device to be available on the USB by checking the vendor and product ID. Then it start to send u-boot command through the fastboot interface. It sets the fastboot_dev to mmc and the fastboot_partition_alias_all to 0.0:0, that means the entire eMMC. This is needed because the unified raw disk image has all the partitions in a single file. At end it uses the flash -raw2sparse command to send the unified raw disk image to the eMMC. And it finish with the done command to tell uuu that the flashing flow is finished.

󱄗 Final Flow

Before what was needed was:

alt text

Note that there was even scripts to put the Yocto generated .subimg files together in a raw disk image, and also the counterpart to extract the .subimg files from a raw disk image after customization.

Now with the new approach:

alt text

What is really used by the astra-update and the U-boot that is loaded is the unified raw disk image. The .subimg files are not used anymore, what made the conversion scripts obsolete.

 Conclusion

Moving Toradex Luna flashing from 18 .subimg files to a single unified raw image makes the whole pipeline simpler, more portable and easier to maintain. Instead of forcing custom tooling for one SoC layout, we reuse the standard image customization flow and only adapt the flashing stage with fastboot + uuu.

In practice this means less glue scripts, fewer fragile conversions, and a more predictable end-user experience: customize one image, flash one image. For PhobOS this is a big step because it keeps the build and customization flow generic while still respecting the Synaptics SL1680 boot requirements.

The Gaia build system cookbook-synaptics recipes has all that is needed to build the custom fastboot enabled U-boot, the uuu.mmc file and the unified raw disk image.

alt text

 It's important to note that this approach is available only for flashing DeimOS and PhobOS, and it's not an official Synaptics/Toradex solution.

Know you are loved ❤️