		Linux on Xvisor Realview-EB-MPCore 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 Realview-EB-MPCore Board. We can use 
this kernel unmodified to run it as a xvisor guest. We have also provide 
Realview-EB-MPCore 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 Realview-EB-MPCore Guest with Xvisor running on QEMU Realview-EB-MPCore 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 Realview-EB-MPCore default settings]
  # make ARCH=arm realview-eb-mpcore-defconfig 
  (Note: realview-eb-mpcore-defconfig will select device tree configuration with only one preconfigured guest. For enabling two preconfigured guest use "make ARCH=arm menuconfig" after the above step and select device tree configuration for two guests from Realview-EB-MPCore options.)

  [4. Build Xvisor]
  # make

  [5. Build Basic Test Code]
  # make -C tests/arm32/realview-eb-mpcore/basic

  [6. Copy defconfig to Linux build directory]
  # cp tests/arm32/realview-eb-mpcore/linux/linux-<linux_version>_realview_ebmp_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 zImage

  [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 zImage

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

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

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

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

  [16. Create xvisor_linux_qemu.img for running it on QEMU]
  # <xvisor_source_directory>/tools/scripts/memimg.py -a 0x00010000 -o xvisor_linux_qemu.img <xvisor_source_directory>/build/vmm.bin@0x00010000 <xvisor_source_directory>/build/tests/arm32/realview-eb-mpcore/basic/arm_test.bin.patched@0x01000000 <xvisor_source_directory>/tests/arm32/realview-eb-mpcore/linux/cmdlist@0x010FF000 ./arch/arm/boot/zImage@0x01100000 <busybox_rootfs_directory>/rootfs.img@0x01400000
  (Note: If we have two preconfigured guests then we will have to add images for second guest. This can be done by appending following arguments to the above command: "<xvisor_source_directory>/build/tests/arm32/realview-eb-mpcore/basic/arm_test.bin.patched@0x08000000 <xvisor_source_directory>/tests/arm32/realview-eb-mpcore/linux/cmdlist@0x080FF000 ./arch/arm/boot/zImage@0x08100000 <busybox_rootfs_directory>/rootfs.img@0x08400000")

  [17. Launch QEMU 0.14.xx or higher]
  # qemu-system-arm -M realview-eb-mpcore -display none -serial stdio -kernel ./xvisor_linux_qemu.img

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

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

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

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

  [22. 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 Realview-EB-MPCore host emulated
   by QEMU 0.14.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 change the ordering of above steps based on your workspace)

