• Running the KVM guest by UEFI Hyp mode

【key words】

UEFI BIOS : Based on uefi-linaro-201304 public version.

HOST KERNEL : Based on linux-linaro-201304 public version.

HOST FDT : Based on HOST KERNEL version

HOST FS : Based on linaro-quantal-fs-201304 public version

FAST MODEL : Based on pre-built (RTSM_A15x124_VE.sh) version. VExpress A15x2 Model.

QEMU : Based on qemu-linaro-201303 public version.

GUEST KENREL: An example from Virtual Open System

GUEST FDT : An example from Virtual Open System

GUEST FS : An example from Virtual Open System

【Contents】

1. How to add a HYP UEFI patch and build UEFI

2. How to build the host side about kernel/FDT/File System

3. How to run the host OS

4. How to build the Qemu

5. How to get the guest side about kernel/FDT/File System

6. How to run the kvm guest

【How to add a HYP UEFI patch and build UEFI】

1.1 Add the patch for HYP

  •         $tar jxvf edk2-uefi_0.1+git15+20130418+09259ca.orig.tar.bz2
            $patch -p1 < uefihyp.patch

1.2 Build the UEFI image with build script

  •      $./uefi-build.sh rtsm_a15mpcore
    And renamed the UEFI with short name ,like UEFIHYP.fd

【How to build the host side about kernel/FDT/File System】

2.1 Build the kernel

  • Get the .config file for KVM, after menuconfig and save it.

     $CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm make menuconfig
  • Compile the kernel to get the zImage (uImage/zImage both OK)

     $CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm make uImage

2.2 Build the FDT

  • In kernel code directory, to produce the .dtb file

      $./scripts/dtc/dtc -O dtb arch/arm/boot/dts/rtsm_ve-cortex_a15x2.dts -o rtsm_ve-cortex_a15x2.dtb

2.3 Build the host file system

For copying files to host file system easily, so we choose the NFS file system. We will boot our file system from a NFS share exported by the machine we use for development. First we need to make sure NFS is installed

      $ sudo apt-get install nfs-kernel-server nfs-common
  • Make sure an appropriate directory is exported in /etc/exports with the right settings. For example:

       /srv/nfsroot 192.168.1.5/255.255.255.0(rw,sync,no_root_squash,no_subtree_check,insecure)
  • The above configuration defines an NFS share in /srv/nfsroot, accessible by any machine on the local network with an IP address of 192.168.1.4. Also, make sure to restart the nfs server after editing /etc/exports:

        $ sudo /etc/init.d/nfs-kernel-server restart

【How to run the host】

3.1 Create a script file named runhyp:

     ./RSTM_VE_Cortex-A15x2 -C motherboard.smsc_91c111.enabled=1 \
                                        -C motherboard.hostbridge.userNetworking=1 \
                                        -C motherboard.flashloader0.fname=UEFIHYP.fd

The default boot selection will start in   2 seconds
[1] SemiHosting
        - VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/zImage
        - Arguments: 
        - LoaderType: Linux kernel with ATAG support
-----------------------
Global FDT Config
        - not configured
-----------------------
[a] Boot Manager
[b] Shell
Start: a
[1] Add Boot Device Entry
[2] Update Boot Device Entry
[3] Remove Boot Device Entry
[4] Update FDT path
[5] Return to main menu
Choice: 1
[1] SemihostFs (0 MB)
        - VenHw(C5B9C74A-6D72-4719-99AB-C59F1art: a
[1] Add Boot Device Entry
[2] Update Boot Device Entry
[3] Remove Boot Device Entry
[4] Update FDT path
[5] Return to main menu
Choice: 1
[1] SemihostFs (0 MB)
        - VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)
[2] VenHw(E7223039-5836-41E1-B542-D7EC736C5E59)
        - VenHw(E7223039-5836-41E1-B542-D7EC736C5E59)
[3] VenHw(02118005-9DA7-443A-92D5-781F022AEDBB)
        - VenHw(02118005-9DA7-443A-92D5-781F022AEDBB)
[4] VenHw(1F15DA3C-37FF-4070-B471-BB4AF12A724A)
        - VenHw(1F15DA3C-37FF-4070-B471-BB4AF12A724A)
[5] VenHw(CC2CBF29-1498-4CDD-8171-F8B6B41D0909)
        - VenHw(CC2CBF29-1498-4CDD-8171-F8B6B41D0909)
