예제 #1
0
static void show_multi_test_result(void)
{
	int ret = RL_NA;
	int row = 3;
	char tmp[128];
	char* rl_str;
	int i,j;
	menu_info* ptest=multi_test_item;
	menu_info* pmenu = menu_auto_test;
	ui_fill_locked();
	ui_show_title(MENU_MULTI_TEST);
	gr_flip();

	for(i = 0; i < MULTI_TEST_CNT; i++) {
		ret = ptest[i].func();
		if(ret == RL_PASS) {
			ui_set_color(CL_GREEN);
			rl_str = TEXT_PASS;
		} else {
			ui_set_color(CL_RED);
			rl_str = TEXT_FAIL;
		}
		memset(tmp, 0, sizeof(tmp));
		for(j=0;i<CASE_NUM;j++){
			if(ptest[i].num==pmenu[j].num)
				break;
		}
		sprintf(tmp, "%s: %s", (pmenu[j].title+1), rl_str);
		row = ui_show_text(row, 0, tmp);
		gr_flip();
	}

	sleep(1);
}
예제 #2
0
파일: gps.c 프로젝트: sky8336/mn201307
int test_gps_start(void)
{
	int ret;
	pthread_t t1;
	int row = 2;

	ui_fill_locked();
	ui_show_title(MENU_TEST_GPS);
	ui_set_color(CL_WHITE);
	row = ui_show_text(row, 0, TEXT_WAIT_TIPS);
	gr_flip();

	ret = gpsOpen();
	if( ret < 0){
		LOGD("gps open failed ret = %d",ret);
		return -1;
	}
	gOpenTime=time(NULL);
	thread_run = 1;
	pthread_create(&t1, NULL, (void*)processThread_show, NULL);
	usleep(10*1000);
	ret = ui_handle_button(TEXT_PASS,NULL,TEXT_FAIL);//, TEXT_GOBACK
	thread_run = 0;
	pthread_join(t1,NULL);
	gpsStop();
	sleep(1);
	gpsClose();

	save_result(CASE_TEST_GPS,ret);
	return ret;
}
static void headless_wait() {
  ui_show_text(0);
  char** headers = prepend_title((const char**)MENU_HEADERS);
  for (;;) {
    finish_recovery(NULL);
    get_menu_selection(headers, MENU_ITEMS, 0, 0);
  }
}
예제 #4
0
static int
really_install_package(const char *path)
{
    ui_set_background(BACKGROUND_ICON_INSTALLING);
    ui_print("正在查找升级包...\n");
    ui_show_indeterminate_progress();
    LOGI("Update location: %s\n", path);

    if (ensure_path_mounted(path) != 0) {
        LOGE("Can't mount %s\n", path);
        return INSTALL_CORRUPT;
    }

    ui_print("正在打开升级包...\n");

    int err;

    if (signature_check_enabled) {
        int numKeys;
        RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
        if (loadedKeys == NULL) {
            LOGE("Failed to load keys\n");
            return INSTALL_CORRUPT;
        }
        LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE);

        // Give verification half the progress bar...
        ui_print("正在校验升级包...\n");
        ui_show_progress(
                VERIFICATION_PROGRESS_FRACTION,
                VERIFICATION_PROGRESS_TIME);

        err = verify_file(path, loadedKeys, numKeys);
        free(loadedKeys);
        LOGI("verify_file returned %d\n", err);
        if (err != VERIFY_SUCCESS) {
            LOGE("signature verification failed\n");
            ui_show_text(1);
            if (!confirm_selection("Install Untrusted Package?", "确认 - 安装不严格的zip卡刷包"))
                return INSTALL_CORRUPT;
        }
    }

    /* Try to open the package.
     */
    ZipArchive zip;
    err = mzOpenZipArchive(path, &zip);
    if (err != 0) {
        LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad");
        return INSTALL_CORRUPT;
    }

    /* Verify and install the contents of the package.
     */
    ui_print("正在安装更新...\n");
    return try_update_binary(path, &zip);
}
예제 #5
0
void ui_final(void)
{
//    evt_exit();

    ui_show_text(0);
    gr_exit();

    //ui_free_bitmaps();
}
int verify_root_and_recovery() {
    if (ensure_path_mounted("/system") != 0)
        return 0;

    int ret = 0;
    struct stat st;
    if (0 == lstat("/system/etc/install-recovery.sh", &st)) {
        if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
            ui_show_text(1);
            ret = 1;
            if (confirm_selection("ROM may flash stock recovery on boot. Fix?", "Yes - Disable recovery flash")) {
                __system("chmod -x /system/etc/install-recovery.sh");
            }
        }
    }

    if (0 == lstat("/system/bin/su", &st)) {
        if (S_ISREG(st.st_mode)) {
            if ((st.st_mode & (S_ISUID | S_ISGID)) != (S_ISUID | S_ISGID)) {
                ui_show_text(1);
                ret = 1;
                if (confirm_selection("Root access possibly lost. Fix?", "Yes - Fix root (/system/bin/su)")) {
                    __system("chmod 6755 /system/bin/su");
                }
            }
        }
    }

    if (0 == lstat("/system/xbin/su", &st)) {
        if (S_ISREG(st.st_mode)) {
            if ((st.st_mode & (S_ISUID | S_ISGID)) != (S_ISUID | S_ISGID)) {
                ui_show_text(1);
                ret = 1;
                if (confirm_selection("Root access possibly lost. Fix?", "Yes - Fix root (/system/xbin/su)")) {
                    __system("chmod 6755 /system/xbin/su");
                }
            }
        }
    }

    ensure_path_unmounted("/system");
    return ret;
}
static int
run_bootmenu(void) {
  time_t start = time(NULL);
  LOGI("Starting bootmenu on %s", ctime(&start));

  if (bypass_check()) {
    int status = INSTALL_SUCCESS;

    exec_script(FILE_PRE_MENU, DISABLE);

    led_alert("blue", ENABLE);
    status = wait_key(KEY_VOLUMEDOWN);

    if (status != INSTALL_ERROR) {
      int mode = get_bootmode();

      switch (mode) {
        case MODE_2NDINIT:
          led_alert("blue", DISABLE);
          led_alert("green", ENABLE);
          snd_init(DISABLE);
          led_alert("green", DISABLE);
          break;

        case MODE_2NDBOOT:
          led_alert("blue", DISABLE);
          led_alert("red", ENABLE);
          snd_boot(DISABLE);
          led_alert("red", DISABLE);
          break;

        case MODE_BOOTMENU:
          status = INSTALL_ERROR;
          break;
      }
    }

    if (status != INSTALL_SUCCESS) {
      ui_init();
      ui_set_background(BACKGROUND_ICON_ERROR);

      ui_show_text(ENABLE);
      LOGI("Start Android BootMenu....\n");

      prompt_and_wait();
      ui_finish();
    }

    led_alert("blue", DISABLE);
    return EXIT_SUCCESS;
  }
  return EXIT_SUCCESS;
}
예제 #8
0
파일: gps.c 프로젝트: sky8336/mn201307
static void gps_show_result(unsigned int result)
{
	char buffer[64];
	int row = 4;
	int i;

	if(result == 1){
		ui_clear_rows(row, 2);
		memset(buffer, 0, sizeof(buffer));
		sprintf(buffer, GPS_TEST_PASS);
	}else if(result == 0){
		ui_clear_rows(row, 2);
		memset(buffer, 0, sizeof(buffer));
		sprintf(buffer, GPS_TEST_FAILED);

	}else if(result == 2){
		ui_clear_rows(row, 2);
		memset(buffer, 0, sizeof(buffer));
		sprintf(buffer, "%s, %ds", GPS_TESTING, sTimeout);
	}else{
		// Must never go to here
		LOGD("wrong show result");
	}
	ui_set_color(CL_WHITE);
	row = ui_show_text(row, 0, buffer);
	memset(buffer, 0, sizeof(buffer));
	row++;
	ui_clear_rows(row, last_sSVNum+1);
	ui_set_color(CL_WHITE);
	sprintf(buffer, "GPS NUM: %d",sSVNum);
	row = ui_show_text(row, 0, buffer);
	gr_flip();
	for(i=0;i<sSVNum;i++){
        memset(buffer, 0, sizeof(buffer));
        sprintf(buffer, "GPS SNR: %d",sSvSnr[i]);
        row = ui_show_text(row, 0, buffer);
	}
	gr_flip();
}
예제 #9
0
파일: otg.c 프로젝트: sky8336/mn201307
int test_otg_start(void)
{
    int cur_row=2;
    int ret;
    pthread_t t1;

    ui_fill_locked();
    ui_show_title(MENU_TEST_OTG);
    ui_set_color(CL_WHITE);
    ui_show_text(cur_row, 0, OTG_TEST_START);
    gr_flip();

    thread_run=1;
    pthread_create(&t1, NULL, (void*)otg_check_thread, NULL);
    usleep(10*1000);
    ret = ui_handle_button(TEXT_PASS, NULL,TEXT_FAIL);
    thread_run=0;
    pthread_join(t1, NULL);
    save_result(CASE_TEST_OTG,ret);
    return ret;
}
예제 #10
0
static UI_CALLBACK(ui_about_cmdline)
{
    unsigned int i, num_options;
    char *name, *param, *desc;
    char *text;
    num_options = cmdline_get_num_options();
    text = lib_malloc(num_options * 0x100);
    text[0] = 0;
    for (i = 0; i < num_options; i++) {
        name = cmdline_options_get_name(i);
        if (name == NULL) {
            log_error(LOG_ERR, "ui_about_cmdline: name is NULL.");
            break;
        }
        strcat(text, name);
        param = cmdline_options_get_param(i);
        if (param != NULL) {
            strcat(text, " ");
            strcat(text, param);
        }
        desc = cmdline_options_get_description(i);
        if (desc != NULL) {
            strcat(text, "\n\t");
            strcat(text, desc);
        } else {
            log_error(LOG_ERR, "ui_about_cmdline: description for '%s' is NULL.", name);
        }
        strcat(text, "\n");
        if (strlen(text) > ((num_options - 1) * 0x100)) {
            log_error(LOG_ERR, "ui_about_cmdline: string buffer not big enough!");
            break;
        }
    }

    ui_show_text(_("Available command-line options:"), text, 600, 400);
    lib_free(text);
}
예제 #11
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;
}
예제 #12
0
int
main(int argc, char **argv) {

    if (argc == 2 && strcmp(argv[1], "adbd") == 0) {
        adb_main();
        return 0;
    }

    // Recovery needs to install world-readable files, so clear umask
    // set by init
    umask(0);

    char* command = argv[0];
    char* stripped = strrchr(argv[0], '/');
    if (stripped)
        command = stripped + 1;

    if (strcmp(command, "recovery") != 0)
    {
        struct recovery_cmd cmd = get_command(command);
        if (cmd.name)
            return cmd.main_func(argc, argv);

#ifdef BOARD_RECOVERY_HANDLES_MOUNT
        if (!strcmp(command, "mount") && argc == 2)
        {
            load_volume_table();
            return ensure_path_mounted(argv[1]);
        }
#endif
        if (!strcmp(command, "setup_adbd")) {
            load_volume_table();
            setup_adbd();
            return 0;
        }
        if (!strcmp(command, "start")) {
            property_set("ctl.start", argv[1]);
            return 0;
        }
        if (!strcmp(command, "stop")) {
            property_set("ctl.stop", argv[1]);
            return 0;
        }
        /* Make sure stdout is not fully buffered, we don't want to
         * have issues when calling busybox commands */
        setlinebuf(stdout);
        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\n", ctime(&start));

    device_ui_init(&ui_parameters);
    ui_init();
    ui_print(EXPAND(RECOVERY_VERSION)"\n");

#ifdef BOARD_RECOVERY_SWIPE
#ifndef BOARD_TOUCH_RECOVERY
    //display directions for swipe controls
    ui_print("Swipe up/down to change selections.\n");
    ui_print("Swipe to the right for enter.\n");
    ui_print("Swipe to the left for back.\n");
#endif
#endif

    load_volume_table();
    process_volumes();
    vold_client_start(&v_callbacks, 0);
    vold_set_automount(1);
    setup_legacy_storage_paths();
    LOGI("Processing arguments.\n");
    ensure_path_mounted(LAST_LOG_FILE);
    rotate_last_logs(10);
    get_args(&argc, &argv);

    int previous_runs = 0;
    const char *send_intent = NULL;
    const char *update_package = NULL;
    const char *update_ubuntu_package = NULL;
    const char *user_data_update_package = NULL;
    int wipe_data = 0, wipe_cache = 0;
    int sideload = 0;
    int headless = 0;

    try_autodeploy(AUTODEPLOY_PACKAGE_FILE);
    try_autodeploy(AUTODEPLOY_PACKAGE_FILE_MULTI);

    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 'd': user_data_update_package = optarg; break;
        case 'w':
#ifndef BOARD_RECOVERY_ALWAYS_WIPES
        wipe_data = wipe_cache = 1;
#endif
        break;
        case 'h':
            ui_set_background(BACKGROUND_ICON_CID);
            ui_show_text(0);
            headless = 1;
            break;
        case 'c': wipe_cache = 1; break;
        case 't': ui_show_text(1); break;
        case 'l': sideload = 1; break;
        case 'v': update_ubuntu_package = UBUNTU_UPDATE_SCRIPT; break;
        case '?':
            LOGE("Invalid command argument\n");
            continue;
        }
    }

    struct selinux_opt seopts[] = {
      { SELABEL_OPT_PATH, "/file_contexts" }
    };

    sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);

    if (!sehandle) {
        fprintf(stderr, "Warning: No file_contexts\n");
        ui_print("Warning:  No file_contexts\n");
    }

    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 (update_package != NULL) {
        status = install_package(update_package);
        if (status != INSTALL_SUCCESS) {
            copy_logs();
            ui_print("Installation aborted.\n");
        }
    } else if (update_ubuntu_package != NULL) {
        LOGI("Performing Ubuntu update");
        ui_set_background(BACKGROUND_ICON_INSTALLING);
        ui_show_indeterminate_progress();
        ui_print("Installing Ubuntu update.\n");
        char tmp[PATH_MAX];
        sprintf(tmp, "%s %s", UBUNTU_UPDATE_SCRIPT, UBUNTU_COMMAND_FILE );
        __system(tmp);
        LOGI("Ubuntu update complete");
        ui_print("Ubuntu update complete.\n");
    } else if (wipe_data) {
        if (device_wipe_data()) status = INSTALL_ERROR;
        ignore_data_media_workaround(1);
        if (erase_volume("/data")) status = INSTALL_ERROR;
        ignore_data_media_workaround(0);
        if (has_datadata() && erase_volume("/datadata")) status = INSTALL_ERROR;
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) {
            copy_logs();
            ui_print("Data wipe failed.\n");
        }
    } else if (wipe_cache) {
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) {
            copy_logs();
            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;
        if (!headless) {
            ui_set_show_text(1);
            ui_set_background(BACKGROUND_ICON_UBUNTU);
        }

        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 (sideload) {
        signature_check_enabled = 0;
        if (!headless)
            ui_set_show_text(1);
        if (0 == apply_from_adb()) {
            status = INSTALL_SUCCESS;
            ui_set_show_text(0);
        }
    }

    if (headless) {
        headless_wait();
    }

    if (user_data_update_package != NULL) {
        status = install_package(user_data_update_package);
        if (status != INSTALL_SUCCESS) ui_print("Installation aborted.\n");
    }

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

    // We reach here when in main menu we choose reboot main system or for some wipe commands on start
    // 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);
    ui_print("Rebooting...\n");
    reboot_main_system(ANDROID_RB_RESTART, 0, 0);

    return EXIT_SUCCESS;
}
int verify_root_and_recovery() {
    if (ensure_path_mounted("/system") != 0)
        return 0;

    int ret = 0;
    struct stat st;
    // check to see if install-recovery.sh is going to clobber recovery
    // install-recovery.sh is also used to run the su daemon on stock rom for 4.3+
    // so verify that doesn't exist...
    if (0 != lstat("/system/etc/.installed_su_daemon", &st)) {
        // check install-recovery.sh exists and is executable
        if (0 == lstat("/system/etc/install-recovery.sh", &st)) {
            if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
                ui_show_text(1);
                ret = 1;
                if (confirm_selection("确保恢复系统?", "是 - 禁止恢复到官方恢复系统")) {
                    __system("chmod -x /system/etc/install-recovery.sh");
                }
            }
        }
    }


    int exists = 0;
    if (0 == lstat("/system/bin/su", &st)) {
        exists = 1;
        if (S_ISREG(st.st_mode)) {
            if ((st.st_mode & (S_ISUID | S_ISGID)) != (S_ISUID | S_ISGID)) {
                ui_show_text(1);
                ret = 1;
                if (confirm_selection("修复ROOT权限?", "是 - 修复ROOT权限 (/system/bin/su)")) {
                    __system("chmod 6755 /system/bin/su");
                }
            }
        }
    }

    if (0 == lstat("/system/xbin/su", &st)) {
        exists = 1;
        if (S_ISREG(st.st_mode)) {
            if ((st.st_mode & (S_ISUID | S_ISGID)) != (S_ISUID | S_ISGID)) {
                ui_show_text(1);
                ret = 1;
                if (confirm_selection("修复ROOT权限?", "是 - 修复ROOT权限 (/system/xbin/su)")) {
                    __system("chmod 6755 /system/xbin/su");
                }
            }
        }
    }

    if (!exists) {
        ui_show_text(1);
        ret = 1;
        if (confirm_selection("设备可能没有ROOT权限,ROOT 设备?", "是 - ROOT 设备 (/system/xbin/su)")) {
            __system("/sbin/install-su.sh");
        }
    }

    ensure_path_unmounted("/system");
    return ret;
}
int
main(int argc, char **argv) {
    if (strcmp(basename(argv[0]), "recovery") != 0)
    {
        if (strstr(argv[0], "minizip") != NULL)
            return minizip_main(argc, argv);
        if (strstr(argv[0], "dedupe") != NULL)
            return dedupe_main(argc, argv);
        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);

    // Recovery needs to install world-readable files, so clear umask
    // set by init
    umask(0);

    // 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));

    device_ui_init(&ui_parameters);
    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;
    int wipe_data = 0, wipe_cache = 0;

    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 '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 (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 (has_datadata() && erase_volume("/datadata")) 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();
    }

    verify_root_and_recovery();

    // 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);

    sync();
    if(!poweroff) {
        ui_print("重启手机...\n");
	#ifdef BOARD_HAS_DUAL_SYSTEM
        if(multiboot==1){
	#endif
			android_reboot(ANDROID_RB_RESTART, 0, 0);
	#ifdef BOARD_HAS_DUAL_SYSTEM
		}else{
			set_reboot_message(multiboot==2);
			sync();
			android_reboot(ANDROID_RB_RESTART, 0, 0);
		}
	#endif
    }
    else {
        ui_print("关闭手机...\n");
        android_reboot(ANDROID_RB_POWEROFF, 0, 0);
    }
    return EXIT_SUCCESS;
}
예제 #15
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));

    device_ui_init(&ui_parameters);
    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;
    int wipe_data = 0, wipe_cache = 0;

    //check delta update first
    handle_deltaupdate_status();

    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 '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 (update_package != NULL) {
        status = install_package(update_package, &wipe_cache, TEMPORARY_INSTALL_FILE);
        if (status == INSTALL_SUCCESS && wipe_cache) {
            if (erase_volume("/cache")) {
                LOGE("Cache wipe (requested by package) failed.");
            }
        }
        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()) {
        prompt_and_wait();
    }

    // Otherwise, get ready to boot the main system...
    finish_recovery(send_intent);
    ui_print("Rebooting...\n");
    android_reboot(ANDROID_RB_RESTART, 0, 0);
    return EXIT_SUCCESS;
}
예제 #16
0
파일: otg.c 프로젝트: sky8336/mn201307
void* otg_check_thread(void)
{
    int fp,fp1,fp2,fp3;
    int i,cur_row,read_len;
    int j = 30;
    unsigned long value=0;
    char support,flag = 0;
    char sta_device[12]={0};
    char sta_insert[4]={0};
    char buffer[64],temp[64];
    char *endptr;

    while(thread_run==1){
	cur_row=3;
	if(access(OTG_FILE_PATH,F_OK)!=-1){
		fp=open(OTG_FILE_PATH,O_RDONLY);
		read(fp,&support,sizeof(char));
		close(fp);
		if(support=='1'){
		      fp1=open(OTG_INSERT_STATUS, O_RDONLY);
		      read(fp1,&sta_insert,sizeof(sta_insert));
		      close(fp1);
			if(NULL!=strstr(sta_insert, "low")){
				j = 30;
				if(0 == flag){
					ui_clear_rows(cur_row, 2);
					ui_set_color(CL_GREEN);
					cur_row=ui_show_text(cur_row, 0, OTG_INSERT);
					//gr_flip();
					usleep(500*1000);
					fp2=open(OTG_DEVICE_HOST,O_RDONLY);
					read(fp2,&sta_device,sizeof(sta_device));
					close(fp2);
					if(NULL!=strstr(sta_device, "Mode = 0x1")){
						LOGD("mmitest %s  Mode = 0x1",__func__ );
						cur_row=ui_show_text(cur_row, 0, OTG_HOST);
						flag = 1;
					}else if(NULL != strstr(sta_device, "Mode = 0x0")){
						cur_row=ui_show_text(cur_row, 0, OTG_DEVICE);
					}
					gr_flip();
					i = 10;
				}else
					cur_row = cur_row + 2;
				if(1 == flag){
					ui_clear_rows(cur_row, 4);
					ui_set_color(CL_GREEN);
					//sleep(3);
					if (0 == access("/sys/block/sda",F_OK)){
						cur_row = ui_show_text(cur_row, 0, TEXT_OTG_UDISK_OK);
						//gr_flip();
						fp3 = open("/sys/block/sda/size",O_RDONLY);
						read_len = read(fp3,buffer,sizeof(buffer));
						if(read_len > 0)
							value = strtoul(buffer,&endptr,0);
						close(fp3);
						LOGD("%s /sys/block/sda/size value = %lu, read_len = %d \n",__FUNCTION__, value, read_len);
						sprintf(temp, "%s %ld MB", TEXT_OTG_CAPACITY,(value/2/1024));
						cur_row = ui_show_text(cur_row, 0, temp);
						gr_flip();
						usbin_state = 0;
						i = 10;
					}else{
						ui_set_color(CL_RED);
						if(i){
							sprintf(temp, "%s, %ds", TEXT_OTG_UDISK_SCANING, i);
							ui_show_text(cur_row, 0, temp);
							gr_flip();
							sleep(1);
							i--;
						}else{
							cur_row = ui_show_text(cur_row, 0, TEXT_OTG_UDISK_NO);
							gr_flip();
						}
						usbin_state = 1;
					}
				}
			} else if(NULL!=strstr(sta_insert, "hign")){
				flag = 0;
				ui_clear_rows(cur_row, 4);
				ui_set_color(CL_RED);
				if(j){
					sprintf(temp, "%s, %ds", OTG_DEVICE_INSERT, j);
					cur_row = ui_show_text(cur_row, 0, OTG_UNSERT);
					cur_row = ui_show_text(cur_row, 0, temp);
					gr_flip();
					sleep(1);
					usbin_state = 1;
					j--;
				}else{
					cur_row = ui_show_text(cur_row, 0, TEXT_OTG_UDISK_NO);
					gr_flip();
					sleep(1);
					ui_push_result(RL_FAIL);
					break;
				}
			}
		}else{
			ui_set_color(CL_RED);
			cur_row = ui_show_text(cur_row, 0, OTG_NOT_SUPPORT);
			gr_flip();
		}
	}else{
		ui_set_color(CL_RED);
		cur_row = ui_show_text(cur_row, 0, OTG_NOT_SUPPORT);
		gr_flip();
	}
	//sleep(1);
    }
  return NULL;
}
예제 #17
0
int
main(int argc, char **argv) {

    if (argc == 2 && strcmp(argv[1], "adbd") == 0) {
        adb_main();
        return 0;
    }

    // Recovery needs to install world-readable files, so clear umask
    // set by init
    umask(0);

    char* command = argv[0];
    char* stripped = strrchr(argv[0], '/');
    if (stripped)
        command = stripped + 1;

    if (strcmp(command, "recovery") != 0)
    {
        struct recovery_cmd cmd = get_command(command);
        if (cmd.name)
            return cmd.main_func(argc, argv);

#ifdef BOARD_RECOVERY_HANDLES_MOUNT
        if (!strcmp(command, "mount") && argc == 2)
        {
            load_volume_table();
            return ensure_path_mounted(argv[1]);
        }
#endif
        if (!strcmp(command, "setup_adbd")) {
            load_volume_table();
            setup_adbd();
            return 0;
        }
        if (!strcmp(command, "start")) {
            property_set("ctl.start", argv[1]);
            return 0;
        }
        if (!strcmp(command, "stop")) {
            property_set("ctl.stop", argv[1]);
            return 0;
        }
        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\n", ctime(&start));

    device_ui_init(&ui_parameters);
    ui_init();
    ui_print(EXPAND(RECOVERY_VERSION)"\n");
	ui_print("Builder: "EXPAND(RECOVERY_BUILDER)"\n");
	ui_print("Date: "EXPAND(RECOVERY_BUILD_TIME)"\n");
	ui_print("weibo:@nx-baby\n");
	__system("/sbin/postrecoveryboot.sh");

//#ifdef BOARD_RECOVERY_SWIPE
//#ifndef BOARD_TOUCH_RECOVERY
    //display directions for swipe controls
    ui_print("Swipe up/down to change selections.\n");
    ui_print("Swipe to the right for enter.\n");
    ui_print("Swipe to the left for back.\n");
//#endif
//#endif

    load_volume_table();
    process_volumes();
    vold_init();
    setup_legacy_storage_paths();
#ifdef QCOM_HARDWARE
    parse_t_daemon_data_files();
	apply_time_zone();
#endif
    LOGI("Processing arguments.\n");
    ensure_path_mounted(LAST_LOG_FILE);
    rotate_last_logs(10);
    get_args(&argc, &argv);

    const char *send_intent = NULL;
    const char *update_package = NULL;
    int wipe_data = 0, wipe_cache = 0;
    int sideload = 0;
    int headless = 0;
    int shutdown_after = 0;

    LOGI("Checking arguments.\n");
    int arg;
    while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
        switch (arg) {
        case 's': send_intent = optarg; break;
        case 'u':
            if (update_package == NULL)
                update_package = optarg;
            break;
        case 'w':
#ifndef BOARD_RECOVERY_ALWAYS_WIPES
        wipe_data = wipe_cache = 1;
#endif
        break;
        case 'h':
            ui_set_background(BACKGROUND_ICON_CID);
            ui_show_text(0);
            headless = 1;
            break;
        case 'c': wipe_cache = 1; break;
        case 't': ui_show_text(1); break;
        case 'l': sideload = 1; break;
        case 'p': shutdown_after = 1; break;
        case '?':
            LOGE("Invalid command argument\n");
            continue;
        }
    }

    struct selinux_opt seopts[] = {
      { SELABEL_OPT_PATH, "/file_contexts" }
    };

    sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);

    if (!sehandle) {
        fprintf(stderr, "Warning: No file_contexts\n");
        //ui_print("Warning:  No file_contexts\n");
    }

    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 (update_package != NULL) {
        status = install_package(update_package);
        if (status != INSTALL_SUCCESS) {
            copy_logs();
            ui_print("Installation aborted.\n");
        } else if (!strcmp(TARGET_DEVICE, "A0001")) { //hack for a0001 ota
            if (strstr(update_package, "/.OTA/"))
                send_intent = "0";
        }
    } else if (wipe_data) {
        if (device_wipe_data()) status = INSTALL_ERROR;
        preserve_data_media(0);
        if (erase_volume("/data")) status = INSTALL_ERROR;
        preserve_data_media(1);
        if (has_datadata() && erase_volume("/datadata")) status = INSTALL_ERROR;
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) {
            copy_logs();
            ui_print("Data wipe failed.\n");
        }
    } else if (wipe_cache) {
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) {
            copy_logs();
            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;
        is_user_initiated_recovery = 1;
        if (!headless) {
            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 (sideload) {
        signature_check_enabled = 0;
        if (!headless)
            ui_set_show_text(1);
        if (0 == apply_from_adb()) {
            status = INSTALL_SUCCESS;
            ui_set_show_text(0);
        }
    }

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

    // We reach here when in main menu we choose reboot main system or for some wipe commands on start
    // 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 (shutdown_after) {
        ui_print("Shutting down...\n");
        reboot_main_system(ANDROID_RB_POWEROFF, 0, 0);
    } else {
        ui_print("Rebooting...\n");
        reboot_main_system(ANDROID_RB_RESTART, 0, 0);
    }
    return EXIT_SUCCESS;
}
예제 #18
0
int
main(int argc, char **argv) {

    if (argc == 2 && strcmp(argv[1], "adbd") == 0) {
        adb_main();
        return 0;
    }

    // Recovery needs to install world-readable files, so clear umask
    // set by init
    umask(0);

    if (strcmp(basename(argv[0]), "recovery") != 0)
    {
        if (strstr(argv[0], "minizip") != NULL)
            return minizip_main(argc, argv);
        if (strstr(argv[0], "dedupe") != NULL)
            return dedupe_main(argc, argv);
        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], "make_ext4fs") != NULL)
            return make_ext4fs_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], "bu") == argv[0] + strlen(argv[0]) - 2)
            return bu_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);
        if (strstr(argv[0], "getprop"))
            return getprop_main(argc, argv);
        return busybox_driver(argc, argv);
    }

