Difference between revisions of "IPhone Restore Procedure"

From The iPhone Wiki
Jump to: navigation, search
(iPhone side (Pre-Restore Preparation))
(iPhone side (Pre-Restore Preparation))
Line 6: Line 6:
 
Code that enables USB MUX (kernel module that forwards USB connections to TCP ports)
 
Code that enables USB MUX (kernel module that forwards USB connections to TCP ports)
 
Found at http://www.pastie.org/954389
 
Found at http://www.pastie.org/954389
See also: USBMuxConnectByPort
+
See also: [[USBMuxConnectByPort]]
 
<pre>
 
<pre>
 
#include <CoreFoundation/CoreFoundation.h>
 
#include <CoreFoundation/CoreFoundation.h>

Revision as of 03:49, 16 May 2010

Process

iTunes side

iTunes has pretty much no say in how the restore goes along. It will send the DeviceTree, RAMDisk, and Kernel (respectively, as far as I know), but in firmwares 1.1.1 and up the program on the RAMDisk pretty much runs the show. On the Restore RAMDisk, it is called 'restored_external'. On the Update RAMDisk, it is called 'restored_update'.

iPhone side (Pre-Restore Preparation)

Code that enables USB MUX (kernel module that forwards USB connections to TCP ports) Found at http://www.pastie.org/954389 See also: USBMuxConnectByPort

#include <CoreFoundation/CoreFoundation.h>
#include "IOUSBDeviceControllerLib.h"
#include <IOKit/IOCFPlugIn.h>
#include <assert.h>
#define kIOSomethingPluginID CFUUIDGetConstantUUIDWithBytes(NULL, \
    0x9E, 0x72, 0x21, 0x7E, 0x8A, 0x60, 0x11, 0xDB, \
    0xBF, 0x57, 0x00, 0x0D, 0x93, 0x6D, 0x06, 0xD2)
#define kIOWhatTheFuckID CFUUIDGetConstantUUIDWithBytes(NULL, \
    0xEA, 0x33, 0xBA, 0x4F, 0x8A, 0x60, 0x11, 0xDB, \
    0x84, 0xDB, 0x00, 0x0D, 0x93, 0x6D, 0x06, 0xD2)

