Android emulating OpenWrt libusb problems

Hello guys, i managed to run openwrt 22.03.0 vm on android phone all working ok except i have issuse with libusb i cannot mount usb NIC to OTG..... any suggestions? btw all is non root on android is that maybe issue ?

How?

(Kinda important if you're asking about your USB OTG connectivity, right?)

Qemu (only one possible way as far as I know). Kvm won't be supported till android 13 release/adaptation so no one is building vm host for android. I think the lack of root is problematic ...I need to read some docs obviously, but don't know from where to start....

???

Let's try this...consider if one wishes to to test/reproduce. Provide details/steps.

  • I get my Android out and open the app store
  • What app? (A Play Store search does not produce "Qemu" as an app in search results)
  • What settings?
  • Menu for USB filter/capture?

Maybe...usually apps have permissions to use what it needs, I'm not sure about taking over the whole USB port, though.

  • Definitely - the Android developer docs
  • The publisher of the app should know if it applies to their app

Its pretty much easy, i used termux. Instaled qemu, compiled arm image and started it on phone. Btw there is some isue with 22.03.2 branch, only main is producing workable image (Building QEMU firmware-questions) I can write detailed instruction but not atm.

Wow...OK.

That's gonna take some time to reproduce...

What Android device?

(Please be liberal in providing details.)

Xiaomi mi max 2. Tomorow ill write step by step. Its not hard at all. Ill upload images and qemu arguments

1 Like

Sorry for 1 day delay had technical issues regarded rooting phone.....
Ok ideas goes like this. More or less anyone of us have some android phone that sit on shelf.
Goals:

  1. Try to emulate in qemu openwrt vm guest on PC and enable network support WAN - LAN virtual nic
    ** PC is testing ground for having working image to use on phone
  2. Enable passtrough to USB on PC to qemu to use real hardware
  3. Migrate all that working emulation on android phone and resolve issues on phone as it goes.

Results:

  1. Emulating on PC - OS Debian 11 x64 .
  • Git pull and compile openwrt
    ** main branch, arm cortex a15
    ** full USB support (add kmod support for USB uhci ohci ehci xhci)
    ** kmod drivers for Asisx USB nic ( ID 0b95:772b ASIX Elec. Corp. AX88772B )
    ** Luci and all other things i need or i think will need
  • All working on qemu-system-arm
    ** Got virtual network as suppose to
  1. Enabling USB passtrough on usb
    ** All working as suppose to with qemu arguments to passtrough USB nic
    **Enabling USB nic as WAN then testing as lan interface. All ok.

  2. Migrating on ROOTED Android phone emulation Android 7+ required, root required for usb passthrough
    *On android install termux
    *Start termux give it wakelock
    *update and install all requirements for working qemu-system-arm

  3. Prepare files
    mkdir qemu
    cd qemu
    #get all ur qemu files here
    #run qemu with arguments
    qemu-system-arm
    -nographic
    -M virt
    -m 128
    -kernel openwrt-armvirt-32-zImage
    -drive file=openwrt-armvirt-32-rootfs-squashfs.img,format=raw,if=virtio
    -append root=/dev/vda
    -device virtio-net,netdev=net0 -netdev user,id=net0,net=192.168.2.0/24,hostfwd=tcp:127.0.0.1:1180-192.168.2.1:80,hostfwd=tcp:127.0.0.1:1122-192.168.2.1:22
    -device virtio-net,netdev=net1 -netdev user,id=net1,net=192.0.2.0/24
    -device usb-ehci,id=ehci
    -device usb-host,vendorid=0x0b95,productid=0x772b

#Wait a bit and see if network will be aquired
On android chrome type 127.0.0.1:1180
login without password to openwrt
See if usb nic interface is present. SUCESS

############################
Passtrough of usb nic card and using it as wan enable icmp. SUCESS
Creating lan bridged network on usb card working as suppose to. SUCESS

Managed to emulate x86 on android 13 with pkvm crosvm, pretty much same thing.
A lot faster ...
Problems:
USB support its .... buggy... didnt manage it to work.

References:
Android_Virtualization.pdf