#ifdef RECOVERY_CHARGEMODE
    handle_chargemode();
#endif

    //__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\n", ctime(&start));

#ifdef RECOVERY_CHARGEMODE
    int flag;
    flag = get_chargemode();

    if(flag == 1){
//        __system("mount /dev/block/mmcblk0p12 /system");
//        __system("sleep 1");
        __system("charge");
    }else {
#endif

    device_ui_init(&ui_parameters);
    ui_init();
    ui_print(EXPAND(RECOVERY_WELCOME)"\n");
    ui_print(EXPAND(RECOVERY_VERSION_INFO)"\n");
    ui_print(EXPAND(RECOVERY_BUILD_DATE)"\n");
	__system("/sbin/postrecoveryboot.sh");

#ifdef BOARD_RECOVERY_SWIPE
#ifndef BOARD_TOUCH_RECOVERY
    //display directions for swipe controls
    ui_print("上/下滑动选择.\n");
//    ui_print("Swipe to the right for enter.\n");
//    ui_print("Swipe to the left for back.\n");
#endif
#endif

    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;
    int wipe_data = 0, wipe_cache = 0;
    int sideload = 0;
//    int headless = 0;

    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 'h':
            ui_set_background(BACKGROUND_ICON_CID);
            ui_show_text(0);
            headless = 1;
            break; */
        case 'c': wipe_cache = 1; break;
        case 't': ui_show_text(1); break;
        case 'l': sideload = 1; break;
        case '?':
            LOGE("Invalid command argument\n");
            continue;
        }
    }

    struct selinux_opt seopts[] = {
      { SELABEL_OPT_PATH, "/file_contexts" }
    };

    sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);

    if (!sehandle) {
        fprintf(stderr, "Warning: No file_contexts\n");
        // ui_print("Warning:  No file_contexts\n");
    }

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

    enable_key_backlight();

    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 (update_package != NULL) {
        status = install_package(update_package);
        if (status != INSTALL_SUCCESS) ui_print("安装终止.\n");
    } else if (wipe_data) {
        if (device_wipe_data()) status = INSTALL_ERROR;
        ignore_data_media_workaround(1);
        if (erase_volume("/data")) status = INSTALL_ERROR;
        ignore_data_media_workaround(0);
        if (has_datadata() && erase_volume("/datadata")) status = INSTALL_ERROR;
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) ui_print("清除数据失败.\n");
    } else if (wipe_cache) {
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) ui_print("清除缓存失败.\n");
    } else if (sideload) {
        signature_check_enabled = 0;
//        if (!headless)
          ui_set_show_text(1);
        if (0 == apply_from_adb()) {
            status = INSTALL_SUCCESS;
            ui_set_show_text(0);
        }
    } 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;
