官网安装教程 实验所需环境中,只有riscv-tools不能通过brew正确安装。。。
理论上使用brew安装是可以的⬇️
$ brew tap riscv/riscv
$ brew install riscv-tools
不过不知道是不是因为m1的缘故,上面命令总会出现问题,安装不成功,因此我使用git命令去安装,过程如下⬇️
git clone https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
riscv-gnu-toolchain git:(master) ✗ git submodule update --init --recursive
大概需要6.5GB(M1)(intel-x86不需要那么多)。
上面命令提示,需要下载的依赖如下⬇️,还是挺多的,每个都需要下载很久。
Submodule 'binutils' (https://sourceware.org/git/binutils-gdb.git) registered for path 'binutils'
Submodule 'gcc' (https://gcc.gnu.org/git/gcc.git) registered for path 'gcc'
Submodule 'glibc' (https://sourceware.org/git/glibc.git) registered for path 'glibc'
Submodule 'musl' (git://git.musl-libc.org/musl) registered for path 'musl'
Submodule 'newlib' (https://sourceware.org/git/newlib-cygwin.git) registered for path 'newlib'
Submodule 'pk' (https://github.com/riscv-software-src/riscv-pk.git) registered for path 'pk'
Submodule 'qemu' (https://gitlab.com/qemu-project/qemu.git) registered for path 'qemu'
Submodule 'riscv-dejagnu' (https://github.com/riscv-collab/riscv-dejagnu.git) registered for path 'riscv-dejagnu'
Submodule 'riscv-gdb' (https://github.com/riscv-collab/riscv-binutils-gdb.git) registered for path 'riscv-gdb'
Submodule 'spike' (https://github.com/riscv-software-src/riscv-isa-sim.git) registered for path 'spike'
当上面依赖下载完毕之后,又回递归下载以下依赖⬇️(不过这一波的下载速度比较快,不会等很久)
Submodule path 'binutils': checked out 'b51c2fec1da205ea3e7354cbb3e253018d64873c'
Submodule path 'gcc': checked out '1ea978e3066ac565a1ec28a96a4d61eaf38e2726'
Submodule path 'glibc': checked out '9826b03b747b841f5fc6de2054bf1ef3f5c4bdf3'
Submodule path 'musl': checked out '85e0e3519655220688e757b9d5bfd314923548bd'
Submodule path 'newlib': checked out '415fdd4279b85eeec9d54775ce13c5c412451e08'
Submodule path 'pk': checked out '2efabd3e6604b8a9e8f70baf52f57696680c7855'
Submodule path 'qemu': checked out '823a3f11fb8f04c3c3cc0f95f968fef1bfc6534f'
Submodule 'capstone' (https://gitlab.com/qemu-project/capstone.git) registered for path 'qemu/capstone'
Submodule 'dtc' (https://gitlab.com/qemu-project/dtc.git) registered for path 'qemu/dtc'
Submodule 'meson' (https://gitlab.com/qemu-project/meson.git) registered for path 'qemu/meson'
Submodule 'roms/QemuMacDrivers' (https://gitlab.com/qemu-project/QemuMacDrivers.git) registered for path 'qemu/roms/QemuMacDrivers'
Submodule 'roms/SLOF' (https://gitlab.com/qemu-project/SLOF.git) registered for path 'qemu/roms/SLOF'
Submodule 'roms/edk2' (https://gitlab.com/qemu-project/edk2.git) registered for path 'qemu/roms/edk2'
Submodule 'roms/ipxe' (https://gitlab.com/qemu-project/ipxe.git) registered for path 'qemu/roms/ipxe'
Submodule 'roms/openbios' (https://gitlab.com/qemu-project/openbios.git) registered for path 'qemu/roms/openbios'
Submodule 'roms/opensbi' (https://gitlab.com/qemu-project/opensbi.git) registered for path 'qemu/roms/opensbi'
Submodule 'roms/qboot' (https://gitlab.com/qemu-project/qboot.git) registered for path 'qemu/roms/qboot'
Submodule 'roms/qemu-palcode' (https://gitlab.com/qemu-project/qemu-palcode.git) registered for path 'qemu/roms/qemu-palcode'
Submodule 'roms/seabios' (https://gitlab.com/qemu-project/seabios.git/) registered for path 'qemu/roms/seabios'
Submodule 'roms/seabios-hppa' (https://gitlab.com/qemu-project/seabios-hppa.git) registered for path 'qemu/roms/seabios-hppa'
Submodule 'roms/sgabios' (https://gitlab.com/qemu-project/sgabios.git) registered for path 'qemu/roms/sgabios'
Submodule 'roms/skiboot' (https://gitlab.com/qemu-project/skiboot.git) registered for path 'qemu/roms/skiboot'
Submodule 'roms/u-boot' (https://gitlab.com/qemu-project/u-boot.git) registered for path 'qemu/roms/u-boot'
Submodule 'roms/u-boot-sam460ex' (https://gitlab.com/qemu-project/u-boot-sam460ex.git) registered for path 'qemu/roms/u-boot-sam460ex'
Submodule 'roms/vbootrom' (https://gitlab.com/qemu-project/vbootrom.git) registered for path 'qemu/roms/vbootrom'
Submodule 'slirp' (https://gitlab.com/qemu-project/libslirp.git) registered for path 'qemu/slirp'
Submodule 'tests/fp/berkeley-softfloat-3' (https://gitlab.com/qemu-project/berkeley-softfloat-3.git) registered for path 'qemu/tests/fp/berkeley-softfloat-3'
Submodule 'tests/fp/berkeley-testfloat-3' (https://gitlab.com/qemu-project/berkeley-testfloat-3.git) registered for path 'qemu/tests/fp/berkeley-testfloat-3'
Submodule 'tests/lcitool/libvirt-ci' (https://gitlab.com/libvirt/libvirt-ci.git) registered for path 'qemu/tests/lcitool/libvirt-ci'
Submodule 'ui/keycodemapdb' (https://gitlab.com/qemu-project/keycodemapdb.git) registered for path 'qemu/ui/keycodemapdb'
…不停的下载依赖。。。。
发生问题:有一个包始终下载不下来⬇️
➜ riscv-gnu-toolchain git:(master) ✗ git submodule update --init --recursive
Cloning into '/Users/levi/riscv-gnu-toolchain/qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/boringssl'...
fatal: unable to access 'https://boringssl.googlesource.com/boringssl/': Failed to connect to boringssl.googlesource.com port 443 after 75148 ms: Operation timed out
fatal: clone of 'https://boringssl.googlesource.com/boringssl' into submodule path '/Users/levi/riscv-gnu-toolchain/qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/boringssl' failed
Failed to clone 'boringssl'. Retry scheduled
Cloning into '/Users/levi/riscv-gnu-toolchain/qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/boringssl'...
fatal: unable to access 'https://boringssl.googlesource.com/boringssl/': Failed to connect to boringssl.googlesource.com port 443 after 75005 ms: Operation timed out
fatal: clone of 'https://boringssl.googlesource.com/boringssl' into submodule path '/Users/levi/riscv-gnu-toolchain/qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/boringssl' failed
Failed to clone 'boringssl' a second time, aborting
Failed to recurse into submodule path 'qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl'
Failed to recurse into submodule path 'qemu/roms/edk2'
Failed to recurse into submodule path 'qemu'
我用git命令尝试下载git clone https://boringssl.googlesource.com/boringssl/
,依然失败。
后面发现可以用https://github.com/google/boringssl.git
替代https://boringssl.googlesource.com/boringssl/
进行下载⬇️
根据提示的位置,进入依赖目录,修改依赖路径。
cd /Users/levi/riscv-gnu-toolchain/qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/
vim .gitmodules
将
[submodule "boringssl"]
path = boringssl
url = https://boringssl.googlesource.com/boringssl
修改为
[submodule "boringssl"]
path = boringssl
url = https://github.com/google/boringssl.git
回到riscv-gnu-toolchain
目录下,重新执行⬇️
cd ~/riscv-gnu-toolchain
git submodule update --init --recursive
首先从git上下载⬇️
git clone https://github.com/google/boringssl.git
复制到对应路径下⬇️
cp -r boringssl /Users/levi/riscv-gnu-toolchain/qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/
cd riscv-gnu-toolchain
./configure --prefix=/opt/riscv-gnu-toolchain --with-cmodel=medany --enable-multilib
# 因为安到opt目录下所以加了sudo 如果不安装在这个目录下 可以不使用sudo
sudo make
打开~/.zshrc
或者 ~/.bash_profile
,在其中添加⬇️
export RISCV_HOME=/opt/riscv-gnu-toolchain
export PATH=${PATH}:${RISCV_HOME}/bin
# 用 source 命令 让环境变量重新加载
source ~/.zshrc
source ~/.bash_profile
命令行运行⬇️
riscv64-unknown-elf-gcc -v
如果得到的输出为⬇️,说明riscv-tool-chain安装成功。
➜ ~ riscv64-unknown-elf-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-unknown-elf-gcc
COLLECT_LTO_WRAPPER=/opt/riscv-gnu-toolchain/libexec/gcc/riscv64-unknown-elf/12.1.0/lto-wrapper
Target: riscv64-unknown-elf
Configured with: /Users/levi/riscv-gnu-toolchain/gcc/configure --target=riscv64-unknown-elf --prefix=/opt/riscv-gnu-toolchain --disable-shared --disable-threads --enable-languages=c,c++ --with-pkgversion=g --with-system-zlib --enable-tls --with-newlib --with-sysroot=/opt/riscv-gnu-toolchain/riscv64-unknown-elf --with-native-system-header-dir=/include --disable-libmudflap --disable-libssp --disable-libquadmath --disable-libgomp --disable-nls --disable-tm-clone-registry --src=/Users/levi/riscv-gnu-toolchain/gcc --enable-multilib --with-abi=lp64d --with-arch=rv64imafdc --with-tune=rocket --with-isa-spec=2.2 'CFLAGS_FOR_TARGET=-Os -mcmodel=medany' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medany'
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 12.1.0 (g)