qemu-system-arm chroot illegal instruction - arm

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.

Related

How to enable accel=kvm (or --enable-kvm) while running qemu on arm host (arm guest)

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.

QEMU: how to use the virt board

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.

"(gdb) run" crash when running executables on qemu emulated arm architecture

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

What is a structure of u-boot flash file? ( ARM versatile pb )

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.

Cross-compile qemu for ARM

I need to cross-compile qemu to use it on a cubieboard2 with an ARM Cortex-A7 CPU and I'm cross-compiling it on Linux Mint.
I can't find anywhere the commands I need to use to do it, the only thing I could find is how to compile qemu on an emulated ARM system. This is what I tried:
git clone git://git.qemu-project.org/qemu.git
./configure --target-list="arm-softmmu arm-linux-user" --prefix=/usr --enable-kvm --enable-linux-user --enable-user --enable-system
make ARCH=ARM CROSS_COMPILE=arm-linux-gnueabihf-
I don't get any errors, everything seems fine, but I don't get an executable file that I can use on my board.
Thanks everyone!

Resources