CN913x u-boot, atf and mv-ddr-marvell - Self Build
Introduction
CN913x based devices use ATF (ARM Trusted Firmware) for the first stage of booting, wrapping a secondary image such as a U-Boot.
Currently mv-ddr-marvell and atf are taken from the mainline, however, u-boot and mrvl_scp_bl2.img are still not public and must be taken from marvell SDK10, or get the binaries from SolidRun GitHub at GitHub - SolidRun/cn913x_build .
Build Instructions
Fetch sources
Clone the ATF source tree from GitHub
git clone https://github.com/ARM-software/arm-trusted-firmware.git arm-trusted-firmware
cd arm-trusted-firmware
git checkout 00ad74c7afe67b2ffaf08300710f18d3dafebb45
Clone the mv-ddr-marvell source tree from GitHub
git clone https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell.git mv-ddr-marvell
cd mv-ddr-marvell
git checkout mv-ddr-devel
Clone the u-boot source tree from GitHub and applying u-boot git patches from SDK10
git clone git://git.denx.de/u-boot.git u-boot
cd u-boot
git checkout v2019.10 -b marvell
git am -3 <path-to>/git-u-boot-<version>-<release>/*.patch
It is also possible to download u-boot.bin from SolidRun GitHub, currently available for the CN913x COM Express Type 7.
Patches to support CN913x CEx7 are available on SolidRun GitHub
Compile
A cross toolchain targeting arm64 is required. Linaro provides prebuilt toolchains here; Generally though any toolchain will do. On Debian Stretch and later, the arm64 toolchain is provided by the crossbuild-essential-arm64 package.
Toolchain - the toolchain can be either taken from Marvell SDK10 or downloaded. Below, an example for gcc-linaro:
Compile U-Boot and ATF
If everything went well there should now be a new file at arm-trusted-firmware/build/t9130/release/flash-image.bin
ready for deployment.
Configure
The above flash-image.bin can be used to boot from Micro-SD, SPI and eMMC.
Please note however that the environment will always be saved on SPI flash unless it was explicitly configured differently through these configuration items:
Note: Since not all of the options are exposed by menuconfig, appending them to configs/sr_cn913x_cex7_defconfig
before running make sr_cn913x_cex7_defconfig
is the easiest.
Deploy
From Linux
To microSD
First insert the target microSD into any computer running Linux and identify its canonical name in /dev, e.g. by reading through dmesg. Errors in this step will result in data loss!
The Boot ROM expects to find a bootable image at 512 bytes, 4096 times into the block device. Use dd for writing the previously compiled flash-image.bin to the designated location. In this example sdX is used as placeholder for the actual device name of your microSD on your system:
This process will also work on the device itself, if it has already booted into Linux.
To eMMC data partition
Since the eMMC is soldered to the board, this procedure has to be done on the device itself after booting into a Linux system first. The process is identical to microSD except for the important detail that the Boot ROM expects to find the bootable image at the first block. This will conflict with any partition table or filesystem on this partition. Therefore using one of the dedicated boot partitions is recommended.
To eMMC boot
Since the eMMC is soldered to the board, this procedure has to be done on the device itself after booting into a Linux system first. Please note that as with the eMMC data partition, the Boot ROM expects to find the bootable image at the start of the partition without any offset.
To avoid accidents, the boot partitions are write protected by default. This protection is easy enough to turn off:
Now the bootable image can be written to either boot partition with dd:
As a last step, the eMMC has to be configured for selecting the intended boot partition. This can be done on the U-Boot console with the mmc partconf
command, or from Linux with the mmc
application from mmc-utils:
From U-Boot
To SPI Flash
This step requires U-Boot running on the target device first, e.g. loaded from microSD or UART. The flash-image.bin can then be loaded from either microSD, eMMC, USB or network, and finally written to the SPI flash.
This sample covers the easiest case where flash-image.bin is available on a fat formatted partition on a USB drive:
u-boot-armada38x/download-serial.sh
An example is as follows -
Embedded in download-serial.sh a small C program that gets built every time the script runs and requires curses libraries.
SolidRun Ltd.