在UBUNTU上使用Qemu和systemd-nspawn搭建RISC-V轻量级用户模式开发环境
- 参考链接
使用Qemu和systemd-nspawn搭建RISC-V轻量级用户模式开发环境 - 知乎
- 安装Qemu
sudo apt update
sudo apt -y install qemu-user-binfmt qemu-user-static systemd-container
sudo apt -y install zstd
- 配置环境
RISCV_FILE=archriscv-2023-10-09.tar.zst
wget -c http://mirrors.wsyu.edu.cn/archriscv/images/${RISCV_FILE}
mkdir archriscv
sudo tar -I zstd -xvf ${RISCV_FILE} -C archriscv
- 启动虚拟机
sudo systemd-nspawn -D ${HOME}/archriscv/ --machine archriscv
- 测试
# pacman -Syyu
# uname -m
riscv64
- 安装gcc
pacman -Syyu g++
pacman -S vi jdk11-openjdk
- 代码
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello RISC-V!\n");
return 0;
}
- 测试
# gcc hello.c -o hello
# file hello
hello: ELF 64-bit LSB pie executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv64-lp64d.so.1, BuildID[sha1]=ca19bb1cab6f06c75002e1a6e0cde25c12432355, for GNU/Linux 4.15.0, not stripped
# ./hello
Hello RISC-V!