Setting Up the Xuantie 900 Series Toolchain and xuantie-qemu Environment
With the rapid development of domestic RISC-V chip technology, Alibaba Pingtouge's Xuantie 900 series processors have attracted much attention for their high performance and low power consumption. To better support the development and debugging work based on the Xuantie 900 series chips, it is crucial to set up a complete toolchain and simulation environment. This article will provide a detailed introduction on how to set up the Xuantie 900 series toolchain and xuantie-qemu environment.
1. Build the platform
Linux distribution: CentOS Linux release 7.6.1810 (Core)
2. Set up the XuanTie 900 series toolchain environment
1. Download Xuantie 900 series toolchain
First, we need to download the Xuantie GNU toolchain for the RISC-V architecture. Go to the Xuantie official website
to get the latest version of the precompiled package and install it according to your operating system. On Linux systems, it is usually sufficient to add the bin path to the $PATH environment variable after extraction.
The toolchain installation package is divided into different versions due to the differences between the execution platform and the target program platform. For example, Xuantie--elf--x86_64-V*-.tar.gz is a RISC-V bare program toolchain suite for the 64-bit Linux platform. The specific classifications are as follows:
According to the execution platform
x86_64: 64-bit Linux platform
i386: 32-bit Linux platform
mingw: Windows Mingw platform
According to the target program platform
elf: Bare program compilation suite
linux: linux application compilation suite
Here we download the latest version 2.8.1 of the Linux application compilation suite for the 64-bit Linux platform, namely Xuantie-900-gcc-linux-5.10.4-glibc-x86_64.
1
2
3
4
wget https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource//1705395627867/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.8.1-20240115.tar.gz
tar -xzvf Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.8.1-20240115.tar.gz
sudo mv Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.8.1-20240115 /opt
exportPATH=/opt/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.8.1-20240115/bin:$PATH
Visit the Xuantie QEMU official repository
to obtain the xuantie-qemu source code suitable for the Xuantie 900 series chips, and then follow the usual steps to compile and install:
cd qemu
mkdir build
cd build
../configure --target-list=riscv64-softmmu,riscv64-linux-user --prefix=/opt/qemu/6.1.0-xuantie
make -j $(nproc)sudo make install
exportPATH=/opt/qemu/6.1.0-xuantie/bin:$PATH
4. Verify xuantie-qemu installation
After the installation is complete, if you can view the specific version of qemu by executing the following command, it means the installation was successful.
1
2
3
$ qemu-riscv64 --version
qemu-riscv64 version 6.0.94 (v6.1.0-12-g03813c9)Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
#include<riscv_vector.h>#include<stdio.h>#define N 15
floatvsum(float*v,intn){vfloat32m1_tvs,vv,vtmp;floats=0.0;inti;intvlmax;vlmax=vsetvlmax_e32m1();printf("vlmax:%d\n",vlmax);vs=vfmv_v_f_f32m1(0.0,vlmax);vtmp=vfmv_v_f_f32m1(0.0,vlmax);for(i=0;i<n-vlmax;i+=vlmax){vv=vle32_v_f32m1(&v[i],vlmax);vtmp=vfadd_vv_f32m1(vtmp,vv,vlmax);}vs=vfredusum_vs_f32m1_f32m1(vs,vtmp,vs,vlmax);s=vfmv_f_s_f32m1_f32(vs);for(;i<n;i++){s+=v[i];}returns;}floatvsum1(float*v,intn){vfloat32m1_tvs,vv;floats;inti;intvl,vlmax;vlmax=vsetvlmax_e32m1();vs=vfmv_v_f_f32m1(0.0,vlmax);for(i=0;n>0;i+=vl,n-=vl){vl=vsetvl_e32m1(n);printf("vl:%d\n",vl);vv=vle32_v_f32m1(&v[i],vl);vs=vfredusum_vs_f32m1_f32m1(vs,vv,vs,vl);}s=vfmv_f_s_f32m1_f32(vs);returns;}floatvsum2(float*v,intn){vfloat32m2_tvv;vfloat32m1_tvs;floats;inti;intvl,vlmax;vlmax=vsetvlmax_e32m1();vs=vfmv_v_f_f32m1(0.0,vlmax);for(i=0;n>0;i+=vl,n-=vl){vl=vsetvl_e32m2(n);printf("vl:%d\n",vl);vv=vle32_v_f32m2(&v[i],vl);vs=vfredusum_vs_f32m2_f32m1(vs,vv,vs,vl);}s=vfmv_f_s_f32m1_f32(vs);returns;}intmain(){inti;floatv[N],sum=0.0;printf("Hello RISC-V!\n");for(i=0;i<N;i++){v[i]=i;}sum=vsum(v,N);printf("%f\n",sum);return0;}
Compile and run the program (at this time you need to specify -cpu, otherwise it will report an illegal instruction exception, i.e., Illegal instruction (core dumped)):
After downloading, enter the busybox source code directory
1
cd busybox-1.33.1
2.2 Configure busybox
1
2
$ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- defconfig
$ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- menuconfig
After opening the configuration menu, go to the first line “Settings”, in the “Build Options” section, select “Build static binary (no shared libs)”, then exit and save the configuration.
Check if CONFIG_STATIC=y is in the .config file, if not, add it manually.
2.3 Compile and Install busybox
1
2
$ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- -j $(nproc)$ make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- install
At this point, a new _install directory will appear under the source directory busyboxsource, where you can see the generated items.
1
2
$ ls _install
bin linuxrc sbin usr
Enter the _install directory and create the following directories
1
2
3
4
$ cd _install
$ mkdir proc sys dev etc etc/init.d
$ ls
bin dev etc linuxrc proc sbin sys usr
Then create another simplest init RC file:
1
2
3
$ cd etc/init.d/
$ touch rcS
$ vim rcS
Edit the file content to:
1
2
3
4
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s
Then modify the rcS file permissions to add executable permissions.
1
$ chmod +x rcS
2.4 Create File System
Continue executing the following command in the _install directory:
At this point, we have successfully set up the toolchain environment for the XuanTie 900 series and the xuantie-qemu simulation environment, which lays the foundation for subsequent development, compilation, linking, running, and debugging of RISC-V applications based on the XuanTie 900 series chips.