1.. SPDX-License-Identifier: BSD-3-Clause 2 Copyright(c) 2020 ARM Corporation. 3 Copyright(c) 2022 StarFive 4 Copyright(c) 2022 SiFive 5 Copyright(c) 2022 Semihalf 6 7Cross compiling DPDK for RISC-V 8=============================== 9 10This chapter describes how to cross compile DPDK for RISC-V from x86 build 11hosts. 12 13.. note:: 14 15 While it's possible to compile DPDK natively on a RISC-V host, it is 16 currently recommended to cross-compile as Linux kernel does not offer any 17 way for userspace to discover the vendor and architecture identifiers of the 18 CPU and therefore any per-chip optimization options have to be chosen via 19 a cross-file or ``c_args``. 20 21 22Prerequisites 23------------- 24 25Ensure that you have all pre-requisites for building DPDK natively as those will 26be required also for cross-compilation. 27 28 29Linux kernel 30~~~~~~~~~~~~ 31 32Make sure that RISC-V host is running Linux kernel 5.13 or newer. This version 33introduces patches necessary for PCIe BAR mapping to userspace. 34 35 36GNU toolchain 37------------- 38 39Obtain the cross toolchain 40~~~~~~~~~~~~~~~~~~~~~~~~~~ 41 42The build process was tested using: 43 44* Ubuntu toolchain (the ``crossbuild-essential-riscv64`` package). 45 46* Latest `RISC-V GNU toolchain 47 <https://github.com/riscv/riscv-gnu-toolchain/releases>`_ on Ubuntu or Arch 48 Linux. 49 50Alternatively the toolchain may be built straight from the source, to do that 51follow the instructions on the riscv-gnu-toolchain github page. 52 53 54Unzip and add into the PATH 55~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 57This step is only required for the riscv-gnu-toolchain. The Ubuntu toolchain is 58in the PATH already. 59 60.. code-block:: console 61 62 tar -xvf riscv64-glibc-ubuntu-20.04-<version>.tar.gz 63 export PATH=$PATH:<cross_install_dir>/riscv/bin 64 65 66Cross Compiling DPDK with GNU toolchain using Meson 67~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 68 69To cross-compile DPDK for a desired target machine use the following command:: 70 71 meson setup cross-build --cross-file <target_machine_configuration> 72 ninja -C cross-build 73 74For example if the target machine is a generic rv64gc RISC-V, use the following 75command:: 76 77 meson setup riscv64-build-gcc --cross-file config/riscv/riscv64_linux_gcc 78 ninja -C riscv64-build-gcc 79 80If riscv-gnu-toolchain is used, binary names should be updated to match. Update 81the following lines in the cross-file: 82 83.. code-block:: console 84 85 [binaries] 86 c = 'riscv64-unknown-linux-gnu-gcc' 87 cpp = 'riscv64-unknown-linux-gnu-g++' 88 ar = 'riscv64-unknown-linux-gnu-ar' 89 strip = 'riscv64-unknown-linux-gnu-strip' 90 ... 91 92Some toolchains (such as freedom-u-sdk one) require also setting ``--sysroot``, 93otherwise include paths might not be resolved. To do so, add the appropriate 94paths to the cross-file: 95 96.. code-block:: console 97 98 [properties] 99 ... 100 sys_root = ['--sysroot', '<path/to/toolchain/sysroot>'] 101 ... 102 103 104Supported cross-compilation targets 105----------------------------------- 106 107Currently the following targets are supported: 108 109* Generic rv64gc ISA: ``config/riscv/riscv64_linux_gcc`` 110 111* SiFive U740 SoC: ``config/riscv/riscv64_sifive_u740_linux_gcc`` 112 113To add a new target support, ``config/riscv/meson.build`` has to be modified by 114adding a new vendor/architecture id and a corresponding cross-file has to be 115added to ``config/riscv`` directory. 116