2. Build CVITEK Software Compilation Environment

2.1. Linux Server

Developers can choose to use:

  • Ubuntu OS computer

  • Windows OS computer + Virtualbox VM (run Ubuntu on it)

In both cases, install Ubuntu 20.04 LTS.

Virtualbox VM Download site: https://www.virtualbox.org/wiki/Downloads

Ubuntu 20.04 LTS Download site: https://releases.ubuntu.com/20.04/ubuntu-20.04.2.0-desktop-amd64.iso

2.1.1. Install Ubuntu on VirtualBoxVM

  • Create and name the new VM

    BuildC004

  • Plan 8GB memory for VM use.

    BuildC005

  • Reserve 200GB hard disk space for subsequent storage of SDK.

    BuildC006

2.1.2. Ubuntu Boot Settings

  • First boot requires mounting the installation disk’s ISO file

    BuildC007

  • Start Installation

    BuildC008

  • Set up VirtualBox Host-only Ethernet Adapter for Host to communicate with VirtualBox (terminal services and files sharing)

    BuildC009

2.1.3. Install SSH Server

SSH Server Installation

sudo apt-get install ssh
sudo apt-get install openssh-server

After installation, some ssh settings can be changed, such as port, password authentication, root login, etc.

vim /etc/ssh/sshd_config
Port 22
PasswordAuthentication yes
PermitRootLogin yes -> 是否开放 root 登入

Restart SSH after modification

/etc/init.d/ssh restart

2.1.4. Install Samba Server

Ubuntu VB requires the Samba package to be installed for subsequent files sharing with Host PC.

Before installing Samba, use ifconfig to get IP information, the first installation will show that there is no net-tool support, it needs to install net-tool

sudo apt install net-tools
sudo apt-get install samba samba-common

Create the samba password for the account

sudo smbpasswd -a cvitek

Modify /etc/samba/smb.conf and add the following

[cvitek]path = /home/cvitek
writable = yes
browseable= yes
valid users = cvitek

Start samba server

sudo service smbd restart

WINDOW PC connects to Samba server (<Server IP>)

_images/BuildC002.png

Refer to 1.2 to install CVITEK Build Environment to compile.

2.2. Build a compilation environment

Before compiling the SDK, the following packages need to be installed in Ubuntu.

sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y ninja-build
sudo apt-get install -y automake
sudo apt-get install -y autoconf
sudo apt-get install -y libtool
sudo apt-get install -y wget
sudo apt-get install -y curl
sudo apt-get install -y git
sudo apt-get install -y gcc
sudo apt-get install -y libssl-dev
sudo apt-get install -y bc
sudo apt-get install -y slib
sudo apt-get install -y squashfs-tools
sudo apt-get install -y android-sdk-libsparse-utils
sudo apt-get install -y android-sdk-ext4-utils
sudo apt-get install -y jq
sudo apt-get install -y cmake
sudo apt-get install -y python3-distutils
sudo apt-get install -y tclsh
sudo apt-get install -y scons
sudo apt-get install -y parallel
sudo apt-get install -y ssh-client
sudo apt-get install -y tree
sudo apt-get install -y python3-dev
sudo apt-get install -y python3-pip
sudo apt-get install -y device-tree-compiler
sudo apt-get install -y libssl-dev
sudo apt-get install -y ssh
sudo apt-get install -y cpio
sudo apt-get install -y squashfs-tools
sudo apt-get install -y fakeroot
sudo apt-get install -y libncurses5
sudo apt-get install -y flex
sudo apt-get install -y bison

2.3. Install SDK

The SDK is usually placed in the customer-specific FTP, /home/SDK/cv18xx_t(SDK_Version), taking SDK V 4.0.0 as an example here.

_images/BuildC003.png

Get t4.0.0_source.tar.gz and unzip it

$ tar zxvf t4.0.0 source.tar.gz

Get host-tool.tar.gz and unzip it in the SDK working directory

$ cd cv180x_t4.0.0_source
$ tar zxvf host-tools.tar.gz

2.4. Compilation

2.4.1. Environment Variables Description

The pre-compilation operation is mostly for setting two environment variables: $CHIP, $BOARD,

$CHIP variable is required to be set according to the user’s SOC.

$BOARD variable has a different driver for each EVB and must be set correctly.

For example:

$BOARD=wevb_0008a_spinor: is SPINOR+DDR2 1333 64 MB hardware combination

$BOARD=wevb_0009a_spinand: is SPINAND+DDR3 1866 128MB hardware combination

Note: wevb_0008a / wevb_0009a can be obtained by the EVB laser model directly.

2.4.2. Compile the Entire Package

