void OpenIBootStart() { setup_openiboot(); pmu_charge_settings(TRUE, FALSE, FALSE); #ifdef OPENIBOOT_INSTALLER framebuffer_setdisplaytext(FALSE); framebuffer_clear(); { int w, h; uint32_t *bgImg = framebuffer_load_image(datainstallerLogoPNG, sizeof(datainstallerLogoPNG), &w, &h, TRUE); if(bgImg) { int x = (framebuffer_width() - w)/2; int y = (framebuffer_height() - h)/3; framebuffer_draw_image(bgImg, x, y, w, h); } else { framebuffer_setdisplaytext(TRUE); bufferPrintf("Failed to load image...\n"); } } #else framebuffer_setdisplaytext(TRUE); framebuffer_clear(); bufferPrintf("Loading openiBoot..."); #ifndef SMALL #ifndef NO_STBIMAGE int defaultOS = 0; int tempOS = 0; const char* hideMenu = nvram_getvar("opib-hide-menu"); const char* sDefaultOS = nvram_getvar("opib-default-os"); const char* sTempOS = nvram_getvar("opib-temp-os"); if(sDefaultOS) defaultOS = parseNumber(sDefaultOS); if(sTempOS) tempOS = parseNumber(sTempOS); if(tempOS!=defaultOS) { switch (tempOS) { case 0: framebuffer_clear(); bufferPrintf("Loading iOS..."); reset_tempos(sDefaultOS); Image* image = images_get(fourcc("ibox")); if(image == NULL) image = images_get(fourcc("ibot")); void* imageData; images_read(image, &imageData); chainload((uint32_t)imageData); break; case 1: framebuffer_clear(); bufferPrintf("Loading iDroid..."); reset_tempos(sDefaultOS); #ifndef NO_HFS #ifndef CONFIG_IPOD radio_setup(); #endif nand_setup(); fs_setup(); if(globalFtlHasBeenRestored) { if(ftl_sync()) { bufferPrintf("ftl synced successfully"); } else { bufferPrintf("error syncing ftl"); } } pmu_set_iboot_stage(0); startScripting("linux"); //start script mode if there is a script file boot_linux_from_files(); #endif break; case 2: framebuffer_clear(); bufferPrintf("Loading Console..."); reset_tempos(sDefaultOS); hideMenu = "1"; break; } } else if(hideMenu && (strcmp(hideMenu, "1") == 0 || strcmp(hideMenu, "true") == 0)) { bufferPrintf("Boot menu hidden. Use 'setenv opib-hide-menu false' and then 'saveenv' to unhide.\r\n"); } else { framebuffer_setdisplaytext(FALSE); isMultitouchLoaded = load_multitouch_images(); framebuffer_clear(); const char* sMenuTimeout = nvram_getvar("opib-menu-timeout"); int menuTimeout = -1; if(sMenuTimeout) menuTimeout = parseNumber(sMenuTimeout); menu_setup(menuTimeout, defaultOS); } #endif #endif #endif //OPENIBOOT_INSTALLER startUSB(); #ifndef CONFIG_IPOD camera_setup(); radio_setup(); #endif sdio_setup(); wlan_setup(); accel_setup(); #ifndef CONFIG_IPOD als_setup(); #endif nand_setup(); #ifndef NO_HFS fs_setup(); #endif pmu_set_iboot_stage(0); startScripting("openiboot"); //start script mode if there is a file bufferPrintf("version: %s\r\n", OPENIBOOT_VERSION_STR); bufferPrintf("-----------------------------------------------\r\n"); bufferPrintf(" WELCOME TO OPENIBOOT\r\n"); bufferPrintf("-----------------------------------------------\r\n"); DebugPrintf(" DEBUG MODE\r\n"); audiohw_postinit(); setReady(TRUE); // Process command queue while(TRUE) { char* command = NULL; CommandQueue* cur; EnterCriticalSection(); if(commandQueue != NULL) { cur = commandQueue; command = cur->command; commandQueue = commandQueue->next; free(cur); } LeaveCriticalSection(); if(command) { setReady(FALSE); processCommand(command); setReady(TRUE); free(command); } } // should not reach here }
void OpenIBootStart() { setup_openiboot(); pmu_charge_settings(TRUE, FALSE, FALSE); framebuffer_setdisplaytext(TRUE); framebuffer_clear(); #ifndef SMALL #ifndef NO_STBIMAGE const char* hideMenu = nvram_getvar("opib-hide-menu"); if(hideMenu && (strcmp(hideMenu, "1") == 0 || strcmp(hideMenu, "true") == 0)) { bufferPrintf("Boot menu hidden. Use 'setenv opib-hide-menu false' and then 'saveenv' to unhide.\r\n"); } else { framebuffer_setdisplaytext(FALSE); const char* sMenuTimeout = nvram_getvar("opib-menu-timeout"); int menuTimeout = -1; if(sMenuTimeout) menuTimeout = parseNumber(sMenuTimeout); menu_setup(menuTimeout); } #endif #endif startUSB(); radio_setup(); sdio_setup(); wlan_setup(); accel_setup(); als_setup(); nand_setup(); #ifndef NO_HFS fs_setup(); #endif pmu_set_iboot_stage(0); startScripting("openiboot"); //start script mode if there is a file bufferPrintf("-----------------------------------------------\r\n"); bufferPrintf(" WELCOME TO OPENIBOOT\r\n"); bufferPrintf("-----------------------------------------------\r\n"); DebugPrintf(" DEBUG MODE\r\n"); audiohw_postinit(); // Process command queue while(TRUE) { char* command = NULL; CommandQueue* cur; EnterCriticalSection(); if(commandQueue != NULL) { cur = commandQueue; command = cur->command; commandQueue = commandQueue->next; free(cur); } LeaveCriticalSection(); if(command) { processCommand(command); free(command); } } // should not reach here }
void OpenIBootStart() { setup_openiboot(); framebuffer_hook(); framebuffer_setdisplaytext(TRUE); #ifndef CONFIG_IPHONE_4 pmu_charge_settings(TRUE, FALSE, FALSE); framebuffer_setdisplaytext(TRUE); framebuffer_clear(); bufferPrintf("Loading openiBoot..."); #ifndef SMALL #ifndef NO_STBIMAGE int defaultOS = 0; int tempOS = 0; const char* hideMenu = nvram_getvar("opib-hide-menu"); const char* sDefaultOS = nvram_getvar("opib-default-os"); const char* sTempOS = nvram_getvar("opib-temp-os"); if(sDefaultOS) defaultOS = parseNumber(sDefaultOS); if(sTempOS) tempOS = parseNumber(sTempOS); if(tempOS!=defaultOS) { switch (tempOS) { case 0: framebuffer_clear(); bufferPrintf("Loading iOS..."); reset_tempos(sDefaultOS); Image* image = images_get(fourcc("ibox")); if(image == NULL) image = images_get(fourcc("ibot")); void* imageData; images_read(image, &imageData); chainload((uint32_t)imageData); break; case 1: framebuffer_clear(); bufferPrintf("Loading iDroid..."); reset_tempos(sDefaultOS); #ifndef NO_HFS #ifndef CONFIG_IPOD radio_setup(); #endif nand_setup(); fs_setup(); if(globalFtlHasBeenRestored) { if(ftl_sync()) { bufferPrintf("ftl synced successfully"); } else { bufferPrintf("error syncing ftl"); } } pmu_set_iboot_stage(0); startScripting("linux"); //start script mode if there is a script file boot_linux_from_files(); #endif break; case 2: framebuffer_clear(); bufferPrintf("Loading Console..."); reset_tempos(sDefaultOS); hideMenu = "1"; break; } } else if(hideMenu && (strcmp(hideMenu, "1") == 0 || strcmp(hideMenu, "true") == 0)) { bufferPrintf("Boot menu hidden. Use 'setenv opib-hide-menu false' and then 'saveenv' to unhide.\r\n"); } else { framebuffer_setdisplaytext(FALSE); isMultitouchLoaded = load_multitouch_images(); framebuffer_clear(); const char* sMenuTimeout = nvram_getvar("opib-menu-timeout"); int menuTimeout = -1; if(sMenuTimeout) menuTimeout = parseNumber(sMenuTimeout); menu_setup(menuTimeout, defaultOS); } #endif #endif #endif #ifndef CONFIG_IPAD startUSB(); #endif #ifndef CONFIG_IPHONE_4 #ifndef CONFIG_IPOD camera_setup(); radio_setup(); #endif sdio_setup(); wlan_setup(); accel_setup(); #ifndef CONFIG_IPOD als_setup(); #endif nand_setup(); #ifndef NO_HFS fs_setup(); #endif pmu_set_iboot_stage(0); startScripting("openiboot"); //start script mode if there is a file #endif bufferPrintf(" ___ _ ____ _ \r\n"); bufferPrintf(" / _ \\ _ __ ___ _ __ (_) __ ) ___ ___ | |_ \r\n"); bufferPrintf("| | | | '_ \\ / _ \\ '_ \\| | _ \\ / _ \\ / _ \\| __|\r\n"); bufferPrintf("| |_| | |_) | __/ | | | | |_) | (_) | (_) | |_ \r\n"); bufferPrintf(" \\___/| .__/ \\___|_| |_|_|____/ \\___/ \\___/ \\__|\r\n"); bufferPrintf(" |_| \r\n"); bufferPrintf("\r\n"); bufferPrintf("version: %s\r\n", OPENIBOOT_VERSION_STR); DebugPrintf(" DEBUG MODE\r\n"); #ifndef CONFIG_IPHONE_4 audiohw_postinit(); #endif // Process command queue while(TRUE) { char* command = NULL; CommandQueue* cur; EnterCriticalSection(); if(commandQueue != NULL) { cur = commandQueue; command = cur->command; commandQueue = commandQueue->next; free(cur); } LeaveCriticalSection(); if(command) { processCommand(command); free(command); } } // should not reach here }
void OpenIBootStart() { setup_openiboot(); pmu_charge_settings(TRUE, FALSE, FALSE); framebuffer_setdisplaytext(TRUE); framebuffer_clear(); //enable multitouch before displaying menu, only 3g first framebuffer_setdisplaytext(FALSE); nand_setup(); fs_setup(); int size; size = fs_extract(1, "/firmware/zephyr2.bin", (void*) 0x09000000); if(size < 0) { bufferPrintf("Cannot find zephyr bin.\r\n"); return; } multitouch_setup((uint8_t*) 0x09000000, size); #ifndef SMALL #ifndef NO_STBIMAGE const char* hideMenu = nvram_getvar("opib-hide-menu"); if(hideMenu && (strcmp(hideMenu, "1") == 0 || strcmp(hideMenu, "true") == 0)) { bufferPrintf("Boot menu hidden. Use 'setenv opib-hide-menu false' and then 'saveenv' to unhide.\r\n"); } else { framebuffer_setdisplaytext(FALSE); const char* sMenuTimeout = nvram_getvar("opib-menu-timeout"); int menuTimeout = -1; if(sMenuTimeout) menuTimeout = parseNumber(sMenuTimeout); menu_setup(menuTimeout); } #endif #endif startUSB(); #ifndef CONFIG_IPOD camera_setup(); radio_setup(); #endif sdio_setup(); wlan_setup(); accel_setup(); #ifndef CONFIG_IPOD als_setup(); #endif nand_setup(); #ifndef NO_HFS fs_setup(); #endif pmu_set_iboot_stage(0); startScripting("openiboot"); //start script mode if there is a file bufferPrintf("version: %s\r\n", OPENIBOOT_VERSION_STR); bufferPrintf("-----------------------------------------------\r\n"); bufferPrintf(" WELCOME TO OPENIBOOT\r\n"); bufferPrintf("-----------------------------------------------\r\n"); DebugPrintf(" DEBUG MODE\r\n"); audiohw_postinit(); // Process command queue while(TRUE) { char* command = NULL; CommandQueue* cur; EnterCriticalSection(); if(commandQueue != NULL) { cur = commandQueue; command = cur->command; commandQueue = commandQueue->next; free(cur); } LeaveCriticalSection(); if(command) { processCommand(command); free(command); } } // should not reach here }
void images_install(void* newData, size_t newDataLen, uint32_t newFourcc, uint32_t replaceFourcc) { ImageDataList* list = NULL; ImageDataList* cur = NULL; ImageDataList* toReplace = NULL; ImageDataList* verify = NULL; int isReplace = (replaceFourcc != newFourcc) ? TRUE : FALSE; int isUpgrade = FALSE; Image* curImage = imageList; while(curImage != NULL) { if(cur == NULL) { list = cur = verify = malloc(sizeof(ImageDataList)); } else { cur->next = malloc(sizeof(ImageDataList)); cur = cur->next; } bufferPrintf("Reading: "); print_fourcc(curImage->type); bufferPrintf(" (%d bytes)\r\n", curImage->padded); cur->type = curImage->type; cur->next = NULL; cur->data = malloc(curImage->padded); nor_read(cur->data, curImage->offset, curImage->padded); if(isReplace && cur->type == replaceFourcc) { isUpgrade = TRUE; } else if(cur->type == newFourcc) { toReplace = cur; } curImage = curImage->next; } if(!isUpgrade) { bufferPrintf("Performing installation... (%d bytes)\r\n", newDataLen); ImageDataList* ibox = malloc(sizeof(ImageDataList)); ibox->type = replaceFourcc; ibox->data = toReplace->data; ibox->next = toReplace->next; toReplace->next = ibox; toReplace->data = images_inject_img3(toReplace->data, newData, newDataLen); images_change_type(ibox->data, ibox->type); } else { bufferPrintf("Performing upgrade... (%d bytes)\r\n", newDataLen); void* newIBoot = images_inject_img3(toReplace->data, newData, newDataLen); free(toReplace->data); toReplace->data = newIBoot; } //check for size and availability size_t newPaddedDataLen=0; size_t totalBytes=0; //if somebody can find how to get padded length for new ibot maybe this loop not needed while(verify != NULL) { cur = verify; verify = verify->next; AppleImg3RootHeader* header = (AppleImg3RootHeader*) cur->data; totalBytes += header->base.size; if(cur->type == newFourcc) { newPaddedDataLen = header->base.size; } } bufferPrintf("Total size to be written %d\r\n",totalBytes); if((ImagesStart + totalBytes) >= 0xfc000) { bufferPrintf("**ABORTED** Writing total image size: 0x%x, new ibot size: 0x%x at 0x%x would overflow NOR!\r\n", totalBytes, newPaddedDataLen,ImagesStart); images_rewind(); images_release(); images_setup(); return; } bufferPrintf("Flashing...\r\n"); images_rewind(); while(list != NULL) { cur = list; list = list->next; AppleImg3RootHeader* header = (AppleImg3RootHeader*) cur->data; bufferPrintf("Flashing: "); print_fourcc(cur->type); bufferPrintf(" (%x, %d bytes)\r\n", cur->data, header->base.size); images_append(cur->data, header->base.size); free(cur->data); free(cur); } bufferPrintf("Flashing Complete, Free space after flashing %d\r\n",0xfc000-MaxOffset); images_release(); images_setup(); bufferPrintf("Configuring openiBoot settings...\r\n"); Volume* volume; io_func* io; io = bdev_open(0); volume = openVolume(io); char buffer [sizeof(XSTRINGIFY(OPENIBOOT_VERSION))]; strcpy(buffer, XSTRINGIFY(OPENIBOOT_VERSION)); add_hfs(volume, (uint8_t*)buffer, sizeof(buffer), "/openiboot"); closeVolume(volume); CLOSE(io); ftl_sync(); if(!nvram_getvar("opib-temp-os")) { nvram_setvar("opib-temp-os", "0"); } if(!nvram_getvar("opib-default-os")) { nvram_setvar("opib-default-os", "1"); } if(!nvram_getvar("opib-menu-timeout")) { nvram_setvar("opib-menu-timeout", "10000"); } nvram_save(); bufferPrintf("openiBoot installation complete.\r\n"); }
void startScripting(char* loadedFrom) { uint32_t size = 0; uint8_t* address = NULL; const char* partitionScript = nvram_getvar("partition-script"); /*get the partition where the script is in NVRAM*/ const char* fileScript = nvram_getvar("file-script"); /*get the path to the file script in NVRAM*/ const char* scriptingLinux = nvram_getvar("scripting-linux"); /*tells whether to run the script before booting linux. Accepted values : true or 1, anything else if false*/ const char* scriptingOpeniboot = nvram_getvar("scripting-openiboot"); /*tells whether to run the script before launching openiboot console. Accepted values : true or 1, anything else if false*/ //uint32_t numberOfLines = 1; /*number of lines in the script files - To be used with the next commented section of code for debug*/ //bufferPrintf("partition-script %s\r\n",partitionScript); /*For debug*/ //bufferPrintf("file-script %s\r\n",fileScript); /*For debug*/ if(!partitionScript) return; if(!fileScript) return; /* ------ extracting the script file at address 0x09000000 ----- */ if(strcmp(loadedFrom, "linux") == 0) { if(!scriptingLinux || (strcmp(scriptingLinux, "true") != 0 && strcmp(scriptingLinux, "1") != 0)) { return; /* terminate the function if scripting is not asked*/ } } if(strcmp(loadedFrom, "openiboot") == 0) { if(!scriptingOpeniboot || (strcmp(scriptingOpeniboot, "true") != 0 && strcmp(scriptingOpeniboot, "1") != 0)) { return; /* terminate the function if scripting is not asked*/ } } Volume* volume; io_func* io; io = bdev_open(parseNumber(partitionScript)); if(io == NULL) { bufferPrintf("fs: cannot read partition!\r\n"); return; } volume = openVolume(io); if(volume == NULL) { bufferPrintf("fs: cannot openHFS volume!\r\n"); return; } HFSPlusCatalogRecord* record; char* name; record = getRecordFromPath(fileScript, volume, &name, NULL); if(record != NULL) { if(record->recordType == kHFSPlusFolderRecord) { bufferPrintf("this path is a folder, not a file\r\n"); return; } else { size = readHFSFile((HFSPlusCatalogFile*)record, &address, volume); if(!address) return; //bufferPrintf("size = %d\r\n",size); /*size of script file, used later*/ } } else { bufferPrintf("No such file or directory\r\n"); return; } closeVolume(volume); CLOSE(io); char* addrBOF = (char*) address; /* pointer on the begening of the file*/ char* addrEOF = (char*) (address + size); /*pointer 1 byte after the file */ char* addr; /*pointer on the current space on memory*/ #if 0 //addrEOF = (void*)address+size+1; /* ----- counting how many lines are present in the script file by the '\n' ----- */ addr = addrBOF; while(addr < addrEOF) { if(*addr=='\r'){ numberOfLines++; } addr++; } bufferPrintf("number of lines : %d\r\n", numberOfLines); #endif char* bufferLine = malloc(100); /* ----- extracting each line to the buffer -----*/ addr = addrBOF; while(addr < addrEOF) { int charAt = 0; while((*addr != '\n') && (addr < addrEOF)) { if(*addr != '\r') { bufferLine[charAt] = *addr; //bufferPrintf("reading char : %c\r\n",*addr); charAt++; } addr++; } bufferLine[charAt]='\0'; bufferPrintf("\r\n%s\r\n", bufferLine); bufferLine[charAt]='\n'; bufferLine[charAt + 1] = '\0'; if(scriptCommand(bufferLine)) { //bufferPrintf("command sent\r\n"); } /*else { //error in command, function scriptCommand returned false }*/ addr++; } free(bufferLine); free(address); }