//        if (!headless) {
          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");
        }
    }

    setup_adbd();

/*    if (headless) {
      headless_wait();
    } */
    if (status != INSTALL_SUCCESS && !is_user_initiated_recovery) {
        ui_set_show_text(1);
        ui_set_background(BACKGROUND_ICON_ERROR);
    }
//    else if (status != INSTALL_SUCCESS || ui_text_visible()) {
    if (status != INSTALL_SUCCESS || ui_text_visible()) {
        prompt_and_wait();
    }

    verify_root_and_recovery();

    // 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);

    sync();
    if(!poweroff) {
        ui_print("正在重启...\n");
        android_reboot(ANDROID_RB_RESTART, 0, 0);
    }
    else {
        ui_print("正在关机...\n");
        android_reboot(ANDROID_RB_POWEROFF, 0, 0);
    }
    return EXIT_SUCCESS;
}

#ifdef RECOVERY_CHARGEMODE
	return 0;
}
예제 #19
0
/**
 * run_bootmenu()
 *
 */
static int run_bootmenu(void) {
  int defmode, mode, status = BUTTON_ERROR;
  int adb_started = 0;
  time_t start = time(NULL);

  LOGI("Starting bootmenu on %s", ctime(&start));

  if (bypass_check()) {

    // init rootfs and mount cache
    exec_script(FILE_PRE_MENU, DISABLE);

    led_alert("blue", ENABLE);

    defmode = get_default_bootmode();

    // get and clean one shot bootmode (or default)
    mode = get_bootmode(1,1);

    if (mode == int_mode("bootmenu")
     || mode == int_mode("recovery")
     || mode == int_mode("shell")) {
        // dont wait if these modes are asked
    } else {
        status = (wait_key(KEY_VOLUMEDOWN) ? BUTTON_PRESSED : BUTTON_TIMEOUT);
    }

    // only start adb if usb is connected
    if (usb_connected()) {
      if (mode == int_mode("2nd-init-adb")
       || mode == int_mode("2nd-boot-adb")
       || mode == int_mode("2nd-system-adb")) {
         exec_script(FILE_ADBD, DISABLE);
         adb_started = 1;
      }
    }

    // on timeout
    if (status != BUTTON_PRESSED) {

      if (mode == int_mode("bootmenu")) {
          led_alert("blue", DISABLE);
          status = BUTTON_PRESSED;
      }
      else if (mode == int_mode("2nd-init") || mode == int_mode("2nd-init-adb")) {
          led_alert("blue", DISABLE);
          led_alert("green", ENABLE);
          snd_init(DISABLE);
          led_alert("green", DISABLE);
          status = BUTTON_TIMEOUT;
      }
      else if (mode == int_mode("2nd-boot") || mode == int_mode("2nd-boot-adb")) {
          led_alert("blue", DISABLE);
          led_alert("red", ENABLE);
          snd_boot(DISABLE);
          led_alert("red", DISABLE);
          status = BUTTON_TIMEOUT;
      }
      else if (mode == int_mode("2nd-system") || mode == int_mode("2nd-system-adb")) {
          led_alert("blue", DISABLE);
          led_alert("red", ENABLE);
          led_alert("green", ENABLE);
          snd_system(DISABLE);
          led_alert("red", DISABLE);
          led_alert("green", DISABLE);
          status = BUTTON_TIMEOUT;
      }
      else if (mode == int_mode("recovery-dev")) {
          led_alert("blue", DISABLE);
          exec_script(FILE_CUSTOMRECOVERY, DISABLE);
          status = BUTTON_TIMEOUT;
      }
      else if (mode == int_mode("recovery")) {
          led_alert("blue", DISABLE);
          exec_script(FILE_STABLERECOVERY, DISABLE);
          status = BUTTON_TIMEOUT;
      }
      else if (mode == int_mode("shell")) {
          led_alert("blue", DISABLE);
          exec_script(FILE_ADBD, DISABLE);
          status = BUTTON_PRESSED;
      }
      else if (mode == int_mode("normal") || mode == int_mode("normal-adb")) {
          led_alert("blue", DISABLE);
          stk_boot(DISABLE);
          status = BUTTON_TIMEOUT;
      }

    }

    if (status == BUTTON_PRESSED ) {

        ui_init();
        ui_set_background(BACKGROUND_DEFAULT);
        ui_show_text(ENABLE);
        led_alert("button-backlight", ENABLE);

        LOGI("Start Android BootMenu....\n");

        main_headers = prepend_title((const char**)MENU_HEADERS);

        /* can be buggy, adb could lock filesystem
        if (!adb_started && usb_connected()) {
            ui_print("Usb connected, starting adb...\n\n");
            exec_script(FILE_ADBD, DISABLE);
        }
        */

        ui_print("Default mode: %s\n", str_mode(defmode));

        if (mode == int_mode("shell")) {
            ui_print("\n");
            ui_print("Current mode: %s\n", str_mode(mode));
            if (!usb_connected()) {
                ui_print(" But USB is not connected !\n");
            }
        }

        checkup_report();
        ui_reset_progress();

        prompt_and_wait();
        free_menu_headers(main_headers);

        ui_finish();
    }

  }
  return EXIT_SUCCESS;
}
예제 #20
0
파일: key.c 프로젝트: sky8336/mn201307
int test_key_start(void)
{
	int ret;
	struct timespec ntime;
	ntime.tv_sec= time(NULL)+KEY_TIMEOUT;
	ntime.tv_nsec=0;
	int menu_count=0;
	int key = -1;
	int test_cnt = sizeof(test_key_info) / sizeof(struct test_key);
	int i = 0;
	int cur_row = 2;
	int count = 0;

	LOGD("mmitest start");
	ui_fill_locked();
	ui_show_title(MENU_TEST_KEY);

	ui_set_color(CL_GREEN);
	cur_row=ui_show_text(cur_row, 0, TEXT_KEY_ILLUSTRATE);

	for(i = 0; i < test_cnt; i++) {
		test_key_info[i].done = 0;
	}
	for(;;) {
		cur_row = 4;
		for(i = 0; i < test_cnt; i++) {
			if(test_key_info[i].done) {
				ui_set_color(CL_GREEN);
			} else {
				ui_set_color(CL_RED);
			}
			cur_row = ui_show_text(cur_row, 0, test_key_info[i].name);
		}
		gr_flip();
		if((count >= test_cnt)) break;
		if(key==ETIMEDOUT) break;
		key = ui_wait_key(&ntime);
		LOGD("mmitest key = %d",key);
		for(i = 0; i < test_cnt; i++) {
			if((test_key_info[i].key == key)
				&&(test_key_info[i].done == 0))	{
				test_key_info[i].done = 1;
				count++;
			}
		}
		LOGD("mmitest count=%d",count);

	}

	LOGD("mmitest key over");

	if(key==ETIMEDOUT){
		ui_set_color(CL_RED);
		ui_show_text(cur_row+2, 0, TEXT_TEST_FAIL);
		gr_flip();
		sleep(1);
		ret=RL_FAIL;
	}else{
		ui_set_color(CL_GREEN);
		ui_show_text(cur_row+2, 0, TEXT_TEST_PASS);
		gr_flip();
		sleep(1);
		ret=RL_PASS;
	}
	save_result(CASE_TEST_KEY,ret);
	return ret;
}
예제 #21
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));

    device_ui_init(&ui_parameters);
    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 *update_patch = NULL;
	const char *file_copy_from_partition_args = NULL;
	const char *copy_custom_files_dir = NULL; //add ainuo
	const char *file1_copy_from_partition_args = NULL;
    int wipe_data = 0, wipe_cache = 0;
    int reboot_to_factorymode = 0;
