- Created by SolidRun on Aug 31, 2021
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
Version 1 Current »
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 https://github.com/SolidRun/cn913x_build.git .
Build Instructions
Fetch sources
Clone the ATF source tree from GitHub
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
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
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:
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
# 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
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:
# 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
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:
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.
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:
# 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:
# 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
mmc partconf
command, or from Linux with the
mmc
application from mmc-utils:
# 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:
# 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 –
./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
Introduction
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.
git clone https://github.com/SolidRun/cn913x_build.git
The runme.sh script is meant to build a ready to use image containing:
mv-ddr-marvell – from mainline
https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell.gitarm-trusted-firmware – from mainline
https://github.com/ARM-software/arm-trusted-firmware.git
** mrvl_scp_bl2.img is not public yet. it is provided in the binaries folderu-boot – from Marvell SDK
patches are applied on git://git.denx.de/u-boot.gitlinux – from mainline
https://github.com/torvalds/linux.git
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:
mkdir $ROOTDIR/patches-sdk-u-boot/
Extract the git-u-boot–.tar.bz2 under the destination folder git-u-boot– and copy the patches
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
./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 –
sudo dd if=images/cn9132-cex7_config_0_ubuntu.img of=/dev/sdX
In u-boot prompt, to continue booting from SD card:
setenv get_images "load mmc 1:1 $kernel_addr_r boot/Image; load mmc 1:1 $fdt_addr_r boot/cn9132-cex7.dtb; setenv root 'root=/dev/mmcblk1p1 rootwait rw'; setenv ramdisk_addr_r -"boot
For burning only the flash-image.bin on an SD card
sudo dd if=images/flash-image.bin of=/dev/sdX bs=512 seek=4096
CN913x Kernel – Self Build
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:
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-
Toolchains based on gcc 8 and later are released by ARM (Ltd) directly.
https://developer.arm.com/open-source/gnu-toolchain/gnu-a
Download and extract the toolchain into some place; and as instructed below the CROSS_COMPILE environment variables needs to be set to the path of the toolchain prefex.
For instance if the toolchain was extracted under /opt/gcc-linaro-7.3.1-2018.05-x86_aarch64-linux-gnu/ then the CROSS_COMPILE needs to be set as follows –
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 –
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
git am *./patch
Compile the Image and device tree
make defconfig#Building the source run make -j${PARALLEL} Image dtbs
Result Files
$ROOTDIR/linux/arch/arm64/boot/Image # kernel image$ROOTDIR/linux/arch/arm64/boot/dts/marvell/cn913?-cex7.dtb #can be cn9130/cn9131/cn9132
- No labels