예제 #1
0
파일: tboot.c 프로젝트: kangkai/tboot
static void display_sysinfo(int no_ui)
{
	struct utsname kernel;

	get_preos_version(NULL);

	if (!uname(&kernel))
		snprintf(ker_version, sizeof(ker_version), "%s %s",
				kernel.sysname, kernel.release);
	else
		snprintf(ker_version, sizeof(ker_version), "Unknown");

	if (!tboot_plugin_get_fw_rev(fw_versions, sizeof(fw_versions)))
		snprintf(fw_versions, sizeof(fw_versions), "Unknown");

	if (!no_ui) {
		tboot_ui_sysinfo("Pre-OS v%s", preos_version);
		tboot_ui_sysinfo("IFWI %s | %s", fw_versions, ker_version);
	}

	pr_info("Kernel version: %s\n", ker_version);

	fastboot_publish("product", DEVICE_NAME);
	fastboot_publish("kernel", ker_version);
	fastboot_publish("preos", preos_version);
	fastboot_publish("ifwi", fw_versions);
}
static EFI_STATUS publish_boot_state(void)
{
	UINT8 state;
	EFI_STATUS ret;

	ret = get_efi_variable_byte(&fastboot_guid, BOOT_STATE_VAR, &state);
	if (EFI_ERROR(ret) || state >= ARRAY_SIZE(BOOT_STATES_STRING))
		return fastboot_publish("boot-state", "unknown");

	return fastboot_publish("boot-state", BOOT_STATES_STRING[state]);
}
예제 #3
0
static int config_parse_line(char *line)
{
    char *c;
    char *key;
    char *value;

    c = strchr(line, '#');
    if (c)
        *c = '\0';

    if (strspn(line, " \t") == strlen(line))
        return 0;

    c = strchr(line, '=');
    if (c == NULL)
        return -1;

    key = line;
    *c = '\0';
    value = c + 1;

    key = strip(key);
    value = strip(value);

    key = strdup(key);
    value = strdup(value);

    fastboot_publish(key, value);

    return 0;
}
예제 #4
0
static void register_secure_unlocked_var(void)
{
	char str_buf[2][4] = {"no","yes"};
	char *secure_buf;
	char *unlocked_buf;
	char *warranty_buf;
	unsigned n;
	int warranty;

	/* [FIXME] memory allocated not freed? */

	secure_buf = malloc(10);
	#ifdef MTK_SECURITY_SW_SUPPORT
        n = get_secure_status();
	#else
	n = 0;
	#endif
	sprintf(secure_buf,"%s",str_buf[n]);
	fastboot_publish("secure", secure_buf);

	unlocked_buf = malloc(10);
	#ifdef MTK_SECURITY_SW_SUPPORT
	n = get_unlocked_status();
	#else
	n = 1;
	#endif
	sprintf(unlocked_buf,"%s",str_buf[n]);
	fastboot_publish("unlocked", unlocked_buf);

	warranty_buf = malloc(10);
	#ifdef MTK_SECURITY_SW_SUPPORT
        sec_query_warranty(&warranty);
	#else
	warranty = 0;
	#endif
	if (warranty >= 0 && warranty <= 1) {
	    sprintf(warranty_buf,"%s",str_buf[warranty]);
	    fastboot_publish("warranty", warranty_buf);
	}

}
예제 #5
0
static void register_off_mode_charge_var(void)
{
	//INIT VALUE
	char str_buf[2][2] = {"0","1"};
	char *value_buf;
	unsigned n;

	value_buf = malloc(5);
	n = get_off_mode_charge_status();
	sprintf(value_buf,"%s",str_buf[n]);
	fastboot_publish("off-mode-charge", value_buf);
}
예제 #6
0
static void register_parition_var(void)
{
	int i;
	unsigned long long p_size;
	char *type_buf;
	char *value_buf;
	char *var_name_buf;
	char *p_name_buf;

	for(i=0;i<PART_MAX_COUNT;i++){
		p_size = partition_get_size(i);
		if(p_size == -1)
			break;
		partition_get_name(i,&p_name_buf);

		partition_get_type(i,&type_buf);
		var_name_buf = malloc(30);
		sprintf(var_name_buf,"partition-type:%s",p_name_buf);
		fastboot_publish(var_name_buf,type_buf);
		//printf("%d %s %s\n",i,var_name_buf,type_buf);

		/*reserved for MTK security*/
		if(!strcmp(type_buf,"ext4")){
			if(!strcmp(p_name_buf,"userdata")){
				p_size -= (u64)1*1024*1024;
				if (p_size > 800*1024*1024) {
				    p_size = 800*1024*1024;
				}
			}
		}
		value_buf = malloc(20);
		sprintf(value_buf,"%llx",p_size);
		var_name_buf = malloc(30);
		sprintf(var_name_buf,"partition-size:%s",p_name_buf);
		fastboot_publish(var_name_buf,value_buf);
		//printf("%d %s %s\n",i,var_name_buf,value_buf);
		
	}
}
static EFI_STATUS publish_firmware(void)
{
	int len;

	len = snprintf((CHAR8 *)firmware_str, sizeof(firmware_str) - 1,
		       (CHAR8 *)"%a %a",
		       SMBIOS_GET_STRING(0, Vendor),
		       SMBIOS_GET_STRING(0, BiosVersion));
	if (len == -1)
		return EFI_INVALID_PARAMETER;

	return fastboot_publish("firmware", firmware_str);
}
static EFI_STATUS publish_board(void)
{
	int len;

	len = snprintf((CHAR8 *)board_str, sizeof(board_str),
		       (CHAR8 *)"%a %a %a",
		       SMBIOS_GET_STRING(2, Manufacturer),
		       SMBIOS_GET_STRING(2, ProductName),
		       SMBIOS_GET_STRING(2, Version));
	if (len < 0)
		return EFI_INVALID_PARAMETER;

	return fastboot_publish("board", board_str);
}
예제 #9
0
int fastboot_init(void *base, unsigned size)
{
	thread_t *thr;
	dprintf(INFO, "fastboot_init()\n");

	download_base = base;
	download_max = size;

	event_init(&usb_online, 0, EVENT_FLAG_AUTOUNSIGNAL);
	event_init(&txn_done, 0, EVENT_FLAG_AUTOUNSIGNAL);

	in = udc_endpoint_alloc(UDC_TYPE_BULK_IN, 512);
	if (!in)
		goto fail_alloc_in;
	out = udc_endpoint_alloc(UDC_TYPE_BULK_OUT, 512);
	if (!out)
		goto fail_alloc_out;

	fastboot_endpoints[0] = in;
	fastboot_endpoints[1] = out;

	req = udc_request_alloc();
	if (!req)
		goto fail_alloc_req;

	if (udc_register_gadget(&fastboot_gadget))
		goto fail_udc_register;

	fastboot_register("getvar:", cmd_getvar);
	fastboot_register("download:", cmd_download);
	fastboot_publish("version", "0.5");

	thr = thread_create("fastboot", fastboot_handler, 0, DEFAULT_PRIORITY, 4096);
	if (!thr)
	{
		goto fail_alloc_in;
	}
	thread_resume(thr);
	return 0;

fail_udc_register:
	udc_request_free(req);
fail_alloc_req:
	udc_endpoint_free(out);	
fail_alloc_out:
	udc_endpoint_free(in);
fail_alloc_in:
	return -1;
}
예제 #10
0
int fastboot_init(void *base, unsigned size)
{
	thread_t *thr;

	dprintf(ALWAYS, "fastboot_init()\n");

	download_base = base;
	download_max = size;

	mtk_wdt_disable(); /*It will re-enable during continue boot*/

	fastboot_register("getvar:", cmd_getvar, FALSE);
	fastboot_publish("version", "0.5");
#ifndef USER_BUILD
	fastboot_register("boot", cmd_boot, FALSE);
#endif
	fastboot_register("signature", cmd_install_sig, FALSE);

#ifdef MTK_EMMC_SUPPORT
	fastboot_register("flash:", cmd_flash_emmc, TRUE);
	#ifndef USER_BUILD
	fastboot_register("erase:", cmd_erase_emmc, FALSE);
	#endif
#else
	fastboot_register("flash:", cmd_flash_nand, TRUE);
	#ifndef USER_BUILD
	fastboot_register("erase:", cmd_erase_nand, FALSE);
	#endif
#endif

	fastboot_register("continue", cmd_continue, FALSE);
	fastboot_register("reboot", cmd_reboot, FALSE);
	fastboot_register("reboot-bootloader", cmd_reboot_bootloader, FALSE);
	fastboot_publish("product", TARGET(BOARD));
	fastboot_publish("kernel", "lk");
	//fastboot_publish("serialno", sn_buf);

	register_parition_var();


	/*LXO: Download related command*/
	fastboot_register("download:", cmd_download, TRUE);

	/*LXO: END!Download related command*/

	fastboot_oem_register();

    fastboot_register("oem p2u", cmd_oem_p2u, FALSE);
    fastboot_register("oem reboot-recovery",cmd_oem_reboot2recovery, FALSE);
	event_init(&usb_online, 0, EVENT_FLAG_AUTOUNSIGNAL);
	event_init(&txn_done, 0, EVENT_FLAG_AUTOUNSIGNAL);

	in = udc_endpoint_alloc(UDC_TYPE_BULK_IN, 512);
	if (!in)
		goto fail_alloc_in;
	out = udc_endpoint_alloc(UDC_TYPE_BULK_OUT, 512);
	if (!out)
		goto fail_alloc_out;

	fastboot_endpoints[0] = in;
	fastboot_endpoints[1] = out;

	req = udc_request_alloc();
	if (!req)
		goto fail_alloc_req;

	if (udc_register_gadget(&fastboot_gadget))
		goto fail_udc_register;

	thr = thread_create("fastboot", fastboot_handler, 0, DEFAULT_PRIORITY, 4096);
	if (!thr)
	{
		goto fail_alloc_in;
	}
	thread_resume(thr);
	return 0;

fail_udc_register:
	udc_request_free(req);
fail_alloc_req:
	udc_endpoint_free(out);
fail_alloc_out:
	udc_endpoint_free(in);
fail_alloc_in:
	return -1;
}
예제 #11
0
int fastboot_init(void *base, unsigned size)
{
	thread_t *thr;

	dprintf(ALWAYS, "fastboot_init()\n");

	download_base = base;
	download_max = size;

	//mtk_wdt_disable(); /*It will re-enable during continue boot*/
	timer_initialize(&wdt_timer);
	timer_set_periodic(&wdt_timer, 5000, (timer_callback)mtk_wdt_restart, NULL);

	fastboot_register("getvar:", cmd_getvar, TRUE);
	fastboot_publish("version", "0.5");
#ifndef USER_BUILD
	fastboot_register("boot", cmd_boot, FALSE);
#endif
	fastboot_register("signature", cmd_install_sig, FALSE);
#ifdef USE_G_ORIGINAL_PROTOCOL

	fastboot_register("flash:", cmd_flash_mmc, TRUE);
	#ifndef USER_BUILD
	fastboot_register("erase:", cmd_erase_mmc, TRUE);
	#endif
#else
#ifdef MTK_EMMC_SUPPORT
	fastboot_register("flash:", cmd_flash_emmc, TRUE);
	#ifndef USER_BUILD
	fastboot_register("erase:", cmd_erase_emmc, TRUE);
	#endif
#else
	fastboot_register("flash:", cmd_flash_nand, TRUE);
	#ifndef USER_BUILD
	fastboot_register("erase:", cmd_erase_nand, TRUE);
	#endif
#endif

#endif


	fastboot_register("continue", cmd_continue, FALSE);
	fastboot_register("reboot", cmd_reboot, FALSE);
	fastboot_register("reboot-bootloader", cmd_reboot_bootloader, FALSE);
	fastboot_publish("product", TARGET(BOARD));
	fastboot_publish("kernel", "lk");
	register_secure_unlocked_var();
#ifdef MTK_OFF_MODE_CHARGE_SUPPORT
	register_off_mode_charge_var();
#endif
	//fastboot_publish("serialno", sn_buf);

	register_parition_var();


	/*LXO: Download related command*/
	fastboot_register("download:", cmd_download, TRUE);
	fastboot_publish("max-download-size", "0x8000000"); //128M = 134217728
	/*LXO: END!Download related command*/

	fastboot_oem_register();

    fastboot_register("oem p2u", cmd_oem_p2u, FALSE);
    fastboot_register("oem reboot-recovery",cmd_oem_reboot2recovery, FALSE);
    fastboot_register("oem append-cmdline",cmd_oem_append_cmdline,FALSE);
#ifdef MTK_OFF_MODE_CHARGE_SUPPORT
	fastboot_register("oem off-mode-charge",cmd_oem_off_mode_charge,FALSE);
#endif
    #ifdef MTK_TC7_COMMON_DEVICE_INTERFACE
    fastboot_register("oem auto-ADB",cmd_oem_ADB_Auto_Enable,FALSE);
    #endif
#if defined(MTK_SECURITY_SW_SUPPORT) && defined(MTK_SEC_FASTBOOT_UNLOCK_SUPPORT)
    fastboot_register("oem unlock",fastboot_oem_unlock, TRUE);
    fastboot_register("oem lock",fastboot_oem_lock, TRUE);
    fastboot_register("oem key",fastboot_oem_key,TRUE);
    fastboot_register("oem lks",fastboot_oem_query_lock_state,TRUE);
#endif
	event_init(&usb_online, 0, EVENT_FLAG_AUTOUNSIGNAL);
	event_init(&txn_done, 0, EVENT_FLAG_AUTOUNSIGNAL);

	in = udc_endpoint_alloc(UDC_TYPE_BULK_IN, 512);
	if (!in)
		goto fail_alloc_in;
	out = udc_endpoint_alloc(UDC_TYPE_BULK_OUT, 512);
	if (!out)
		goto fail_alloc_out;

	fastboot_endpoints[0] = in;
	fastboot_endpoints[1] = out;

	req = udc_request_alloc();
	if (!req)
		goto fail_alloc_req;

	if (udc_register_gadget(&fastboot_gadget))
		goto fail_udc_register;

	thr = thread_create("fastboot", fastboot_handler, 0, DEFAULT_PRIORITY, 4096);
	if (!thr)
	{
		goto fail_alloc_in;
	}
	thread_resume(thr);
	return 0;

fail_udc_register:
	udc_request_free(req);
fail_alloc_req:
	udc_endpoint_free(out);
fail_alloc_out:
	udc_endpoint_free(in);
fail_alloc_in:
	return -1;
}
/* "device-state": Indicates the device's lock state as per Google's
 * Verified Boot specification. Possible values are "unlocked",
 * "locked", "verified". */
static EFI_STATUS publish_device_state(void)
{
	return fastboot_publish("device-state", get_current_state_string());
}
/* "product-name": Reports "product_name" field in DMI.  */
static EFI_STATUS publish_product_name(void)
{
	return fastboot_publish("product-name",
				SMBIOS_GET_STRING(1, ProductName));
}
/* "secureboot": Indicates whether UEFI Secure Boot is enabled. This
   is a pre-requisite for Verified Boot.  */
static EFI_STATUS publish_secureboot(void)
{
	return fastboot_publish("secureboot",
				is_efi_secure_boot_enabled() ? "yes" : "no" );
}
/* "serialno": The device serial number. */
static EFI_STATUS publish_serialno(void)
{
	char *serial = get_serial_number();
	return fastboot_publish("serialno", serial ? serial : "N/A");
}