Before setting the environment variables, the following commands are required to initialize the environment. The ICs and EVB version numbers currently supported by the SDK will be listed by the system.

$ source build/cvisetup.sh
  -----------------------------------------------------------------------
    Usage:
    (1) menuconfig - Use menu to configure your board.
        ex: $ menuconfig
    (2) defconfig $CHIP_ARCH - List EVB boards($BOARD) by CHIP_ARCH.
        ** cv183x ** -> ['cv1829', 'cv1832', 'cv1835', 'cv1838', 'cv9520', 'cv7581']
       ** cv182x ** -> ['cv1820', 'cv1821', 'cv1822', 'cv1823', 'cv1825', 'cv1826', 'cv7327', 'cv7357']
       ** cv181x ** -> ['cv181x', 'cv1823a', 'cv1821a', 'cv1820a', 'cv1811h', 'cv1811c', 'cv1810c', 'cv1812h']
       ** cv180x ** -> ['cv180x', 'cv1800b', 'cv1800c', 'cv1801b', 'cv1801c']
        ex: $ defconfig cv183x    (3) defconfig $BOARD - Choose EVB board settings.
        ex: $ defconfig cv1835_wevb_0002a
        ex: $ defconfig cv1826_wevb_0005a_spinand
        ex: $ defconfig cv180x_fpga_c906
  -----------------------------------------------------------------------

After initialization, the compilation configuration can be set in the following two ways

2.4.2.1. Set by defconfig

Select IC: Take cv180x as an example, the system will print out the EVB ($CHIP_$BOARD) board supported by cv180x built-in.

$ defconfig cv180x
* cv180x * the avaliable cvitek EVB boards
  cv180x - cv180x_fpga [FPGA]
           cv180x_palladium [PALLADIUM]
 cv1800b - cv1800b_wdmb_0008a_spinor [C906B + SPINOR 8MB + QFN SIP 64MB]
           cv1800b_wevb_0008a_spinor [C906B + SPINOR 16MB + QFN SIP 64MB]
 cv1800c - cv1800c_wevb_0009a_spinor [C906B + SPINOR 16MB + QFN SIP 64MB]
 cv1801b - cv1801b_wevb_0008a_spinor [C906B + SPINOR 16MB + QFN SIP 128MB]
 cv1801c - cv1801c_wdmb_0009a_spinor [C906B + SPINOR 16MB + QFN SIP 128MB]
           cv1801c_wevb_0009a_spinand [C906B + SPINAND 256MB + QFN SIP 128MB]
           cv1801c_wevb_0009a_spinor [C906B + SPINOR 16MB + QFN SIP 128MB]
           cv1812h_wevb_0007a_spinor [C906B + SPINOR 16MB + BGA SIP 256MB]

Select the EVB version number cv1801c_wevb_0009a_spinor, then the system will list the automatically set environment variables. (Subsequently, cvi_print_env can also be used to print the environment variables currently in use)

$ defconfig cv1801c_wevb_0009a_spinor

====== Environment Variables =======

  PROJECT: cv1801c_wevb_0009a_spinor, DDR_CFG=ddr3_1866_x16
  CHIP_ARCH: CV180X, DEBUG=0
  SDK VERSION: musl_riscv64, RPC=0
  ATF options: ATF_KEY_SEL=default, BL32=1
  Linux source folder:linux_5.10, Uboot source folder: u-boot-2021.10
  CROSS_COMPILE_PREFIX: riscv64-unknown-linux-musl-
  ENABLE_BOOTLOGO: 0
  Flash layout xml: build/boards/cv180x/cv1801c_wevb_0009a_spinor/part
ition/partition_spinor.xml
  Sensor tuning bin: gcore_gc4653
  Output path: install/soc_cv1801c_wevb_0009a_spinor

2.4.2.2. Set by Menuconfig

After initialization, type in menuconfig to enter the following page to select various SDK internal settings, including CHIP, EVB board number, etc.

_images/image12.png _images/image13.png

The configuration process can be set/returned by [Enter] [Space] [ESC]

After configuration, press [S] to save the configuration file, then press [Q] to leave the graphical interface

(Or press ESC and a graphical interface will automatically pop up asking whether to save)

Select IC (cv1801c as an example)

_images/image14.png

The EVB version number will list the corresponding choices, and the selection of EVB will also specify the compiled image’s DDR and Flash size (for this example, the selected EVB comes with DDR3 and 16MB of SPINOR Flash).

_images/image15.png

Finally, exit the selection and save the settings (they will be stored in. /build/.config) to complete the selection of the SDK compilation configuration.

2.4.3. Compile the Entire SDK Files

