KVM working on the Cubietruck

ctg

I managed to get KVM working on the Cubietruck last week. It’s not exactly simple, but this post describes in overview how to do it.

(1) You will need a Cubietruck, a CP2102 serial cable, a micro SDHC card, a card reader for your host computer, and a network patch cable (the board supports wifi but it doesn’t work with the newer kernel we’ll be using). Optional: 2.5″ SATA HDD or SSD.

(2) Start with Hans De Goede’s AllWinner remix of Fedora 19, and get that working. It’s important to read his README file carefully.

(3) Build this upstream kernel with this configuration:

make oldconfig
make menuconfig

In menuconfig, enable Large Page Address Extension (LPAE), and then enable KVM in the Virtualization menu.

LOADADDR=0x40008000 make uImage dtbs
make modules
sudo cp arch/arm/boot/uImage /boot/uImage.sunxi-test
sudo cp arch/arm/boot/dts/sun7i-a20-cubietruck.dtb /boot/sun7i-a20-cubietruck.dtb.sunxi-test
sudo make modules_install

Reboot, interrupt u-boot (using the serial console), and type the following commands to load the new kernel:

setenv bootargs console=ttyS0,115200 loglevel=9 earlyprintk ro rootwait root=/dev/mmcblk0p3
ext2load mmc 0 0x46000000 uImage.sunxi-test
ext2load mmc 0 0x4b000000 sun7i-a20-cubietruck.dtb.sunxi-test
env set fdt_high ffffffff
bootm 0x46000000 - 0x4b000000

(4) Build this modified u-boot which supports Hyp mode.

make cubietruck_config
make
sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/YOURSDCARD bs=1024 seek=8

Reboot again, use the commands above to boot into the upstream kernel, and if everything worked you should see:

Brought up 2 CPUs
SMP: Total of 2 processors activated.
CPU: All CPU(s) started in HYP mode.
CPU: Virtualization extensions available.

Also /dev/kvm should exist.

(5) Hack QEMU to create Cortex-A7 CPUs using this one-line patch.

Edit: dgilmore tells me this is no longer necessary. Instead make sure you use the qemu -cpu host option.

Then you should be able to create VMs using libvirt. Note if using libguestfs you will need to use the direct backend (LIBGUESTFS_BACKEND=direct) because of this libvirt bug.

7 Comments

Filed under Uncategorized

7 responses to “KVM working on the Cubietruck

  1. sean

    That is excellent work! I know it wasn’t easy and it took you quite a while to get working. 🙂

  2. Tim Fletcher

    I’ve got this working on current Debian with kvm from git, without your patch by using the cpu option of host

    • rich

      I’m using -cpu host. It might have been that qemu have fixed this problem upstream since I tried.

      • rich

        I looked at the latest qemu source and I don’t see how it can work. Maybe your kernel doesn’t include the snippet that checks that cpu->kvm_target is set correctly.

  3. Tim Fletcher

    The full command that I am using to boot the VM is below, works joins it to openvswitch and boots the linaro KVM test image.

    /usr/src/git/qemu/arm-softmmu/qemu-system-arm -name linaro-test -m 1024 -smp 2 -cpu host -M vexpress-a15 -kernel /root/linaro-vm/zImage -dtb /root/linaro-vm/vexpress-v2p-ca15-tc1.dtb -append root=/dev/mmcblk0p2 rw rootwait mem=1024M console=ttyAMA0,115200n8 text -drive if=sd,cache=writeback,file=/root/linaro-vm/kvm.qcow2 -net tap,ifname=linaro-test,script=/root/bin/ovs-ifup,downscript=/root/bin/ovs-ifdown -net nic,model=lan9118,id=linaro-test -nographic -enable-kvm

  4. Pingback: Cubietruck: QEMU, KVM, Fedora | Kashyap Chamarthy

  5. Pingback: Cubietruck: QEMU, KVM and Fedora | Kashyap Chamarthy

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.