#ifdef RECOVERY_HAS_MEDIA
    int wipe_media = 0;
#endif /* RECOVERY_HAS_MEDIA */
#ifdef RECOVERY_HAS_EFUSE
    const char *efuse_version = NULL;
	const char *efuse_machine = NULL;					/* add for m6 */
    int set_efuse_version = 0;
    int set_efuse_ethernet_mac = 0;
    int set_efuse_bluetooth_mac = 0;
	int set_efuse_machine_id = 0;						/* add for m6 */
#ifdef EFUSE_LICENCE_ENABLE
    int set_efuse_audio_license = 0;
#endif /* EFUSE_LICENCE_ENABLE */
#endif /* RECOVERY_HAS_EFUSE */

    int arg;
    while ((arg = getopt_long(argc, argv, "", OPTIONS, NULL)) != -1) {
        switch (arg) {
        case 'a': copy_custom_files_dir = optarg; break; //add ainuo
        case 'p': previous_runs = atoi(optarg); break;
        case 's': send_intent = optarg; break;
        case 'u': update_package = optarg; break;
		case 'x': update_patch = optarg; break;
        case 'w': wipe_data = wipe_cache = 1; break;
        case 'c': wipe_cache = 1; break;
        case 'f': reboot_to_factorymode = 1; break;
		case 'z': file_copy_from_partition_args = optarg; break;
		case 'y': file1_copy_from_partition_args = optarg; break;
#ifdef RECOVERY_HAS_MEDIA
        case 'm': wipe_media = 1; break;
#endif /* RECOVERY_HAS_MEDIA */
        case 't': ui_show_text(1); break;
#ifdef RECOVERY_HAS_EFUSE
        case 'v': set_efuse_version = 1; efuse_version = optarg; break;
        case 'd': set_efuse_ethernet_mac = 1; break;
        case 'b': set_efuse_bluetooth_mac = 1; break;
		case 'M': set_efuse_machine_id = 1; efuse_machine = optarg; break; 	/* add for m6 */
#ifdef EFUSE_LICENCE_ENABLE
        case 'l': set_efuse_audio_license = 1; break;
#endif /* EFUSE_LICENCE_ENABLE */

#endif /* RECOVERY_HAS_EFUSE */
        case '?':
            LOGE("Invalid command argument\n");
            continue;
        }
    }

    device_recovery_start();

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

    /**
     *  Disable auto reformat, we should *NOT* do this.
     *
     *  For /media partition, we cannot do it because this will break
     *  any file system that's non-FAT.
     */
