Ubuntu22.04安装riscv64-toolchain和QEMU

riscv64-toolchain环境搭建

安装跨平台工具

提供跨平台编译的各种库

sudo apt install libc6-riscv64-cross
适用于GNU/Linux的linux-gnu-toolchain

安装riscv64-linux-gnu-gcc

sudo apt install binutils-riscv64-linux-gnu
sudo apt install gcc-riscv64-linux-gnu

查看版本

$ riscv64-linux-gnu-gcc --version
riscv64-linux-gnu-gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
适用于嵌入式的unknown-elf-toolchain

安装riscv64-unknown-elf-gcc

sudo apt install binutils-riscv64-unknown-elf
sudo apt install gcc-riscv64-unknown-elf

查看版本

$ riscv64-unknown-elf-gcc --version
riscv64-unknown-elf-gcc () 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

安装QEMU

下载并编译QEMU

首先我们安装依赖包,获取 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 libsdl2-dev \
              git tmux python3 python3-pip ninja-build

下载源码包

# 如果下载速度过慢使用百度网盘链接:链接: https://pan.baidu.com/s/1fIdp6NP0qLdamjExRcwSEw 提取码: krxe 
wget https://download.qemu.org/qemu-7.0.0.tar.xz
# 解压
tar xvJf qemu-7.0.0.tar.xz

编译安装并配置 RISC-V 支持

cd qemu-7.0.0
./configure --target-list=riscv64-softmmu,riscv64-linux-user  # 如果要支持图形界面,可添加 " --enable-sdl" 参数
make -j$(nproc)
配置环境变量

可以使用,sudo make install 将 QEMU 安装到 /usr/local/bin 目录下,这里将环境变量配置到~/.bashrc

vim ~/.bashrc

在文件末尾添加

# qemu-7.0.0
export PATH=$PATH:$HOME/opt/programming/risc-v/qemu-7.0.0/build

查看版本

$ qemu-system-riscv64 --version
QEMU emulator version 7.0.0
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
$ qemu-riscv64 --version
qemu-riscv64 version 7.0.0
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers

你可能感兴趣的:(risc-v,risc-v)