		Linux on Xvisor RISC-V Virt64 SMP Guest

Linux is a computer operating system which is based on free and open source
software. the underlying source code can be used, freely modified, and
redistributed, both commercially and non-commercially, by anyone under
licenses such as the GNU General Public License. For more information on
Linux read the wiki page http://en.wikipedia.org/wiki/Linux

Linux already contains a support for device-tree based boards. We can use
linux kernel unmodified to run it as a RISC-V Virt64 guest. We also provide
a defconfig for building kernel. To obtain Linux kernel sources visit the
following url: http://www.kernel.org

Please follow the steps below to build & run Linux kernel with Busybox
RootFS on Virt64 (paravirtualized RISC-V 64bit) Guest with Xvisor running
on QEMU model (v5.1 or higher):

  [1. Build environment for Xvisor]
  # CROSS_COMPILE=riscv64-unknown-linux-gnu-

  [2. GoTo Xvisor source directory]
  # cd <xvisor_source_directory>

  [3. Configure Xvisor with Generic-64bit default settings]
  # make ARCH=riscv generic-64b-defconfig

  [4. Build Xvisor & DTBs]
  # make

  [5. Build Basic Firmware]
  # make -C tests/riscv/virt64/basic

  [6. GoTo OpenSBI source directory]
  # cd <opensbi_source_directory>

  [7. Build OpenSBI]
  # make PLATFORM=generic

  [8. GoTo Linux source directory]
  # cd <linux_source_directory>

  [9. Configure Linux in build directory]
  # cp arch/riscv/configs/defconfig arch/riscv/configs/tmp-virt64_defconfig
  # <xvisor_source_directory>/tests/common/scripts/update-linux-defconfig.sh -p arch/riscv/configs/tmp-virt64_defconfig -f <xvisor_source_directory>/tests/riscv/virt64/linux/linux_extra.config
  # make O=<linux_build_directory> ARCH=riscv tmp-virt64_defconfig

  [10. Build Linux in build directory to reflect changes in kernel image]
  # make O=<linux_build_directory> ARCH=riscv Image dtbs

  [11. Create BusyBox RAMDISK to be used as RootFS for Linux kernel]
  (Note: For subsequent steps, we will assume that your RAMDISK is located at <busybox_rootfs_directory>/rootfs.img)
  (Note: Please refer tests/common/busybox/README.md for creating rootfs.img using BusyBox)

  [12. GoTo Xvisor source directory]
  # cd <xvisor_source_directory>

  [13. Create disk image for Xvisor]
  # mkdir -p ./build/disk/tmp
  # mkdir -p ./build/disk/system
  # cp -f ./docs/banner/roman.txt ./build/disk/system/banner.txt
  # cp -f ./docs/logo/xvisor_logo_name.ppm ./build/disk/system/logo.ppm
  # mkdir -p ./build/disk/images/riscv/virt64
  # dtc -q -I dts -O dtb -o ./build/disk/images/riscv/virt64-guest.dtb ./tests/riscv/virt64/virt64-guest.dts
  # cp -f ./build/tests/riscv/virt64/basic/firmware.bin ./build/disk/images/riscv/virt64/firmware.bin
  # cp -f ./tests/riscv/virt64/linux/nor_flash.list ./build/disk/images/riscv/virt64/nor_flash.list
  # cp -f ./tests/riscv/virt64/linux/cmdlist ./build/disk/images/riscv/virt64/cmdlist
  # cp -f ./tests/riscv/virt64/xscript/one_guest_virt64.xscript ./build/disk/boot.xscript
  # cp -f <linux_build_directory>/arch/riscv/boot/Image ./build/disk/images/riscv/virt64/Image
  # dtc -q -I dts -O dtb -o ./build/disk/images/riscv/virt64/virt64.dtb ./tests/riscv/virt64/linux/virt64.dts
  # cp -f <busybox_rootfs_directory>/rootfs.img ./build/disk/images/riscv/virt64/rootfs.img
  # genext2fs -B 1024 -b 32768 -d ./build/disk ./build/disk.img

  [14. Launch QEMU]
  # qemu-system-riscv64 -cpu rv64,x-h=true -M virt -m 512M -nographic -bios <opensbi_source_directory>/build/platform/qemu/virt64/firmware/fw_jump.bin -kernel ./build/vmm.bin -initrd ./build/disk.img -append 'vmm.bootcmd="vfs mount initrd /;vfs run /boot.xscript;vfs cat /system/banner.txt"'

  [15. Kick Guest0 to start Basic Firmware]
  XVisor# guest kick guest0

  [16. Bind to virtual UART]
  XVisor# vserial bind guest0/uart0

  [17. Copy linux from NOR flash to RAM and start linux booting from RAM]
  [guest0/uart0] basic# autoexec
  (Note: "autoexec" is a short-cut command)
  (Note: The <xvisor_source_directory>/tests/riscv/virt64/linux/cmdlist file
   which we have added to guest NOR flash contains set of commands for booting
   linux from NOR flash)

  [18. Wait for Linux prompt to come-up and then try out some commands]
  [guest0/uart0] / # ls

  [19. Enter character seqence 'ESCAPE+x+q" return to Xvisor prompt]
  [guest0/uart0] / #

  (Note: replace all <> brackets based on your workspace)
  (Note: some of the above steps will need to be adapted for other
   types of RISC-V host)
  (Note: for more info on your desired RISC-V host refer docs/riscv/)
  (Note: you are free to change the ordering of above steps based
   on your workspace)
