I have downloaded latest qemu Windows version then run below line
qemu-system-aarch64 -M virt,gic_version=3 -cpu cortex-a53 -smp 2 -nographic
-m 2048 -kernel mybaremetal.axf -s -S
to emulate a dual core cortex-a53, and I can use an aarch64 gdb client to connect to it, at the entry of mybaremetal.axf, I checked the exception level of excution by:
mrs x1, CurrentEL
I always get value 4 in x1, but value 0xc is expected here as in ARM document, it says: On powerup and on reset, the processor enters EL3
anyone knows the reason?
QEMU's Cortex-A53 emulation by default only emulates a CPU with EL1, not EL2 or EL3, and therefore (as the architecture requires) we boot up in EL1. If you want a CPU with EL2 or EL3 you need to specifically enable it on the command line, with -machine virtualization=on to enable EL2, and -machine secure=on to enable EL3. Note that EL2 support is very recent and at the moment you'll need to build from upstream git master to get that (it will be in the upcoming QEMU 2.9.0 release).
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'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.
I'm going through a course on gdb. In the later lessons the course covers debugging on ARM architecture, so I'm presented a setup that allows me to emulate such situation.
My current setup comprises:
Windows 10: physical host
Ubuntu 12.04.5 LTS: guest os via Oracle Virtual Box on Windows 10
Linux debian-armel 2.6.32-5-versatile: guest os via qemu 2.8.0 on Ubuntu
The ARM Debian image comes from https://people.debian.org/~aurel32/qemu/armel/
The image is launched with
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" -m 256 -redir tcp:2222::22
I modified the sources.list and apt.conf to allow apt to work, since the distro is quite outdated. I updated and upgraded and installed gcc and gdb.
The problem arises when trying to debug; I can load executables in gdb:
root#debian-armel:~/video-11/video-11# file ./main
./main: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
but when I try to run it inside gdb, I receive this message and the execution hangs, until I'm able to kill the gdb process from another console:
------------[ cut here ]------------
WARNING: at /build/linux-2.6-fIxTVd/linux-2.6-2.6.32/debian/build/source_armel_none/kernel/sched.c:2628 wake_up_process+0x2c/0x48()
Modules linked in: loop sg smc91x sr_mod mii cdrom psmouse evdev ext3 jbd mbcache sd_mod crc_t10dif sym53c8xx scsi_transport_spi scsi_mod
[<c002b068>] (unwind_backtrace+0x0/0xdc) from [<c0046f88>] (warn_slowpath_common+0x4c/0x80)
[<c0046f88>] (warn_slowpath_common+0x4c/0x80) from [<c00446f0>] (wake_up_process+0x2c/0x48)
[<c00446f0>] (wake_up_process+0x2c/0x48) from [<c0026930>] (arch_ptrace+0x214/0x4bc)
[<c0026930>] (arch_ptrace+0x214/0x4bc) from [<c00508d8>] (sys_ptrace+0x9c/0x164)
[<c00508d8>] (sys_ptrace+0x9c/0x164) from [<c0024ec0>] (ret_fast_syscall+0x0/0x28)
---[ end trace 98ab50bc781b314f ]---
How can I resolve this issue?
Not my answer, but to enable the question to be marked as closed:
This is likely a bug in the guest kernel (though not certainly so), so
I would start by trying with a more recent kernel than 2.6.32, which
is now nearly 8 years old. – Peter Maydell Mar 3 '17 at 13:14