Wednesday, February 7, 2024

RISC-v on ZC706 Evaluation Board - Part VI: Building fesvr-zynq with Petalinux

 As of RISC-v on ZC706 Evaluation Board - Part V: Running Petalinux, I'm back to square one, need to figure out how to build fesvr-zynq with Petalinux. First, set all environment as I can:

source <path-to-installed-PetaLinux>/settings.sh
source <path-to-installed-PetaLinux>/components/yocto/buildtools/environment-setup-x86_64-petalinux-linux
source <path-to-installed-Xilinx>/Vitis/2022.1/settings64.sh
export PATH=$PATH:<path-to-installed-Xilinx>/Vitis/2022.1/gnu/aarch32/lin/gcc-arm-linux-gnueabi/x86_64-petalinux-linux/usr/bin/arm-xilinx-linux-gnueabi
cd <path-to-fpga-zynq>/zc706 && make fesvr-zynq

Now, it complain:
arm-xilinx-linux-gnueabi-g++ -O2 -std=c++11 -Wall -L fpga-zynq/common/build -lfesvr -Wl,-rpath,/usr/local/lib -I fpga-zynq/common/csrc -I fpga-zynq/testchipip/csrc -I fpga-zynq/rocket-chip/riscv-tools/riscv-fesvr/ -Wl,-rpath,/usr/local/lib  -o fpga-zynq/common/build/fesvr-zynq /mnt/ext4/fpga-zynq/common/csrc/fesvr_zynq.cc fpga-zynq/common/csrc/zynq_driver.cc fpga-zynq/testchipip/csrc/blkdev.cc

Vitis/2022.1/gnu/aarch32/lin/gcc-arm-linux-gnueabi/x86_64-petalinux-linux/usr/lib/arm-xilinx-linux-gnueabi/gcc/arm-xilinx-linux-gnueabi/11.2.0/include/stdint.h:9:16: fatal error: stdint.h: No such file or directory

   9 | # include_next <stdint.h>
     |                ^~~~~~~~~~

Still sounds like some configuration is missing for the build. With export CFLAGS/CPPFLAGS/CXXFLAGS or set them in make cmdline to "-I<path-to-Xilinx>/Vitis/2022.1/gnu/aarch32/lin/gcc-arm-linux-gnueabi/x86_64-petalinux-linux/usr/include" doesn't help either.

Search shows me a link from lowRISC as Building the front-end server:

# set up the RISCV environment variables
# set up the Xilinx environment variables
cd $TOP/riscv-tools/riscv-fesvr
mkdir build_fpga
cd build_fpga
../configure --host=arm-xilinx-linux-gnueabi
make -j$(nproc)

Once compilation has completed, you should find the following files:

ls -l fesvr-zedboard
ls -l libfesvr.so

To copy your new front-end server to the FPGA image:

cd $TOP/fpga-zynq/zedboard
make ramdisk-open
sudo cp $TOP/riscv-tools/riscv-fesvr/build_fpga/fesvr-zedboard \
  ramdisk/home/root/fesvr-zynq
sudo cp $TOP/riscv-tools/riscv-fesvr/build_fpga/libfesvr.so \
  ramdisk/usr/local/lib/libfesvr.so
make ramdisk-close
sudo rm -fr ramdisk

The proxy kernel (pk) used by the FPGA is the same one used in simulation. While not normally necessary, the proxy kernel can be recompiled using the following commands:

cd $TOP/fpga-zynq/zedboard
make ramdisk-open
sudo cp $TOP/riscv-tools/riscv-pk/build/pk ramdisk/home/root/pk
make ramdisk-close
sudo rm -fr ramdisk

lowRISC also has its risc-fesvr build instruction at fpga-zynq/README.md, slightly different from https://github.com/ucb-bar/fpga-zynq. And actually the two would behave same, if I use Xilinx 2016, which create a 'SDK' folder, and after run 'source SDK/2016.2/settings64.sh', 'make fesvr-zynq':

mkdir -p fpga-zynq/common/build
cd fpga-zynq/common/build && \
fpga-zynq/rocket-chip/riscv-tools/riscv-fesvr/configure \
        --host=arm-xilinx-linux-gnueabi
&& \
make libfesvr.so
checking build system type... x86_64-unknown-linux-gnu
checking host system type... arm-xilinx-linux-gnueabi
checking for arm-xilinx-linux-gnueabi-gcc... arm-xilinx-linux-gnueabi-gcc
checking whether the C compiler works... no
configure: error: in `fpga-zynq/common/build':
configure: error: C compiler cannot create executables
See `config.log' for more details

same error as following the lowRISC instructions. Now need to figure out the problem from the config.log file. The log file indicates several warnings for same thing:

fpga-zynq/rocket-chip/riscv-tools/riscv-fesvr/configure: line 2365: ~/SDK/2016.2/gnu/arm/lin/bin/arm-xilinx-linux-gnueabi-gcc: No such file or directory

The gcc compiler does exist, but file ./arm-xilinx-linux-gnueabi-gcc shows:
./arm-xilinx-linux-gnueabi-gcc: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.16, stripped

which means I need to enable 32bit support in WSL as I mentioned in Run Linux on Windows - WSL, by doing:

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt install gcc:i386 gcc-multilib g++-multilib libc6:i386

With that, finally I'm able to do make fesvr-zynq, fesvr-zynq and libfesvr.so would be generated under fpga-zynq/common/build folder. When copying fesvr-zynq, also need to copy common/build/libfesvr.so to /usr/local/lib on the board. As mentioned in above lowRISC instructions and fpga-zynq, it is possible to recreate the ram disk, however, I'm getting this when trying the commands under WSL: cpio: dev/console: Cannot mknod: Operation not supported. Not sure whether this is WSL limitation or something I have missed. Give up on this for now. So I tried to copy the new executable. For that, might need to get IP from dhcp server if the board is connected to a network. Modifying /etc/network/interfaces with line 'iface eth0 inet dhcp', then do 'ifdown eth0' and 'ifup eth0' will temporarily work as the change of the interfaces file won't survive of a reboot. After successfully get IP from dhcp server, ssh may still not work with error: Unable to negotiate with a.b.c.d port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1. Can try tftp as:

cd ~
tftp -g -r fesvr-zynq tftp_server
cd  /usr/local/lib
tftp -g -r libfesvr.so tftp_server

Now, run fesvr-zynq without argument would get usage print out (with the original fesvr-zynq executable, used to get "ERROR: No cores found" error, same error as running 'fesvr-zynq pk hello'), but still not able to load the bbl or run the hello code.

PS: README.md in fpga-zynq/rocket-chip/riscv-tools/fpga-fesvr shows:

This repository is deprecated; it has been absorbed into the Spike repository (https://github.com/riscv/riscv-isa-sim).


0 Comments:

Post a Comment