	Xvisor on Allwinner A20 board (or Sun7i) using SD Booting 

This section of readme explains how to build & run Xvisor on actual Allwinner
A20 boards (cubieboard2 for example) using SD booting feature of Sun7i SOC.

By default, Xvisor for Sun7i 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.

As first step of SD booting on Sun7i SOC, we need to re-partition and program
a SD card (> 4GB card) with Uboot. For detailed info on preparing SD card for 
booting refer: https://github.com/linux-sunxi/u-boot-sunxi/wiki

However, to enable both Core on the Allwinner A20 you need a u-boot version
supporting PSCI. This is not part of sunxi ou u-boot default git tree so you
need to use https://github.com/jcdubois/u-boot as your git tree fro u-boot in
the above link.

Once we have SD card prepared for SD booting, we add 2 images to the boot 
partition of SD card:
 1) U-Boot compatible Xvisor binary (uvmm.bin)
 2) DTB for Xvisor (one_guest_pb-a8.dtb)
 3) Disk image containing guest binaries (disk.img)

Following are steps to create these images and then boot Xvisor on Allwinner
A20:

  [1. Build environment]
  # CROSS_COMPILE=arm-none-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; make dtbs

  [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 for Realview-PB-A8 Guest, this creates firmware.bin]
  # make -C tests/arm32/realview-pb-a8/basic
  
  [7. Create disk image for Xvisor]
  # mkdir -p ./build/disk/images/arm32/realview-pb-a8
  # ./build/tools/dtc/dtc -I dts -O dtb -o ./build/disk/images/arm32/realview-pb-a8.dtb ./tests/arm32/realview-pb-a8/realview-pb-a8.dts
  # cp -f ./build/tests/arm32/realview-pb-a8/basic/firmware.bin ./build/disk/images/arm32/realview-pb-a8/firmware.bin
  # cp -f ./tests/arm32/realview-pb-a8/basic/nor_flash.list ./build/disk/images/arm32/realview-pb-a8/nor_flash.list
  # genext2fs -B 1024 -b 16384 -d ./build/disk ./build/disk.img
  OR
  # mkdir -p ./build/disk/images/arm32/realview-pb-a8
  # ./build/tools/dtc/dtc -I dts -O dtb -o ./build/disk/images/arm32/realview-pb-a8.dtb ./tests/arm32/realview-pb-a8/realview-pb-a8.dts
  # cp -f ./build/tests/arm32/realview-pb-a8/basic/firmware.bin ./build/disk/images/arm32/realview-pb-a8/firmware.bin
  # cp -f ./tests/arm32/realview-pb-a8/linux/nor_flash.list ./build/disk/images/arm32/realview-pb-a8/nor_flash.list
  # cp -f ./tests/arm32/realview-pb-a8/linux/cmdlist ./build/disk/images/arm32/realview-pb-a8/cmdlist
  # cp -f <linux_build_directory>/arch/arm/boot/Image ./build/disk/images/arm32/realview-pb-a8/Image
  # cp -f <busybox_rootfs_directory>/rootfs.img ./build/disk/images/arm32/rootfs.img
  # genext2fs -B 1024 -b 16384 -d ./build/disk ./build/disk.img

  (Note: For creating <linux_build_directory>/arch/arm/boot/Image refer
   <xvisor_source_directory>/tests/arm32/realview-pb-a8/linux/README)
  (Note: For creating <busybox_rootfs_directory>/rootfs.img refer
   <xvisor_source_directory>/tests/arm32/common/busybox/README)

  [8. Unplug bootable SD card from the A20 board and plug it on your development machine]

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

  [10. Copy uvmm.bin, DTB, and disk.img to boot 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/sun7i/cubieboard2/one_guest_pb-a8.dtb <path_to_mounted_boot_partition_of_sd_card>
  # cp -f build/disk.img <path_to_mounted_boot_partition_of_sd_card>

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

  [12. Unplug SD card from your development machine and plug it back on A20 board]

  [13. Connect to serial port of A20 board using Putty or Minicom]

  [14. Power-up or Reset A20 board and press any key when U-Boot shows auto-boot count down]

  [15. Enable MMC interface from U-Boot command line]
  sun7i# mmc dev 0:0

  [16. Copy Xvisor from SD card to SDRAM]
  sun7i# fatload mmc 0 0x40200000 uvmm.bin

  [17. Copy the Xvisor DTB from SD card to SDRAM]
  sun7i# fatload mmc 0 0x40800000 one_guest_pb-a8.dtb

  [18. Copy disk image from SD card to SDRAM]
  sun7i# fatload mmc 0 0x41000000 disk.img

  [19. Jump into Xvisor after disabling MMU, interrupts, etc]
  sun7i# bootm 0x40200000 - 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 one_guest_pb-a8.dtb
   fatload mmc 0 0x41000000 disk.img
   bootm 0x40200000 - 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.)

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

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

  [22. Say 'hi' to Basic Firmware]
  [guest0/uart0] basic# hi

  (Note: If you had linux images loaded in guest NOR flash
   then instead of above step you can start booting linux,
   basic# autoexec)

  [23. Say 'hello' to Basic Firmware]
  [guest0/uart0] basic# hello

  [24. Check various commands of Basic Firmware]
  [guest0/uart0] basic# help

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

  (Note: replace all <> brackets based on your workspace)

