Skip to content

Instantly share code, notes, and snippets.

@JRHeaton
Created May 19, 2010 03:15
Show Gist options
  • Save JRHeaton/405909 to your computer and use it in GitHub Desktop.
Save JRHeaton/405909 to your computer and use it in GitHub Desktop.
#include <recovery.h>
int main(int argc, const char **argv) {
if(argc < 3) {
printf("Usage: %s <ramdisk> <kernel>\n", argv[0]);
return -1;
}
printf("Connecting to device...");
iUSBRecoveryDeviceRef device = iUSBRecoveryDeviceCreate(kUSBPIDRecovery, NULL);
if(!device) {
printf("Failed\n");
return -1;
}
printf("Done\n");
iUSBRecoveryDeviceSendCommand(device, CFSTR("bgcolor 255 0 0"));
CFStringRef welcome = iUSBRecoveryDeviceReadResponse(device, 1000, 1000);
if(welcome) CFRelease(welcome);
iUSBRecoveryDeviceSendCommand(device, CFSTR("bgcolor 0 255 0"));
printf("Sending ramdisk...");
CFStringRef filePath = CFStringCreateWithCString(kCFAllocatorDefault, argv[1], kCFStringEncodingUTF8);
if(!iUSBRecoveryDeviceSendFile(device, filePath, NULL)) {
printf("Failed\n");
CFRelease(filePath);
iUSBRecoveryDeviceRelease(device);
return -1;
}
CFRelease(filePath);
printf("Done\n");
printf("Resetting connection...");
iUSBRecoveryDeviceRelease(device);
device = iUSBRecoveryDeviceCreate(kUSBPIDRecovery, NULL);
if(!device) {
printf("Failed\n");
return -1;
}
printf("Done\n");
iUSBRecoveryDeviceSendCommand(device, CFSTR("bgcolor 0 0 255"));
printf("Sending command \"ramdisk\"...");
if(!iUSBRecoveryDeviceSendCommand(device, CFSTR("ramdisk"))) {
printf("Failed\n");
iUSBRecoveryDeviceRelease(device);
return -1;
}
printf("Done\n");
printf("Sending kernel...");
filePath = CFStringCreateWithCString(kCFAllocatorDefault, argv[2], kCFStringEncodingUTF8);
if(!iUSBRecoveryDeviceSendFile(device, filePath, NULL)) {
printf("Failed\n");
CFRelease(filePath);
iUSBRecoveryDeviceRelease(device);
return -1;
}
CFRelease(filePath);
printf("Done\n");
iUSBRecoveryDeviceSendCommand(device, CFSTR("bgcolor 255 0 0"));
printf("Reading device response...\n");
CFStringRef response = iUSBRecoveryDeviceReadResponse(device, 1000, 1000);
if(response) {
CFShow(response);
CFRelease(response);
}
printf("\n");
printf("Sending command \"bootx\"...");
iUSBRecoveryDeviceSendCommand(device, CFSTR("bootx"));
printf("Done\n");
iUSBRecoveryDeviceRelease(device);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment