sysprog21 / semu

A minimalist RISC-V system emulator capable of running Linux kernel
MIT License
251 stars 47 forks source link

Implement virtio-blk device #21

Closed shengwen-tw closed 1 year ago

shengwen-tw commented 1 year ago

This pull request aims to provide the support of the virtio-blk device for the project. The modification mainly includes:

  1. A code implementation of virtio-blk device
  2. Device tree source adjustment
  3. Linux kernel configuration adjustment
  4. Interrupt assignment / handling of the virtio-blk device

To test the new feature, you need to:

  1. Create a test disk image using dd, cfdisk, losetup, and mkfs.ext4, where I followed the guide of the presentation "Embedded linux from scratch in 45 minutes" at page 35.
  2. Launch the emulator using:
    ./semu <linux-image> [<dtb>] [<disk-img>]

The virtio-blk device should be enumerated at /dev/vda during the boot-up process. The following experiment can help to verify the device works properly:

  1. Observe the partition table of the disk:
    fdisk -l
  2. Mount the disk to a directory:
    mkdir mnt/
    mount /dev/vda1 mnt/
  3. Try writing some thing to the mount directory:
    echo "Hello World!" > mnt/test.txt
  4. Unmount the disk:
    umount mnt/
  5. After re-launching the semu, the written file should remain existing.
jserv commented 1 year ago

Check kvm-host for generating ext4 file system image for validation.

jserv commented 1 year ago

Update README.md for command line options.

jserv commented 1 year ago

Thank @shengwen-tw for contributing!

shengwen-tw commented 1 year ago

Thanks for the code review!