int
main(int argc, char **argv) {
	if (strcmp(basename(argv[0]), "recovery") != 0)
	{
	    if (strstr(argv[0], "flash_image") != NULL)
	        return flash_image_main(argc, argv);
	    if (strstr(argv[0], "volume") != NULL)
	        return volume_main(argc, argv);
	    if (strstr(argv[0], "edify") != NULL)
	        return edify_main(argc, argv);
	    if (strstr(argv[0], "dump_image") != NULL)
	        return dump_image_main(argc, argv);
	    if (strstr(argv[0], "erase_image") != NULL)
	        return erase_image_main(argc, argv);
	    if (strstr(argv[0], "mkyaffs2image") != NULL)
	        return mkyaffs2image_main(argc, argv);
	    if (strstr(argv[0], "unyaffs") != NULL)
	        return unyaffs_main(argc, argv);
        if (strstr(argv[0], "nandroid"))
            return nandroid_main(argc, argv);
        if (strstr(argv[0], "reboot"))
            return reboot_main(argc, argv);
#ifdef BOARD_RECOVERY_HANDLES_MOUNT
        if (strstr(argv[0], "mount") && argc == 2 && !strstr(argv[0], "umount"))
        {
            load_volume_table();
            return ensure_path_mounted(argv[1]);
        }
#endif
        if (strstr(argv[0], "poweroff")){
            return reboot_main(argc, argv);
        }
        if (strstr(argv[0], "setprop"))
            return setprop_main(argc, argv);
		return busybox_driver(argc, argv);
	}
    __system("/sbin/postrecoveryboot.sh");

    int is_user_initiated_recovery = 0;
    time_t start = time(NULL);

    // If these fail, there's not really anywhere to complain...
    freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
    freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);
    printf("Starting recovery on %s", ctime(&start));

    ui_init();
    ui_print(EXPAND(RECOVERY_VERSION)"\n");
    load_volume_table();
    process_volumes();
    LOGI("Processing arguments.\n");
    get_args(&argc, &argv);

    int previous_runs = 0;
    const char *send_intent = NULL;
    const char *update_package = NULL;
    const char *encrypted_fs_mode = NULL;
    int wipe_data = 0, wipe_cache = 0;
    int toggle_secure_fs = 0;
    encrypted_fs_info encrypted_fs_data;

    LOGI("Checking arguments.\n");
    int arg;
    while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
        switch (arg) {
        case 'p': previous_runs = atoi(optarg); break;
        case 's': send_intent = optarg; break;
        case 'u': update_package = optarg; break;
        case 'w': 
#ifndef BOARD_RECOVERY_ALWAYS_WIPES
		wipe_data = wipe_cache = 1;
#endif
		break;
        case 'c': wipe_cache = 1; break;
        case 'e': encrypted_fs_mode = optarg; toggle_secure_fs = 1; break;
        case 't': ui_show_text(1); break;
        case '?':
            LOGE("Invalid command argument\n");
            continue;
        }
    }

    LOGI("device_recovery_start()\n");
    device_recovery_start();

    printf("Command:");
    for (arg = 0; arg < argc; arg++) {
        printf(" \"%s\"", argv[arg]);
    }
    printf("\n");

    if (update_package) {
        // For backwards compatibility on the cache partition only, if
        // we're given an old 'root' path "CACHE:foo", change it to
        // "/cache/foo".
        if (strncmp(update_package, "CACHE:", 6) == 0) {
            int len = strlen(update_package) + 10;
            char* modified_path = malloc(len);
            strlcpy(modified_path, "/cache/", len);
            strlcat(modified_path, update_package+6, len);
            printf("(replacing path \"%s\" with \"%s\")\n",
                   update_package, modified_path);
            update_package = modified_path;
        }
    }
    printf("\n");

    property_list(print_property, NULL);
    printf("\n");

    int status = INSTALL_SUCCESS;
    
    if (toggle_secure_fs) {
        if (strcmp(encrypted_fs_mode,"on") == 0) {
            encrypted_fs_data.mode = MODE_ENCRYPTED_FS_ENABLED;
            ui_print("Enabling Encrypted FS.\n");
        } else if (strcmp(encrypted_fs_mode,"off") == 0) {
            encrypted_fs_data.mode = MODE_ENCRYPTED_FS_DISABLED;
            ui_print("Disabling Encrypted FS.\n");
        } else {
            ui_print("Error: invalid Encrypted FS setting.\n");
            status = INSTALL_ERROR;
        }

        // Recovery strategy: if the data partition is damaged, disable encrypted file systems.
        // This preventsthe device recycling endlessly in recovery mode.
        if ((encrypted_fs_data.mode == MODE_ENCRYPTED_FS_ENABLED) &&
                (read_encrypted_fs_info(&encrypted_fs_data))) {
            ui_print("Encrypted FS change aborted, resetting to disabled state.\n");
            encrypted_fs_data.mode = MODE_ENCRYPTED_FS_DISABLED;
        }

        if (status != INSTALL_ERROR) {
            if (erase_volume("/data")) {
                ui_print("Data wipe failed.\n");
                status = INSTALL_ERROR;
            } else if (erase_volume("/cache")) {
                ui_print("Cache wipe failed.\n");
                status = INSTALL_ERROR;
            } else if ((encrypted_fs_data.mode == MODE_ENCRYPTED_FS_ENABLED) &&
                      (restore_encrypted_fs_info(&encrypted_fs_data))) {
                ui_print("Encrypted FS change aborted.\n");
                status = INSTALL_ERROR;
            } else {
                ui_print("Successfully updated Encrypted FS.\n");
                status = INSTALL_SUCCESS;
            }
        }
    } else if (update_package != NULL) {
        status = install_package(update_package);
        if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n");
    } else if (wipe_data) {
        if (device_wipe_data()) status = INSTALL_ERROR;
        if (erase_volume("/data")) status = INSTALL_ERROR;
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n");
    } else if (wipe_cache) {
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n");
    } else {
        LOGI("Checking for extendedcommand...\n");
        status = INSTALL_ERROR;  // No command specified
        // we are starting up in user initiated recovery here
        // let's set up some default options
        signature_check_enabled = 0;
        script_assert_enabled = 0;
        is_user_initiated_recovery = 1;
        ui_set_show_text(1);
        ui_set_background(BACKGROUND_ICON_CLOCKWORK);
        
        if (extendedcommand_file_exists()) {
            LOGI("Running extendedcommand...\n");
            int ret;
            if (0 == (ret = run_and_remove_extendedcommand())) {
                status = INSTALL_SUCCESS;
                ui_set_show_text(0);
            }
            else {
                handle_failure(ret);
            }
        } else {
            LOGI("Skipping execution of extendedcommand, file not found...\n");
        }
    }

    if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) {
        ui_set_show_text(1);
        ui_set_background(BACKGROUND_ICON_ERROR);
    }
    if (status != INSTALL_SUCCESS || ui_text_visible()) {
        prompt_and_wait();
    }

    // If there is a radio image pending, reboot now to install it.
    maybe_install_firmware_update(send_intent);

    // Otherwise, get ready to boot the main system...
    finish_recovery(send_intent);
    if(!poweroff)
        ui_print("Rebooting...\n");
    else
        ui_print("Shutting down...\n");
    sync();
    reboot((!poweroff) ? RB_AUTOBOOT : RB_POWER_OFF);
    return EXIT_SUCCESS;
}
Beispiel #2
0
int
main(int argc, char **argv) {
    time_t start = time(NULL);

    // If these fail, there's not really anywhere to complain...
    freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
    freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);
    printf("Starting recovery on %s", ctime(&start));

    ui_init();
    ui_set_background(BACKGROUND_ICON_INSTALLING);
    load_volume_table();
    get_args(&argc, &argv);

    int previous_runs = 0;
    const char *send_intent = NULL;
    const char *update_package = NULL;
    const char *encrypted_fs_mode = NULL;
    int wipe_data = 0, wipe_cache = 0;
    int toggle_secure_fs = 0;
    encrypted_fs_info encrypted_fs_data;

    int arg;
    while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
        switch (arg) {
        case 'p': previous_runs = atoi(optarg); break;
        case 's': send_intent = optarg; break;
        case 'u': update_package = optarg; break;
        case 'w': wipe_data = wipe_cache = 1; break;
        case 'c': wipe_cache = 1; break;
        case 'e': encrypted_fs_mode = optarg; toggle_secure_fs = 1; break;
        case 't': ui_show_text(1); break;
        case '?':
            LOGE("Invalid command argument\n");
            continue;
        }
    }

    device_recovery_start();

    printf("Command:");
    for (arg = 0; arg < argc; arg++) {
        printf(" \"%s\"", argv[arg]);
    }
    printf("\n");

    if (update_package) {
        // For backwards compatibility on the cache partition only, if
        // we're given an old 'root' path "CACHE:foo", change it to
        // "/cache/foo".
        if (strncmp(update_package, "CACHE:", 6) == 0) {
            int len = strlen(update_package) + 10;
            char* modified_path = malloc(len);
            strlcpy(modified_path, "/cache/", len);
            strlcat(modified_path, update_package+6, len);
            printf("(replacing path \"%s\" with \"%s\")\n",
                   update_package, modified_path);
            update_package = modified_path;
        }
    }
    printf("\n");

    property_list(print_property, NULL);
    printf("\n");

    int status = INSTALL_SUCCESS;

    if (toggle_secure_fs) {
        if (strcmp(encrypted_fs_mode,"on") == 0) {
            encrypted_fs_data.mode = MODE_ENCRYPTED_FS_ENABLED;
            ui_print("Enabling Encrypted FS.\n");
        } else if (strcmp(encrypted_fs_mode,"off") == 0) {
            encrypted_fs_data.mode = MODE_ENCRYPTED_FS_DISABLED;
            ui_print("Disabling Encrypted FS.\n");
        } else {
            ui_print("Error: invalid Encrypted FS setting.\n");
            status = INSTALL_ERROR;
        }

        // Recovery strategy: if the data partition is damaged, disable encrypted file systems.
        // This preventsthe device recycling endlessly in recovery mode.
        if ((encrypted_fs_data.mode == MODE_ENCRYPTED_FS_ENABLED) &&
                (read_encrypted_fs_info(&encrypted_fs_data))) {
            ui_print("Encrypted FS change aborted, resetting to disabled state.\n");
            encrypted_fs_data.mode = MODE_ENCRYPTED_FS_DISABLED;
        }

        if (status != INSTALL_ERROR) {
            if (erase_volume("/data")) {
                ui_print("Data wipe failed.\n");
                status = INSTALL_ERROR;
            } else if (erase_volume("/cache")) {
                ui_print("Cache wipe failed.\n");
                status = INSTALL_ERROR;
            } else if ((encrypted_fs_data.mode == MODE_ENCRYPTED_FS_ENABLED) &&
                      (restore_encrypted_fs_info(&encrypted_fs_data))) {
                ui_print("Encrypted FS change aborted.\n");
                status = INSTALL_ERROR;
            } else {
                ui_print("Successfully updated Encrypted FS.\n");
                status = INSTALL_SUCCESS;
            }
        }
    } else if (update_package != NULL) {
        status = install_package(update_package);
        if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n");
    } else if (wipe_data) {
        if (device_wipe_data()) status = INSTALL_ERROR;
        if (erase_volume("/data")) status = INSTALL_ERROR;
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n");
    } else if (wipe_cache) {
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) ui_print("Cache wipe failed.\n");
    } else {
        status = INSTALL_ERROR;  // No command specified
    }

    if (status != INSTALL_SUCCESS) ui_set_background(BACKGROUND_ICON_ERROR);
    if (status != INSTALL_SUCCESS || ui_text_visible()) {
        //assume we want to be here and its not an error - give us the pretty icon!
        ui_set_background(BACKGROUND_ICON_MAIN);
        prompt_and_wait();
    }

    // Otherwise, get ready to boot the main system...
    finish_recovery(send_intent);
    ui_print("Rebooting...\n");
    sync();
    reboot(RB_AUTOBOOT);
    return EXIT_SUCCESS;
}
Beispiel #3
0
int
main(int argc, char **argv) {
//    while(1);
	time_t start = time(NULL);
	// If these fail, there's not really anywhere to complain...
	freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
	freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);
	//    printf("Starting recovery on %s", ctime(&start));
