Cross-compile Linux Kernel

Follow the steps below to cross-compile the Linux kernel:

  1. Execute the following to install dependencies and create the kernel:
    apt-get install build-essential linux-source bc kmod cpio flex libncurses5-dev libelf-dev libssl-dev dwarves bison git
  2. Check out 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

    where, Configuration_File is starfive_visionfive2_defconfig.

  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 the Linux kernel:
    make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv -<jx>

    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 may take some time.

    This script generates he following files which are used when porting rootfs, dtb, and the kernel to VisionFive 2:
    • The kernel image file Image.gz is created under the linux/arch/riscv/boot directory.
    • The dtb file Image.gz is created under the linux/arch/riscv/boot directory.