同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Hi3861环境搭建前,请先完成搭建系统基础环境。
须知: 本节描述安装包方式搭建编译环境的操作步骤。如果是Docker方式安装编译环境,无需安装表1中的Linux服务器相关工具,仅需安装Windows工作台软件。
Hi3861开发板对环境配置的特有要求如下表所示。
表 1 Hi3861开发板对环境配置的特有要求
须知:
- 如果后续通过“HPM组件方式”或“HPM包管理器命令行工具方式”获取源码,不需要安装gcc_riscv32编译工具。
- (推荐)如果后续通过“镜像站点方式”或“代码仓库方式”获取源码,需要安装gcc_riscv32编译工具。安装gcc_riscv32编译工具时,请确保编译工具的环境变量路径唯一。
执行以下命令进行安装:
sudo apt-get install build-essential && sudo apt-get install gcc && sudo apt-get install g++ && sudo apt-get install make && sudo apt-get install zlib* && sudo apt-get install libffi-dev
打开Linux编译服务器终端。
运行如下命令,安装SCons安装包。
python3 -m pip install scons
运行如下命令,查看是否安装成功。如果安装成功,查询结果下图所示。
scons -v
运行如下命令,安装python模块setuptools。
pip3 install setuptools
安装GUI menuconfig工具(Kconfiglib),建议安装Kconfiglib 13.2.0+版本,任选如下一种方式。
命令行方式:
sudo pip3 install kconfiglib
安装包方式:
下载.whl文件(例如:kconfiglib-13.2.0-py2.py3-none-any.whl)。
运行如下命令,安装.whl文件。
sudo pip3 install kconfiglib-13.2.0-py2.py3-none-any.whl
安装pycryptodome,任选如下一种方式。
安装升级文件签名依赖的Python组件包,包括:pycryptodome、six、ecdsa。安装ecdsa依赖six,请先安装six,再安装ecdsa。
命令行方式:
sudo pip3 install pycryptodome
安装包方式:
下载.whl文件(例如:pycryptodome-3.9.9-cp38-cp38-manylinux1_x86_64.whl)。
运行如下命令,安装.whl文件。
sudo pip3 install pycryptodome-3.9.9-cp38-cp38-manylinux1_x86_64.whl
安装six,任选如下一种方式。
命令行方式:
sudo pip3 install six --upgrade --ignore-installed six
安装包方式:
下载.whl文件(例如:six-1.12.0-py2.py3-none-any.whl)。
运行如下命令,安装.whl文件。
sudo pip3 install six-1.12.0-py2.py3-none-any.whl
安装ecdsa,任选如下一种方式。
命令行方式:
sudo pip3 install ecdsa
安装包方式:
下载.whl文件(例如:ecdsa-0.14.1-py2.py3-none-any.whl)。
运行如下命令,安装.whl文件。
sudo pip3 install ecdsa-0.14.1-py2.py3-none-any.whl
须知: Hi3861平台仅支持使用libgcc运行时库的静态链接,不建议开发者使用libgcc运行时库的动态链接,会导致商业分发时被GPL V3污染。
打开Linux编译服务器终端。
环境准备,请安装"gcc, g++, bison, flex, makeinfo"软件,确保工具链能正确编译。
sudo apt-get install gcc && sudo apt-get install g++ && sudo apt-get install flex bison && sudo apt-get install texinfo
下载riscv-gnu-toolchain交叉编译工具链。
git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
打开文件夹riscv-gnu-toolchain,先删除空文件夹,以防止下载newlib,binutils,gcc时冲突。
cd riscv-gnu-toolchain && rm -rf riscv-newlib && rm -rf riscv-binutils && rm -rf riscv-gcc
下载riscv-newlib-3.0.0。
git clone -b riscv-newlib-3.0.0 https://github.com/riscv/riscv-newlib.git
下载riscv-binutils-2.31.1。
git clone -b riscv-binutils-2.31.1 https://github.com/riscv/riscv-binutils-gdb.git
下载riscv-gcc-7.3.0。
git clone -b riscv-gcc-7.3.0 https://github.com/riscv/riscv-gcc
添加riscv-gcc-7.3.0补丁。
访问gcc官方补丁链接89411,86724,按照补丁链接中要求的修改,手动将变更添加到对应的.c和.h文件中,注意由于patch版本与下载的gcc版本有所偏差,行数有可能对应不上,请自行查找patch中的关键字定位到对应行。
下载GMP 6.1.2,并解压安装。
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
下载mpfr-4.0.2 ,并解压安装。
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
下载mpc-1.1.0 ,并解压安装。
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
打开文件夹riscv-gnu-toolchain,新建工具链输出目录。
cd /opt && mkdir gcc_riscv32
编译binutils。
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 ..
编译newlib。
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 ..
编译gcc。
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
设置环境变量。
vim ~/.bashrc
将以下命令拷贝到.bashrc文件的最后一行,保存并退出。
export PATH=/opt/gcc_riscv32/bin:$PATH
生效环境变量。
source ~/.bashrc
Shell命令行中输入如下命令,如果能正确显示编译器版本号,表明编译器安装成功。
riscv32-unknown-elf-gcc -v
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。