//	printf("............just for aibing debug \n\r");
//	while(1);
	ui_init();
	//    ui_set_background(BACKGROUND_ICON_INSTALLING);
	load_volume_table();
	get_args(&argc, &argv);

	int previous_runs = 0;
	const char *send_intent = NULL;
	const char *update_package = NULL;
	const char *encrypted_fs_mode = NULL;
	int wipe_data = 0, wipe_cache = 0;
	int toggle_secure_fs = 0;
	encrypted_fs_info encrypted_fs_data; 
	int arg;
	while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
		switch (arg) {
			case 'p': previous_runs = atoi(optarg); break;
			case 's': send_intent = optarg; break;
			case 'u': update_package = optarg; break;
			case 'w': wipe_data = wipe_cache = 1; break;
			case 'c': wipe_cache = 1; break;
			case 'e': encrypted_fs_mode = optarg; toggle_secure_fs = 1; break;
			case 't': ui_show_text(1); break;
			case '?':
				  LOGE("Invalid command argument\n");
				  continue;
		}
	}
	//reinit wipe_data and wipe_cache as it will do in clean boot;
	wipe_data = wipe_cache = 0;

	device_recovery_start();

	printf("Aibing test Command:");
	for (arg = 0; arg < argc; arg++) {
		printf(" \"%s\"", argv[arg]);
	}
	printf("\n");
	if (update_package) {
		printf("in update_package run?????\n");
		// For backwards compatibility on the cache partition only, if
		// we're given an old 'root' path "CACHE:foo", change it to
		// "/cache/foo".
		if (strncmp(update_package, "CACHE:", 6) == 0) {
			int len = strlen(update_package) + 10;
			char* modified_path = malloc(len);
			strlcpy(modified_path, "/cache/", len);
			strlcat(modified_path, update_package+6, len);
			printf("(replacing path \"%s\" with \"%s\")\n",
					update_package, modified_path);
			update_package = modified_path;
		}
	}
	printf("list start\n");

	property_list(print_property, NULL);
	printf("list end\n");

	int status = INSTALL_SUCCESS;
	int mcu_status = INSTALL_SUCCESS;
	int mpeg_status = INSTALL_SUCCESS;
	int overridekey_status = INSTALL_SUCCESS;
	int tractor_prop_status = INSTALL_SUCCESS;
	int radio_status = INSTALL_SUCCESS;
	if (toggle_secure_fs) {
		if (strcmp(encrypted_fs_mode,"on") == 0) {
			encrypted_fs_data.mode = MODE_ENCRYPTED_FS_ENABLED;
			printf("Enabling Encrypted FS.\n");
		} else if (strcmp(encrypted_fs_mode,"off") == 0) {
			encrypted_fs_data.mode = MODE_ENCRYPTED_FS_DISABLED;
			printf("Disabling Encrypted FS.\n");
		} else {
			printf("Error: invalid Encrypted FS setting.\n");
			status = INSTALL_ERROR;
		}

		// Recovery strategy: if the data partition is damaged, disable encrypted file systems.
		// This preventsthe device recycling endlessly in recovery mode.
		if ((encrypted_fs_data.mode == MODE_ENCRYPTED_FS_ENABLED) &&
				(read_encrypted_fs_info(&encrypted_fs_data))) {
			printf("Encrypted FS change aborted, resetting to disabled state.\n");
			encrypted_fs_data.mode = MODE_ENCRYPTED_FS_DISABLED;
		}

		if (status != INSTALL_ERROR) {
			if (erase_volume("/data")) {
				printf("Data wipe failed.\n");
				status = INSTALL_ERROR;
			} else if (erase_volume("/cache")) {
				printf("Cache wipe failed.\n");
				status = INSTALL_ERROR;
			} else if ((encrypted_fs_data.mode == MODE_ENCRYPTED_FS_ENABLED) &&
					(restore_encrypted_fs_info(&encrypted_fs_data))) {
				printf("Encrypted FS change aborted.\n");
				status = INSTALL_ERROR;
			} else {
				printf("Successfully updated Encrypted FS.\n");
				status = INSTALL_SUCCESS;
			}
		}
	} else if (update_package != NULL) {
		status = install_package(update_package);
		if (status != INSTALL_SUCCESS) printf("Installation aborted.\n");
	} else if (wipe_data) {
		if (device_wipe_data()) status = INSTALL_ERROR;
		if (erase_volume("/data")) status = INSTALL_ERROR;
		if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
		if (status != INSTALL_SUCCESS) printf("Data wipe failed.\n");
	} else if (wipe_cache) {
		if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
		if (status != INSTALL_SUCCESS) printf("Cache wipe failed.\n");
	} else {
		status = INSTALL_ERROR;  // No command specified
	}
	
	printf("Recovery svn version:%d, Compile Time: %s %s\n", 
			SVN_VERSION,__DATE__,  __TIME__);
	sprintf(version_buf, "Recovery svn version:%d, Compile Time: %s %s", 
			SVN_VERSION,__TIME__, __DATE__);
	
	int fd = 0;
	fd = open("/dev/recovery",O_RDWR | O_CREAT | O_TRUNC);
	if(fd < 0) {
		printf("open recovery devices error\n");
		return EXIT_SUCCESS;
	} 
	
	int recovery_mode = 0;
	ioctl(fd, RECOVERY_GET_VAL, &recovery_mode);