[6] VenHw(09831032-6FA3-4484-AF4F-0A000A8D3A82)
        - VenHw(09831032-6FA3-4484-AF4F-0A000A8D3A82)
Select the Boot Device: 1
File path of the EFI Application or the kernel: uImage
Boot Type: [a] ATAGS, [g] Global FDT or [l] Local FDT? [a/g/l] l
Add an initrd: [y/n] n
Arguments to pass to the binary: console=ttyAMA0 root=/dev/nfs nfsroot=192.168.1.5:/srv/nfsroot/ rw ip=dhcp
File path of the local FDT: rtsm_ve-ca15x2.dtb
Description for this new Entry: NFS
[1] Add Boot Device Entry
[2] Update Boot Device Entry
[3] Remove Boot Device Entry
[4] Update FDT path
[5] Return to main menu
Choice: 5
[1] SemiHosting
        - VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/zImage
        - Arguments: 
        - LoaderType: Linux kernel with ATAG support
[2] NFS
        - VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/uImage
        - Arguments: console=ttyAMA0 root=/dev/nfs nfsroot=192.168.1.5:/srv/nfsroot/ rw ip=dhcp
        - FDT: VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/rtsm_ve-ca15x2.dtb
        - LoaderType: Linux kernel with Local FDT
-----------------------
Global FDT Config
        - not configured
-----------------------
[a] Boot Manager
[b] Shell
Start: 2

【How to build the Qemu】

4.1 QEMU requires a few dependencies, we can use the tools provided by Ubuntu, to easily get all of them for the cross compiled ARM build of QEMU:

      $ sudo apt-get build-dep qemu-linaro
      $ sudo apt-get install xapt
  • Create a file like /etc/apt/sources.list.d/armel-precise.list with the required repositories:

      deb [arch=armel] http://ports.ubuntu.com/ubuntu-ports precise main restricted universe multiverse
      deb-src [arch=armel] http://ports.ubuntu.com/ubuntu-ports precise main restricted universe multiverse
  • Now we can build and install the required packages:

      $ sudo xapt -a armel -m -b zlib1g-dev libglib2.0-dev libfdt-dev libpixman-1-dev
      $ sudo dpkg -i /var/lib/xapt/output/*.deb
  • We also need to download and install this package on Ubuntu.

      $ sudo apt-get install pkg-config-arm-linux-gnueabi

4.2 Build the Qemu

       $tar zxvf qemu-linaro-1.4.0-2013.03.tar.gz
   
       $ ./configure --cross-prefix=arm-linux-gnueabi- \
                     --target-list=arm-softmmu \
                     --audio-drv-list="" \
                     --audio-card-list=""\
                     --enable-fdt\
                     --enable-kvm\
                     --static

        $ make
  • This will create an ARM QEMU binary in arm-softmmu/qemu-system-arm, which we will be able to use in our host

【How to get the guest side about kernel/FDT/File System】

5.1 Get the kernel uImage, and convert to zImage

      $wget http://www.virtualopensystems.com/media/kvm-resources/uImage
      $ dd if=uImage of=zImage skip=64 bs=1

5.2 Get the FDT

      $wget http://www.virtualopensystems.com/media/kvm-resources/guest-a15.dtb

5.3 Get the File System and change to Initrd file

  • Get the file system

      $wget http://www.virtualopensystems.com/media/kvm-resources/fs-alip-armel.cramfs
  • Change to Initrd

     $ mkdir mnt1 mnt2
     $ sudo mount -o loop fs-alip-armel.cramfs mnt1
     $ sudo cp -a ./mnt1/* ./mnt2/
     $ cd ./mnt2
     $ sudo ln -s sbin/init init
     $ sudo sh -c "find . | cpio -o -H newc | gzip > ../initrd.cpio.gz"

【How to run the kvm guest】

6.1 Run to the host

6.2 Copy the required files for guest os to the NFS root fold

6.3 Run the kvm guest

     $ ./qemu-system-arm  -enable-kvm \
                                  -kernel zImage\
                                  -initrd initrd.cpio.gz\
                                  -append "console=ttyAMA0 mem=512M" \
                                  -dtb guest-a15.dtb \
                                  -m 512 -M vexpress-a15 -cpu cortex-a15 -nographic 

ARM/UEFI/Virtualization+Fastmodel (last modified 2013-06-20 23:25:08)