How to run VirtIO on AGL Reference Hardware
This guide explains how to run virtual AGL on bare-metal AGL (AGL-in-AGL) on AGL Reference Hardware board with help of QEMU.
For simplicity reasons, this guide configures only virtio-blk and virtio-rng.
To run two AGLs, flash storage (SD-Card or eMMC) with two partitions for different root file systems is needed.
NOTE: To be able to use eMMC, a method to partition and flash it is needed. For example, U-Boot can be used for that, but necessary configuration options shall be enabled in U-Boot for that.
Partition SD-Card or eMMC to have two partitions, at least 1 GiB each. Actually, can be less but just rounded up to have nice number.
For example, SD-Card can be partitioned using fdisk utility.
Execute fdisk:sudo fdisk <disk>
Here <disk> should be SD-Card device file, for example /dev/sdb.
CAUCTION: Using wrong SD-Card device file can result in data lost on your computer!
Partition SD-Card:$ fdisk /tmp/disk
ÂWelcome to fdisk (util-linuxÂ
2.33
.
1
).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
ÂDevice does not contain a recognized partition table.
Created aÂ
new
ÂDOS disklabel with disk identifierÂ
0x8fb74b1e
.
ÂCommand (mÂ
for
Âhelp): n
Partition type
  Â
p  primary (
0
Âprimary,Â
0
Âextended,Â
4
Âfree)
  Â
e  extended (containerÂ
for
Âlogical partitions)
Select (
default
Âp):
ÂUsingÂ
default
Âresponse p.
Partition number (
1
-
4
,Â
default
Â1
):
First sector (
2048
-
5242879
,Â
default
Â2048
):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (
2048
-
5242879
,Â
default
Â5242879
): +1GiB
ÂCreated aÂ
new
ÂpartitionÂ
1
Âof typeÂ
'Linux'
Âand of sizeÂ
1
ÂGiB.
ÂCommand (mÂ
for
Âhelp): n
Partition type
  Â
p  primary (
1
Âprimary,Â
0
Âextended,Â
3
Âfree)
  Â
e  extended (containerÂ
for
Âlogical partitions)
Select (
default
Âp): p
Partition number (
2
-
4
,Â
default
Â2
):
First sector (
2099200
-
5242879
,Â
default
Â2099200
):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (
2099200
-
5242879
,Â
default
Â5242879
): +1GiB
ÂCreated aÂ
new
ÂpartitionÂ
2
Âof typeÂ
'Linux'
Âand of sizeÂ
1
ÂGiB.
ÂCommand (mÂ
for
Âhelp): w
The partition table has been altered.
Syncing disks.
For example, eMMC can be partitioned from U-Boot command line using:
gpt write mmcÂ
1
Â"name=linux1_rootfs,size=1GiB;name=linux2_rootfs,size=1GiB;name=misc,size=4KiB"
NOTE: gpt command should be enable in U-Boot configuration.
NOTE: partition 'misc' are needed to make fastboot happy when using it to flash eMMC.
Download Koky Koi M2:
repo init -u https://gerrit.automotivelinux.org/gerrit/AGL/AGL-repo -b master -m koi_10.92.0.xml
repo sync -c -d
Build AGL for virtio-aarch64 machine:
source meta-agl/scripts/aglsetup.sh -m virtio-aarch64 -f
bitbake agl-image-minimal
Flash root file system to the second partition on SD-Card or eMMC.
Flashing SD-Card:
cd build/tmp/deploy/images/virtio-aarch64
sudo ddÂ
if
=agl-image-minimal-virtio-aarch64.ext4 of=FILE
Here FILE should be SD-Card second partition device file, for example /dev/sdb2.
CAUCTION: Using wrong SD-Card partition device file can result in data lost on your computer!Flashing eMMC via fastboot
cd build/tmp/deploy/images/virtio-aarch64
img2simg agl-image-minimal-virtio-aarch64.ext4 agl-image-minimal-virtio-aarch64.ext4.img
fastboot flash linux2_rootfs agl-image-minimal-virtio-aarch64.ext4.img
NOTE: U-Boot should have fastboot running.
Build AGL for AGL Reference Hardware.
NOTE: To build AGLÂ for AGL Reference Hardware and for virtio, the same folder could be reused. It takes a little bit more time when switching between AGL Reference Hardware build and virtio build but this overhead is not critical.
Initialize build environment:source meta-agl/scripts/aglsetup.sh -m h3ulcb -f agl-refhw-h3
In build/conf/local.conf add:AGL_DEFAULT_IMAGE_FSTYPES =Â
"ext4"
IMAGE_INSTALL_append =Â
"qemu"
CAUTION: Calling aglsetup.sh with "-f" flag will remove above modification in "local.conf", so they will be needed to be re-applied.
Build AGL for AGL Reference Hardware:bitbake agl-image-minimal
Add Linux 2 kernel to the Linux 1 rootfs:
cp tmp/deploy/images/virtio-aarch64/Image tmp/work/h3ulcb-agl-linux/agl-image-minimal/
1.0
-r0/rootfs/linux2
bitbake agl-image-minimal -c image_ext4 -f
bitbake agl-image-minimal -c image_complete
Flash root file system to the first partition on SD-Card or eMMC.
Flashing SD-Card:
cd build/tmp/deploy/images/h3ulcb
sudo ddÂ
if
=agl-image-minimal-h3ulcb.ext4 of=FILE
Here FILE should be SD-Card second partition device file, for example /dev/sdb1.
CAUCTION: Using wrong SD-Card partition device file can result in data lost on your computer!Flashing eMMC via fastboot:
cd build/tmp/deploy/images/h3ulcb
img2simg agl-image-minimal-h3ulcb.ext4 agl-image-minimal-h3ulcb.ext4.img
fastboot flash linux1_rootfs agl-image-minimal-h3ulcb.ext4.img
NOTE: U-Boot should have fastboot running.
Boot AGL Reference Hardware board using Linux located on the first partition of SD-Card or eMMC
setenv bootargs 'console=ttySC0,115200 root=/dev/mmcblk0p1 rootwait ro rootfstype=ext4'
ext4load mmc 1:1 0x48000000 /boot/r8a7795-agl-refhw.dtb
ext4load mmc 1:1 0x48080000 /boot/Image
booti 0x48080000 - 0x48000000
Run QEMU from Linux 1 command line
qemu-system-aarch64 \
 Â
-machine virt \
 Â
-cpu cortex-a57 \
 Â
-m 2048 \
 Â
-serial mon:stdio \
 Â
-global virtio-mmio.force-legacy=false \
 Â
-drive id=disk0,file=/dev/mmcblk0p2,if=none,format=raw \
 Â
-device virtio-blk-device,drive=disk0 \
 Â
-object rng-random,filename=/dev/urandom,id=rng0 \
 Â
-device virtio-rng-device,rng=rng0 \
 Â
-nographic \
 Â
-kernel /linux2
 Â
-append 'root=/dev/vda rw mem=2048M'
NOTE: mmcblk0p2 above is used for when root file system is flashed on eMMC. In case of SD-Card, mmcblk1p2 has to be used.
- It is possible to exit from QEMU using monitor commands. Enter "Ctrl+a h" for help.
KVM
NOTE: QEMU is a bit slow because KVM is not working. Adding "-enable-kvm" to QEMU command fails with
|
Somewhere in the Internet suggested:
- To use "-cpu host" but it did not help.
- To use taskset to set to specific CPU core. Not tried since requires busybox reconfiguration to enable taskset.
- Update QEMU and/or KVM to latest version. There was some kvm_init_vcpu signature changes.