Execute the compilation and get the images available for burning.

cvitek@cvitek-VirtualBox:~/working_dir$ build_all
. Run build_uboot () function
...
/work/install/cv1801c_wevb_0009a_spinor/upgrade.zip done!

The complied file will be placed in ./install/soc_<EVB Name>/

2.4.4. Compile part of the SDK files

2.4.4.1. Compile Uboot Separately

Each EVB board defines in a specific location the initialization operations that the EVB needs to take before entering U-Boot or defines a specific PINMUX. Taking the board cv1801c_wevb_0009a_spinor as an example, they will be defined in.

build/boards/CV181X/$CHIP_$BOARD/u-boot/cvi_board_init.c
int cvi_board_init(void)
{
#if defined(CV180X_QFN_88_PIN)
    PINMUX_CONFIG(PAD_MIPI_TXP1, IIC2_SCL);
    PINMUX_CONFIG(PAD_MIPI_TXM1, IIC2_SDA);
    PINMUX_CONFIG(PAD_MIPI_TXP0, XGPIOC_13);
    PINMUX_CONFIG(PAD_MIPI_TXM0, CAM_MCLK1);
#elif defined(CV180X_QFN_88_PIN_38)
    return 0;
}

The corresponding u-boot configuration, defined in CV181X:

./build/boards/CV181X/$CHIP_$BOARD/u-boot/$CHIP_$BOARD_defconfig
Partial cvitek_cv1801c_wevb_0009a_spinor_defconfig
CONFIG_RISCV=y
CONFIG_SYS_MALLOC_F_LEN=0x2000
CONFIG_NR_DRAM_BANKS=1
CONFIG_DEFAULT_DEVICE_TREE="cv180x_asic"
CONFIG_IDENT_STRING=" cvitek_cv180x"

Modify Uboot Config with a graphical interface

_images/image16.png

After exiting, the settings will be stored in:

./u-boot/build/"$CHIP"_"$BOARD"/.config

Execute compilation

$ build_uboot

When completed, fip.bin will be generated

Compile U-Boot fragments in Makefile

u-boot-build: ${UBOOT_PATH}/${UBOOT_OUTPUT_FOLDER} ${UBOOT_CVIPART_DEP} ${UBOOT_OUTPUT_CONFIG_PATH}
   $(call print_target)
   ${Q}rm -f ${UBOOT_CVI_BOARD_INIT_PATH}
   ${Q}ln -s ${BUILD_PATH}/boards/${PROJECT_FULLNAME}/u-boot/cvi_board_init.c ${UBOOT_CVI_BOARD_INIT_PATH}
   ${Q}$(MAKE) -j${NPROC} -C ${UBOOT_PATH} olddefconfig
   ${Q}$(MAKE) -j${NPROC} -C ${UBOOT_PATH} all
   $(call uboot_compress_action)

2.4.4.2. Compile kernel separately

Modify the kernel (ex:*.dts, kernel) and recompile the Linux kernel image.

Each EVB has a corresponding dts file to define its device tree, take cv1801c_wevb_0009a_spinor for example, its DTS file is defined in:

