Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xcode and usb iphone passthrough #25

Closed
tombombadilom opened this issue Sep 6, 2021 · 10 comments
Closed

xcode and usb iphone passthrough #25

tombombadilom opened this issue Sep 6, 2021 · 10 comments
Labels
documentation Improvements or additions to documentation

Comments

@tombombadilom
Copy link
Collaborator

tombombadilom commented Sep 6, 2021

How to add an iphone to use with xcode

Références:
https://stackoverflow.com/questions/67279997/connect-iphone-via-usb-to-sosumi-qemu
sickcodes/Docker-OSX#133

Define usb port to be usb passthrough

it is easier to select a usb bus where your iphone is single but in case you can't follow the udev rules

plug your iphone to usb

$ lsusb
Bus 001 Device 004: ID 05ac:12a8 Apple, Inc. iPhone 5/5C/5S/6/SE

Since qemu runs as a regular user, it cannot connect to hot-plug USB devices unless you change permssions on the host. Being in group plugdev might be sufficient for standard USD block devices. For others, such as an iphone, you need to manually change the /dev/bus/usb/xxx/yyy to group users or create /etc/udev/rules.d/97-iphone.rules.

https://www.linuxquestions.org/questions/blog/kingbeowulf-74138/qemu-usb-passthrough-with-specifics-for-iphone-37830/

sudo vim /etc/udev/rules.d/97-iphone.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="05ac", ATTRS{idProduct}=="*",GROUP="users", MODE="0660"