void init_usb() {
    IOUSBDeviceDescriptionRef desc = IOUSBDeviceDescriptionCreateFromDefaults(NULL);
    IOUSBDeviceDescriptionSetSerialString(desc, CFSTR("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
    IOUSBDeviceControllerRef controller;
    assert(!IOUSBDeviceControllerCreate(NULL, &controller));
    //assert(!IOUSBDeviceControllerSetDescription(controller, desc));
    CFMutableDictionaryRef match = IOServiceMatching("IOUSBDeviceInterface");
    CFMutableDictionaryRef dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    CFDictionarySetValue(dict, CFSTR("USBDeviceFunction"), CFSTR("PTP"));
    CFDictionarySetValue(match, CFSTR("IOPropertyMatch"), dict);
    io_service_t service;
    while(1) {
        service = IOServiceGetMatchingService(kIOMasterPortDefault, match);
        if(!service) {
            printf("Didn't find, trying again\n");
            sleep(1);
        } else {
            break;
        }
    }
    IOCFPlugInInterface **iface;
    SInt32 score;
    printf("123\n");
    assert(!IOCreatePlugInInterfaceForService(
        service,
        kIOSomethingPluginID,
        kIOCFPlugInInterfaceID,
        &iface,
        &score
        ));
    void *thing;
    assert(!((*iface)->QueryInterface)(iface, CFUUIDGetUUIDBytes(kIOWhatTheFuckID), &thing));
    IOReturn (**table)(void *, ...) = *((void **) thing);
    assert(!table[0x10/4](thing, 0));
    assert(!table[0x2c/4](thing, 0xff, 0));
    assert(!table[0x30/4](thing, 0x50, 0));
    assert(!table[0x34/4](thing, 0x43, 0));
    assert(!table[0x44/4](thing, 0));
    IODestroyPlugInInterface(iface);
    assert(!table[0x14/4](thing, 0));
}

iPhone side (Procedure)

Wait For Storage Device (wait_for_storage_device)

Create Filesystem Partitions (create_filesystem_partitions)

ASR Stuff (restore_images)

Mount Filesystems (mount_filesystems)

Fix Up /Var (fixup_var)

Unmount Filesystems (unmount_filesystems)

Clear Persistent Boot Args (clear_persistent_boot_args)

NOR Update Prep(update_NOR)

Actual NOR Update Routine(Img3_update_NOR)

Flash Individual NOR Image(Img3_flash_NOR_image)

Update Baseband (update_baseband)

Set Boot Stage (set_boot_stage)

End NAND Epoch Update (end_nand_epoch_update)

Set Final NVRAM Arguments (no official name)

Restore Log

//struct that the restore daemon gets the information for and sends back to iTunes
2008-10-19 16:46:57.000 iTunes[221:13fe7]: type query response = <CFDictionary 0x13e2db10 [0xa01101a0]>{type = mutable, count = 5, capacity = 12, pairs = (
	3 : <CFString 0x125be4b0 [0xa01101a0]>{contents = "SerialNumber"} = <CFString 0x1257f230 [0xa01101a0]>{contents = "xxxxxxxxxxx"} //censored for obvious reasons
	5 : <CFString 0x125f96e0 [0xa01101a0]>{contents = "Result"} = <CFString 0x125bc9c0 [0xa01101a0]>{contents = "Success"}
	9 : <CFString 0xa011ad80 [0xa01101a0]>{contents = "Type"} = <CFString 0x12301bd0 [0xa01101a0]>{contents = "com.apple.mobile.restored"}
	12 : <CFString 0xce76220 [0xa01101a0]>{contents = "HardwareModel"} = <CFString 0x1237e0e0 [0xa01101a0]>{contents = "N82AP"}
	13 : <CFString 0x11295040 [0xa01101a0]>{contents = "RestoreProtocolVersion"} = <CFNumber 0x1019ad0 [0xa01101a0]>{value = +11, type = kCFNumberSInt32Type}
)}

//'''???'''
2008-10-19 16:46:57.000 iTunes[221:13fe7]: unable to open /Users/willstrafach/Library/Caches/Cleanup At Startup/iPhone Temporary Files/Firmware/device_map.txt: No such file or directory

//device type
2008-10-19 16:46:57.000 iTunes[221:13fe7]: board config = n82ap

//restore process
2008-10-19 16:46:57.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 28 progress -1 //start [[iPhone Restore Daemon#wait_for_storage_device]] routine. 
2008-10-19 16:46:57.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 11 progress -1 //start [[iPhone Restore Daemon#create_filesystem_partitions]] routine.
2008-10-19 16:46:57.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 12 progress -1 //all prepared! after this point it performs a wipe and does the actual partition creation.
2008-10-19 16:47:03.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 12 progress -1 //???
2008-10-19 16:47:09.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 0 
2008-10-19 16:47:19.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 1
2008-10-19 16:47:27.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 5
2008-10-19 16:47:28.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 6
2008-10-19 16:47:31.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 7
2008-10-19 16:47:33.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 8
2008-10-19 16:47:36.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 9
2008-10-19 16:47:38.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 10
2008-10-19 16:47:39.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 11
2008-10-19 16:47:40.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 12
2008-10-19 16:47:41.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 13
2008-10-19 16:47:41.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 14
2008-10-19 16:47:43.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 15
2008-10-19 16:47:44.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 16
2008-10-19 16:47:45.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 17
2008-10-19 16:47:46.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 18
2008-10-19 16:47:47.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 19
2008-10-19 16:47:48.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 20
2008-10-19 16:47:49.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 21
2008-10-19 16:47:50.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 22
2008-10-19 16:47:51.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 23
2008-10-19 16:47:52.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 24
2008-10-19 16:47:54.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 25
2008-10-19 16:47:55.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 26
2008-10-19 16:47:56.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 27
2008-10-19 16:47:57.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 28
2008-10-19 16:47:58.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 29
2008-10-19 16:47:59.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 30
2008-10-19 16:48:00.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 31
2008-10-19 16:48:01.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 32
2008-10-19 16:48:03.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 33
2008-10-19 16:48:04.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 34
2008-10-19 16:48:04.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 35
2008-10-19 16:48:05.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 36
2008-10-19 16:48:06.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 37
2008-10-19 16:48:07.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 38
2008-10-19 16:48:08.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 39
2008-10-19 16:48:09.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 40
2008-10-19 16:48:10.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 41
2008-10-19 16:48:13.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 42
2008-10-19 16:48:14.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 43
2008-10-19 16:48:15.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 44
2008-10-19 16:48:17.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 45
2008-10-19 16:48:18.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 46
2008-10-19 16:48:18.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 47
2008-10-19 16:48:20.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 48
2008-10-19 16:48:21.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 49
2008-10-19 16:48:23.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 50
2008-10-19 16:48:26.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 51
2008-10-19 16:48:26.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 52
2008-10-19 16:48:28.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 53
2008-10-19 16:48:29.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 54
2008-10-19 16:48:30.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 55
2008-10-19 16:48:32.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 56
2008-10-19 16:48:33.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 57
2008-10-19 16:48:34.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 58
2008-10-19 16:48:36.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 59
2008-10-19 16:48:37.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 60
2008-10-19 16:48:38.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 61
2008-10-19 16:48:40.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 62
2008-10-19 16:48:44.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 63
2008-10-19 16:48:46.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 64
2008-10-19 16:48:47.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 65
2008-10-19 16:48:49.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 66
2008-10-19 16:48:51.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 67
2008-10-19 16:48:52.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 68
2008-10-19 16:48:53.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 69
2008-10-19 16:48:54.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 70
2008-10-19 16:48:56.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 71
2008-10-19 16:48:57.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 72
2008-10-19 16:48:58.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 73
2008-10-19 16:48:59.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 74
2008-10-19 16:48:59.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 75
2008-10-19 16:49:00.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 76
2008-10-19 16:49:00.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 77
2008-10-19 16:49:01.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 78
2008-10-19 16:49:01.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 79
2008-10-19 16:49:02.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 80
2008-10-19 16:49:02.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 81
2008-10-19 16:49:03.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 82
2008-10-19 16:49:03.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 83
2008-10-19 16:49:04.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 84
2008-10-19 16:49:04.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 85
2008-10-19 16:49:05.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 86
2008-10-19 16:49:05.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 87
2008-10-19 16:49:06.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 88
2008-10-19 16:49:06.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 89
2008-10-19 16:49:06.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 90
2008-10-19 16:49:07.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 91
2008-10-19 16:49:07.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 92
2008-10-19 16:49:08.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 93
2008-10-19 16:49:08.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 94
2008-10-19 16:49:09.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 95
2008-10-19 16:49:09.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 96
2008-10-19 16:49:10.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 97
2008-10-19 16:49:10.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 98
2008-10-19 16:49:11.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 13 progress 100
2008-10-19 16:49:11.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 14 progress -1
2008-10-19 16:50:32.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 15 progress -1
2008-10-19 16:50:39.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 16 progress -1
2008-10-19 16:50:39.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 15 progress -1 //starting [[iPhone Restore Daemon#mount_filesystems]] routine.
2008-10-19 16:50:39.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 16 progress -1 //this message is sent when both partitions have been successfully mounted and checked for errors.
2008-10-19 16:50:44.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 17 progress -1 //starting [[iPhone Restore Daemon#fixup_var]] routine.
2008-10-19 16:52:32.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 29 progress -1
2008-10-19 16:52:32.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 29 progress -1 //starting [[iPhone Restore Daemon#unmount_filesystems]] routine.
2008-10-19 16:52:33.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 25 progress -1 //starting [[iPhone Restore Daemon#clear_persistent_boot_args]] routine.
2008-10-19 16:52:33.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 35 progress -1
2008-10-19 16:52:33.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 18 progress -1 //starting [[iPhone Restore Daemon#Img3_update_NOR]] routine.
2008-10-19 16:53:32.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 20 progress -1 //starting [[iPhone Restore Daemon#set_boot_stage]] routine.
2008-10-19 16:53:32.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: operation 32 progress -1 //starting [[iPhone Restore Daemon#end_nand_epoch]] routine.

//restore finished with no errors
2008-10-19 16:53:32.000 iTunes[221:13fe7]: device returned status 0
2008-10-19 16:53:32.000 iTunes[221:13fe7]: <Restore Device 0x114f4a00>: Restore succeeded
2008-10-19 16:53:32.000 iTunes[221:13fe7]: _AMRestoreModeDeviceFinalize: 0x114f4a00