//	recovery_mode = UPDATE_SYSTEM;

	/*	test_functions()  */
	//remove_logo_config_file();

	if(recovery_mode == CLEAN_MODE) {
		ui_set_cleanboot_background();
		ui_set_cleanboot_system();
		clean_boot();
		while(system_cleanboot_end == 0) {
			//printf("waiting thread is end");
			usleep(50000);
		}
		sync();
		ui_set_cleanboot_succ();
		sleep(3);
		close_backlight();
		reboot(RB_AUTOBOOT);
		printf("reboot end, it should never been output\n");
	} else if (recovery_mode == UPDATE_RECOVERY){
		ui_set_prepare_background();
		sleep(1);
		burning_recovery_image();
	} else if (recovery_mode == UPDATE_SYSTEM  || recovery_mode == BACKUP_MODE){
		ui_set_burning_background(BURNING_MISC_UPDATING);
		sleep(1);
		overridekey_status = update_overridekey();
		tractor_prop_status = update_tractorprop();
		radio_status = update_radioCFG();
		mpeg_status = mpeg_update();
		update_status &= ~(0x03 << 2);
		update_status |= mpeg_status << 2;
		ui_set_burning_reflesh(update_status);
		sleep(1);
		printf("mcu_start\n");
		mcu_status = mcu_update();		
		update_status &= ~(0x03 << 4);
		update_status |= (mcu_status << 4);
		ui_set_burning_reflesh(update_status);
		sleep(1);
		if(status == INSTALL_ERROR){
			printf("++check auto Burning update.zip in data tractor...\n");
			status = device_burn_data_if_exist();
			if(status == INSTALL_SUCCESS) {
				//burning_recovery_image();
			}
			ui_set_burning_status();
			printf("--check auto Burning update.zip in data tractor: %d\n", status);	 
			update_status &= ~(0x03);
			update_status |= status;
		}
		ui_set_burning_reflesh(update_status);
		sleep(3);
/*		
		if ( (mcu_status == INSTALL_SUCCESS) ||
				(status == INSTALL_SUCCESS)  || 
				(mpeg_status == INSTALL_SUCCESS)||
				(overridekey_status == INSTALL_SUCCESS)) {
			if (set_skip() == INSTALL_ERROR) {
				ui_set_burning_background(BURNING_RESULT_FAILURE);
				sleep(3);
				mcu_reset_cpu();
				return EXIT_FAILURE;
			}
		}
*/
		printf("end \n");
		if ( (status != INSTALL_SUCCESS) && 
				(mcu_status != INSTALL_SUCCESS) &&
				(mpeg_status != INSTALL_SUCCESS) && 
				(overridekey_status != INSTALL_SUCCESS)&& 
				(radio_status != INSTALL_SUCCESS)) {
			ui_set_burning_background(BURNING_RESULT_FAILURE);
			sleep(3);
			mcu_reset_cpu();
			return EXIT_FAILURE;
		}
		sync();
		ui_set_burning_background(BURNING_RESULT_SUCCESS);
		sleep(3);
		//while mcu is burning,  the mcu need to restart and reset the main cpu. 
		if (mcu_status == INSTALL_SUCCESS) {
			mcu_reset_cpu();
		} else {
			close_backlight();
			reboot(RB_AUTOBOOT);
		}
	}while(0);
	return EXIT_SUCCESS;
}