0x05ac vendor ID in this case is for an Apple iPhone 5C. For iphones specifically, it can help to disable usbmuxd with an empty /etc/udev/rules.d/39-usbmuxd.rules
Now, either reboot (ha! this ain't windows!) or run as root

sudo udevadm control -R

then edit yout lanch-mac-os.sh and add

-usb \
-device usb-ehci,id=ehci \
-device usb-host,bus=ehci.0,vendorid=0x05ac,productid=0x12a8,guest-reset=false,id=iphone \

Warning if you intend to code with xcode or upgrade your iphone with your mac , remove the productid . see comment below.

Pairing an iOS device with Xcode

  • Open Xcode and go to Window > Devices and Simulators.
  • Plug your iOS device into your Mac using a lightning cable. You may need to select to Trust This Computer on your device.
  • Select your device and then select the Connect via network checkbox to pair your device:

https://stackoverflow.com/questions/10087985/xcode-doesnt-see-my-ios-device-but-itunes-does

Do I need to be a Apple Developer Member to deploy apps on my iphone ?

https://developer.apple.com/forums/thread/81424

when you launch your mac os x you should get this :

tom@toms-iMac ~ % lsusb
Bus 004 Device 002: ID 0627:0001 0627 QEMU USB Mouse  Serial: 89126-0000:00:04.0-3
Bus 004 Device 003: ID 0627:0001 0627 QEMU USB Keyboard  Serial: 68284-0000:00:04.0-2
Bus 004 Device 001: ID 05ac:12a8 Apple Inc. iPhone  Serial: 650d4ab950e8ece4cd07b637044440618c9080b4
Bus 000 Device 001: ID 1d6b:IPCI Linux Foundation USB 2.0 Bus 
Bus 000 Device 001: ID 1d6b:IPCI
IPCI
IPCI
IPCI Linux Foundation USB 2.0 Bus
@tombombadilom
Copy link
Collaborator Author

iphone

@tombombadilom
Copy link
Collaborator Author

tombombadilom commented Sep 7, 2021

NB: Big scare while updating iphone ios from mac os x finder. The phone remained unusable and blocked in restore mode.
After analysis it appears that the productid is different in restore mode.
So to upgrade, backup and restore your iphone I strongly advise you to remove the mention of the productid in your startup script qemu.

-usb \
-device usb-ehci,id=ehci \
-device usb-host,bus=ehci.0,vendorid=0x05ac,guest-reset=false,id=iphone \

@arindas
Copy link
Owner

arindas commented Sep 7, 2021

Thank you for posting your solution here. Linked it in the README

@rawlines
Copy link

I find relevant to post also an issue i had while connecting an iphone with Ubuntu 22.04 as host.

Following the top tutorial, the iphone connects perfectly and is detected by the vm, but when issuing the update required by mac: "A software update is required to connect to iPhone", it was no longer able to connect the iphone to the VM. Also, QEMU was continuously throwing this errors:

...
qemu-system-x86_64: libusb_set_configuration: -6 [BUSY]
qemu-system-x86_64: libusb_set_configuration: -6 [BUSY]
qemu-system-x86_64: libusb_set_configuration: -6 [BUSY]
qemu-system-x86_64: libusb_set_configuration: -6 [BUSY]
qemu-system-x86_64: libusb_set_configuration: -6 [BUSY]
qemu-system-x86_64: libusb_set_configuration: -6 [BUSY]
qemu-system-x86_64: libusb_set_configuration: -6 [BUSY]
...

By a little of search, i can figure out that my host machine was somehow blocking the device. This is because the drivers from the host machine, claims the device before it is forwarded to the VM.

Making an lsusb -t, i can figure out which drivers were claiming the device:

/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
    ...
    |__ Port 4: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 1: Dev 4, If 0, Class=Hub, Driver=hub/2p, 480M
            |__ Port 1: Dev 21, If 1, Class=Vendor Specific Class, Driver=, 480M
            |__ Port 1: Dev 21, If 2, Class=Vendor Specific Class, Driver=, 480M
            |__ Port 1: Dev 21, If 0, Class=Imaging, Driver=usbfs, 480M
    ...

As you can see, in the iphone case, it detects several interfaces for a single device, each interface may load a different driver. Is important to unbind every driver from the device to make QEMU forward it properly.

In my personal case, when hot plugging my device to the VM, the If 0 gets claimed by usbfs driver. Issuing the foillowing command for unbinding the device from the driver, makes the vm to automatically detect the iphone:

echo "1-4.1.1:4.0" | sudo tee /sys/bus/usb/drivers/usbfs/unbind

@MohamadTheWarrior
Copy link

When I tried @rawlines command it gave me this output:

tee: /sys/bus/usb/drivers/usbfs/unbind: No such device

So, what I did to find the correct identifier for my connected iPhone was typing ls /sys/bus/usb/drivers/usbfs/ in the command line and my indentifier was 1-3:1.0.

@ErichPetersen
Copy link

ErichPetersen commented Mar 25, 2024

Is anyone having trouble redirecting the USB port to communicate with the iPhone on Sonoma?
I tried everything but XCode and Finder don't find the iPhone.

@tombombadilom
Copy link
Collaborator Author

No idea, personally, I'm stuck in Ventura and I didn't find a way to bypass the security disk to allow the Sonoma upgrade.
Can I ask you, how did you do ? Can you share it with us ?

@tombombadilom
Copy link
Collaborator Author

Is anyone having trouble redirecting the USB port to communicate with the iPhone on Sonoma? I tried everything but XCode and Finder don't find the iPhone.

I assume that you have read all the thread, to make it short.
You have to connect the iPhone to a USB device, and if possible avoid plugging it on a hub.
The reason is that, once you choose your USB plug, you have to make it passthrough QEMU to the VM.
As a result, this plug won't be available for your host or any other VM.
Once you have done that, you should be able to see it in your Sonoma.

@ErichPetersen
Copy link

No idea, personally, I'm stuck in Ventura and I didn't find a way to bypass the security disk to allow the Sonoma upgrade. Can I ask you, how did you do ? Can you share it with us ?

Hi @tombombadilom,
I just did the Software Update from macOS.

I'm using this package to virtualize macOS: https://oneclick-macos-simple-kvm.notaperson535.is-a.dev/

@ErichPetersen
Copy link

Is anyone having trouble redirecting the USB port to communicate with the iPhone on Sonoma? I tried everything but XCode and Finder don't find the iPhone.

I assume that you have read all the thread, to make it short. You have to connect the iPhone to a USB device, and if possible avoid plugging it on a hub. The reason is that, once you choose your USB plug, you have to make it passthrough QEMU to the VM. As a result, this plug won't be available for your host or any other VM. Once you have done that, you should be able to see it in your Sonoma.

The problem is that Sonoma requires qemu-xhci.
I downgraded to Ventura and reverted the configuration to usb-ehci, then I was able to communicate with the iPhone again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

5 participants