int main(int argc, char **argv)
{
	struct statfs buf;
	int ret = 0;
	/* Files written only read/writable by root */
	umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);

	/* initialize libmicroui */
#ifdef USE_GUI
	mui_init();
#endif

	pr_info(" -- UserFastBoot %s for %s --\n", USERFASTBOOT_VERSION, DEVICE_NAME);

	mui_set_background(BACKGROUND_ICON_INSTALLING);

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

	sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1);

	if (!sehandle) {
		pr_error("Warning: No file_contexts\n");
	}

	load_volume_table();
	aboot_register_commands();
	register_userfastboot_plugins();
	ret = statfs("/tmp", &buf);
	if (!ret){
		unsigned long size = buf.f_bsize * buf.f_bfree;
		fastboot_init(size);
	}
	else
		pr_error("Error when acuiring tmpfs size:-%d\n", errno);


	/* Shouldn't get here */
	exit(1);
}
Example #2
0
int main(int argc, char **argv)
{
	pthread_t t_auto, t_input, t_uevent, t_sighandler;
	//Volume *vol;
	int ret;
	char *disk_conf;
	void (*ui_update)(void *) = NULL;
	sigset_t set;

	/* block signals for all theads */
	sigemptyset(&set);
	sigaddset(&set, SIGPIPE);
	sigaddset(&set, SIGALRM);
	if (pthread_sigmask(SIG_BLOCK, &set, NULL))
		pr_critial("block signal failed.\n");

	/* create a dedicate thread to handle signals */
	if (pthread_create(&t_sighandler, NULL, sig_handler, &set))
		pr_critial("create signal handler thread failed.\n");

	if (argc > 1)
		ret = load_config(argv[1]);
	else
		ret = load_config(NULL);
	/* currently, missing config file is not critical */
	if (ret)
		pr_warning("can't load tboot configuration.\n");

	if (ret = tboot_ui_init(tboot_config_get(UI_CONF_KEY)))
		pr_error("UI crashed!\n");

	tboot_config_set(UI_CONF_KEY, tboot_ui_getconfpath());

	ev_init(input_callback, NULL);

	display_sysinfo(ret);

	if (!ret) {
		ui_update = ui_callback;
	}

	pr_info(" -- preos v%s for %s --\n", preos_version, DEVICE_NAME);
	import_kernel_cmdline(parse_cmdline_option);

	disk_conf = tboot_config_get(DISK_CONFIG_KEY);
	if (!disk_conf) {
		pr_error("Invalid tboot config disk_conf.\n");
		die();
	}

	setup_disk_information(disk_conf);

	aboot_register_commands();

	register_tboot_plugins();

	if (pthread_create(&t_input, NULL, input_listener_thread,
					NULL)) {
		pr_perror("pthread_create");
		die();
	}

	lcd_state_init();

	if (pthread_create(&t_uevent, NULL, uevent_thread, ui_update)) {
		pr_perror("pthread_create t_uevent");
		die();
	}

	/*
	vol = volume_for_path(SDCARD_VOLUME);
	if (vol)
		try_update_sw(vol, 1);
	*/

	if (g_use_autoboot && !g_update_location) {
		/*
		 * Create menu items for debug boot, this is a feature for developers
		 * only.
		 *
		 * Developers (kernel developers) put kernel, cmdline,
		 * rmadisk.img(optional) to platform boot directory  in kexec enabled
		 * preos.
		 *
		 * Generally, there are two ways to do that.
		 *
		 * 1. you can put these files into /boot after the system boot
		 * into rootfs.
		 * 2. you can put these files into platform.img.gz and create a new
		 * platform.img.gz and then flash it to target device.
		 *
		 * Previous, if the system can't boot into rootfs, the only way left
		 * is flash a new platform image. Apparently, it's a huge effort.
		 *
		 * To make more choice, two kernels are supported now, so make sure
		 * there is a works kernel in /boot , you can always boot into
		 * normal system and put a new kernel by any other way, such as scp,
		 * ftp and etc.
		 */

		/*
		 * make our menu acts more like grub which more users familiar with.
		 */
		tboot_ui_menu_item("Boot: kernel", start_default_kernel);
		tboot_ui_menu_item("Boot: kernel.bak", start_backup_kernel);
		tboot_ui_menu_item("Boot: kernel/rootfs on TF/micro-SD card",
				start_mmc_kernel);
		/*
		 * boot from NFS is quite useless now because the usb network bandwidth
		 * is too narrow to satisfy the boot up sequence. It may (80%) hang at
		 * system boot up, especially at X server start up
		 *
		 * So, by default, disable it.
		 */
		if (strcasecmp(tboot_config_get(ENABLE_NFS_KEY), "yes") == 0)
			tboot_ui_menu_item("Boot: kernel/rootfs on NFS",
					start_nfs_kernel);

		tboot_ui_menu_selected(3);      // set debug boot: kernel selected

		if (pthread_create(&t_auto, NULL, autoboot_thread, NULL)) {
			pr_perror("pthread_create");
			die();
		}
	}

	/*
	 * dealy to start tboot server
	 */
	do {
		sleep(1);
	} while (autoboot_enabled || power_pressed);

	pr_info("Listening for the fastboot protocol over USB.\n");
	fastboot_init(g_scratch_size * MEGABYTE);

	/* Shouldn't get here */
	tboot_ui_exit();

	if (tboot_config)
		hashmapFree(tboot_config);
//	tboot_cmds_free();

	exit(1);
}