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
7 Cross compiling DPDK for RISC-V
8 ===============================
10 This chapter describes how to cross compile DPDK for RISC-V from x86 build
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``.
25 Ensure that you have all pre-requisites for building DPDK natively as those will
26 be required also for cross-compilation.
32 Make sure that RISC-V host is running Linux kernel 5.13 or newer. This version
33 introduces patches necessary for PCIe BAR mapping to userspace.
39 Obtain the cross toolchain
40 ~~~~~~~~~~~~~~~~~~~~~~~~~~
42 The build process was tested using:
44 * Ubuntu toolchain (the ``crossbuild-essential-riscv64`` package).
46 * Latest `RISC-V GNU toolchain
47 <https://github.com/riscv/riscv-gnu-toolchain/releases>`_ on Ubuntu or Arch
50 Alternatively the toolchain may be built straight from the source, to do that
51 follow the instructions on the riscv-gnu-toolchain github page.
54 Unzip and add into the PATH
55 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
57 This step is only required for the riscv-gnu-toolchain. The Ubuntu toolchain is
60 .. code-block:: console
62 tar -xvf riscv64-glibc-ubuntu-20.04-<version>.tar.gz
63 export PATH=$PATH:<cross_install_dir>/riscv/bin
66 Cross Compiling DPDK with GNU toolchain using Meson
67 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 To cross-compile DPDK for a desired target machine use the following command::
71 meson cross-build --cross-file <target_machine_configuration>
74 For example if the target machine is a generic rv64gc RISC-V, use the following
77 meson riscv64-build-gcc --cross-file config/riscv/riscv64_linux_gcc
78 ninja -C riscv64-build-gcc
80 If riscv-gnu-toolchain is used, binary names should be updated to match. Update
81 the following lines in the cross-file:
83 .. code-block:: console
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'
92 Some toolchains (such as freedom-u-sdk one) require also setting ``--sysroot``,
93 otherwise include paths might not be resolved. To do so, add the appropriate
94 paths to the cross-file:
96 .. code-block:: console
100 sys_root = ['--sysroot', '<path/to/toolchain/sysroot>']
104 Supported cross-compilation targets
105 -----------------------------------
107 Currently the following targets are supported:
109 * Generic rv64gc ISA: ``config/riscv/riscv64_linux_gcc``
111 * SiFive U740 SoC: ``config/riscv/riscv64_sifive_u740_linux_gcc``
113 To add a new target support, ``config/riscv/meson.build`` has to be modified by
114 adding a new vendor/architecture id and a corresponding cross-file has to be
115 added to ``config/riscv`` directory.