Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

CN913x u-boot, atf and mv-ddr-marvell – Self Build

...

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 https://github.com/SolidRun/cn913x_build.git .

Build Instructions

Fetch sources

  • Clone the ATF source tree from GitHub

Code Block
git clone https://github.com/ARM-software/arm-trusted-firmware.git arm-trusted-firmwarecd arm-trusted-firmwaregit checkout 00ad74c7afe67b2ffaf08300710f18d3dafebb45
  • Clone the mv-ddr-marvell source tree from GitHub

Code Block
git clone https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell.git mv-ddr-marvellcd mv-ddr-marvellgit checkout mv-ddr-devel
  • Clone the u-boot source tree from GitHub and applying u-boot git patches from SDK10

Code Block
git clone git://git.denx.de/u-boot.git u-bootcd u-bootgit checkout v2019.10 -b marvellgit 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:

Code Block
wget http://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xztar -xvf gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xzexport CROSS_COMPILE=[path-to-your-toolchain/]/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
  • Compile U-Boot and ATF

Code Block
# 1. U-Bootcd u-boot# run make menuconfig to customize (optional)make sr_cn913x_cex7_defconfigmake DEVICE_TREE=cn9132-cex7-A# 2. ATFcd atf-marvellexport BL33=<patch to u-boot directory>/u-boot/u-boot.binexport SCP_BL2=<path to image>/mrvl_scp_bl2.imgcd arm-trusted-firmware/make DEBUG=1 USE_COHERENT_MEM=0 LOG_LEVEL=20 PLAT=t9130 MV_DDR_PATH=/home/alon/work/cn913x/mv-ddr-marvell/mv_ddr-SDK-10.3.3.0-PR8/ CP_NUM=3 all fipmake -j${PARALLEL} USE_COHERENT_MEM=0 LOG_LEVEL=20 PLAT=t9130 MV_DDR_PATH=../build/mv-ddr-marvell CP_NUM=3 all fip

If everything went well there should now be a new file at 

Code Block
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:

Code Block
# SPI FlashCONFIG_ENV_IS_IN_MMC=nCONFIG_ENV_IS_IN_SPI_FLASH=y# eMMC boot 0CONFIG_MVEBU_MMC_BOOT=yCONFIG_ENV_IS_IN_MMC=yCONFIG_ENV_IS_IN_SPI_FLASH=nCONFIG_SYS_MMC_ENV_DEV=1CONFIG_SYS_MMC_ENV_PART=1  #eMMc boot 1CONFIG_MVEBU_MMC_BOOT=yCONFIG_ENV_IS_IN_MMC=yCONFIG_ENV_IS_IN_SPI_FLASH=nCONFIG_SYS_MMC_ENV_DEV=1CONFIG_SYS_MMC_ENV_PART=2# microSDCONFIG_MVEBU_MMC_BOOT=yCONFIG_ENV_IS_IN_MMC=yCONFIG_ENV_IS_IN_SPI_FLASH=nCONFIG_SYS_MMC_ENV_DEV=1CONFIG_SYS_MMC_ENV_PART=0#Remove any other CONFIG_ENV_IS_IN_* occurrences in defconfig file

Note: Since not all of the options are exposed by menuconfig, appending them to 

Code Block
configs/sr_cn913x_cex7_defconfig

 before running 

Code Block
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:

Code Block
dd if=flash-image.bin of=/dev/sdX bs=512 seek=4096 conv=sync

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.

Code Block
dd if=flash-image.bin of=/dev/sdX conv=sync
  • To eMMC bootY

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:

Code Block
# for boot0:echo 0 | sudo tee /sys/block/mmcblk0boot0/force_ro# for boot1:echo 0 | sudo tee /sys/block/mmcblk0boot1/force_ro

Now the bootable image can be written to either boot partition with dd:

Code Block
# for boot0sudo dd if=flash-image.bin of=/dev/mmcblk0boot0 conv=fsync# for boot1sudo dd if=flash-image.bin of=/dev/mmcblk0boot1 conv=fsync

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 

Code Block
mmc partconf

command, or from Linux with the 

Code Block
mmc

application from mmc-utils:

