		Linux on Xvisor VExpress-A9 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 VExpress-A9 Board. We can use 
this kernel unmodified to run it as a xvisor guest. We have also provide 
VExpress-A9 defconfig for various linux kernel versions for ease in 
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 VExpress-A9 Guest with Xvisor running on QEMU VExpress-A9 Host:

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

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

  [3. Configure Xvisor with VExpress-A9 default settings]
  # make ARCH=arm vexpress-a9-defconfig 

  [4. Enable VExpress-A9 Guest from menuconfig]
  # make menuconfig
  SELECT '1x vexpress-a9 guest' DTS from 'VExpress Options'

  [5. Build Xvisor]
  # make

  [6. Build Basic Test Code]
  # make -C tests/arm32/vexpress-a9/basic

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

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

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

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

  [11. 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

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

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

  [14. Create final compressed kernel image]
  # ${CROSS_COMPILE}objcopy -O binary <linux_build_directory>/arch/arm/boot/compressed/vmlinux <linux_build_directory>/arch/arm/boot/zImage

  [15. 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/arm32/common/busybox/README for creating rootfs.img using BusyBox)

  [16. GoTo Linux build directory]
  # cd <linux_build_directory>

  [17. Create xvisor_linux_qemu.img for running it on QEMU]
  # <xvisor_source_directory>/tools/scripts/memimg.py -a 0x60010000 -o xvisor_linux_qemu.img <xvisor_source_directory>/build/vmm.bin@0x60010000 <xvisor_source_directory>/build/tests/arm32/vexpress-a9/basic/arm_test.bin.patched@0x61000000 <xvisor_source_directory>/tests/arm32/vexpress-a9/linux/cmdlist@0x610FF000 ./arch/arm/boot/zImage@0x61100000 <busybox_rootfs_directory>/rootfs.img@0x61400000

  [18. Launch QEMU 0.15.xx or higher]
  # qemu-system-arm -M vexpress-a9 -display none -serial stdio -kernel ./xvisor_linux_qemu.img

  [19. Kick Guest0 for starting Basic Test]
  XVisor# guest kick 0

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

  [21. Copy linux from NOR flash to RAM and start linux booting from RAM]
  [guest0/uart0] arm-test# copy 0x60400000 0x40100000 0x300000
  (Note: This command will copy zImage to RAM)
  [guest0/uart0] arm-test# copy 0x61000000 0x40400000 0x600000
  (Note: This command will copy rootfs.img to RAM)
  [guest0/uart0] arm-test# start_linux 0x60400000 0x61000000 0x600000
  (Note: This command will start linux booting)
  OR
  [guest0/uart0] arm-test# autoexec
  (Note: "autoexec" is a short-cut command)

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

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

  (Note: replace all <> brackets based on your workspace)
  (Note: the above steps assumes Xvisor running on VExpress-A9 host 
   emulated by QEMU 0.15.xx or higher. For other types of ARM host some of the 
   above steps will need to be adapted for that specfic ARM host. For more info
   on your desired ARM host refer docs/arm/)
  (Note: you are free to the change ordering of above steps based on your workspace)


