示例#1
0
int main(int argc, char *argv[])
{
	uint8_t bus = 0, port = 0;

	struct option long_options[] = {
		{"help",	no_argument,		0, 'h'},
		{"device",	required_argument,	0, 'd'},
		{"read-flash",	required_argument,	0, 'r'},
		{"write-flash",	required_argument,	0, 'w'},
		{"erase-flash",	no_argument,		0, 'c'},
		{"lock",	no_argument,		0, 'x'},
		{"fsr",		optional_argument,	0, 1},
		{"read-ip",	required_argument,	0, 2},
		{"write-ip",	required_argument,	0, 3},
		{"erase-all",	no_argument,		0, 4},
		{0, 0, 0, 0}
	};

	while (1) {
		int c;

		c = getopt_long(argc, argv, "hd:r:w:cx", long_options,
								NULL);
		if (c == -1)
			break;

		switch (c) {
		case 'd': // device
			if (sscanf(optarg, "%hhu-%hhu", &bus, &port) != 2) {
				fprintf(stderr, "invalid USB device\n");
				return EXIT_FAILURE;
			}

			cmd_device(bus, port);
			break;
		case 'r': // read flash
			if (!spi_started)
				cmd_device(0, 0);

			cmd_read_flash(optarg);
			break;
		case 'w': // write flash
			if (!spi_started)
				cmd_device(0, 0);

			cmd_write_flash(optarg);
			break;
		case 'c': // erase flash
			if (!spi_started)
				cmd_device(0, 0);

			cmd_erase_flash();
			break;
		case 'x': // lock flash
			if (!spi_started)
				cmd_device(0, 0);

			cmd_lock();
			break;
		case 1: // read/write fsr
			if (!spi_started)
				cmd_device(0, 0);

			if (optarg) {
				char *check = NULL;
				unsigned long int value;

				value = strtoul(optarg, &check, 16);
				if (strlen(check) || value > 0xff) {
					fprintf(stderr, "invalid FSR value\n");
					return EXIT_FAILURE;
				}
				cmd_write_fsr(value);
			} else
				cmd_read_fsr();
			break;
		case 2: // read info page
			if (!spi_started)
				cmd_device(0, 0);

			cmd_read_ip(optarg);
			break;
		case 3: // write info page
			if (!spi_started)
				cmd_device(0, 0);

			cmd_write_ip(optarg);
			break;
		case 4: // erase all
			if (!spi_started)
				cmd_device(0, 0);

			cmd_erase_all();
			break;
		default:
			cmd_show_usage(argv[0]);
			return EXIT_SUCCESS;
		}
	}

	if (spi_started)
		spi_end();

	return EXIT_SUCCESS;
}
示例#2
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
}