I'm trying to play with QEMU, especially with the virt board and device trees, but there isn't much documentation about it.
I managed to emulate a vexpress a9 board and install archlinux on it, mainly thanks to this link, with the following commands:
wget http://archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz
mkdir archlinux_arm_root
bsdtar -xpf ArchLinuxARM-armv7-latest.tar.gz -C archlinux_arm_root
qemu-img create -f raw disk_img.img 1G
mkfs.ext4 -F disk_img.img
sudo mkdir /mnt/root
sudo mount -o loop disk_img.img /mnt/root
sudo cp -rf archlinux_arm_root/* /mnt/root/
sudo umount /mnt/root
cp archlinux_arm_root/boot/zImage zImage
cp archlinux_arm_root/boot/dtbs/vexpress-v2p-ca9.dtb device_tree.dtb
qemu-system-arm -m 1024M -M vexpress-a9 -cpu cortex-a9 -kernel zImage -dtb device_tree.dtb -append "root=/dev/mmcblk0 rw roottype=ext4 console=ttyAMA0" -drive if=sd,driver=raw,cache=writeback,file=disk_img.img -nographic
I created a raw disk image, then manually installed archlinux (by mounting the disk image and copying the root file system of arch on it).
The command to emulate the board and boot on arch specifies the machine/cpu/kernel/device tree/disk image to use. The -drive option defines a new drive, and since it's an SD one I need to tell qemu to use /dev/mmcblk0 with -append. Please correct me if I said anything incorrect.
Firstly I simply want to emulate this machine without using the sd interface, but somehow just can't manage to do so.
But more importantly I'd like to emulate a virt board.
You can't really run the vexpress-a9 board without using the SD interface, because that is the only interface that hardware has for block devices, so your choices are "SD" or "no block device at all".
Our documentation for running Arm guests on QEMU is here https://wiki.qemu.org/Documentation/Platforms/ARM and that page links to a tutorial for booting Debian on the 'virt' board for 64-bit guests: https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/ and one for 32-bit guests: https://translatedcode.wordpress.com/2016/11/03/installing-debian-on-qemus-32-bit-arm-virt-board/ so I would start with whichever of those you want.
Related
I am trying to make a baremetal arm os in qemu with baremetal bios as well as kernel.
When I try qemu-system-arm -machine virt -bios boot.bin -nographic boot.bin gets mapped to 0x00 and when i try qemu-system-arm -machine virt -kernel kernel.bin kernel.bin gets mapped to 0x40010000.
So when I do qemu-system-arm -machine virt -bios boot.bin -kernel kernel.bin boot.bin gets mapped to 0x00 but i don't find kernel.bin. I tried to check at 0x40000000 but there also some garbage value is there(might not be garbage but it is not kernel.bin)
I don't find any documentation telling about this, also if I were to use -drive option how can I go forward on this? like Do i need to write a driver for accessing the drive if yes where can I see documentation or something which can guide
If you pass a firmware image to the 'virt' board using -bios then QEMU will put the kernel image (and any initrd) in the 'fw-cfg' device. Guest code in the bios image can then access the fw-cfg device to tell it to DMA the kernel image to whatever address it likes. (This facility is provided primarily for the UEFI BIOS, though of course any guest code can use the fw-cfg device if it likes.)
The data at 0x40000000 is the device tree blob, which is what your bios image should be reading in order to find out where in the address map all the hardware devices are. (This part is documented, at the bottom of https://www.qemu.org/docs/master/system/arm/virt.html)
Note that '-kernel' means "I am a Linux kernel, load me in whatever seems the most appropriate way". If you didn't want that, and just wanted "load a binary image at the address I specify", have a look at the "generic loader" device instead.
in Linux x86_64 host machine, can simply run qemu with KVM enable by this command
qemu-system-x86_64 \
-enable-kvm \
-cpu max \
-smp cores=4,threads=1 \
-m 4096 \
-nographic \
-hda hd.raw \
-hdb cloud.img \
-device virtio-net-pci,netdev=n1 \
-netdev user,id=n1,hostfwd=tcp::2222-:22
In the guest machine, the performance gets almost native host performance.
Now I want to run an Arm guest machine in an Arm Host (ex: raspberry pi)
and it does not allow me to enable kvm,
How can I get near-native performance in an Arm guest machine (Arm host linux)
The basic principle is the same as for x86, but there are some restrictions:
Your host must be running 64-bit Arm, not 32-bit
You need to use the qemu-system-aarch64 binary
You need to pass -enable-kvm
You need to tell QEMU to emulate a machine type which supports KVM: this means the 'virt' machine type
You need to tell QEMU to give the guest the same CPU and interrupt controller as the host: '-cpu host -machine gic-version=host'
You also of course need to have a QEMU command line that works in the first place, i.e. passing QEMU a guest kernel that has support for the machine type and devices being emulated, a suitable filesystem, whatever devices you need, etc -- all the things you need for any kind of QEMU run, whether pure emulated or accelerated.
I install qemu-system-arm in Ubuntu 16.04 to run firmware of dlink DIR868L. But when I use the command chroot ./squashfs-root/ /bin/sh, it just shows Illegal instruction. I get squashfs-root/from DIR868LB1_FW203b01.bin by binwalk and I am sure that /bin/sh exists in squashfs-root/.
I start qemu by sudo qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.32-5-versatile -initrd initrd.img-2.6.32-5-versatile -hda debian_squeeze_armel_standard.qcow2 -append "root=/dev/sda1" -net nic -net tap and use scp to cpoy squashfs-root/ into virtual mechine. And I met the same problem when using debian_wheezy_armel_standard.qcow2
What should I do ? It has bothered me for the whole afternoon.
Or can anyone give me an example to run the arm firmware in qemu ? I only find lots of examples using firmware based on mips.
Thanks a lot !
The problem is almost certainly because whatever CPU is in the DIR868lL is newer than the ARM926 CPU that the "versatilepb" board has. If the binaries from that firmware are built to use newer instructions, then running them in an emulation of an older CPU will result in an 'illegal instruction' signal, just as if you'd run them on real older ARM hardware.
This is similar to taking binaries that were built for a Core2 Duo and trying to run them on your old Pentium system: it won't work.
I am trying to create an ARM virtual machine for my code and I want to have at least 3 network interfaces in the VM (bridged to interfaces in the host), I tried to do it in many different ways but again and again, it get only 1 interface (eth0)
I tried to run qemu in this way:
sudo qemu-system-arm -m 2048M -M vexpress-a15 -cpu cortex-a15 -kernel zImage -dtb vexpress-v2p-ca15-tc1.dtb -no-reboot -initrd initramfs.cpio.anp.gz -nographic -append 'console=ttyAMA0,115200' -net nic,name=eth0 -net tap,ifname=tap0 -net nic,name=eth1 -net tap,ifname=tap1}
but I get only eth0 in my guest OS.
How can I add eth1/eth2 to the VM?
You can't do this with vexpress-a15 -- it is a model of a specific development board which in hardware has only one ethernet adaptor and no PCI bus you could use to plug more ethernet devices into.
Unless you have a strong requirement to use vexpress-a15 in particular I would recommend using the "virt" board instead, which is much more flexible and in particular has a PCI bus that you can use to provide the number of ethernet devices you need. (You'll probably need to rebuild your kernel appropriately and you'll need to tweak your commandline too.)
I'm working on creating file that I can load with -kernel option of qemu. I mostly mind here u-boot config file that I have found information should be placed somewhere in file. That file have to contain u-boot binary, freebsd kernel and RTOS to run ( so i can choose which kernel to load or do some experimental developement in loading 2 OS at same time - eg. FreeBSD is loaded by u-boot and then FreeBSD loads FreeRTOS on 2nd core - so called ASMP ). It seems there is no tools around to do that in automatic way ( I mean supporting multiple kernels in one flash file ). So I need to know how is u-boot flash file structured to make my own and pass it to qemu emulating am versatilepb.
qemu-system-arm -M versatilepb -m 128M -nographic -kernel myflashfile
So the answer here depends in part on the board you are emulating with QEMU. Next, unfortunately the versatilepb has been dropped from mainline U-Boot some time ago (and being ARM926EJS it is not the ideal core for ASMP, you may wish to try vexpress a9 instead). Now, all of that said, you want -pflash to pass along a binary file you control the contents of as the parallel flash device used by the machine. And you lay that out however you like since you're still using -kernel u-boot.bin to boot the machine. You may however find it easier to use -tftp /some/dir and load the files via the network instead.