#if 0
    if (ensure_path_mounted("/data") != 0) {
        ui_print("Can't mount 'data', wipe it!\n");
        if (erase_volume("/data")) {
            ui_print("Data wipe failed.\n");
        }
    }

    if (ensure_path_mounted("/cache") != 0) {
        ui_print("Can't mount 'cache', wipe it!\n");
        if (erase_volume("/cache")) {
            ui_print("Cache wipe failed.\n");
        }
    }

#ifdef RECOVERY_HAS_MEDIA
    if (ensure_path_mounted(MEDIA_ROOT) != 0) {
        ui_print("Can't mount 'media', wipe it!\n");
        if (erase_volume(MEDIA_ROOT)) {
            ui_print("Media wipe failed.\n");
        }
    }
#endif
#endif /* 0 */

	char *file_path = NULL;
	char *partition_type = NULL;
	char *partition = NULL;
	char *offset_str = NULL;
	char *size_str = NULL;
	ssize_t part_offset;
	ssize_t file_size;

	if(file_copy_from_partition_args)
	{
		if(((file_path = strtok(file_copy_from_partition_args, ":")) == NULL) ||
			((partition_type = strtok(NULL, ":")) == NULL)	||
			((partition = strtok(NULL, ":")) == NULL)	||
			((offset_str = strtok(NULL, ":")) == NULL)	||
			((size_str = strtok(NULL, ":")) == NULL))
		{
			printf("file_copy_from_partition_args Invalid!\n");
		}
		else
		{
			part_offset = atoi(offset_str);
			file_size = atoi(size_str);
			file_copy_from_partition(file_path, partition_type, partition, part_offset, file_size);
		}	
	}

	if(file1_copy_from_partition_args)
	{
		if(((file_path = strtok(file1_copy_from_partition_args, ":")) == NULL) ||
			((partition_type = strtok(NULL, ":")) == NULL)	||
			((partition = strtok(NULL, ":")) == NULL)	||
			((offset_str = strtok(NULL, ":")) == NULL)	||
			((size_str = strtok(NULL, ":")) == NULL))
		{
			printf("file1_copy_from_partition_args Invalid!\n");
		}
		else
		{
			part_offset = atoi(offset_str);
			file_size = atoi(size_str);
			file_copy_from_partition(file_path, partition_type, partition, part_offset, file_size);
		}	
	}

    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 (update_package != NULL) {
        status = install_package(update_package, &wipe_cache, TEMPORARY_INSTALL_FILE);
        if (status == INSTALL_SUCCESS && wipe_cache) {
            if (erase_volume("/cache")) {
                LOGE("Cache wipe (requested by package) failed.");
            }
        }
        if (status != INSTALL_SUCCESS)
		{
			ui_print("Installation aborted.\n");
			goto process_failed;
        }
    }

    if (update_patch != NULL) {
        status = install_package(update_patch, &wipe_cache, TEMPORARY_INSTALL_FILE);
        if (status != INSTALL_SUCCESS)
		{
			ui_print("Installation patch aborted.\n");
			goto process_failed;
		}
    }
	
    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");
			goto process_failed;
        }
    }
    
    if (wipe_cache) {
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS)
		{
			ui_print("Cache wipe failed.\n");
			goto process_failed;
        }
    }
    