./build/boards/cv180x/"$CHIP"_"$BOARD"/dts_riscv/"$CHIP"_"$BOARD".dts`
#/dts-v1/;
#include "cv180x_base_riscv.dtsi"
#include "cv180x_asic_qfn.dtsi"
#include "cv180x_asic_spinor.dtsi"
#include "cv180x_default_memmap.dtsi"

/ {
};

Its corresponding linux configuration is defined in:

./build/boards/"$CHIP"_"$BOARD"/linux/"$CHIP"_"$BOARD"_defconfig
Partial cv1801c_wevb_0009a_spinor
CONFIG_SYSVIPC=y
CONFIG_POSIX_MQUEUE=y
CONFIG_NO_HZ_IDLE=y
CONFIG_HIGH_RES_TIMERS=y
CONFIG_PREEMPT=y
CONFIG_IKCONFIG=y
CONFIG_IKCONFIG_PROC=y
CONFIG_LOG_BUF_SHIFT=15
CONFIG_BLK_DEV_INITRD=y
...

Modify Kernel Config with graphical interface

$ menuconfig_kernel
_images/image17.png

After exiting, the settings will be store in:

./linux/build/"$CHIP"_"$BOARD"/.config
$ build_kernel

When completed, boot.spinor will be generated

Compile Kernel fragments in Makefile.

kernel-build: ${KERNEL_OUTPUT_CONFIG_PATH}
   $(call print_target)
   ${Q}echo LOCALVERSION=${LOCALVERSION}
   ${Q}$(MAKE) -j${NPROC} -C ${KERNEL_PATH} O=${KERNEL_PATH}/${KERNEL_OUTPUT_FOLDER} olddefconfig
   ${Q}$(MAKE) -j${NPROC} -C ${KERNEL_PATH}/${KERNEL_OUTPUT_FOLDER} Image modules
   ${Q}$(MAKE) -j${NPROC} -C ${KERNEL_PATH}/${KERNEL_OUTPUT_FOLDER} modules_install headers_install INSTALL_HDR_PATH=${KERNEL_PATH}/${KERNEL_OUTPUT_FOLDER}/$(ARCH)/usr
   ${Q} ln -sf ${KERNEL_PATH}/${KERNEL_OUTPUT_FOLDER}/$(ARCH)/usr/include ${KERNEL_PATH}/${KERNEL_OUTPUT_FOLDER}/usr/include

2.4.4.3. Compile middleware separately

Modify middleware (cvi_test / sample_dsi), recompile middleware and system

The generated Install/PROJECT_NAME/system.* contains the latest middleware

$ build_middleware; pack_rootfs
pushd "$MW_PATH"/component/isp
make all
popd

pushd "$MW_PATH"/sample
make all

build_middleware will recompile the Sensor driver (in middleware/component/isp/) and sample application (in middleware/sample/), and finally pack_rootfs will package the changed driver and application into a burnable image.

2.5. Partitions

CV181X SDK will generate the following image files, each representing a different partition, listed below:

  • FIP : Bootloader/U-Boot partition

    • CV180X/ CV181X C906 adopts FSBL+OPENSBI+UBOOT architecture, and also reuses (FIP) file name after the final package, which is convenient for subsequent use.

  • BOOT : Partition for Linux Kernel

  • 2nd(dual-system) : The partition where Yun on Processor (YOC) is located.

  • MISC : Boot Logo partition

  • ROOTFS : root file system partition

  • SYSTEM: Partition where CVITEK libraries are located

  • DATA : Using data partition

Note: The 2nd partition is a dual-system-specific partition and exists only in a dual-system environment.

2.5.1. Partition File Modification

The same EVB may have different Flash, and the SDK will separate them with different board numbers. For example cv1811c_wdmb_0006a_spinand and cv1811c_wdmb_0006a_spinor represent the Flash on the development board as SPINAND and SPINOR respectively, and the partition files are placed in

./build/boards/<CHIP>/<EVB_Name>/partition/partition_<physical_partition>.xml

Note:physical_partition supports SPINAND/SPINOR。

For example, the partition files of cv1801c_wdmb_0009a_spinor are displayed as follows:

In a single-system environment:

build/boards/cv181x/cv1811c_wdmb_0006a_spinor/partition/partition_spinor.xml
<physical_partition type="spinor">
   <partition label="fip" size_in_kb="800" readonly="false" file="fip.bin"/>
   <partition label="BOOT" size_in_kb="2600" readonly="false" file="boot.spinor"/>
   <partition label="ENV" size_in_kb="64" file="" />
   <partition label="ROOTFS" size_in_kb="4000" readonly="false" file="rootfs.spinor" />
   <partition label="DATA" size_in_kb="512" readonly="false" file="data.spinor" mountpoint="/mnt/data" type="jffs2" />
</physical_partition>

In a dual-system environment:

build/boards/cv181x/cv1811c_wdmb_0006a_spinor/partition/partition_spinor.xml
<physical_partition type="spinor">
   <partition label="fip" size_in_kb="512" readonly="false" file="fip.bin"/>
   <partition label="2nd" size_in_kb="3072" readonly="false" file="yoc.bin"/>
   <partition label="BOOT" size_in_kb="5120" readonly="false" file="boot.spinor"/>
   <partition label="MISC" size_in_kb="128" readonly="false" file="logo.jpg"/>
   <partition label="PARAM" size_in_kb="64" file="" />
   <partition label="PARAM_BAK" size_in_kb="64" file="" />
   <partition label="ENV" size_in_kb="64" file="" />
   <partition label="ENV_BAK" size_in_kb="64" file="" />
   <partition label="ROOTFS" size_in_kb="3392" readonly="false" file="rootfs.spinor" />
   <partition label="DATA" size_in_kb="1024" readonly="false" file="data.spinor" mountpoint="/mnt/data" type="jffs2" />
</physical_partition>
  • physical_partiti type: flash type.

  • partition label: partition name.

  • size_in_kb: partition size (in KB).

  • file: name of the image file pointed to.

  • type: (in the partition tab field) file system format.

  • mountpoint: partition mount path.

Note: The 2nd partition is a dual-system-specific partition and exists only in a dual-system environment.