【参考】环境部署 - rCore-Tutorial-deploy - GitBook :
https://rcore-os.github.io/rCore-Tutorial-deploy/docs/pre-lab/env.html
【参考】实验环境配置 — rCore-Tutorial-Book-v3 0.1 文档 :
https://rcore-os.github.io/rCore-Tutorial-Book-v3/chapter0/5setup-devel-env.html
【参考】qemu/qemu: Official QEMU mirror : https://github.com/qemu/qemu

测试环境:
腾讯云 cvm.S5.SMALL2(中国-上海) Ubuntu Server 18.04.1 LTS 64位;
阿里云 ecs.t6-c2m1.large(印度尼西亚-雅加达)Ubuntu Server 20.04.1 LTS 64位;
WSL 2 Ubuntu 20.04 LTS(本地-境内)
使用体验
*ubuntu 软件源仓库,rust 仓库 云服务器使用自家镜像仓库,本地使用清华,中科大镜像。
腾讯云:github 丢包极其严重,控制台无法使用 ctrl + c/v 快捷键(20210619)
阿里云:github 没有丢包(可能服务器海外的缘故),性能除外,整体使用流畅。
本地:github 偶尔丢包(不稳定),性能加持,解压,编译速度奇快,网络除外,整体使用舒适。

1. 【可选】配置 WSL 2 环境

可参考:x64: WSL 2 环境安装 - 零一魔法 - CSDN: https://blog.csdn.net/m0_49270962/article/details/118057987

2. 配置 rust 开发环境

2.1 运行 rust 安装脚本

【参考】Getting started - Rust Programming Language :
https://www.rust-lang.org/learn/get-started

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

若官方脚本运行出现网络速度较慢的情况,可以选择 修改为 rustup 镜像地址:
(https://blog.csdn.net/m0_49270962/article/details/118058074)

2.2 根据提示安装 rust

根据提示,安装 nightly 版本。

Tips
在安装中选择 nightly complete 版本,会报错
error: failed to install component: 'rustc-docs-x86_64-unknown-linux-gnu', detected conflict: 'share/doc/rust/html/rustc'
解决方案
方法一:使用 nightly default 安装方案,
方法二:先使用 stable default 方案,再通过以下命令安装并切换到 nightly 版本

rustup install nightly
rustup default nightly

2.3 重启 终端

  • 查看 rust 版本
    rustc --version
    

2.4 【可选】修改 cargo 软件包镜像地址

可参考:修改 cargo 软件包镜像地址 - 零一魔法 - CSDN博客: https://blog.csdn.net/m0_49270962/article/details/118058433

2.5 添加 rust 编译依赖

# 增加 RISC-V 三元组
rustup target add riscv64imac-unknown-none-elf
# rustup target add riscv64gc-unknown-none-elf
# 增加需要的 cargo-binutils
cargo install cargo-binutils --vers ~0.2
rustup component add llvm-tools-preview rust-src

Tips

# 报错
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `memchr`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

...

error: aborting due to previous error

error: failed to compile `cargo-binutils v0.2.0`, intermediate artifacts can be found at `/tmp/cargo-installZT2MKV`

Caused by:
  build failed

解决方案

# 手动安装 gcc
sudo apt install gcc

3. 编译安装 Qemu 模拟器

【参考】Running 64- and 32-bit RISC-V Linux on QEMU — RISC-V - Getting Started Guide :
https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html#prerequisites

若软件包源包含较新版本的 qemu,可直接安装

sudo apt install qemu

3.1 安装 Qemu 依赖包

  1. 更新软件源列表
    sudo apt update
    
  2. 安装 Qemu 依赖包
    sudo apt install autoconf automake autotools-dev curl \
        libmpc-dev libmpfr-dev libgmp-dev gawk build-essential \
        bison flex texinfo gperf libtool patchutils bc \
        zlib1g-dev libexpat-dev pkg-config libglib2.0-dev \
        libpixman-1-dev git tmux python3
    

Tips

# 报错
E: Unable to locate package libmpc-dev
E: Unable to locate package libmpfr-dev
E: Unable to locate package libgmp-dev
E: Package 'gawk' has no installation candidate
E: Package 'bison' has no installation candidate
E: Package 'flex' has no installation candidate
E: Package 'texinfo' has no installation candidate
E: Unable to locate package gperf
E: Unable to locate package patchutils
E: Package 'git' has no installation candidate

解决方案

# 更新软件包列表
sudo apt update

3.2 下载并解压源码包

# 下载
wget https://download.qemu.org/qemu-5.0.0.tar.xz
# 解压
tar xvJf qemu-5.0.0.tar.xz

3.3 编译并配置 RISC-V 支持

cd qemu-5.0.0
./configure --target-list=riscv64-softmmu,riscv64-linux-user
make -j$(nproc)

3.4 安装 qemu

sudo make install
  • 确认 qemu 版本
    qemu-system-riscv64 --version
    qemu-riscv64 --version
    

3.5 安装并运行 rCore

【参考】第二章:最小化内核 - 使用 Qemu 运行内核 - 《rCore 手册(rCore tutorial doc)》 - 书栈网 · BookStack :
https://www.bookstack.cn/read/rCore_tutorial_doc/1661c9c62f632357.md
【参考】rcore-os/rCore: Rust version of THU uCore OS. Linux compatible. :
https://github.com/rcore-os/rCore

  1. 克隆仓库
    git clone https://github.com/rcore-os/rCore-Tutorial-v3.git
    cd rCore-Tutorial-v3
    git checkout main
    
  2. 编译运行
    cd os
    make run
    

Tips

# 报错
Could not allocate dynamic translator buffer

解决方案

# 允许模拟器过量使用内存
sudo sysctl vm.overcommit_memory=1
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