rCore qemu risc-v experimental environment configuration

Posted by Hodo on Fri, 28 Jan 2022 10:39:23 +0100

[reference] environment deployment - rcore tutorial deploy - gitbook:
https://rcore-os.github.io/rCore-Tutorial-deploy/docs/pre-lab/env.html
[reference] experimental environment configuration - rCore-Tutorial-Book-v3 0.1 document:
https://rcore-os.github.io/rCore-Tutorial-Book-v3/chapter0/5setup-devel-env.html
[reference] qemu/qemu: Official QEMU mirror: https://github.com/qemu/qemu

Test environment:
Tencent cloud CVM S5. Small2 (China Shanghai) Ubuntu Server 18.04.1 LTS 64 bit;
Alibaba cloud ECs t6-c2m1. Large (Indonesia Jakarta) Ubuntu Server 20.04.1 LTS 64 bit;
WSL 2 Ubuntu 20.04 LTS (local domestic)
user's experience
*ubuntu software source warehouse, t rust warehouse, cloud server uses its own image warehouse, and Tsinghua University and China University of science and technology image are used locally.
Tencent cloud: the packet loss of github is extremely serious, and the console cannot use ctrl + c/v shortcut key (20210619)
Alibaba cloud: github has no packet loss (possibly due to overseas servers), except for performance. It is used smoothly as a whole.
Local: github occasionally loses packets (unstable), with performance blessing, decompression and extremely fast compilation speed. Except for the network, it is comfortable to use as a whole.

1. [optional] configure WSL 2 Environment

Refer to: x64: WSL 2 environment installation - zero Magic - CSDN: https://blog.csdn.net/m0_49270962/article/details/118057987

2. Configure the t rust development environment

2.1 run the t rust installation script

[reference] Getting started - Rust Programming Language:
https://www.rust-lang.org/learn/get-started

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

If the network speed is slow when the official script runs, you can choose Change to rustup image address:
(https://blog.csdn.net/m0_49270962/article/details/118058074)

2.2 install t rust according to the prompts

Follow the prompts to install the nightly version.

Tips
If nightly complete version is selected during installation, an error will be reported
error: failed to install component: 'rustc-docs-x86_64-unknown-linux-gnu', detected conflict: 'share/doc/rust/html/rustc'
Solution
Method 1: use nightly default installation scheme,
Method 2: first use the stable default scheme, then install and switch to the nightly version through the following command

rustup install nightly
rustup default nightly

2.3 restart the terminal

  • View the version of trust
    rustc --version
    

2.4 [optional] modify the image address of cargo package

For reference: modify the image address of cargo package - zero Magic - CSDN blog: https://blog.csdn.net/m0_49270962/article/details/118058433

2.5 add t rust compilation dependency

# Add RISC-V triples
rustup target add riscv64imac-unknown-none-elf
# rustup target add riscv64gc-unknown-none-elf
# Add required cargo binutils
cargo install cargo-binutils --vers ~0.2
rustup component add llvm-tools-preview rust-src

Tips

# report errors
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

Solution

# Manually install gcc
sudo apt install gcc

3. Compile and install Qemu simulator

[reference] 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

If the software package source contains a newer version of qemu, you can install it directly

sudo apt install qemu

3.1 installing Qemu dependency package

  1. Update software source list
    sudo apt update
    
  2. Install Qemu dependency package
    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

# report errors
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

Solution

# Update package list
sudo apt update

3.2 download and unzip the source package

# download
wget https://download.qemu.org/qemu-5.0.0.tar.xz
# decompression
tar xvJf qemu-5.0.0.tar.xz

3.3 compile and configure RISC-V support

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

3.4 installation qemu

sudo make install
  • Confirm qemu version
    qemu-system-riscv64 --version
    qemu-riscv64 --version
    

3.5 install and run rCore

[reference] Chapter 2: minimize the kernel - run the kernel using Qemu - rCore tutorial doc - BookStack.com · BookStack:
https://www.bookstack.cn/read/rCore_tutorial_doc/1661c9c62f632357.md
[reference] rcore OS / rcore: rust version of thu UCORE OS Linux compatible. :
https://github.com/rcore-os/rCore

  1. Clone warehouse
    git clone https://github.com/rcore-os/rCore-Tutorial-v3.git
    cd rCore-Tutorial-v3
    git checkout main
    
  2. Compile and run
    cd os
    make run
    

Tips

# report errors
Could not allocate dynamic translator buffer

Solution

# Allow simulator to overuse memory
sudo sysctl vm.overcommit_memory=1

Topics: Operating System Rust qemu risc-v