Thanks to Houge for this contribution.
Part 1 Compile and package the kernel, create deb sources
It is especially important to create a RISC-V core for StarFive VisionFive, The complete process is as follows.
#Debian or Ubuntu #Debian Install dependencies： apt install libncurses-dev libssl-dev bc flex bison gcc-riscv64-linux-gnu build-essential ccache cpio fakeroot flex git kmod libelf-dev libncurses5-dev libssl-dev lz4 qtbase5-dev rsync schedtool wget zstd pahole dwarves -y #Ubuntu Install dependencies： apt install libncurses-dev libssl-dev bc flex bison gcc-riscv64-linux-gnu build-essential ccache cpio fakeroot flex git kmod libelf-dev libncurses5-dev libssl-dev lz4 qtbase5-dev rsync schedtool wget zstd dwarves -y # Download the source code： #download link: https://github.com/starfive-tech/linux mkdir -p linux-build # Create compiling directory cd linux-build # Enter the directory wget https://github.com/starfive-tech/linux/archive/54fad564dc7a117704e99248c3984f907e1867d5.tar.gz # Download the specific kernel source code according to the latest commits tar -xpvf 54fad564dc7a117704e99248c3984f907e1867d5.tar.gz # Unzip the source code mv linux-54fad564dc7a117704e99248c3984f907e1867d5 linux-5.17.0-rc5 # Create a simple name for the unzipped source directory cd linux-5.17.0-rc5 # Enter the directory cp arch/riscv/configs/starfive_jh7100_fedora_defconfig .config # Copy the kernel configuration file to the root directory of the kernel source and name it .config make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- menuconfig # Use cross-compiler to configure the kernel make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -jX bindeb-pkg LOCALVERSION=-starfive-xxx #Use -jX all threads, and finally take a name you like # After the compilation is completed, 4 deb files will be generated in the upper directory, similar to the following figure:
Let’s see how to build with Arch:
Archlinux or other distributions can be created in a similar way
Here are some little tricks about the file system:
When you use the btrfs filesystem, you can create a subvolume in the /mnt/ directory. If you compile it under a subvolume, you can take a snapshot later and make a backup;
When you use the zfs file system, it is recommended to use the zvol block device and format it as an ext4 file system, mount it in the /mnt/xxx/ directory and build and package it. Because doing so facilitates backup, cloning and rapid deployment.
# The following operations are performed with root privileges by default pacman -S yay # install my favorite yay pacman -S paru # install your favorite yay # Choose one of the above operations yay -S debootstrap debian-archive-keyring ubuntu-keyring # Install some important tools in Debian system. debootstrap can install the base system of various architectures to the specified directory. keyring can provide a key to verify that the deb package has not been tampered with. debootstrap unstable /mnt/xxx https://mirror.sjtu.edu.cn/debian/ # Download the latest debian sid base system from the Shanghai Jiaotong University Debian mirror source and install it to the /mnt/xxx directory debootstrap impish /mnt/xxx https://mirror.sjtu.edu.cn/ubuntu/ # Download the latest ubuntu 21.10 base system from the Shanghai Jiaotong University ubuntu mirror source and install it to the /mnt/xxx directory systemd-nspawn -D /mnt/xxx/ -M kernel --bind-ro=/etc/resolv.conf # Use systemd-nspawn to create a debian/ubuntu x86_64 base system container named kernel # Follow-up operations can refer to the operations of Debian and Ubuntu above. After completion, you need to remember the location of the packaged deb package. You may need to use root privileges to copy these debs to a directory that is convenient for you to wait for the next step.
Complete the kernel compilation and packaging, don’t be too happy.
Note that copy the dtb file of StarFive VisionFive in the kernel source directory to a directory you remember. The directory where this dtb is located is /arch/riscv/boot/dts/starfive/.
Continuing below, there are two methods of operation for installing the kernel deb, and I recommend the second one. The first one is simple, but not true, that is to copy the compiled and packaged risc-v kernel to the future system and install it directly. The command is: dpkg -i xxx.deb. I prefer to call the the second method “fundamentalism” of the Debian /Ubuntu installation software that is to set up our private RISC-V deb source. The advantage of this is that your friends can install the kernel you made according to the tradition of Debian/Ubuntu, and can maintain this kernel version to facilitate their subsequent updates. Let’s talk about setting up a Deb source.
Choose the right server:
In the company, you can create a virtual machine of Ubuntu on the NAS, and then map the network to your company LAN so that everyone can access it normally.
For a personal user like me, I choose a cloud and build an Ubuntu VPS as the deb source server. Just start working on your VPS.
apt install reprepro --yes # Install reprepro, deb ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime hwclock --systohc apt install ntpdate ntpdate -s time.nist.gov # The purpose of the above operations is to synchronize the time of the VPS or virtual machine to the standard Beijing time to prevent the time from mismatching and the inability to install and update software gpg --gen-key # Generate your key. Subsequent deb packages will be signed with this private key. Other machines need to download your public key for verification.
The above picture is the generated key, which can be displayed with gpg --list-keys. Pay attention to the long string of characters: 706CE3DD…, write down the last 8 digits: 33372332, they are important, don’t ask me how I know
apt install apache2 -y # Install a web server that you can operate, I am more used to apache
Create a directory under the web server directory as follows:
mkdir -p /var/www/html/ubuntu-impish cd /var/www/html/ubuntu-impish mkdir -p conf db dists pool touch conf/distributions #distributions file touch conf/options #options of description # Note that ubuntu-impish is a name. You can choose whatever name you like, and you can freely handle it according to your needs.
Let’s configure distributions:
Origin: ubuntu Suite: impish Label: ubuntu Codename: impish Architectures: riscv64 Components: main Description: Apt repository for StarFive VisionFive V1 SignWith: 33372332
Let me explain the above:
• If your origin is Debian, write Debian, if it is Ubuntu, write Ubuntu
• Write Suite as the codename of your distribution
• Label is similar to Origin
• Codename is just a release codename
• About components, because we only meet the use of a small range of friends, main is enough, if strict maintenance is required, it is best to classify in detail
• The description part is free for everyone
• SignWith is the place to sign, remember that 8 bit key of yours?
Let’s export our public key to the source directory:
# Reemphasize that 8-bit key gpg --export --armor 33372332 > /var/www/html/ubuntu-impish/gpg-public.key
The picture above is the general appearance after creation.
Now you can publish or revoke the kernel deb package you created:
reprepro -b /var/www/html/ubuntu-impish -C main includedeb impish/< The deb directory you compiled and packaged earlier >/*.deb # This is to publish your deb package, then a TUI will pop up, where you enter the password (the password you entered when gpg created the key pair) reprepro -b /var/www/html/ubuntu-impish -C main remove impish < deb package name > # Remove or undo deb packages from the repository
If all goes well, your private deb repository is created. Take care of it~
Summary of the first part:
Cross-compilation is recommended for kernel compilation and packaging, which is fast
Remember to copy the dtb out to facilitate final processing
It is strongly recommended to use the traditional setup source server to manage the built deb packages