arindas / mac-on-linux-with-qemu

Runs macOS on linux with qemu.
MIT License
196 stars 18 forks source link

xcode and usb iphone passthrough #25

Closed tombombadilom closed 3 years ago

tombombadilom commented 3 years ago

How to add an iphone to use with xcode

Références: https://stackoverflow.com/questions/67279997/connect-iphone-via-usb-to-sosumi-qemu https://github.com/sickcodes/Docker-OSX/issues/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

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 commented 3 years ago

iphone

tombombadilom commented 3 years ago

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 commented 3 years ago

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

rawlines commented 1 year ago

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 commented 1 year ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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.