• 6.S081环境配置-问题解决


    Mac(m1)安装6.S081所需实验环境 riscv-tools

    0. 说明

    官网安装教程 实验所需环境中,只有riscv-tools不能通过brew正确安装。。。

    理论上使用brew安装是可以的⬇️

    $ brew tap riscv/riscv
    $ brew install riscv-tools
    
    • 1
    • 2

    不过不知道是不是因为m1的缘故,上面命令总会出现问题,安装不成功,因此我使用git命令去安装,过程如下⬇️

    1. 首先安装riscv-gnu-toolchain

    git clone https://github.com/riscv/riscv-gnu-toolchain
    
    • 1

    2. 然后递归下载相关依赖⬇️(可能需要大半天的时间)

    cd riscv-gnu-toolchain                                
    riscv-gnu-toolchain git:(master)git submodule update --init --recursive   
    
    • 1
    • 2
    2.1 说明:下面是递归下载依赖时,自动下载的内容⬇️

    大概需要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'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    当上面依赖下载完毕之后,又回递归下载以下依赖⬇️(不过这一波的下载速度比较快,不会等很久)

    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'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    …不停的下载依赖。。。。

    3. 解决boringssl的下载失败问题

    发生问题:有一个包始终下载不下来⬇️

    ➜  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'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    我用git命令尝试下载git clone https://boringssl.googlesource.com/boringssl/,依然失败。

    后面发现可以用https://github.com/google/boringssl.git替代https://boringssl.googlesource.com/boringssl/进行下载⬇️

    方案1,修改依赖路径(不推荐,有点麻烦)

    根据提示的位置,进入依赖目录,修改依赖路径。

    cd /Users/levi/riscv-gnu-toolchain/qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/
    vim .gitmodules
    
    • 1
    • 2

    [submodule "boringssl"]
            path = boringssl
            url = https://boringssl.googlesource.com/boringssl
    
    • 1
    • 2
    • 3

    修改为

    [submodule "boringssl"]
            path = boringssl
            url = https://github.com/google/boringssl.git
    
    • 1
    • 2
    • 3

    回到riscv-gnu-toolchain目录下,重新执行⬇️

    cd ~/riscv-gnu-toolchain
    git submodule update --init --recursive
    
    • 1
    • 2
    方案2,从github上下载后cp到需要的路径下

    首先从git上下载⬇️

    git clone https://github.com/google/boringssl.git
    
    • 1

    复制到对应路径下⬇️

    cp -r boringssl /Users/levi/riscv-gnu-toolchain/qemu/roms/edk2/CryptoPkg/Library/OpensslLib/openssl/
    
    • 1

    4. 下载完毕,安装(大概需要个把小时)

    cd riscv-gnu-toolchain
    ./configure --prefix=/opt/riscv-gnu-toolchain --with-cmodel=medany --enable-multilib
    # 因为安到opt目录下所以加了sudo 如果不安装在这个目录下 可以不使用sudo
    sudo make
    
    • 1
    • 2
    • 3
    • 4

    5. 配置环境变量

    打开~/.zshrc 或者 ~/.bash_profile,在其中添加⬇️

    export RISCV_HOME=/opt/riscv-gnu-toolchain
    export PATH=${PATH}:${RISCV_HOME}/bin
    
    • 1
    • 2
    # 用 source 命令 让环境变量重新加载
    source ~/.zshrc
    source ~/.bash_profile
    
    • 1
    • 2
    • 3

    6. 验证安装是否成功

    命令行运行⬇️

    riscv64-unknown-elf-gcc -v
    
    • 1

    如果得到的输出为⬇️,说明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) 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  • 相关阅读:
    索引——MySQL
    【C++】函数重载 ① ( 函数重载概念 | 函数重载判断标准 - 参数个数 / 类型 / 顺序 | 返回值不是函数重载判定标准 )
    K8s使用RDMA进行高速通信
    Linux shell编程学习笔记11:关系运算
    apache httpd 换行解析漏洞
    23111709[含文档+PPT+源码等]计算机毕业设计基于Spring Boot智能无人仓库管理-进销存储
    Codeforces Round #835 (Div. 4) A~G
    vlan trunk stp攻防
    图灵奖得主LeCun指明AI未来的出路在于自主学习,这家公司已踏上征途
    springboot 集成webSocket
  • 原文地址:https://blog.csdn.net/ahundredmile/article/details/126809478