		Xvisor on Linaro QEMU SMDKC210 Host

This section of readme explains how to build & run Xvisor for SMDKC210 
emulated by QEMU. 

By default, Xvisor for SMDKC210 supports Realview-PB-A8 guest so we will
show how to run Basic Firmware on Realview-PB-A8 guest. For more info 
refer, <xvisor_source>/tests/arm32/realview-pb-a8/basic/README.

Please follow the steps below to build & run Basic Firmware on Realview-PB-A8 
guest with Xvisor running on QEMU SMDKC210 Host:

  [1. Build environment for Xvisor]
  # export CROSS_COMPILE=arm-linux-gnueabi-

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

  [3. Configure Xvisor with Generic v7 default settings]
  # make ARCH=arm generic-v7-defconfig

  [4. Build Xvisor & DTBs]
  # make; make dtbs

  [5. Build Basic Firmware]
  # make -C tests/arm32/vexpress-a9/basic

  [6. Copy defconfig to Linux build directory]
  # cp tests/arm32/vexpress-a9/linux/linux-<linux_version>_defconfig <linux_build_directory>/.config

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

  [8. Configure Linux in build directory]
  # make O=<linux_build_directory> ARCH=arm oldconfig

  [9. Build Linux in build directory]
  # make O=<linux_build_directory> ARCH=arm Image

  [10. Patch Linux kernel to replace sensitive non-priviledged instructions]
  # <xvisor_source_directory>/arch/arm/cpu/arm32/elf2cpatch.py -f <linux_build_directory>/vmlinux | <xvisor_source_directory>/build/tools/cpatch/cpatch32 <linux_build_directory>/vmlinux 0

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

  [12. 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)

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

  [14. Create disk image for Xvisor with Guest Linux and Guest Basic Firmware]
  # 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/arm32/vexpress-a9
  # ./build/tools/dtc/dtc -I dts -O dtb -o ./build/disk/images/arm32/vexpress-a9x2.dtb ./tests/arm32/vexpress-a9/vexpress-a9x2.dts
  # cp -f ./build/tests/arm32/vexpress-a9/basic/firmware.bin.patched ./build/disk/images/arm32/vexpress-a9/firmware.bin
  # cp -f ./tests/arm32/vexpress-a9/linux/nor_flash.list ./build/disk/images/arm32/vexpress-a9/nor_flash.list
  # cp -f ./tests/arm32/vexpress-a9/linux/cmdlist ./build/disk/images/arm32/vexpress-a9/cmdlist
  # cp -f <linux_build_directory>/arch/arm/boot/Image ./build/disk/images/arm32/vexpress-a9/Image
  # ./build/tools/dtc/dtc -I dts -O dtb -p 0x800 -o ./build/disk/images/arm32/vexpress-a9/vexpress-v2p-ca9.dtb ./tests/arm32/vexpress-a9/linux/vexpress-v2p-ca9.dts
  # cp -f <busybox_rootfs_directory>/rootfs.img ./build/disk/images/arm32/rootfs.img
  # genext2fs -B 1024 -b 16384 -d ./build/disk ./build/disk.img
  OR
  [14. Create disk image for Xvisor with only Guest Basic Firmware]
  # 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/arm32/vexpress-a9
  # ./build/tools/dtc/dtc -I dts -O dtb -o ./build/disk/images/arm32/vexpress-a9x2.dtb ./tests/arm32/vexpress-a9/vexpress-a9x2.dts
  # cp -f ./build/tests/arm32/vexpress-a9/basic/firmware.bin.patched ./build/disk/images/arm32/vexpress-a9/firmware.bin
  # cp -f ./tests/arm32/vexpress-a9/basic/nor_flash.list ./build/disk/images/arm32/vexpress-a9/nor_flash.list
  # genext2fs -B 1024 -b 16384 -d ./build/disk ./build/disk.img

  [15. Launch QEMU]
  # qemu-system-arm -M smdkc210 -m 256M -display none -serial stdio -kernel build/vmm.bin -dtb build/arch/arm/board/generic/dts/exynos4/smdkc210/one_guest_vexpress-a9.dtb -initrd build/disk.img

  [16. Kick Guest0 for starting Basic Firmware]
  XVisor# guest kick guest0

  [17. Bind to virtual UART0 of Linux Guest]
  XVisor# vserial bind guest0/uart0

  [18. Try few commands of Basic firmware or goto next step]
  [guest0/uart0] basic# hi
  [guest0/uart0] basic# hello
  [guest0/uart0] basic# help

  [19. 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/arm32/vexpress-a9/linux/cmdlist file
   which we have added to guest NOR flash contains set of commands for booting
   linux from NOR flash)

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

  [21. 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 ARM host)
  (Note: for more info on your desired ARM host refer docs/arm/)
  (Note: you are free to change the ordering of above steps based
   on your workspace)
