riscvarchive / risc-v-getting-started-guide

The official RISC-V getting started guide
https://risc-v-getting-started-guide.readthedocs.io/en/latest/
Creative Commons Attribution 4.0 International
198 stars 56 forks source link

kernel panic when running the qemu riscv command #37

Closed mherkazandjian closed 3 years ago

mherkazandjian commented 3 years ago

The following command:

sudo qemu-system-riscv64 -nographic -machine virt  -kernel linux/arch/riscv/boot/Image -append "root=/dev/vda ro console=ttyS0" -drive file=busybox/busybox,format=raw,id=hd0 -device virtio-blk-device,drive=hd0

that is described in the getting started guide https://github.com/riscv/risc-v-getting-started-guide/blame/master/source/linux-qemu.rst#L161 gives a kernel panic

image

what is the expected behavior when that command is executed?

mherkazandjian commented 3 years ago

I created a Dockerfile that can be used to reproduce the issue:

FROM ubuntu:18.04

## disable interactive input when using apt
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update

## install a bunch of pre-requisites
RUN apt-get install -y \
         autoconf \
         automake \
         autotools-dev \
         curl \
         wget \
         libmpc-dev \
         libmpfr-dev \
         libgmp-dev \
         gawk \
         build-essential \
         bison \
         flex \
         texinfo \
         gperf \
         libtool \
         patchutils \
         bc \
         zlib1g-dev \
         libexpat-dev git \
         python3 \
         python3-dev \
         gcc-riscv64-linux-gnu \
         pkg-config \
         libglib2.0-dev \
         libpixman-1-0 \
         libpixman-1-dev \
         ninja-build

RUN apt-get clean

WORKDIR /opt

RUN curl -L https://download.qemu.org/qemu-5.0.0.tar.xz --output - | xzcat - | tar -xf  - \
    && mv qemu-5.0.0 qemu \
    && cd qemu \
    && ./configure --target-list=riscv64-softmmu \
    && make -j $(nproc) \
    && make install 

RUN curl -L https://github.com/torvalds/linux/archive/refs/tags/v5.4.tar.gz --output - | tar -xzf - \
    && mv linux-5.4 linux \
    && cd linux \
    && make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- defconfig \
    && make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j $(nproc)

RUN curl https://busybox.net/downloads/busybox-1.32.1.tar.bz2 | bunzip2 - | tar -xf - \
    && mv busybox-1.32.1 busybox \
    && cd busybox \
    && CROSS_COMPILE=riscv64-linux-gnu- make defconfig \
    && CROSS_COMPILE=riscv64-linux-gnu- make -j $(nproc) 

i am actually running qemu outside the docker container (i.e i am not using the qemu that is built inside the container). Trying to run the riscv kernel from inside the container actually does not display any message it just freezes and display this message

image

when i pass the -bios none flag, it just hangs with no output being displayed

the command that i used is:

qemu-system-riscv64 -nographic -machine virt -bios none \
     -kernel linux/arch/riscv/boot/Image -append "root=/dev/vda ro console=ttyS0" \
     -drive file=busybox/busybox,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -bios none

in the user guide i think

-drive file=busybox,format=raw,id=hd0

should be replaced by

-drive file=busybox/busybox,format=raw,id=hd0

mherkazandjian commented 3 years ago

I resolved the problem by using a rootfs. This is not mentioned in the getting started guide.

CY-Pan commented 3 years ago

I resolved the problem by using a rootfs. This is not mentioned in the getting started guide.

I met exactly the same problem as yours. I searched for tutorials to make a rootfs, but got no working one. Could you please show me how to make the rootfs from busybox/_install or just tell me where to get my answers? Thank you!

louyshong commented 3 years ago

A good tutorial on how to prepare a root filesystem: https://ibug.io/blog/2019/04/os-lab-1/ Note also that if you want to run make menuconfig as in the tutorial, you'll need to install libncurses5-dev

iPAS commented 2 years ago

Maybe.. pushd . cd busybox/_install mkdir -p ../../initramfs find -print0 | cpio -0oH newc | gzip -9 > ../../initramfs/initramfs.cpio.gz