net/ark: support new devices
[dpdk.git] / doc / guides / linux_gsg / cross_build_dpdk_for_riscv.rst
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
7 Cross compiling DPDK for RISC-V
8 ===============================
9
10 This chapter describes how to cross compile DPDK for RISC-V from x86 build
11 hosts.
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
22 Prerequisites
23 -------------
24
25 Ensure that you have all pre-requisites for building DPDK natively as those will
26 be required also for cross-compilation.
27
28
29 Linux kernel
30 ~~~~~~~~~~~~
31
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.
34
35
36 GNU toolchain
37 -------------
38
39 Obtain the cross toolchain
40 ~~~~~~~~~~~~~~~~~~~~~~~~~~
41
42 The 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
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.
52
53
54 Unzip and add into the PATH
55 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
56
57 This step is only required for the riscv-gnu-toolchain. The Ubuntu toolchain is
58 in 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
66 Cross Compiling DPDK with GNU toolchain using Meson
67 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68
69 To cross-compile DPDK for a desired target machine use the following command::
70
71    meson cross-build --cross-file <target_machine_configuration>
72    ninja -C cross-build
73
74 For example if the target machine is a generic rv64gc RISC-V, use the following
75 command::
76
77    meson riscv64-build-gcc --cross-file config/riscv/riscv64_linux_gcc
78    ninja -C riscv64-build-gcc
79
80 If riscv-gnu-toolchain is used, binary names should be updated to match. Update
81 the 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
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:
95
96 .. code-block:: console
97
98    [properties]
99    ...
100    sys_root = ['--sysroot', '<path/to/toolchain/sysroot>']
101    ...
102
103
104 Supported cross-compilation targets
105 -----------------------------------
106
107 Currently 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
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.