Code Block
# from Linux:# use boot0mmc bootpart enable 1 0 /dev/mmcblk0# use boot1mmc bootpart enable 2 0 /dev/mmcblk0# from U-Boot# use boot0mmc partconf 0 0 1 0# use boot1mmc partconf 0 0 2 0

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:

Code Block
# start USB stackusb start# scanning usb for storage devices... 1 Storage Device(s) found <-- indicates success# load flash-image.bin to ramload usb 0:1 $kernel_addr_r flash-image.bin# u-boot will indicate how many btes were read. Make sure to verify the number!# initialize spi flashsf probe# optionally erasesf erase 0 0x800000# finally write loaded filesf write $kernel_addr_r 0 0x$filesize

https://github.com/SolidRun/u-boot-armada38x/blob/u-boot-2013.01-15t1-clearfog/download-serial.sh

An example is as follows –

Code Block
./download-serial.sh /dev/ttyUSB0 flash-image.bin

Embedded in download-serial.sh a small C program that gets built every time the script runs and requires curses libraries.

Verified Boot

TBD Read more here: Verified Boot

CN913x Build – Script

...

The main intention of this manual is to provide build scripts that are easy to handle compared to Marvell’s build environment and self build for CN913x based products.

Code Block
git clone https://github.com/SolidRun/cn913x_build.git

The runme.sh script is meant to build a ready to use image containing:

U-Boot based on SDK10 

The CN913x u-boot is not public yet, and was taken from Marvell’s SDK10

In order to use use the script with the SDK 1186 patches, create a directory in ROOTDIR:

Code Block
mkdir $ROOTDIR/patches-sdk-u-boot/

Extract the git-u-boot–.tar.bz2 under the destination folder git-u-boot– and copy the patches

Code Block
cp <sdk patch directory>/Base_SDK/base-patches-SDK-10.3.3.0-PR8/uboot/git-uboot-2019.10-SDK-10.3.3.0-PR8/*.patch patches-sdk-u-boot/ $ROOTDIR/patches-sdk-u-boot/

The script will apply the u-boot patches onto the mainline u-boot.

If the SDK patches directory doesn’t exist, the script will take by default the u-boot.bin provided in the binaries directory.

Run Script

Code Block
./runme.sh

The script will generate a ready to use images at ROOTDIR/images. flash_image.bin for SPI and cn9132_cex7_config_0_ubuntu.img for eMMC or SD card

Deploy

For SD card bootable images:
Plug in a micro SD into your machine and run the following, where sdX is the location of the SD card got probed into your machine –

Code Block
sudo dd if=images/cn9132-cex7_config_0_ubuntu.img of=/dev/sdX

In u-boot prompt, to continue booting from SD card:

...

rw

...

For burning only the flash-image.bin on an SD card

Code Block
sudo dd if=images/flash-image.bin of=/dev/sdX bs=512 seek=4096

...

Introduction

Below are details how to build  Linux kernel for CEX7 , and Buildroot (filesystem), based on the built ATF and U-Boot.

Building From Sources

Toolchain

The toolchain can be either taken from Marvell SDK10 or downloaded. Below, an example for gcc-linaro:

Code Block
wget http://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xztar -xvf gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xzexport CROSS_COMPILE=[path-to-your-toolchain]/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

 

...

Code Block
export ARCH=arm64export CROSS_COMPILE=[path-to-your-toolchain]/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-export ROOTDIR=`pwd`

U-Boot

Your CN913x CEx7 unit should come with a U-Boot burnt into to its SPI NOR Flash.
Otherwise, run the .runme.sh file from SolidRun GitHub or build you own U-Boot following CN913x-u-boot, atf and mv-ddr-marvell-Self Build.

Linux Kernel

  • To build from source; follow the following steps –

Code Block
cd $ROOTDIRexport ARCH=arm64export CROSS_COMPILE=[path-to-your-toolchain]/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.gitcd linuxgit checkout v5.8git am *./patchmake defconfig#Building the source run make -j${PARALLEL} Image dtbs
  • Download the device tress patches from SolidRun GitHub and apply the patches in linux folder

Code Block
git am *./patch
  • Compile the Image and device tree

Code Block
make defconfig#Building the source run make -j${PARALLEL} Image dtbs
  • Result Files

...

-ui-children