#ifdef RECOVERY_HAS_MEDIA
    if (wipe_media) {
        if (wipe_media && erase_volume(MEDIA_ROOT)) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS)
		{
			ui_print("Media wipe failed.\n");
			goto process_failed;
        }
    } 
#endif /* RECOVERY_HAS_MEDIA */    
//    else {
//        status = INSTALL_ERROR;  // No command specified
//    }

    //add ainuo
    if (copy_custom_files_dir != NULL) {
        status = copy_custom_files(MEDIA_ROOT, copy_custom_files_dir);
        if (status != INSTALL_SUCCESS) ui_print("Copy custom files failed.\n");
    }

#ifdef RECOVERY_HAS_EFUSE
    if (set_efuse_version) {
        status = recovery_efuse(EFUSE_VERSION, efuse_version);
		if (status != INSTALL_SUCCESS)
		{
			ui_print("efuse write version failed.\n");
			goto process_failed;
        }
    }
#ifdef EFUSE_LICENCE_ENABLE
    if (set_efuse_audio_license) {
        status = recovery_efuse(EFUSE_LICENCE, NULL);
		if (status != INSTALL_SUCCESS)
		{
			ui_print("efuse write licence failed.\n");
			goto process_failed;
        }
    }
#endif /* EFUSE_LICENCE_ENABLE */

    if (set_efuse_ethernet_mac) {
        status = recovery_efuse(EFUSE_MAC, NULL);
		if (status != INSTALL_SUCCESS)
		{
			ui_print("efuse write MAC addr failed.\n");
			goto process_failed;
        }
    }

    if (set_efuse_bluetooth_mac) {
        status = recovery_efuse(EFUSE_MAC_BT, NULL);
		if (status != INSTALL_SUCCESS)
		{
			ui_print("efuse write BT MAC failed.\n");
			goto process_failed;
        }
	}
	
	if (set_efuse_machine_id) {							/* add for m6 */
        status = recovery_efuse(EFUSE_MACHINEID, efuse_machine);
    }	
