Coding with Titans

so breaking things happens constantly, but never on purpose

Raspberry Pi 3 and QEMU

At first glance, it seemed to me to be a really easy task. Install QEMU for Windows, download latest Raspbian and run! Unfortunately after whole evening of tries I still fail to have it usable anyhow. Maybe it’s not totally not running, but still it’s pretty useless in terms of any further development of application without a device. Simply, at current state (as of 2018-02-18) of QEMU, it doesn’t support emulation of the USB controller, and since the whole network relays on it, there are huge connectivity issues (no network interface at all, so no SSH, no tools installation, no file transfers neither).

Just for reference, here is the tutorial I followed, not to be very bold, that I have discovered everything myself. I appreciate the work already done by QEMU team and others involved. I only hope they can emulate BCM2836’s USB anytime soon…

Probably since the spec of the USB controller is not publicly available, it makes the whole thing harder and that’s why the emulation not yet available. Although I found some article describing try of porting the USB driver itself into the Xinu OS running on Raspberry Pi. Maybe this could be used somehow to create the opposite.

OK. That’s a NO GO for the moment. Is there any other solution?

Well, yes, there is. After a while, it turned out that there are plenty of people (here, here or here) doing some heresy, but at the end of the day, it works. Instead of running Raspbian on emulator of the Raspberry Pi hardware, they use the ARM Versatile/PB board, which works somehow as expected. Among the best, it has network working!

This is pretty amazing, but also has some own quirks. First – a set of kernel patches must be applied to make it boot. Secondly it can handle only up to 256 MB of RAM (qemu exits with an error, when more is specified). Should be enough to start the device, but it’s quite low for some serious scenarios of audio/video processing. Thankfully Dhruv Vyas prepared required QEMU binaries in this open-sourced project (well, took over the work after xecdesign.com went down few years ago and is updating it along with all recent Raspbian releases). Great job!

So after downloading updated kernel, it’s just a matter of issuing single long command (Windows 10 shell):

"C:\Program Files\qemu\qemu-system-arm.exe" -m 256 -M versatilepb \
 -cpu arm1176 -serial stdio -no-reboot -kernel kernel-qemu-4.14.79-stretch \
 -dtb versatile-pb.dtb -net nic -net user -append "root=/dev/sda2 panic=1" \
 -drive format=raw,media=disk,index=0,file=D:/Raspi/2018-11-13-raspbian-stretch-lite.img

Update paths accordingly to your installation. Then QEMU will start fine.

PS.

One final note. It would be recommended at the very beginning to enlarge the SD card image to get some extra space for new programs to be installed.

This could be done with following command:

"C:\Program Files\qemu\qemu-img.exe" resize D:/Raspi/2018-11-13-raspbian-stretch-lite.img +2G

That’s all. Have fun!