1# 安装Hi3861开发板特有环境 2 3 4除上述[安装库和工具集](quickstart-pkg-install-package.md)和[安装编译工具](quickstart-pkg-install-tool.md)外,针对Hi3861开发板还需要安装特定的编译工具。 5 6 7## 工具要求 8 9 **表1** Hi3861 WLAN模组需要安装的编译工具 10 11| 开发工具 | 用途 | 12| -------- | -------- | 13| SCons3.0.4+ | 编译构建工具 | 14| python模块:setuptools、kconfiglib、pycryptodome、six、ecdsa | 编译构建工具 | 15| gcc riscv32 | 编译构建工具 | 16 17 18## 操作步骤 19 20相关操作在Ubuntu环境下进行。 21 22 23### 安装Scons 24 251. 运行如下命令,安装SCons安装包。 26 27 ``` 28 python3 -m pip install scons 29 ``` 30 312. 运行如下命令,查看是否安装成功。如果安装成功,查询结果下图所示。 32 33 ``` 34 scons -v 35 ``` 36 37 **图1** SCons安装成功界面,版本要求3.0.4以上 38 39  40 41 42### 安装python模块 43 441. 运行如下命令,安装python模块setuptools。 45 46 ``` 47 pip3 install setuptools 48 ``` 49 502. 安装GUI menuconfig工具(Kconfiglib),建议安装Kconfiglib 13.2.0+版本,任选如下一种方式。 51 52 - **命令行方式:** 53 54 ``` 55 sudo pip3 install kconfiglib 56 ``` 57 - **安装包方式:** 58 1. 下载.whl文件(例如:kconfiglib-13.2.0-py2.py3-none-any.whl)。 59 下载路径:“[https://pypi.org/project/kconfiglib#files](https://pypi.org/project/kconfiglib#files)” 60 2. 运行如下命令,安装.whl文件。 61 62 ``` 63 sudo pip3 install kconfiglib-13.2.0-py2.py3-none-any.whl 64 ``` 65 663. 安装pycryptodome,任选如下一种方式。 67 68 安装升级文件签名依赖的Python组件包,包括:pycryptodome、six、ecdsa。安装ecdsa依赖six,请先安装six,再安装ecdsa。 69 - **命令行方式:** 70 71 ``` 72 sudo pip3 install pycryptodome 73 ``` 74 75 - **安装包方式:** 76 1. 下载.whl文件(例如:pycryptodome-3.9.9-cp38-cp38-manylinux1_x86_64.whl)。 77 下载路径:“[https://pypi.org/project/pycryptodome/#files](https://pypi.org/project/pycryptodome/#files)”。 78 2. 运行如下命令,安装.whl文件。 79 80 ``` 81 sudo pip3 install pycryptodome-3.9.9-cp38-cp38-manylinux1_x86_64.whl 82 ``` 83 844. 安装six,任选如下一种方式。 85 - **命令行方式:** 86 87 ``` 88 sudo pip3 install six --upgrade --ignore-installed six 89 ``` 90 - **安装包方式:** 91 1. 下载.whl文件(例如:six-1.12.0-py2.py3-none-any.whl)。 92 下载路径:“[https://pypi.org/project/six/#files](https://pypi.org/project/six/#files)” 93 2. 运行如下命令,安装.whl文件。 94 95 ``` 96 sudo pip3 install six-1.12.0-py2.py3-none-any.whl 97 ``` 98 995. 安装ecdsa,任选如下一种方式。 100 - **命令行方式:** 101 102 ``` 103 sudo pip3 install ecdsa 104 ``` 105 - **安装包方式:** 106 1. 下载.whl文件(例如:ecdsa-0.14.1-py2.py3-none-any.whl)。 107 下载路径:“[https://pypi.org/project/ecdsa/#files](https://pypi.org/project/ecdsa/#files)” 108 2. 运行如下命令,安装.whl文件。 109 110 ``` 111 sudo pip3 install ecdsa-0.14.1-py2.py3-none-any.whl 112 ``` 113 114 115### 安装gcc_riscv32(WLAN模组类编译工具链) 116 117>  **须知:** 118> - Hi3861开发板平台仅支持使用libgcc运行时库的静态链接,不建议开发者使用libgcc运行时库的动态链接,以免产品需遵从GPLV3许可证。 119> 120> - 通过下述步骤2-14,编译好了gcc_riscv32镜像,提供给开发者[直接下载](https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz)使用。直接下载gcc_riscv32镜像的开发者可省略下述2-14步。 121 1221. 打开Linux编译服务器终端。 123 1242. 下载riscv-gnu-toolchain交叉编译工具链。 125 126 ``` 127 git clone --recursive https://gitee.com/mirrors/riscv-gnu-toolchain.git 128 ``` 129 1303. 打开文件夹riscv-gnu-toolchain,先删除空文件夹,以防止下载newlib,binutils,gcc时冲突。 131 132 ``` 133 cd riscv-gnu-toolchain && rm -rf riscv-newlib && rm -rf riscv-binutils && rm -rf riscv-gcc 134 ``` 135 1364. 下载riscv-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. 下载riscv-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. 下载riscv-gcc-7.3.0。 149 150 ``` 151 git clone -b riscv-gcc-7.3.0 https://github.com/riscv/riscv-gcc 152 ``` 153 1547. 添加riscv-gcc-7.3.0补丁。 155 156 访问gcc官方补丁链接[89411](https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=026216a753ef0a757a9e368a59fa667ea422cf09;hp=2a23a1c39fb33df0277abd4486a3da64ae5e62c2),[86724](https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff;f=gcc/graphite.h;h=be0a22b38942850d88feb159603bb846a8607539;hp=4e0e58c60ab83f1b8acf576e83330466775fac17;hb=b1761565882ed6a171136c2c89e597bc4dd5b6bf;hpb=fbd5f023a03f9f60c6ae36133703af5a711842a3),按照补丁链接中要求的修改,手动将变更添加到对应的.c和.h文件中,注意由于patch版本与下载的gcc版本有所偏差,行数有可能对应不上,请自行查找patch中的关键字定位到对应行。 157 1588. 下载[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. 下载[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. 下载[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. 打开文件夹riscv-gnu-toolchain,新建工具链输出目录。 177 178 ``` 179 cd /opt && mkdir gcc_riscv32 180 ``` 181 18212. 编译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. 编译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. 编译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. 设置环境变量。 201 202 >  **说明:** 203 > 204 > 如果直接采用编译好的riscv32 gcc包,请先执行以下命令将压缩包解压到根目录: 205 > 206 > ``` 207 > tar -xvf gcc_riscv32-linux-7.3.0.tar.gz -C ~ 208 > ``` 209 > 注意之后设置和生效环境变量时,所设置的路径为根目录。 210 211 打开`.bashrc`文件。 212 213 ``` 214 vim /opt/.bashrc 215 ``` 216 217 将以下命令拷贝到的最后一行,保存并退出。 218 219 ``` 220 export PATH=/opt/gcc_riscv32/bin:$PATH 221 ``` 222 22316. 生效环境变量。 224 225 ``` 226 source /opt/.bashrc 227 ``` 228 22917. Shell命令行中输入如下命令,如果能正确显示编译器版本号,表明编译器安装成功。 230 231 ``` 232 riscv32-unknown-elf-gcc -v 233 ``` 234