	Xvisor on Raspberry-Pi (or BCM2835 SOC) using SD Booting 

This section of readme explains how to build & run Xvisor on actual 
Raspberry Pi board using SD booting feature of Raspberry Pi (or BCM2835 SOC).

By default, Xvisor for BCM2835 supports Realview-EB-MPCore guest so we will 
show how to run Basic Firmware (and/or Linux) on Realview-EB-MPCore guest.

As first step of SD booting on BCM2835 SOC, we prepare a SD card (> 4GB) with
Uboot. To do this,
 1) Setup SD card with debian weezy image and make sure that you get
    Raspberry Pi linux console on serial port
    (For detailed steps, http://elinux.org/RPi_Easy_SD_Card_Setup)
 2) Now compile and install u-boot on SD card for Raspberry Pi so that you get
    u-boot prompt whenever you power-on Raspberry Pi
    (For detailed steps, http://elinux.org/RPi_U-Boot)

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

Following are steps to create these images and boot Xvisor on Raspberry Pi:

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

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

  [3. Configure Xvisor with Generic-v6 default settings]
  # make ARCH=arm generic-v6-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 0x00008000 -e 0x00008000 -n Xvisor -d build/vmm.bin build/uvmm.bin

  [6. Build Basic Firmware for Realview-EB-MPCore Guest, this creates firmware.bin.patched]
  # make -C tests/arm32/realview-eb-mpcore/basic
  
  [7. Create disk image for Xvisor]
  # mkdir -p ./build/disk/images/arm32/realview-eb-mpcore
  # ./build/tools/dtc/dtc -I dts -O dtb -o ./build/disk/images/arm32/realview-eb-mpcore.dtb ./tests/arm32/realview-eb-mpcore/realview-eb-mpcore.dts
  # cp -f ./build/tests/arm32/realview-eb-mpcore/basic/firmware.bin.patched ./build/disk/images/arm32/realview-eb-mpcore/firmware.bin
  # cp -f ./tests/arm32/realview-eb-mpcore/basic/nor_flash.list ./build/disk/images/arm32/realview-eb-mpcore/nor_flash.list
  # genext2fs -B 1024 -b 16384 -d ./build/disk ./build/disk.img
  OR
  # mkdir -p ./build/disk/images/arm32/realview-eb-mpcore
  # ./build/tools/dtc/dtc -I dts -O dtb -o ./build/disk/images/arm32/realview-eb-mpcore.dtb ./tests/arm32/realview-eb-mpcore/realview-eb-mpcore.dts
  # cp -f ./build/tests/arm32/realview-eb-mpcore/basic/firmware.bin.patched ./build/disk/images/arm32/realview-eb-mpcore/firmware.bin
  # cp -f ./tests/arm32/realview-eb-mpcore/linux/nor_flash.list ./build/disk/images/arm32/realview-eb-mpcore/nor_flash.list
  # cp -f ./tests/arm32/realview-eb-mpcore/linux/cmdlist ./build/disk/images/arm32/realview-eb-mpcore/cmdlist
  # cp -f <linux_build_directory>/arch/arm/boot/Image ./build/disk/images/arm32/realview-eb-mpcore/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-eb-mpcore/linux/README)
  (Note: For creating <busybox_rootfs_directory>/rootfs.img refer
   <xvisor_source_directory>/tests/arm32/common/busybox/README)

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

  [9. Unplug bootable SD card from Raspberry Pi and plug it on your development machine]

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

  [11. Copy uvmm.bin, DTB, and disk.im 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/bcm2835/one_guest_ebmp.dtb <path_to_mounted_boot_partition_of_sd_card>
  # cp -f build/udisk.img <path_to_mounted_boot_partition_of_sd_card>

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

  [13. Unplug SD card from your development machine and plug it back on Raspberry Pi]

  [14. Connect to serial port of Raspberry Pi using Putty or Minicom]

  [15. Power-up or Reset Raspberry Pi and press any key when U-Boot shows auto-boot count down]

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

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

  [18. Copy Xvisor DTB from SD card to SDRAM]
  U-Boot> fatload mmc 0 0x00800000 one_guest_ebmp.dtb

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

  [20. Jump into Xvisor after disabling MMU, interrupts, etc]
  U-Boot> bootm 0x00200000 0x02000000 0x00800000

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

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

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

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

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

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

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


	Xvisor on QEMU Raspberry-Pi (or BCM2835 SOC) Host

This section of readme explains how to build & run Xvisor on Raspberry-Pi QEMU
(Raspberry-Pi QEMU source, https://github.com/Torlus/qemu.git, and use the
rpi branch).

By default, Xvisor for BCM2835 supports Realview-EB-MPCore guest so we will 
show how to run Basic Firmware (and/or Linux) on Realview-EB-MPCore guest.

Please follow the steps below to build & run Basic Firmware on 
Realview-EB-MPCore guest with Xvisor running on QEMU Raspberry-Pi Host:

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

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

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

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

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

  [6. Create disk image for Xvisor]
  # mkdir -p ./build/disk/images/arm32/realview-eb-mpcore
  # ./build/tools/dtc/dtc -I dts -O dtb -o ./build/disk/images/arm32/realview-eb-mpcore.dtb ./tests/arm32/realview-eb-mpcore/realview-eb-mpcore.dts
  # cp -f ./build/tests/arm32/realview-eb-mpcore/basic/firmware.bin.patched ./build/disk/images/arm32/realview-eb-mpcore/firmware.bin
  # cp -f ./tests/arm32/realview-eb-mpcore/basic/nor_flash.list ./build/disk/images/arm32/realview-eb-mpcore/nor_flash.list
  # genext2fs -B 1024 -b 16384 -d ./build/disk ./build/disk.img
  OR
  # mkdir -p ./build/disk/images/arm32/realview-eb-mpcore
  # ./build/tools/dtc/dtc -I dts -O dtb -o ./build/disk/images/arm32/realview-eb-mpcore.dtb ./tests/arm32/realview-eb-mpcore/realview-eb-mpcore.dts
  # cp -f ./build/tests/arm32/realview-eb-mpcore/basic/firmware.bin.patched ./build/disk/images/arm32/realview-eb-mpcore/firmware.bin
  # cp -f ./tests/arm32/realview-eb-mpcore/linux/nor_flash.list ./build/disk/images/arm32/realview-eb-mpcore/nor_flash.list
  # cp -f ./tests/arm32/realview-eb-mpcore/linux/cmdlist ./build/disk/images/arm32/realview-eb-mpcore/cmdlist
  # cp -f <linux_build_directory>/arch/arm/boot/Image ./build/disk/images/arm32/realview-eb-mpcore/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-eb-mpcore/linux/README)
  (Note: For creating <busybox_rootfs_directory>/rootfs.img refer
   <xvisor_source_directory>/tests/arm32/common/busybox/README)

  [7. Launch QEMU]
  # qemu-system-arm -M raspi -m 256M -display none -serial stdio -kernel build/vmm.bin -dtb build/arch/arm/board/generic/dts/bcm2835/one_guest_ebmp.dtb -initrd build/disk.img

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

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

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

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

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

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

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

