arm raspi2/raspi3 emulation has no USB support

Bug #1772165 reported by George
28
This bug affects 4 people
Affects Status Importance Assigned to Milestone
QEMU
Fix Released
Wishlist
Unassigned

Bug Description

Using Qemu 2.12.0 on ArchLinux.

Trying to emulate arm device with `qemu-system-arm` and attach usb device for unput using

` -usb -device usb-host,bus=001,vendorid=0x1d6b,productid=0x0002 `

# lsusb returns

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 014: ID 13d3:3487 IMC Networks
Bus 001 Device 004: ID 0457:11af Silicon Integrated Systems Corp.
Bus 001 Device 003: ID 0bda:57e6 Realtek Semiconductor Corp.
Bus 001 Device 002: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

# qemu returns
qemu-system-arm: -device usb-host,bus=001,vendorid=0x1d6b,productid=0x0002: Bus '001' not found

Tried with connecting external usb keyboard but that didn't seem to work either.

Tags: arm usb
Revision history for this message
Peter Maydell (pmaydell) wrote :

Can you give the full QEMU command line you're using? (I suspect the reason for this error is that the board model you're using does not have a USB controller.)

Revision history for this message
George (vortelf) wrote :

qemu-system-arm -M raspi2 -append "rw earlyprintk loglevel=8 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2" -cpu arm1176 -dtb bcm2709-rpi-2-b.dtb -hda DietPi_v6.8_RPi-ARMv6-Stretch.img -kernel kernel7.img -m 1G -smp 4 -serial stdio -usb -device usb-host,bus=001,vendorid=0x1d6b,productid=0x0002

tags: added: usb
Revision history for this message
Peter Maydell (pmaydell) wrote :

Thanks. The USB controller for the raspi2/raspi3 boards is not currently modelled, so it's expected that USB devices won't work.

Revision history for this message
George (vortelf) wrote :

How then should I be able to actually use the vm when there is no input?

Revision history for this message
Peter Maydell (pmaydell) wrote :

Serial terminal is how I've used the raspi3 board before.

Revision history for this message
George (vortelf) wrote :

Serial terminal doesn't work with this options. Would you provide options with which i'll be able to access and login into the terminal. SSH is also a good solution.

Revision history for this message
Peter Maydell (pmaydell) wrote :

This is for raspi3 but may be a useful reference:
https://translatedcode.wordpress.com/2018/04/25/debian-on-qemus-raspberry-pi-3-model/

Probably what you're hitting is that the kernel/dtb default to the second serial terminal, so you can try adding 'console=ttyAMA0' to the -append options, or alternatively maybe using -serial null -serial stdio to drop the 1st serial output and send the second to the terminal.

Since the raspi networking sits behind USB, QEMU doesn't support that, so no ssh option, I'm afraid.

Revision history for this message
George (vortelf) wrote :

Whenever I append `console=ttyAMA0` I get kernel panic `Division by zero in kernel` and -serial stdio doen't seem to work.

Revision history for this message
Gerd Hoffmann (kraxel-redhat) wrote :

Beside rpi3 usb emulation not being there you are using the wrong argument. bus= specifies the *guest* bus. hostbus= can be used to specify the host bus number. When passing through devices using vendorid and productid this should not be needed though. Oh, and you can't pass through usb hubs, only individual devices.

Peter Maydell (pmaydell)
tags: added: arm
summary: - qemu-system-arm: -device usb-
- host,bus=001,vendorid=0x04f2,productid=0x0111: Bus '001' not found
+ arm raspi2/raspi3 emulation has no USB support
Peter Maydell (pmaydell)
Changed in qemu:
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
mcandre (andrew-pennebaker) wrote :

Out of curiousity, does the raspi2 machine support a PCI bus? I am trying to boot Debian arm64 with qemu-system-aarch64, and am running into all manner of complaints from qemu about missing devices. Is there another machine like virt, but that offers support for boot devices?