#endif /* RECOVERY_HAS_EFUSE */

	int howReboot;
process_failed:
    if (status != INSTALL_SUCCESS) ui_set_background(BACKGROUND_ICON_ERROR);
    if (status != INSTALL_SUCCESS || ui_text_visible()) {
        ui_show_text(1);
        howReboot = prompt_and_wait();
        if (REBOOT_FACTORY_TEST == howReboot)
            reboot_to_factorymode = 1;
    }

    // Otherwise, get ready to boot the main system...
    finish_recovery(send_intent);
    ui_print("Rebooting...\n");

    sync();

    if (reboot_to_factorymode) {
        property_set("androidboot.mode", "factorytest");
        android_reboot(ANDROID_RB_RESTART, 0, "factory_testl_reboot");
    } else {
        android_reboot(ANDROID_RB_RESTART, 0, 0);
    }

    return EXIT_SUCCESS;
}
예제 #22
0
파일: about.c 프로젝트: bobsummerwill/VICE
static UI_CALLBACK(info_dialog_license_callback)
{
    ui_show_text(_("VICE is FREE software!"), info_license_text, -1, -1);
}
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;
}
예제 #24
0
파일: about.c 프로젝트: bobsummerwill/VICE
static UI_CALLBACK(info_dialog_no_warranty_callback)
{
    ui_show_text(_("No warranty!"), info_warranty_text, -1, -1);
}
예제 #25
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;
}
예제 #26
0
파일: about.c 프로젝트: bobsummerwill/VICE
static UI_CALLBACK(info_dialog_contrib_callback)
{
    ui_show_text(_("Contributors to the VICE project"), info_contrib_text, -1, -1);
}
int verify_root_and_recovery() {
    if (ensure_path_mounted("/system") != 0)
        return 0;

    int ret = 0;
    struct stat st;
    // check to see if install-recovery.sh is going to clobber recovery
    // install-recovery.sh is also used to run the su daemon on stock rom for 4.3+
    // so verify that doesn't exist...
    if (0 != lstat("/system/etc/.installed_su_daemon", &st)) {
        // check install-recovery.sh exists and is executable
        if (0 == lstat("/system/etc/install-recovery.sh", &st)) {
            if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
                ui_show_text(1);
                ret = 1;
                if (confirm_selection("ROM may flash stock recovery on boot. Fix?", "Yes - Disable recovery flash")) {
                    __system("chmod -x /system/etc/install-recovery.sh");
                }
            }
        }
    }


    int exists = 0;
    if (0 == lstat("/system/bin/su", &st)) {
        exists = 1;
        if (S_ISREG(st.st_mode)) {
            if ((st.st_mode & (S_ISUID | S_ISGID)) != (S_ISUID | S_ISGID)) {
                ui_show_text(1);
                ret = 1;
                if (confirm_selection("Root access possibly lost. Fix?", "Yes - Fix root (/system/bin/su)")) {
                    __system("chmod 6755 /system/bin/su");
                }
            }
        }
    }

    if (0 == lstat("/system/xbin/su", &st)) {
        exists = 1;
        if (S_ISREG(st.st_mode)) {
            if ((st.st_mode & (S_ISUID | S_ISGID)) != (S_ISUID | S_ISGID)) {
                ui_show_text(1);
                ret = 1;
                if (confirm_selection("Root access possibly lost. Fix?", "Yes - Fix root (/system/xbin/su)")) {
                    __system("chmod 6755 /system/xbin/su");
                }
            }
        }
    }

    if (!exists) {
        ui_show_text(1);
        ret = 1;
        if (confirm_selection("Root access is missing. Root device?", "Yes - Root device (/system/xbin/su)")) {
            __system("/sbin/install-su.sh");
        }
    }

    ensure_path_unmounted("/system");
    return ret;
}
예제 #28
0
int main(int argc, char **argv)
{
	int interactive = 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));

    ui_init();
    ui_set_background(BACKGROUND_ICON_INSTALLING);

    // djp952 - at least for now I want to see everything
    ui_show_text(1);

    volumes_init("/sbin/recovery.fstab");
    get_args(&argc, &argv);
	
    int previous_runs = 0;
    const char *send_intent = NULL;
    const char *update_package = NULL;
    int wipe_data = 0, wipe_cache = 0;
    int toggle_secure_fs = 0;
	
	// TEMP: Dump arguments to see what they look like
	//int index = 0;
	//for(index = 0; index < argc; index++) ui_print("ARG%d = [%s]\n", index, argv[index]);

    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 = 1; break;
        case 'c': wipe_cache = 1; break;
        case 't': ui_show_text(1); break;
        case '?':
            LOGE("Invalid command argument: %c\n", arg);
            continue;
        }
    }

    device_recovery_start();

    //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");
	
	//
	// EXECUTE RECOVERY
	//

	// Automatic: --wipe_data
	if(wipe_data) {
		
		interactive = 0;				// No interactive menu mode
		cmd_wipe_device();				// Wipe the device
	}
	
	// Automatic: --wipe_cache
	if(wipe_cache) {

		interactive = 0;				// No interactive menu mode
		cmd_wipe_cache();				// Wipe the cache
	}
	
	// Interactive
	if(interactive) {
		
		cmd_show_usage();				// Explain how to navigate
		menu_mainmenu();				// Launch the main menu
	}
	
	//
	// FINISH RECOVERY
	//

    // Clean up and write out the logs
    finish_recovery(send_intent);
	
	// Unmount all volumes
	const Volume* iterator = foreach_volume(NULL);
	while(iterator != NULL) {
	
		unmount_volume(iterator, NULL);
		iterator = foreach_volume(iterator);
	}
	
    sync();							// One more sync for good luck
    reboot(RB_AUTOBOOT);			// Reboot
    return EXIT_SUCCESS;			// Done
}