1# Installing Tools Specially Required by the Hi3861 Development Board 2 3 4In addition to the general [libraries and tools](quickstart-pkg-install-package.md) and [compilation tools](quickstart-pkg-install-tool.md), the Hi3861 development board requires the tools listed in this topic for source code building. 5 6 7## Required Tools 8 9 **Table 1** Tools required by the Hi3861 WLAN module 10 11| Tool| Function| 12| -------- | -------- | 13| SCons3.0.4+ | Executes script compilation.| 14| Python modules: setuptools, Kconfiglib, PyCryptodome, six, and ecdsa| Executes script compilation.| 15| gcc riscv32 | Executes script compilation.| 16 17 18## Procedure 19 20Perform the following steps in Ubuntu. 21 22 23### Installing Scons 24 251. Run the following command to install the SCons installation package: 26 27 ``` 28 python3 -m pip install scons 29 ``` 30 312. Run the following command to check whether SCons is successfully installed. If the installation is successful, the query result as shown below is displayed. 32 33 ``` 34 scons -v 35 ``` 36 37 **Figure 1** Successful SCons installation (the version must be 3.0.4 or later) 38 39 ![hi3861-scons-install-success](figures/hi3861-scons-install-success.png) 40 41 42### Installing Python Modules 43 441. Install setuptools. 45 46 ``` 47 pip3 install setuptools 48 ``` 49 502. Install the GUI menuconfig tool (Kconfiglib). You are advised to install Kconfiglib 13.2.0 or later. 51 52 - **Command line:** 53 54 ``` 55 sudo pip3 install kconfiglib 56 ``` 57 - **Installation package:** 58 1. Download the .whl file, for example, **kconfiglib-13.2.0-py2.py3-none-any.whl**. 59 Download path: [https://pypi.org/project/kconfiglib#files](https://pypi.org/project/kconfiglib#files) 60 2. Install the .whl file. 61 62 ``` 63 sudo pip3 install kconfiglib-13.2.0-py2.py3-none-any.whl 64 ``` 65 663. Install PyCryptodome using either of the following methods: 67 68 Install the Python component packages on which the file signature depends, including **PyCryptodome**, **six**, and **ecdsa**. As the installation of **ecdsa** depends on that of **six**, install **six** first. 69 - **Command line:** 70 71 ``` 72 sudo pip3 install pycryptodome 73 ``` 74 75 - **Installation package:** 76 1. Download the .whl file, for example, **pycryptodome-3.9.9-cp38-cp38-manylinux1_x86_64.whl**. 77 Download path: [https://pypi.org/project/pycryptodome/#files](https://pypi.org/project/pycryptodome/#files) 78 2. Install the .whl file. 79 80 ``` 81 sudo pip3 install pycryptodome-3.9.9-cp38-cp38-manylinux1_x86_64.whl 82 ``` 83 844. Install **six** using either of the following methods: 85 - **Command line:** 86 87 ``` 88 sudo pip3 install six --upgrade --ignore-installed six 89 ``` 90 - **Installation package:** 91 1. Download the .whl file, for example, **six-1.12.0-py2.py3-none-any.whl**. 92 Download path: [https://pypi.org/project/six/#files](https://pypi.org/project/six/#files) 93 2. Install the .whl file. 94 95 ``` 96 sudo pip3 install six-1.12.0-py2.py3-none-any.whl 97 ``` 98 995. Install **ecdsa** using either of the following methods: 100 - **Command line:** 101 102 ``` 103 sudo pip3 install ecdsa 104 ``` 105 - **Installation package:** 106 1. Download the .whl file, for example, **ecdsa-0.14.1-py2.py3-none-any.whl**. 107 Download path: [https://pypi.org/project/ecdsa/#files](https://pypi.org/project/ecdsa/#files) 108 2. Install the .whl file. 109 110 ``` 111 sudo pip3 install ecdsa-0.14.1-py2.py3-none-any.whl 112 ``` 113 114 115### Installing gcc_riscv32 (Compiler Toolchain for the WLAN Module) 116 117> ![icon-notice.gif](public_sys-resources/icon-notice.gif) **NOTICE** 118> - Hi3861 supports only the static link of the libgcc library. The dynamic link is not recommended because version 3 of the GNU General Public License (GPLv3) will be polluted during commercial distribution. 119> 120> - Steps 2 to 14 of the following procedure are used to build the **gcc_riscv32** image. You can directly [download the image](https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz) and skip these steps. 121 1221. Start the Linux server. 123 1242. Download the **RISC-V GNU** toolchain. 125 126 ``` 127 git clone --recursive https://gitee.com/mirrors/riscv-gnu-toolchain.git 128 ``` 129 1303. Open the **riscv-gnu-toolchain** folder and delete empty folders to prevent conflicts during the download of **Newlib**, **Binutils**, and **GCC**. 131 132 ``` 133 cd riscv-gnu-toolchain && rm -rf riscv-newlib && rm -rf riscv-binutils && rm -rf riscv-gcc 134 ``` 135 1364. Download RISC-V Newlib 3.0.0. 137 138 ``` 139 git clone -b riscv-newlib-3.0.0 https://github.com/riscv/riscv-newlib.git 140 ``` 141 1425. Download RISC-V Binutils 2.31.1. 143 144 ``` 145 git clone -b riscv-binutils-2.31.1 https://github.com/riscv/riscv-binutils-gdb.git 146 ``` 147 1486. Download RISC-V GCC 7.3.0. 149 150 ``` 151 git clone -b riscv-gcc-7.3.0 https://github.com/riscv/riscv-gcc 152 ``` 153 1547. Add the RISC-V GCC 7.3.0 patch. 155 156 Visit the GCC official patch links [89411](https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=026216a753ef0a757a9e368a59fa667ea422cf09;hp=2a23a1c39fb33df0277abd4486a3da64ae5e62c2) and [86724](https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff;f=gcc/graphite.h;h=be0a22b38942850d88feb159603bb846a8607539;hp=4e0e58c60ab83f1b8acf576e83330466775fac17;hb=b1761565882ed6a171136c2c89e597bc4dd5b6bf;hpb=fbd5f023a03f9f60c6ae36133703af5a711842a3), and manually add the changes to the .c and .h files based on the requirements in the patch links. Note that the number of rows may not match because of the differences in the patch and GCC versions. If this is the case, search for the keyword in the patch to locate the corresponding row. 157 1588. Download, decompress, and install [GMP 6.1.2](https://gmplib.org/download/gmp/gmp-6.1.2.tar.bz2). 159 160 ``` 161 tar -xvf gmp-6.1.2.tar.bz2 && mkdir build_gmp && cd build_gmp && ../gmp-6.1.2/configure --prefix=/usr/local/gmp-6.1.2 --disable-shared --enable-cxx && make && make install 162 ``` 163 1649. Download, decompress, and install [mpfr-4.0.2](https://www.mpfr.org/mpfr-4.0.2/mpfr-4.0.2.tar.gz). 165 166 ``` 167 tar -xvf mpfr-4.0.2.tar.gz && mkdir build_mpfr && cd build_mpfr && ../mpfr-4.0.2/configure --prefix=/usr/local/mpfr-4.0.2 --with-gmp=/usr/local/gmp-6.1.2 --disable-shared && make && make install 168 ``` 169 17010. Download, decompress, and install [mpc-1.1.0](https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz). 171 172 ``` 173 tar -xvf mpc-1.1.0.tar.gz && mkdir build_mpc && cd build_mpc && ../mpc-1.1.0/configure --prefix=/usr/local/mpc-1.1.0 --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-4.0.2 --disable-shared && make && make install 174 ``` 175 17611. Open the **riscv-gnu-toolchain** folder and create a directory for toolchain output. 177 178 ``` 179 cd /opt && mkdir gcc_riscv32 180 ``` 181 18212. Build Binutils. 183 184 ``` 185 mkdir build_binutils && cd build_binutils && ../riscv-binutils-gdb/configure --prefix=/opt/gcc_riscv32 --target=riscv32-unknown-elf --with-arch=rv32imc --with-abi=ilp32 --disable-__cxa_atexit --disable-libgomp --disable-libmudflap --enable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-multilib --enable-poison-system-directories --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --with-system-zlib CFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" CXXFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" CXXFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" CFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" --bindir=/opt/gcc_riscv32/bin --libexecdir=/opt/gcc_riscv32/riscv32 --libdir=/opt/gcc_riscv32 --includedir=/opt/gcc_riscv32 && make -j16 && make install && cd .. 186 ``` 187 18813. Build Newlib. 189 190 ``` 191 mkdir build_newlib && cd build_newlib && ../riscv-newlib/configure --prefix=/opt/gcc_riscv32 --target=riscv32-unknown-elf --with-arch=rv32imc --with-abi=ilp32 --disable-__cxa_atexit --disable-libgomp --disable-libmudflap --enable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-multilib --enable-poison-system-directories --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --with-system-zlib CFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" CXXFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" \CXXFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" CFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" --bindir=/opt/gcc_riscv32/bin --libexecdir=/opt/gcc_riscv32 --libdir=/opt/gcc_riscv32 --includedir=/opt/gcc_riscv32 && make -j16 && make install && cd .. 192 ``` 193 19414. Build GCC. 195 196 ``` 197 mkdir build_gcc && cd build_gcc && ../riscv-gcc/configure --prefix=/opt/gcc_riscv32 --target=riscv32-unknown-elf --with-arch=rv32imc --with-abi=ilp32 --disable-__cxa_atexit --disable-libgomp --disable-libmudflap --enable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-multilib --enable-poison-system-directories --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --with-system-zlib CFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" CXXFLAGS="-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -fPIE" LDFLAGS="-Wl,-z,relro,-z,now,-z,noexecstack" CXXFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" CFLAGS_FOR_TARGET="-Os -mcmodel=medlow -Wall -fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -fno-short-enums -fno-short-wchar" --with-headers="/opt/gcc-riscv32/riscv32-unknown-elf/include" --with-mpc=/usr/local/mpc-1.1.0 --with-gmp=/usr/local/gmp-6.1.2 --with-mpfr=/usr/local/mpfr-4.0.2 && make -j16 && make install 198 ``` 199 20015. Set an environment variable. 201 > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** 202 > 203 > If you are using the riscv32 gcc package, run the following command to decompress the package to the root directory: 204 > 205 > ``` 206 > tar -xvf gcc_riscv32-linux-7.3.0.tar.gz -C ~ 207 > ``` 208 209 210 211 ``` 212 vim ~/.bashrc 213 ``` 214 215 Copy the following command to the last line of the .bashrc file, save the file, and exit. 216 217 218 ``` 219 export PATH=~/gcc_riscv32/bin:$PATH 220 ``` 221 22216. Validate the environment variable. 223 224 ``` 225 source ~/.bashrc 226 ``` 227 22817. Check whether the compiler is successfully installed. If the compiler version number is correctly displayed, the installation is successful. 229 230 ``` 231 riscv32-unknown-elf-gcc -v 232 ``` 233