Revision history for this message
Peter Maydell (pmaydell) wrote : Re: [Qemu-devel] [Bug 1772165] Re: arm raspi2/raspi3 emulation has no USB support

On Sun, 24 Mar 2019 at 17:34, mcandre <email address hidden> wrote:
> Out of curiousity, does the raspi2 machine support a PCI bus?

No. There is no PCI bus on the raspi2 hardware and so there
is no PCI bus in QEMU's model of it.

> I am
> trying to boot Debian arm64 with qemu-system-aarch64, and am running
> into all manner of complaints from qemu about missing devices. Is there
> another machine like virt, but that offers support for boot devices?

I'm not sure what you mean by "boot devices" here. "virt" is
generally the machine we would recommend if you just want to
boot Debian. If you haven't seen this blog post before it might
be of use:
https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/

thanks
-- PMM

Revision history for this message
Aditya Govardhan (aditya-govardhan) wrote :

After reading change logs, I believe USB support for raspi2/raspi3 is not added yet. Which means host internet network can't be accessed by emulated machine.

I would be glad to help in documentation of differences between real Raspberry Pi devices and QEMU emulated raspi2/raspi3 since I have seen a lot of tutorials on internet trying to use QEMU for emulating raspberry pi. These tutorials most of the times are just hacks, like using versatilepb or using custom kernel instead of the Raspbian OS.

I have gathered as much info as possible over the last week through these tutorials, QEMU raspi code and change logs, and believe a good documentation of this info could help future users trying to emulate raspi.

Finally, I am able to run latest Raspbian OS (2019-07-10) lite version on raspi2 using the following command where I have extracted kernel image and dtb file from second partition:

qemu-system-arm -M raspi2 -kernel bootpart/kernel7l.img -dtb bootpart/bcm2709-rpi-2-b.dtb -drive file=2019-07-10-raspbian-buster-lite.img,format=raw,if=sd -append "rw console=ttyAMA0 loglevel=8 root=/dev/mmcblk0p2 fsck.repair=yes rootwait memtest=1" -serial stdio

