	Xvisor on BeagleBoard-xM (or OMAP3) using SD Booting 

This section of readme explains how to build & run Xvisor on real hardware 
BeagleBoard-xM using SD booting feature of OMAP3 SOC.

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

We need to add 2 images in boot partition of SD card that is shipped with
BeagleBoard-xM:
 1) U-Boot compatible Xvisor binary and DTBs (uvmm.bin).
 2) Disk image containing guest binaries (disk.img).

Following are the steps to create these images and then boot Xvisor on
Beagleboard-xM using U-Boot-2011.03 or higher:

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

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

  [3. Configure Xvisor for Beagleboard (or OMAP3)]
  # make ARCH=arm generic-v7-defconfig

  [4. Build Xvisor and DTBs, this creates vmm.bin]
  # 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 0x88000000 -e 0x88000000 -n Xvisor -d build/vmm.bin build/uvmm.bin

  [6. Build Basic Firmware for Realview-PB-A8 Guest, this creates firmware.bin.patched]
  # 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.patched ./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.patched ./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. Make U-boot compatible initrd for use with bootm command]
  # mkimage -A arm -O linux -T ramdisk -a 0x89000000 -n "Xvisor ramdisk" -d build/disk.img build/udisk.img

  [9. Unplug SD card from BeagleBoard-xM 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 to boot partition of SD card]
  # cp -f build/uvmm.bin <path_to_mounted_boot_partition_of_sd_card>

  [12. Copy DTB to boot partition of SD card]
  # cp -f build/arch/arm/board/generic/dts/omap3/beagleboard-xm/one_guest_pb-a8.dtb <path_to_mounted_boot_partition_of_sd_card>

  [13. Copy disk image to boot partition of SD card]
  # cp -f build/udisk.img <path_to_mounted_boot_partition_of_sd_card>

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

  [15. Unplug SD card from your development machine and plug it back on BeagleBoard-xM]

  [16. Connect to serial port of BeagleBoard-xM using Putty or Minicom]

  [17. Power-up or Reset BeagleBoard-xM and press any key when U-Boot shows auto-boot count down]

  [18. Enabled MMC interface from U-Boot command line interface]
  OMAP3 beagleboard.org # mmc dev 0:0

  [19. Copy Xvisor from SD card to SDRAM]
  OMAP3 beagleboard.org # fatload mmc 0 0x80200000 uvmm.bin

  [20. Copy disk image from SD card to SDRAM]
  OMAP3 beagleboard.org # fatload mmc 0 0x8B000000 udisk.img

  [21. Copy DTB from SD card to SDRAM]
  OMAP3 beagleboard.org # fatload mmc 0 0x8A000000 one_guest_pb-a8.dtb

  [22. Jump into Xvisor after disabling MMU, interrupts, etc]
  OMAP3 beagleboard.org # bootm 0x80200000 0x8B000000 0x8A000000

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

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

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

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

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

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

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


	Xvisor on Linaro QEMU BeagleBoard (or OMAP3) using NAND Booting 

This section of readme explains how to build & run Xvisor from nand-flash on
BeagleBoard emulated by QEMU Linaro. 

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

We need to have 4 images to create the nand-flash image:
 1) X-loader for OMAP3 (2nd stage bootloader for OMAP3).
 2) U-Boot-2011.03 binary for OMAP3 (3rd stage bootloader).
 3) U-Boot compatible Xvisor binary and DTBs (uvmm.bin).
 4) Disk image containing guest binaries (disk.img).

The steps to create these images and boot Xvisor on Beagleboard QEMU are as
follows:

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

  [2. Download and build U-Boot-2011.03 from source - this creates u-boot.bin]
  # wget ftp://ftp.denx.de/pub/u-boot/u-boot-2011.03.tar.bz2
  # tar -xvf u-boot-2011.03.tar.bz2
  # cd u-boot-2011.03
  # make omap3_beagle_config
  # make
  # cd ..

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

  [4. Configure Xvisor for Beagleboard (or OMAP3)]
  # make ARCH=arm generic-v7-defconfig

  [5. Build Xvisor and DTBs, this creates vmm.bin]
  # make; make dtbs

  [6. Add uboot header to vmm.bin for use with bootm command]
  # mkimage -A arm -O linux -T kernel -C none -a 0x80008000 -e 0x80008000 -n Xvisor -d build/vmm.bin build/uvmm.bin

  [7. Build Basic Firmware for Realview-PB-A8 Guest, this creates firmware.bin.patched]
  # make -C tests/arm32/realview-pb-a8/basic

  [8. 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.patched ./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.patched ./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)

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

  [10. Create a flat binary with all our binaries appended]
  # ./tools/scripts/memimg.py -a 0 -o build/beagle.img docs/arm/omap3-beagle-x-load-1.5.0.bin.ift@0x0 <path-to-u-boot-binary>/u-boot.bin@0x80000 build/uvmm.bin@0x280000 ./build/arch/arm/board/generic/dts/omap3/beagleboard/one_guest_pb-a8.dtb@0x680000 build/udisk.img@0x700000

  [11. Build the beagleboard nand-flash image from the flat binary created]
  # ./tools/bbflash/bb_nandflash.sh build/beagle.img build/beagle-nand.bin ./build/tools/bbflash/bb_nandflash_ecc 

  [12. Launch QEMU Linaro]
  # qemu-system-arm -M beagle -drive file=build/beagle-nand.bin,if=mtd -display none -serial stdio -s

  [13. Copy Xvisor from nand-flash to SDRAM]
  OMAP3 beagleboard.org # nand read 0x80200000 0x280000 0x200000

  [14. Copy disk image from nand-flash to SDRAM]
  OMAP3 beagleboard.org # nand read 0x84000000 0x700000 0x1000040

  [15. Copy Xvisor DTB from nand-flash to SDRAM]
  OMAP3 beagleboard.org # nand read 0x80800000 0x680000 0x10000

  [16. Jump into Xvisor after disabling MMU, interrupts, etc]
  OMAP3 beagleboard.org # bootm 0x80200000 0x84000000 0x80800000

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

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

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

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

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

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

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

