Compile Linux (Cross Compile)

Follow the steps below to cross compile Linux:

  1. Execute the following to install dependencies and create kernel:
    apt-get install build-essential linux-source bc kmod cpio flex libncurses5-dev libelf-dev libssl-dev dwarves bison git
  2. Checkout the kernel files from StarFive GitHub:
    git clone https://github.com/starfive-tech/linux
  3. Execute the following command to switch to code branch:
    cd linux
    git checkout -b JH7110_VisionFive2_devel origin/JH7110_VisionFive2_devel
    git pull
  4. Execute the following command to set the default configuration of compiling Linux kernel:
    make <Configuration_File> CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv
    Tip: <Configuration_File>: This file is starfive_visionfive2_defconfig on VisionFive 2.
  5. Execute the following command to set other software configuration of compiling Linux kernel:
    make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv menuconfig
  6. Compile Linux Kernel:
    make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv -jx
    Note: Here you need to change the -jx value according to the number of cores in your CPU. If your CPU has 8 cores, change this to -j8. This process will take some time and therefore please wait patiently. This process is quite time-consuming, please be patient and wait.
    Result:
    The system will generate the kernel image file Image.gz under linux/arch/riscv/boot directory.
    Figure 1. Example Output
    The system will generate the dtb file Image.gz under linux/arch/riscv/boot directory.
    Figure 2. Generating dtb
    When porting rootfs, dtb, and kernel to VisionFive 2, Image.gz and .dtb files will be used.