I am not able to connect network devices, not able to use images other than lite image (https://bugs.launchpad.net/qemu/+bug/1837347) and unsure why this command is showing Hardware name as BCM2835 when the QEMU raspi code has BCM2836 associated with raspi2 (https://github.com/qemu/qemu/blob/59c58f96b270f5edd4ad10954c3a96556cb3a728/hw/arm/bcm2836.c#L31).

I highly appreciate the support provided for raspi2 and raspi3 till now.

Thank you.

Revision history for this message
Peter Maydell (pmaydell) wrote :

I think the two main things we would need would be:
 (1) a proper data sheet for the pi2/pi3 USB controller. Last time I looked there wasn't one available; it's pretty hard to model the controller properly without it. (Perhaps one has been released since I last looked.)
 (2) somebody who cares about the pi2/pi3 models and has the time to invest in writing a device model for them

Revision history for this message
Weber Kai (weberkai) wrote :

Hi!

I've googled: "usb" "designware" "otg" "datasheet"

I think this is the kernel driver for this device: https://github.com/torvalds/linux/tree/master/drivers/usb/dwc3

Maybe it should be possible to use this as a reference? Maybe try to redirect the proprietary drivers system calls? I don't know...

I've also found theses docs, which explains the device a little bit:
http://www.infradead.org/~mchehab/kernel_docs_pdf/driver-api.pdf
https://media.digikey.com/pdf/Data%20Sheets/Austriamicrosystems%20PDFs/AS3524.pdf
https://www.intel.com/content/dam/www/programmable/us/en/pdfs/literature/hb/arria-10/a10_54018.pdf

Thanks.

Revision history for this message
Peter Maydell (pmaydell) wrote :

Thanks for digging those up. Unfortunately just the driver sources aren't really enough information for a good device model, and the other docs are just overviews without the level of detail we need.

Revision history for this message
Clement Deschamps (clemd) wrote :

It looks like a similar USB controller is part of a TI SoC:

http://www.ti.com/lit/ug/spruhj7a/spruhj7a.pdf

Clement

Revision history for this message
Davide Bacilieri (davbac) wrote :

Right now with
`qemu-system-arm -kernel kernel7.img -dtb bcm2709-rpi-2-b.dtb -cpu arm1176 -M raspi2 -hda 2018-11-13-raspbian-stretch-full.img`
I can access the serial console using `Ctrl+Alt+3` in the QEMU window.
Using raspbian via this serial console is (as far as I can see) the same as using the Lite version.
The main display doesn't accept any mouse/ keyboard input, and `-device usb-mouse` generates a `qemu-system-arm: -device usb-mouse: No 'usb-bus' bus found for device 'usb-mouse` error, even after the `-machine usb=on` command

Revision history for this message
Doug Rabson (dougrabson) wrote :

I think this PDF describes the same OTC controller as the rpi one:

http://rockchip.fr/RK312X%20TRM/chapter-26-usb-otg-2-0.pdf

Revision history for this message
Paul Zimmerman (pauldzim) wrote :

Have you seen the patch series I have posted on the qemu-devel mailing
list? "[PATCH v5 0/7] dwc-hsotg (aka dwc2) USB host controller emulation."
If you could test that and give your 'tested-by', it could help get the
patch series accepted. That would require you to download the latest Qemu
source code, apply the patches, and build it yourself.

Revision history for this message
Dims (dims) wrote :

So, is it still true, that QEMU doesn't support USB on Raspberry Pi?

In other words I can't emulate Raspberry Pi actually?

What about documentation and QEMU helps? They reports usb for raspi2, for example:

$qemu-system-arm -machine raspi2 -device help | grep usb-host
name "usb-host", bus usb-bus

Is this incorrect information?

Also, when I was truing to configure USB passthrough, I was getting permission errors on /dev/usb/* probably indicating it was doing something.

If it doesn't support usb, then why isn't it write error message?

Revision history for this message
mcandre (andrew-pennebaker) wrote : Re: [Bug 1772165] Re: arm raspi2/raspi3 emulation has no USB support

Which Beagle boards, Jetson Nano, other devices have rich support from
qemu? ARM is critical going forward.

On Mon, Oct 5, 2020, 10:20 AM Dims <email address hidden> wrote:

> So, is it still true, that QEMU doesn't support USB on Raspberry Pi?
>
> In other words I can't emulate Raspberry Pi actually?
>
> What about documentation and QEMU helps? They reports usb for raspi2,
> for example:
>
> $qemu-system-arm -machine raspi2 -device help | grep usb-host
> name "usb-host", bus usb-bus
>
> Is this incorrect information?
>
> Also, when I was truing to configure USB passthrough, I was getting
> permission errors on /dev/usb/* probably indicating it was doing
> something.
>
> If it doesn't support usb, then why isn't it write error message?
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1772165
>
> Title:
> arm raspi2/raspi3 emulation has no USB support
>
> Status in QEMU:
> Confirmed
>
> Bug description:
> Using Qemu 2.12.0 on ArchLinux.
>
> Trying to emulate arm device with `qemu-system-arm` and attach usb
> device for unput using
>
> ` -usb -device usb-host,bus=001,vendorid=0x1d6b,productid=0x0002 `
>
> # lsusb returns
>
> Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 001 Device 014: ID 13d3:3487 IMC Networks
> Bus 001 Device 004: ID 0457:11af Silicon Integrated Systems Corp.
> Bus 001 Device 003: ID 0bda:57e6 Realtek Semiconductor Corp.
> Bus 001 Device 002: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129
> Card Reader Controller
> Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
>
> # qemu returns
> qemu-system-arm: -device
> usb-host,bus=001,vendorid=0x1d6b,productid=0x0002: Bus '001' not found
>
>
> Tried with connecting external usb keyboard but that didn't seem to work
> either.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/qemu/+bug/1772165/+subscriptions
>

Revision history for this message
Paul Zimmerman (pauldzim) wrote :

As of version 5.1, Qemu now supports USB on Raspberry PI 2 and 3. There are a few caveats:

- If you are running a Raspbian image, you must add "dwc_otg.fiq_fsm_enable=0"
  to the '-kernel' command-line parameters.
- Raspbian images 2016-05-27-raspbian-jessie and earlier don't work, see
  Bug 1892604.
- It has only been tested with Raspbian and with mainline Linux kernels, so
  e.g. BSD kernels probably won't work

I guess this bug should be closed, I'll look into how to do that.

Revision history for this message
Paul Zimmerman (pauldzim) wrote :

I misspoke in my last comment, that first bullet should have said

- If you are running a Raspbian image, you must add "dwc_otg.fiq_fsm_enable=0"
  to the '-append' command-line parameters.

Revision history for this message
Dims (dims) wrote :

I did this, but still can't access USB device, connected to host, from guest.

Also I have

$ lsusb
unable to initalize libusb: -99

on guest.

Playing with usb options gave nothing.

Revision history for this message
Dims (dims) wrote :

Command lines I use are like following

$QEMU_EXE \
    -kernel qemu-rpi-kernel/kernel-qemu-4.4.34-jessie \
    -cpu arm1176 \
    -m 256 \
    -M versatilepb \
    -append "dwc_otg.lpm_enable=0 root=/dev/sda2 panic=1" \
    -hda 2017-07-05-raspbian-jessie.img \
    -usb \
    -nic user \
    -serial stdio \
    -no-reboot \

# -device usb-dwc2 \
# -device usb-host,hostbus=1,hostport=3 \

# -usb \
# -device qemu-xhci,id=xhci \

# -device usb-net,netdev=mynet0 \
# -netdev user,id=mynet0,net=192.168.10.0/24,dhcpstart=192.168.10.1 \

#-usb \

# -device qemu-xhci \
# -device usb-ehci,id=ehci \

Revision history for this message
Paul Zimmerman (pauldzim) wrote :

You need to use -M raspi2 (or -M raspi3 for 64-bit kernels) to enable the Raspberry Pi emulation. And you need version 5.1 or newer of Qemu to get the dwc2 USB emulation. I don't think any Linux distributions provide that new of a Qemu, so you might have to build it yourself.

Here is the command line I use to run the Raspbian image 2019-09-26-raspbian-buster.img. I extracted bcm2709-rpi-2-b.dtb and kernel7.img from the FAT partition inside the image file.

qemu-system-arm -M raspi2 -drive file=2019-09-26-raspbian-buster.img,format=raw,if=sd -dtb bcm2709-rpi-2-b.dtb -kernel kernel7.img -append 'rw earlycon=pl011,0x3f201000 console=ttyAMA0 loglevel=8 root=/dev/mmcblk0p2 fsck.repair=yes net.ifnames=0 rootwait memtest=1 dwc_otg.fiq_fsm_enable=0' -serial stdio -no-reboot -netdev user,id=net0 -usb -device usb-kbd -device usb-tablet -device usb-net,netdev=net0

That should give you a graphical emulation with working keyboard, mouse and networking. Mass-storage also works, but I left that out for simplicity.

But note that if you absolutely must pass-through a USB device from the host, it probably won't work. That's because the dwc2 controller emulation is connected through a full-speed hub emulation, so unless your USB device is connected at full-speed on the host, it probably won't work.

Revision history for this message
Paul Zimmerman (pauldzim) wrote :

Here is that command line again, hopefully readable this time:

qemu-system-arm -M raspi2 \
    -drive file=2019-09-26-raspbian-buster.img,format=raw,if=sd \
    -dtb bcm2709-rpi-2-b.dtb \
    -kernel kernel7.img \
    -append 'rw earlycon=pl011,0x3f201000 console=ttyAMA0 \
        loglevel=8 root=/dev/mmcblk0p2 fsck.repair=yes \
        net.ifnames=0 rootwait memtest=1 \
        dwc_otg.fiq_fsm_enable=0' \
    -serial stdio -no-reboot \
    -netdev user,id=net0 \
    -usb -device usb-kbd -device usb-tablet \
    -device usb-net,netdev=net0

Revision history for this message
Peter Maydell (pmaydell) wrote :

On Mon, 5 Oct 2020 at 21:38, mcandre <email address hidden> wrote:
> Which Beagle boards, Jetson Nano, other devices have rich support from
> qemu? ARM is critical going forward.

If you just want to be able to run a Linux kernel and Arm
userspace code and you don't have a strong preference
for which board to use, we recommend using the 'virt'
board. See the notes on choosing a board model in the docs:
https://www.qemu.org/docs/master/system/target-arm.html#choosing-a-board-model

thanks
-- PMM

Revision history for this message
Thomas Huth (th-huth) wrote :

Since USB emulation has been added in QEMU 5.1, I'm marking this feature request as done now. If there are still issues, please open a new ticket instead.

Changed in qemu:
status: Confirmed → Fix Released
Revision history for this message
Carlo Bramini (carlo-bramix) wrote :

I'm also trying to run QEMU for emulating Raspberry PI, but I'm still unable to make working external USB devices like keyboard and mouse.
Unlike previous users, I'm not using a linux distro but Microsoft Windows 10 instead.
I'm using the precompiled 64bit executables downloaded from https://qemu.weilnetz.de/w64/ as suggested from the download page at qemu.org for Windows targets.
The version printed by the emulator is:

> QEMU emulator version 6.2.0 (v6.2.0-11889-g5b72bf03f5-dirty)
> Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers

I'm launching the emulator with this command as administrator:

qemu-system-arm -M raspi2b -drive file=2020-12-02-raspios-buster-armhf.img,format=raw,if=sd -dtb qemu-rpi-kernel\native-emuation\dtbs\bcm2709-rpi-2-b.dtb -kernel qemu-rpi-kernel\native-emuation\kernels\kernel7.img -append "rw earlycon=pl011,0x3f201000 console=ttyAMA0 loglevel=8 root=/dev/mmcblk0p2 fsck.repair=yes net.ifnames=0 rootwait memtest=1 dwc_otg.fiq_fsm_enable=0" -serial stdio -no-reboot -netdev user,id=net0 -usb -device usb-kbd -device usb-tablet -device usb-net,netdev=net0

Besides few obvious changes, like the separator character for directories (\ instead of /) and quotes (" instead of '), the command is the same as the one described above.

The emulator starts, the desktop of the OS appears, but still no keyboard and no mouse support.
However, I can still login by using the terminal provided by the emulated serial terminal.

Is the feature expected to work also on the port of QEMU for Windows?

Revision history for this message
Philippe Mathieu-Daudé (philmd) wrote :

On Tue, Feb 22, 2022 at 3:15 PM Carlo Bramini
<email address hidden> wrote:
>
> I'm also trying to run QEMU for emulating Raspberry PI, but I'm still unable to make working external USB devices like keyboard and mouse.
> Unlike previous users, I'm not using a linux distro but Microsoft Windows 10 instead.
> I'm using the precompiled 64bit executables downloaded from https://qemu.weilnetz.de/w64/ as suggested from the download page at qemu.org for Windows targets.

> The emulator starts, the desktop of the OS appears, but still no keyboard and no mouse support.
> However, I can still login by using the terminal provided by the emulated serial terminal.
>
> Is the feature expected to work also on the port of QEMU for Windows?

Yes.

However upstream QEMU bugs are now tracked on https://gitlab.com/qemu-
project/qemu/-/issues - so if you can reproduce it with the latest
version from upstream QEMU, please report it there.

Regards,

Phil.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.