libimobiledevice / idevicerestore

Restore/upgrade firmware of iOS devices
https://libimobiledevice.org
GNU Lesser General Public License v3.0
1.27k stars 389 forks source link

Device failing to enter recovery mode #317

Open devhem opened 4 years ago

devhem commented 4 years ago

I have the problem that as soon more then one phone is connected the machine idevicerestore fails with an error :"ERROR: Failed to place device in recovery mode" and keeps the phone stuck.

Plattform: windows Source: it's reproduceable with the current pushed source code Build: with msys64 Systems: tested on different windows10 machines, different iTunes versions, different phones, different cables - no change noticable Call: idevicerestore -C -l -e -y -d

Behaviour: As long only one phone is connected the whole process runs without any problem through. As soon a second phone is conneced the call fails with the error and phone is stuck.

Do you have any idea what could trigger that problem? I saw there was a change in that code area on 11 Oct 2019 commit [https://github.com/libimobiledevice/idevicerestore/commit/767fcceaeb456f5e281a6bd1b3f51713e4989293] - but no clue if that could be related to that behaviour.

` idevice_event_cb: device 0000000000000000 (udid: 1bfd3526abc6a6ccb46b57e4413e754d2a35406a) connected in normal mode idevice_event_cb: device 0000000000000000 (udid: 1bfd3526abc6a6ccb46b57e4413e754d2a35406a) connected in normal mode

taanders commented 4 years ago

I confirm that there is some random issues on detecting iOS devices at recovery mode. I found out that when Windows Update driver (ver 423.36.0.0) is loaded for iOS device (device shows also three instances on Device Manager at Windows ) it is working even worse. It is bit complicated to remove those 423 drivers from use but I was able to do that with NirSoft USBDeView tool. Search for vid 05ac for Apple devices.

devhem commented 4 years ago

@taanders Thank you for the hint with USBDeView tool.

I checked the connected devices and they are all using the driver which gets installed alongside with iTunes (e.g. 10.0.18362.1 in that case)

Do you have any further idead what could be the reason? The problem didn't exist a few weeks ago, till now it was working perfectly - with current state in git it's failing on all my tests.

taanders commented 4 years ago

I think best way for now is to revert broking changes from commit 767fcceaeb456f5e281a6bd1b3f51713e4989293 until someone figures out how it is not working properly. I think it is something related device detection callbacks.

devhem commented 4 years ago

@taanders Thank you for the hint. i made a fork and implemented a #define to switch between old WAIT_FOR (__usleep) method and new mutex method: https://github.com/devhem/idevicerestore/commit/419a60a0b593a9545db66e13929fbae1f842cd15

With the current state + enabled WAIT_FOR it's working again as expected.

@nikias It would be interresting if that problem (more then one connected device leads to the problem) only appears on windows or also on linux with the new mutex-method.

taanders commented 4 years ago

Hi @devhem, thanks for your commit. Does your definitions fix also issue with multiple devices or is it still existing? As @nikias wrote before @282:

Ok I pushed some commits, but I ended up not checking for multiple devices and just pick the first one it finds.

_Originally posted by @nikias in https://github.com/libimobiledevice/idevicerestore/issues/282#issuecomment-538976017

I think it acts on Mac like the same:

What platform are you guys on? I tested this on macOS

Originally posted by @nikias in https://github.com/libimobiledevice/idevicerestore/issues/282#issuecomment-536555845

yogendra123456 commented 4 years ago

Hi all,

i used latest libmobiledevice code (18-5-2020) for restore device on windows 10 Device given ERROR: Device failed to enter restore mode.

when i debug idevicerestore code then below given code it given error...

if (client->mode->index != MODE_RESTORE) { mutex_lock(&client->device_event_mutex); info("Waiting for device to enter restore mode...\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 180000); if (client->mode != &idevicerestore_modes[MODE_RESTORE] || (client->flags & FLAG_QUIT)) { mutex_unlock(&client->device_event_mutex); error("ERROR: Device failed to enter restore mode.\n"); if (delete_fs && filesystem) unlink(filesystem); return -1; } mutex_unlock(&client->device_event_mutex); }

+++++++++++++++++++++++++++ Stashbag created. Getting ApNonce in normal mode... d0 fd 73 4e b0 d8 bc 08 90 67 db c8 20 71 1b a9 ff a8 fb eb Trying to fetch new SHSH blob Getting SepNonce in normal mode... 08 df a5 c7 68 8b 58 c5 9c d6 da 65 73 88 d5 4f 88 84 df 22 Request URL set to https://gs.apple.com/TSS/controller?action=2 Sending TSS request attempt 1... response successfully received Received SHSH blobs Committing stashbag... Stashbag committed! Entering recovery mode... INFO: device serial number is DX3TH4ZCFRC5 Waiting for device to enter restore mode... ERROR: Device failed to enter restore mode. +++++++++++++++++++++++++++++++

singulart commented 3 years ago

@taanders Thank you for the hint. i made a fork and implemented a #define to switch between old WAIT_FOR (__usleep) method and new mutex method: devhem@419a60a

With the current state + enabled WAIT_FOR it's working again as expected.

@nikias It would be interresting if that problem (more then one connected device leads to the problem) only appears on windows or also on linux with the new mutex-method.

Hi @taanders, I am trying to implement your hint with WAIT_FOR, but since I don't code in C, I need some more of your help. When compiling the project code on MacOS Big Sur, I first get a warning about implicit WAIT_FOR, and then the error:

/Library/Developer/CommandLineTools/usr/bin/make  all-recursive
Making all in src
  CC       idevicerestore-idevicerestore.o
  CC       idevicerestore-common.o
  CC       idevicerestore-tss.o
  CC       idevicerestore-fls.o
  CC       idevicerestore-mbn.o
  CC       idevicerestore-img3.o
  CC       idevicerestore-img4.o
  CC       idevicerestore-ftab.o
  CC       idevicerestore-ipsw.o
  CC       idevicerestore-normal.o
  CC       idevicerestore-dfu.o
  CC       idevicerestore-recovery.o
recovery.c:253:2: warning: implicit declaration of function 'WAIT_FOR' is invalid in C99 [-Wimplicit-function-declaration]
        WAIT_FOR(client->mode != &idevicerestore_modes[MODE_RECOVERY] || (client->flags & FLAG_QUIT), 30);
        ^
1 warning generated.
  CC       idevicerestore-restore.o
  CC       idevicerestore-asr.o
  CC       idevicerestore-fdr.o
  CC       idevicerestore-limera1n.o
  CC       idevicerestore-download.o
  CC       idevicerestore-locking.o
  CC       idevicerestore-socket.o
  CC       idevicerestore-thread.o
  CC       idevicerestore-jsmn.o
  CC       idevicerestore-json_plist.o
  CCLD     idevicerestore
Undefined symbols for architecture x86_64:
  "_WAIT_FOR", referenced from:
      _recovery_enter_restore in idevicerestore-recovery.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [idevicerestore] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
tausift0 commented 3 years ago

I have found a workaround that fixed it but still I need to do this after every restart of my Windows. I use 3uTools. Go to Toolbox>iTunes Utility>Repair Driver>Advanced Repair>Uninstall the old driver files stored in the system

Once it finishes then you won't have any issues and the device will be detected in Recovery mode.

But I would still like this issue to be fixed in future.