		Xvisor on R-Car H2 Lager board using SD Booting

This section of readme explains how to build & run Xvisor on actual Renesas
R-Car H2 Lager board using SD card.

By default, Xvisor for R-Car H2 supports Vexpress-A15 guest so we will show
how to run Basic Firmware on Vexpress-A15 guest. For more info refer,
<xvisor_source>/tests/arm32/vexpress-a15/basic/README.

For Xvisor on R-Car H2 board, we need a u-boot supporting HYP-mode booting.
This is not available in opensource u-boot by default so we build u-boot with
our changes as follows:
1) Clone sources from: git://git.denx.de/u-boot.git and checkout commit,
hash: f7ca1f76fd01f3fc7e75fb3fd801c7bef16598db "net: sh-eth: Add cache
writeback control after setting bit of DMA descriptor"
2) Apply patches provided in <xvisor_source>/docs/arm/rcar-lager
3) Build u-boot as using commands
# make lager_xvisor_defconfig ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

Once we have build u-boot with HYP-mode booting, flash the u-boot to QSPI
as described in Start-Up Guide fot Renesas Lager board.

Following are steps to create these images and then boot Xvisor on R-Car H2
using SD card:

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

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

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

  [4. Build Xvisor and DTBs]
  # make

  [5. Make U-Boot compatible uvmm.bin for use with bootm command]
  # mkimage -A arm -O linux -T kernel -C none -a 0x40008000 -e 0x40008000 -n Xvisor -d build/vmm.bin build/uvmm.bin

  [6. Build Basic Firmware]
  # make -C tests/arm32/vexpress-a15/basic

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

  [8. Configure Linux in build directory]
  # cp arch/arm/configs/vexpress_defconfig arch/arm/configs/tmp-vexpress-a15_defconfig
  # <xvisor_source_directory>/tests/common/scripts/update-linux-defconfig.sh -p arch/arm/configs/tmp-vexpress-a15_defconfig -f <xvisor_source_directory>/tests/arm32/vexpress-a15/linux/linux_extra.config
  # make O=<linux_build_directory> ARCH=arm tmp-vexpress-a15_defconfig

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

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

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

  [12. 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-a15
  # dtc -q -I dts -O dtb -o ./build/disk/images/arm32/vexpress-a15-guest.dtb ./tests/arm32/vexpress-a15/vexpress-a15-guest.dts
  # cp -f ./build/tests/arm32/vexpress-a15/basic/firmware.bin ./build/disk/images/arm32/vexpress-a15/firmware.bin
  # cp -f ./tests/arm32/vexpress-a15/linux/nor_flash.list ./build/disk/images/arm32/vexpress-a15/nor_flash.list
  # cp -f ./tests/arm32/vexpress-a15/linux/cmdlist ./build/disk/images/arm32/vexpress-a15/cmdlist
  # cp -f ./tests/arm32/vexpress-a15/xscript/one_guest_vexpress-a15.xscript ./build/disk/boot.xscript
  # cp -f <linux_build_directory>/arch/arm/boot/Image ./build/disk/images/arm32/vexpress-a15/Image
  # cp -f <linux_build_directory>/arch/arm/boot/dts/vexpress-v2p-ca15-tc1.dtb ./build/disk/images/arm32/vexpress-a15/vexpress-v2p-ca15-tc1.dtb
  # cp -f <busybox_rootfs_directory>/rootfs.img ./build/disk/images/arm32/vexpress-a15/rootfs.img
  # genext2fs -B 1024 -b 32768 -d ./build/disk ./build/disk.img
  OR
  [12. 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-a15
  # dtc -q -I dts -O dtb -o ./build/disk/images/arm32/vexpress-a15-guest.dtb ./tests/arm32/vexpress-a15/vexpress-a15-guest.dts
  # cp -f ./build/tests/arm32/vexpress-a15/basic/firmware.bin ./build/disk/images/arm32/vexpress-a15/firmware.bin
  # cp -f ./tests/arm32/vexpress-a15/basic/nor_flash.list ./build/disk/images/arm32/vexpress-a15/nor_flash.list
  # cp -f ./tests/arm32/vexpress-a15/xscript/one_guest_vexpress-a15.xscript ./build/disk/boot.xscript
  # genext2fs -B 1024 -b 32768 -d ./build/disk ./build/disk.img

  [13. Make U-boot compatible initrd for use with bootm command]
  # mkimage -A arm -O linux -T ramdisk -a 0x41000000 -n "Xvisor ramdisk" -d build/disk.img build/udisk.img

  [14. Unplug SD card from the R-Car H2 board and plug it on your development machine]

  [15. Mount boot partition (or partition 0) of SD card on your development machine]

  [16. Copy uvmm.bin, DTB, and disk.img to first partition of SD card]
  # cp -f build/uvmm.bin <path_to_mounted_boot_partition_of_sd_card>
  # cp -f build/arch/arm/board/generic/dts/renesas/r8a7790-lager.dtb <path_to_mounted_boot_partition_of_sd_card>
  # cp -f build/udisk.img <path_to_mounted_boot_partition_of_sd_card>

  [17. Unmount first partition (or partition 0) of SD card from your development machine]

  [18. Unplug SD card from your development machine and plug it back on R-Car H2 board]

  [19. Connect to serial port of R-Car H2 board using Putty or Minicom]

  [20. Power-up or Reset R-Car H2 board and press any key when U-Boot shows auto-boot count down]

  [21. Enable MMC interface from U-Boot command line]
  U-Boot> mmc dev 0:0

  [22. Copy Xvisor from SD card to SDRAM]
  U-Boot> fatload mmc 0 0x40200000 uvmm.bin

  [23. Copy the Xvisor DTB from SD card to SDRAM]
  U-Boot> fatload mmc 0 0x40800000 r8a7790-lager.dtb

  [24. Copy disk image from SD card to SDRAM]
  U-Boot> fatload mmc 0 0x41000000 udisk.img

  [25. Jump into Xvisor after disabling MMU, interrupts, etc]
  U-Boot> bootm 0x40200000 0x41000000 0x40800000

  (Note: If you want to "autoboot" then you need to create a boot.scr file
   on the root of the SD card. To do so edit a boot.cmd text file and add all
   the commmands you want to execute automatically. For example you can put
   the following commands in the "boot.cmd" file:
   mmc dev 0:0
   fatload mmc 0 0x40200000 uvmm.bin
   fatload mmc 0 0x40800000 r8a7790-lager.dtb
   fatload mmc 0 0x41000000 udisk.img
   bootm 0x40200000 0x41000000 0x40800000
   Then you can create the boot.scr file wit the following command:
   # mkimage -C none -A arm -T script -d boot.cmd boot.scr
   Put the boot.scr file a the root of your SD card.)

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

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

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

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

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

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