In my personal projects I used QEMU extensively to emulate ARM devices, these are some of my posts on the subject:
- Hello world for bare metal ARM using QEMU
- U-boot for ARM on QEMU
- Busybox for ARM on QEMU
- Booting Linux with U-Boot on QEMU ARM
- Linux NFS Root under QEMU ARM emulator
- Debugging ARM programs inside QEMU
- QEMU ARM semihosting
- Emulating ARM PL011 serial ports
- Using CodeSourcery bare metal toolchain for Cortex-M3
- Compile Linux kernel 3.2 for ARM and emulate with QEMU
- ARM926 interrupts in QEMU
I read the changelog of the 1.5.0 release, and it contains some changes that might make many of my tutorials and many of my advices in comments not work correctly on newer QEMU versions. The developers did anyway a good job of supporting the possibility to go back to the previous behaviour, the page contains information on how to do it.
The bottom line is, if you want to follow my guides on QEMU be aware of compatibility with different versions.
Posted in: Software
Balaji
2013/10/03
Hi Balau,
I want to test a SP805 based watchdog timer in Qemu-1.5.93. But the model is not emulated in the qemu source. Is there any possibility to add watchdog timer support to Qemu. Can you tell me if it is possible.
Balau
2013/10/04
Surely it’s possible to add a new peripheral to QEMU, but I don’t know if there’s a sort of guide for doing it. You can read the documentation in the source, read the source code of a peripheral you know well and ask qemu development mailing list about it.
hamza
2016/03/07
hi balau
i need to Patch QEMU to enable memory accesses for different memory types (physical
and virtual memory, special function registers) to allow MMU table walk and SMP
debugging. have u any suggestion ?
Balau
2016/03/07
I don’t know, I’d start reading the text files inside the source tree, such as HACKING and docs directories, then grep the files for MMU/mmu to try to understand where it’s implemented.
marwa
2016/03/28
hello
i want to run qemu with i386 (host architecture) i use busybox to create the file system
./i386-softmmu/qemu-system-i386 -M pc -kernel bzImage -initrd busybox-1.21.0/rootfs_lib.img.gz -append “root=/dev/mmcblk0 rw physmap.enabled=0 console=ttyAMA0 rdinit=/sbin/init ” -serial stdio —> qemu window display booting the kernel and then it display nothing ,
and i got kernel panic if i try this ./i386-softmmu/qemu-system-i386 -M pc -kernel /home/marwa/Bureau/lauterbach/i386_qemu/linux-4.1.18/arch/i386/boot/bzImage -initrd /home/marwa/Bureau/lauterbach/i386_qemu/busybox-1.21.0/rootfs_lib.img.gz
have u any idea how to fix this
Balau
2016/03/28
I don’t think it has anything to do with busybox because at least it would display some kernel messages before mounting the RAM filesystem and executing busybox.
marwa
2016/03/28
so why i got a kernel panic no init found ? what could be the problem ?
Balau
2016/03/28
In your previous comment you said the qemu window displays “booting the kernel” and then it displays nothing. Now you say the error message is “no init found” so it’s clearly two different problems and I suppose you solved the first one by yourself. Another commenter had a similar problem, his issue was that he was compiling busybox as an executable that needed shared libraries but did not provide those libraries. Other suggestions are in my comment above him.
marwa
2016/03/30
those are steps that i followed
i compile the kernel 4.4.1 with arch =i386
i download busybox 1.21.0
make ARCH=i386 menuconfig
I checked the option to compile Busybox as a static executable
make ARCH=i386 install
cd _install
mkdir proc sys dev lib etc etc/init.d
gedit etc/inittab
::sysinit:/etc/init.d/rcS
sudo chmod +x etc/inittab
sudo gedit etc/init.d/rcS
#!/bin/sh
echo “hello” // hello display when starting the qemu
mount -t proc none /proc
mount -t sysfs none /sys
/sbin/mdev -s
sudo chmod +x _install/etc/init.d/rcS
find . | cpio -o –format=newc > ../rootfs.img
cd ..
gzip -c rootfs.img > rootfs.img.gz
./i386-softmmu/qemu-system-i386 -M pc -kernel /home/marwa/Bureau/lauterbach/i386_qemu/linux-4.1.18/arch/i386/boot/bzImage -initrd /home/marwa/Bureau/lauterbach/i386_qemu/busybox-1.21.0/rootfs.img.gz -append “root=/dev/ram rdinit=/sbin/init”
i have tried this command too
./i386-softmmu/qemu-system-i386 -M pc -kernel /home/marwa/Bureau/lauterbach/i386_qemu/linux-4.1.18/arch/i386/boot/bzImage -initrd /home/marwa/Bureau/lauterbach/i386_qemu/busybox-1.21.0/rootfs.img.gz -append “root=/dev/ram rdinit=/bin/sh”
but i got this msg in qemu ‘shell
starting init :/bin/sh exists but couldn’t execute it
kernel panic – not syncing no working init found
please have u any idea how to fix this error
Balau
2016/04/03
I just did exactly what you said. The one with “rdinit=/dbin/init” doesn’t open any console but it doesn’t give kernel panic either. If I remove the inittab step instead I can open a console inside QEMU window, so you can try that, but I don’t think it can improve the situation.
The qemu execution with “rdinit=/bin/sh” works without problems.
I don’t know, maybe it’s the version of the tools.
My QEMU version is:
QEMU emulator version 2.5.0 (Debian 1:2.5+dfsg-5), Copyright (c) 2003-2008 Fabrice Bellard
My GCC is:
gcc (Debian 5.3.1-13) 5.3.1 20160323
Also, you said kernel 4.1.1 so I downloaded that, but then I notice your directory is 4.1.18. I don’t have time to try also 4.1.18, but I suppose the outcome is the same.
Be sure that _install/bin/busybox file is executable and has the correct architecture:
$ objdump -f _install/bin/busybox
_install/bin/busybox: file format elf32-i386
architecture: i386
marwa
2016/04/04
the output of this command objdump -f _install/bin/busybox :
format de fichier elf64-x86-64
architecture: i386:x86-64, fanions 0x00000102:
EXEC_P, D_PAGED
i have a question , is i386 a x32 system or x64 system , , i think what u did is running qemu on x32 system and what i did is runnig qemu on x64 system , sorry if there is some confusion , also u mean by gcc the cross compiler ??
well what i’m trying to do is running qemu on x64 system then on x32 system , i tried to run it with x64 arch and i got kernel panic error so i didn’t even try to run it with x32 arch
so i guess if i try to do what u said with arch 32 il will work , but what about x64 arch which is suppose to be much more easy because no need to cross compiler it isn’t ?
marwa
2016/04/04
sorry can u tell me what commands u use to get file format of busybox elf32-i386 , im so confused
Balau
2016/04/04
I ran exactly what you told you ran. But my computer is a 32-bit Debian desktop, and your computer is probably a 64-bit Linux system, so we probably get two different results for that reason. Usually i386, i686 and x86 are intended to be 32-bit, while amd64 and x86_64 are intended to be 64bit. But in this particular case it depends on Busybox Makefiles and configurations. To compile a 32bit executable on a 64bit machine usually GCC needs the -m32 flag. To pass it to Busybox you can make menuconfig, go in build settings and add -m32 to CFLAGS and LDFLAGS. See also this:
https://gcc.gnu.org/onlinedocs/gcc-4.9.3/gcc/i386-and-x86-64-Options.html#i386-and-x86-64-Options
QEMU is an emulator, that runs on a host and emulates a guest. The host architecture and the guest architecture can be different. For example you can have a 64-bit host and QEMU emulates a 32-bit guest.
Then there is the operating system that can be 32-bit or 64-bit. Note that if you compile Linux for a 32-bit i386 architecture it can also run on modern x86_64 because there is compatibility.
marwa
2016/04/04
thank u so much , it works for x64 system , but with x32 system when i add -m32 as u said and i compiled busybox , i got this error fatal error: sys/cdefs.h: No such file then i added apt-get install libc6-dev-i386
and i got another error: error fatal error: asm/error.h , i did that
sudo ln -s /usr/include/i386-linux-gnu/asm /usr/include/asm
sudo apt-get install gcc-multilib
and i got this error
/usr/bin/ld: architecture i386 du fichier d’entrée « applets/applets.o » est incompatible avec la sortie i386:x86-64
collect2: error: ld returned 1 exit status
make[1]: *** [applets/built-in.o] Erreur 1
make: *** [applets_dir] Erreur 2
Balau
2016/04/05
It seems that applets.o has been correctly compiled for 32bit, but the linker is trying to create a 64bit executable. Did you put -m32 also in LDFLAGS? when you compile busybox add also the option V=1 to show the commands that are being executed to compile and link, and you can also copy them and execute them yourself without make, just to test.
marwa
2016/04/13
export CFLAGS=’m32′
export CXXFLAGS=’-m32′
export LDFLAGS=’-m32′
those 3 commands fix the error
marwa
2016/04/19
hey again
last time i run qemu for 64 bit with kernel compiled with 32 bits(i386) with success but then i found that i need a kernel compiled with 64 bit
i prepared file system with busybox
i got that elf file
_install/bin/busybox: format de fichier elf64-x86-64
architecture: i386:x86-64, fanions 0x00000102:
EXEC_P, D_PAGED
adresse de départ 0x0000000000522024
and i compiled linux kernel
make ARCH=x86_64 x86_64_defconfig
make ARCH=x86_64
and i configured qemu
./configure –target-list=x86_64-softmmu –disable-vnc –enable-sdl –disable-kvm –enable-debug
make
then when i run qemu i got a kernel panic _ not syncing vfs :unable to mount rootfs on unknown block(1,0) which is something bizarre and frustrated
./x86_64-softmmu/qemu-system-x86_64 -M pc -kernel /linux-4.1.18/arch/x86_64/boot/bzImage -initrd /busybox-1.21.0/rootfs.img.gz -append “root=/dev/ram rdinit=/bin/sh”
Balau
2016/04/20
It is a generic error that I have already seen many times for different reasons. sometimes the rootfs image was created incorrectly, sometimes the file passed to rdinit did not exist, sometimes it’s not the right architecture. You could try “
gunzip < ./busybox-1.21.0/rootfs.img.gz | cpio -t
” to make sure that “bin/sh
” is shown.You can search in the comments of my blog to see if there’s something that works for you by searching google for:
site:balau82.wordpress.com not syncing vfs unable to mount root on unknown block
marwa
2016/04/21
hey
well i fix the error by using buildroot
git clone git://git.buildroot.net/buildroot buildroot.git
cd buildroot.git
make menuconfig
Target Options -> Target Architecture(x86_64)
* Toolchain -> Toolchain type (External toolchain)
System configuration -> Run a getty (login prompt) after boot (BR2_TARGET_GENERIC_GETTY)
System configuration -> getty options -> TTY Port (ttyAMA0) (BR2_TARGET_GENERIC_GETTY_PORT)
Target Packages -> Show packages that are also provided by busybox (BR2_PACKAGE_BUSYBOX_SHOW_OTHERS)
Filesystem images -> cpio the root filesystem (for use as an initial RAM filesystem) (BR2_TARGET_ROOTFS_CPIO)
….
then i just added rootfs.cpio ‘s path to the kernel configuration
CONFIG_INITRAMFS_SOURCE=”…./buildroot.git/output/images/rootfs.cpio”
CONFIG_NET_9P=y
CONFIG_NET_9P_VIRTIO=y
in the other hand i didn’t change the rootfs made by busybox and i run qemu and it worked perfectly
./x86_64-softmmu/qemu-system-x86_64 -M pc -kernel /linux-4.1.18/arch/x86_64/boot/bzImage -initrd /busybox-1.21.0/rootfs.img.gz -append “root=/dev/ram rdinit=/bin/sh”