当前位置:网站首页>RISCV64

RISCV64

2022-07-07 16:49:00 InfoQ

安装 Linux Lab

# 使用普通用户下载 Cloud Lab,然后再选择 linux-lab 仓库:
git clone https://gitee.com/tinylab/cloud-lab.git
cd cloud-lab/
# 启动 Linux Lab 并根据控制台上打印的用户名和密码登录实验环境
tools/docker/run linux-lab

安装 qemu-system-riscv64

export QEMU_VERSION=5.0.0
wget https://download.qemu.org/qemu-${QEMU_VERSION}.tar.xz
tar xvJf qemu-${QEMU_VERSION}.tar.xz
cd qemu-${QEMU_VERSION}
./configure --target-list=riscv64-softmmu --prefix=/opt/qemu
make -j $(nproc)
sudo make install
ERROR: glib-2.48 gthread-2.0 is required to compile QEMU
Please call configure before running make!
make: *** [Makefile:84: config-host.mak] Error 1
""
/bin/sh: 1: : Permission denied
make: *** [Makefile:916: install-datadir] Error 127
sudo apt-get install libglib2.0-dev
ERROR: pixman >= 0.21.8 not present.
 Please install the pixman devel package.
sudo apt-get install libpixman-1-dev

下载最新的 Linux 源码

wget -c https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.18.9.tar.gz
tar xvf linux-5.18.9.tar.gz
cd linux-5.18.9
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j $(nproc)

下载最新的 BusyBox

wget -c https://www.busybox.net/downloads/busybox-1.35.0.tar.bz2
tar xvf busybox-1.35.0.tar.bz2
cd busybox-1.35.0
cd busybox
CROSS_COMPILE=riscv64-linux-gnu- make defconfig
CROSS_COMPILE=riscv64-linux-gnu- make -j $(nproc)
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- install

制作 rootfs

cd _install
mkdir proc sys dev etc etc/init.d
ls
# bin dev etc linuxrc proc sbin sys usr
sudo mknod dev/console c 5 1
sudo mknod dev/ram b 1 0
cat etc/init.d/rcS
etc/init.d/rcS
#!bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s
rootfs
chmod +x etc/init.d/rcS
find -print0 | cpio -0oH newc | gzip -9 > ../rootfs.img

运行

/opt/qemu/bin/qemu-system-riscv64 \
 -nographic -machine virt \
 -kernel linux-5.18.9/arch/riscv/boot/Image \
 -initrd busybox-1.35.0/rootfs.img \
 -bios fw_jump.elf \
 -append "root=/dev/ram rdinit=/sbin/init"
Kernel panic - not syncing: VFS: Unable to mount
null
正常启动后,查看 
uname
null
 

参考

Running 64- and 32-bit RISC-V Linux on QEMU — RISC-V - Getting Started Guide (risc-v-getting-started-guide.readthedocs.io)
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://xie.infoq.cn/article/b1eae73e2adf6553884b95e25