Beispiel #1
0
static void getvar_has_slot(char *part_name, char *response)
{
	if (part_name && (!strcmp(part_name, "boot") ||
			  !strcmp(part_name, "system")))
		fastboot_okay("yes", response);
	else
		fastboot_okay("no", response);
}
Beispiel #2
0
int fastboot_oem_lock(const char *arg, void *data, unsigned sz)
{
    int ret = B_OK;
    char msg[128] = {0};
    int inFactory = 0;
    int requireConfirmation = 0;

    ret = sec_is_in_factory(&inFactory);
    if (ret)
        return ret;

    requireConfirmation = inFactory ? 0 : 1;

    lock_warranty();

    while(1)
    {
        if(mtk_detect_key(MT65XX_MENU_SELECT_KEY) || !requireConfirmation) //VOL_UP
        {
            fastboot_info("Start lock flow\n");
            //Invoke security check after confiming "yes" by user
            ret = fastboot_oem_lock_chk();
            if(ret != B_OK)
            {
                sprintf(msg, "\nlock failed - Err:0x%x \n", ret);
                video_printf("lock failed...return to fastboot in 3s\n");
                mdelay(3000);
                fastboot_boot_menu();
                fastboot_fail(msg);
            }
            else
            {
                video_printf("lock Pass...return to fastboot in 3s\n");
                mdelay(3000);
                fastboot_boot_menu();
                fastboot_okay("");
            }
            break;
        }
        else if(mtk_detect_key(MT65XX_MENU_OK_KEY))//VOL_DOWN
        {
            video_printf("return to fastboot in 3s\n");
            mdelay(3000);
            fastboot_boot_menu();
            fastboot_okay("");
            break;
        }
        else
        {
            //If we press other keys, discard it.
        }
    }
    return ret;
}
static void cmd_getvar(const char *arg, void *data, unsigned sz)
{
	struct fastboot_var *var;

	for (var = varlist; var; var = var->next) {
		if (!strcmp(var->name, arg)) {
			fastboot_okay(var->value);
			return;
		}
	}
	fastboot_okay("");
}
Beispiel #4
0
void cmd_reboot_bootloader(const char *arg, void *data, unsigned sz)
{
  dprintf(INFO, "rebooting the device to bootloader\n");
  fastboot_okay("");
  Set_Clr_RTC_PDN1_bit13(true); //Set RTC fastboot bit
  mtk_arch_reset(1); //bypass pwr key when reboot
}
Beispiel #5
0
void cmd_flash_mmc(const char *arg, void *data, unsigned sz)
{
	unsigned long long ptn = 0;
	unsigned long long size = 0;

	ptn = mmc_ptn_offset(arg);
	if(ptn == 0) {
		fastboot_fail("partition table doesn't exist");
		return;
	}

	if (!strcmp(arg, "boot") || !strcmp(arg, "recovery")) {
		if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
			fastboot_fail("image is not a boot image");
			return;
		}
	}

	size = mmc_ptn_size(arg);
	if (ROUND_TO_PAGE(sz,511) > size) {
		fastboot_fail("size too large");
		return;
	}

	if (mmc_write(ptn , sz, (unsigned int *)data)) {
		fastboot_fail("flash write failure");
		return;
	}
	fastboot_okay("");
	return;
}
Beispiel #6
0
static void write_raw_image(block_dev_desc_t *dev_desc, disk_partition_t *info,
		const char *part_name, void *buffer,
		unsigned int download_bytes)
{
	lbaint_t blkcnt;
	lbaint_t blks;

	/* determine number of blocks to write */
	blkcnt = ((download_bytes + (info->blksz - 1)) & ~(info->blksz - 1));
	blkcnt = blkcnt / info->blksz;

	if (blkcnt > info->size) {
		error("too large for partition: '%s'\n", part_name);
		fastboot_fail("too large for partition");
		return;
	}

	puts("Flashing Raw Image\n");

	blks = dev_desc->block_write(dev_desc->dev, info->start, blkcnt,
				     buffer);
	if (blks != blkcnt) {
		error("failed writing to device %d\n", dev_desc->dev);
		fastboot_fail("failed writing to device");
		return;
	}

	printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
	       part_name);
	fastboot_okay("");
}
static void cmd_erase(struct protocol_handle *phandle, const char *arg)
{
    int partition_fd;
    char path[PATH_MAX];
    D(DEBUG, "cmd_erase %s\n", arg);

    if (flash_find_entry(arg, path, PATH_MAX)) {
        fastboot_fail(phandle, "partition table doesn't exist");
        return;
    }

    if (path == NULL) {
        fastboot_fail(phandle, "Couldn't find partition");
        return;
    }

    partition_fd = flash_get_partiton(path);
    if (partition_fd < 0) {
        fastboot_fail(phandle, "partiton file does not exists");
    }

    if (flash_erase(partition_fd)) {
        fastboot_fail(phandle, "failed to erase partition");
        flash_close(partition_fd);
        return;
    }

    if (flash_close(partition_fd) < 0) {
        D(ERR, "could not close device %s", strerror(errno));
        fastboot_fail(phandle, "failed to erase partition");
        return;
    }
    fastboot_okay(phandle, "");
}
Beispiel #8
0
static int oem_uniqueid_handler(int argc, char **argv)
{
    int retval = -1;
    ST_RESULT result;
    uint8_t uniqueKey[SECURE_TOKEN_UNIQUE_KEY_SIZE_IN_BYTES];
    char hexuniqueKey[SECURE_TOKEN_UNIQUE_KEY_SIZE_IN_BYTES * 3 + 2];

    DX_CC_HostInit();
    result = sep_sectoken_request_token(uniqueKey);
    pr_info("sep_sectoken_request_token() == 0x%x\n", result);
    if (ST_FAIL_SEP_DRIVER_OP == result)
        pr_info("sep_sectoken_request_token() ==" "ST_FAIL_SEP_DRIVER_OP\n");
    retval = (result != ST_SUCCESSFUL);

    if (retval != 0)
        fastboot_fail("cannot get uniqueid");
    else {
        snhexdump(hexuniqueKey, sizeof(hexuniqueKey) - 1, uniqueKey,
                  SECURE_TOKEN_UNIQUE_KEY_SIZE_IN_BYTES);
        pr_info("%s\n", hexuniqueKey);
        hexdump_buffer(uniqueKey, SECURE_TOKEN_UNIQUE_KEY_SIZE_IN_BYTES, fastboot_info, 16);
    }
    fastboot_okay("");
    DX_CC_HostFinish();
    return retval;
}
static void cmd_download(struct protocol_handle *phandle, const char *arg)
{
    unsigned len = strtoul(arg, NULL, 16);
    int old_fd;

    if (len > 256 * 1024 * 1024) {
        fastboot_fail(phandle, "data too large");
        return;
    }

    fastboot_data(phandle, len);

    old_fd = protocol_get_download(phandle);
    if (old_fd >= 0) {
        off_t len = lseek(old_fd, 0, SEEK_END);
        D(INFO, "disposing of unused fd %d, size %ld", old_fd, len);
        close(old_fd);
    }

    phandle->download_fd = protocol_handle_download(phandle, len);
    if (phandle->download_fd < 0) {
        fastboot_fail(phandle, "download failed");
        return;
    }

    fastboot_okay(phandle, "");
}
Beispiel #10
0
void fb_nand_erase(const char *cmd)
{
	struct part_info *part;
	struct mtd_info *mtd = NULL;
	int ret;

	ret = fb_nand_lookup(cmd, &mtd, &part);
	if (ret) {
		error("invalid NAND device");
		fastboot_fail("invalid NAND device");
		return;
	}

	ret = board_fastboot_erase_partition_setup(part->name);
	if (ret)
		return;

	ret = _fb_nand_erase(mtd, part);
	if (ret) {
		error("failed erasing from device %s", mtd->name);
		fastboot_fail("failed erasing from device");
		return;
	}

	fastboot_okay("");
}
void fb_nand_erase(const char *partname, char *response)
{
	struct part_info *part;
	nand_info_t *nand = NULL;
	int ret;

	/* initialize the response buffer */
	response_str = response;

	ret = fb_nand_lookup(partname, response, &nand, &part);
	if (ret) {
		error("invalid NAND device");
		fastboot_fail(response_str, "invalid NAND device");
		return;
	}

	ret = board_fastboot_erase_partition_setup(part->name);
	if (ret)
		return;

	ret = _fb_nand_erase(nand, part);
	if (ret) {
		error("failed erasing from device %s", nand->name);
		fastboot_fail(response_str, "failed erasing from device");
		return;
	}

	fastboot_okay(response_str, "");
}
void cmd_flash_nand(const char *arg, void *data, unsigned sz)
{
	u8 msg[128] = {0};

	if(sz  == 0)
	{
		fastboot_okay("");
		return;
	}

    //Please DO NOT get any data for reference if security check is not passed
    if(!security_check(&data, &sz, 0, arg))
    {
        sprintf(msg, "\nSecurity deny - Err:0x%x \n", sec_error());
    	dprintf(DBG_LV, msg);
    	fastboot_fail_wrapper(msg);
        return;
    }

	dprintf(DBG_LV, "cmd_flash_nand, data:0x%x\n",*(int*)data);

    if(cmd_flash_nand_img(arg,data,sz))
    {
        //[Security] Notify security check that is the end.
        sz = 0;
        security_check(&data, &sz, IMAGE_TRUNK_SIZE, arg); 
    }
}
Beispiel #13
0
void fb_mmc_flash_write(const char *cmd, void *download_buffer,
			unsigned int download_bytes)
{
	struct blk_desc *dev_desc;
	disk_partition_t info;

	dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
	if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
		error("invalid mmc device\n");
		fastboot_fail("invalid mmc device");
		return;
	}

	if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
		printf("%s: updating MBR, Primary and Backup GPT(s)\n",
		       __func__);
		if (is_valid_gpt_buf(dev_desc, download_buffer)) {
			printf("%s: invalid GPT - refusing to write to flash\n",
			       __func__);
			fastboot_fail("invalid GPT partition");
			return;
		}
		if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
			printf("%s: writing GPT partitions failed\n", __func__);
			fastboot_fail(
				      "writing GPT partitions failed");
			return;
		}
		printf("........ success\n");
		fastboot_okay("");
		return;
	} else if (part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info)) {
		error("cannot find partition: '%s'\n", cmd);
		fastboot_fail("cannot find partition");
		return;
	}

	if (is_sparse_image(download_buffer)) {
		struct fb_mmc_sparse sparse_priv;
		struct sparse_storage sparse;

		sparse_priv.dev_desc = dev_desc;

		sparse.blksz = info.blksz;
		sparse.start = info.start;
		sparse.size = info.size;
		sparse.write = fb_mmc_sparse_write;
		sparse.reserve = fb_mmc_sparse_reserve;

		printf("Flashing sparse image at offset " LBAFU "\n",
		       sparse.start);

		sparse.priv = &sparse_priv;
		write_sparse_image(&sparse, cmd, download_buffer,
				   download_bytes);
	} else {
		write_raw_image(dev_desc, &info, cmd, download_buffer,
				download_bytes);
	}
}
int download_ex(u32 data_length)//Big image and parallel transfer.
{
	thread_t *thr;

	init_engine_context(&ctx);
	init_sto_info(&sto_info, FALSE);  //no checksum enabled.
	sto_info.to_write_data_len = data_length;

	thr = thread_create("fastboot", write_storage_proc, 0, DEFAULT_PRIORITY, 16*1024);
	if (!thr)
	{
		return -1;
	}
	thread_resume(thr);

	TIME_START;

	read_usb_proc(&data_length);

	//wait for write thread end.
	event_wait(&ctx.thr_end_ev);

	destroy_engine(&ctx);

	if(ctx.b_error)
	{
		fastboot_fail_wrapper("\n@DOWNLOAD ERROR@\nPlease re-plug your USB cable\n");
		fastboot_state = STATE_ERROR;
	}else
	{
		fastboot_okay("");
	}
	return 0;
}
Beispiel #15
0
void tboot_config_keywords(void)
{
	int i;

	if (!tboot_config) {
		pr_error("tboot config wasn't init.\n");
		return;
	}

	fastboot_info("\n");
	fastboot_info("Keyword             Current value\n");
	fastboot_info("---------------------------------\n");
	for (i = 0; tc_keys[i]; i++) {
		char *buf;
		int len = 0;
		int left = 0;
		if (asprintf(&buf, "%-20s%s\n", tc_keys[i],
					tboot_config_get(tc_keys[i])) == -1)
			continue;
		fastboot_info(buf);
		free(buf);
	}
	fastboot_info("\n");
	fastboot_okay("");
}
static void cmd_getvar(struct protocol_handle *phandle, const char *arg)
{
    const char *value;
    D(DEBUG, "cmd_getvar %s\n", arg);

    value = fastboot_getvar(arg);

    fastboot_okay(phandle, value);
}
Beispiel #17
0
static void getvar_product(char *var_parameter, char *response)
{
	const char *board = env_get("board");

	if (board)
		fastboot_okay(board, response);
	else
		fastboot_fail("Board not set", response);
}
static void cmd_oem(struct protocol_handle *phandle, const char *arg) {
    const char *response = "";

    //TODO: Maybe it should get download descriptor also
    if (trigger_oem_cmd(arg, &response))
        fastboot_fail(phandle, response);
    else
        fastboot_okay(phandle, response);
}
Beispiel #19
0
static void getvar_platform(char *var_parameter, char *response)
{
	const char *p = env_get("platform");

	if (p)
		fastboot_okay(p, response);
	else
		fastboot_fail("platform not set", response);
}
static void cmd_continue(struct protocol_handle *phandle, const char *arg)
{
    fastboot_okay(phandle, "");
#if 0
    udc_stop();

    boot_linux_from_flash();
#endif
}
Beispiel #21
0
static void getvar_serialno(char *var_parameter, char *response)
{
	const char *tmp = env_get("serial#");

	if (tmp)
		fastboot_okay(tmp, response);
	else
		fastboot_fail("Value not set", response);
}
Beispiel #22
0
void cmd_continue(const char *arg, void *data, unsigned sz)
{
  g_boot_mode = NORMAL_BOOT;
  fastboot_okay("");
  udc_stop();
  mtk_wdt_init(); //re-open wdt
  /*Will not return*/
  boot_linux_from_storage();
}
Beispiel #23
0
void cmd_continue(const char *arg, void *data, unsigned sz)
{
  g_boot_mode = NORMAL_BOOT;
  if(has_set_p2u) 
  {
    set_p2u(has_set_p2u);
    fastboot_info("phone will continue boot up after 5s...");
    fastboot_okay("");
    mdelay(5000);
  }
  else
  {
    fastboot_okay("");
  }
  udc_stop();
  mtk_wdt_init(); //re-open wdt
  /*Will not return*/
  boot_linux_from_storage();
}
void fb_nand_flash_write(const char *partname, unsigned int session_id,
			 void *download_buffer, unsigned int download_bytes,
			 char *response)
{
	struct part_info *part;
	nand_info_t *nand = NULL;
	int ret;

	/* initialize the response buffer */
	response_str = response;

	ret = fb_nand_lookup(partname, response, &nand, &part);
	if (ret) {
		error("invalid NAND device");
		fastboot_fail(response_str, "invalid NAND device");
		return;
	}

	ret = board_fastboot_write_partition_setup(part->name);
	if (ret)
		return;

	if (is_sparse_image(download_buffer)) {
		struct fb_nand_sparse sparse_priv;
		sparse_storage_t sparse;

		sparse_priv.nand = nand;
		sparse_priv.part = part;

		sparse.block_sz = nand->writesize;
		sparse.start = part->offset / sparse.block_sz;
		sparse.size = part->size  / sparse.block_sz;
		sparse.name = part->name;
		sparse.write = fb_nand_sparse_write;

		ret = store_sparse_image(&sparse, &sparse_priv, session_id,
					 download_buffer);
	} else {
		printf("Flashing raw image at offset 0x%llx\n",
		       part->offset);

		ret = _fb_nand_write(nand, part, download_buffer, part->offset,
				     download_bytes, NULL);

		printf("........ wrote %u bytes to '%s'\n",
		       download_bytes, part->name);
	}

	if (ret) {
		fastboot_fail(response_str, "error writing the image");
		return;
	}

	fastboot_okay(response_str, "");
}
Beispiel #25
0
void fb_nand_flash_write(const char *cmd, void *download_buffer,
			 unsigned int download_bytes)
{
	struct part_info *part;
	struct mtd_info *mtd = NULL;
	int ret;

	ret = fb_nand_lookup(cmd, &mtd, &part);
	if (ret) {
		error("invalid NAND device");
		fastboot_fail("invalid NAND device");
		return;
	}

	ret = board_fastboot_write_partition_setup(part->name);
	if (ret)
		return;

	if (is_sparse_image(download_buffer)) {
		struct fb_nand_sparse sparse_priv;
		struct sparse_storage sparse;

		sparse_priv.mtd = mtd;
		sparse_priv.part = part;

		sparse.blksz = mtd->writesize;
		sparse.start = part->offset / sparse.blksz;
		sparse.size = part->size / sparse.blksz;
		sparse.write = fb_nand_sparse_write;
		sparse.reserve = fb_nand_sparse_reserve;

		printf("Flashing sparse image at offset " LBAFU "\n",
		       sparse.start);

		sparse.priv = &sparse_priv;
		write_sparse_image(&sparse, cmd, download_buffer,
				   download_bytes);
	} else {
		printf("Flashing raw image at offset 0x%llx\n",
		       part->offset);

		ret = _fb_nand_write(mtd, part, download_buffer, part->offset,
				     download_bytes, NULL);

		printf("........ wrote %u bytes to '%s'\n",
		       download_bytes, part->name);
	}

	if (ret) {
		fastboot_fail("error writing the image");
		return;
	}

	fastboot_okay("");
}
Beispiel #26
0
void cmd_getvar(const char *arg, void *data, unsigned sz)
{
	struct fastboot_var *var;
	char response[MAX_RSP_SIZE];

	if(!strcmp(arg, "all")){
		for (var = varlist; var; var = var->next){
			snprintf(response, MAX_RSP_SIZE,"\t%s: %s", var->name, var->value);
			fastboot_info(response);
		}
		fastboot_okay("Done!!");
		return;
	}
	for (var = varlist; var; var = var->next) {
		if (!strcmp(var->name, arg)) {
			fastboot_okay(var->value);
			return;
		}
	}
	fastboot_okay("");
}
void cmd_flash_emmc(const char *arg, void *data, unsigned sz)
{
	sparse_header_t *sparse_header;
	/* 8 Byte Magic + 2048 Byte xml + Encrypted Data */
	unsigned int *magic_number = (unsigned int *) data;
	int ret=0;
#if 0
	if (magic_number[0] == DECRYPT_MAGIC_0 &&
		magic_number[1] == DECRYPT_MAGIC_1)
	{
#ifdef SSD_ENABLE
		ret = decrypt_scm((u32 **) &data, &sz);
#endif
		if (ret != 0)
		{
			dprintf(CRITICAL, "ERROR: Invalid secure image\n");
			return;
		}
	}
	else if (magic_number[0] == ENCRYPT_MAGIC_0 &&
		magic_number[1] == ENCRYPT_MAGIC_1)
	{
#ifdef SSD_ENABLE
		ret = encrypt_scm((u32 **) &data, &sz);
#endif
		if (ret != 0)
		{
			dprintf(CRITICAL, "ERROR: Encryption Failure\n");
			return;
		}
	}
#endif
	if(sz  == 0)
	{
		fastboot_okay("");
		return;
	}

	sparse_header = (sparse_header_t *) data;

	dprintf(DBG_LV, "cmd_flash_emmc, data:0x%x,, n sparse_header->magic = 0x%x\n",*(int*)data, sparse_header->magic );

	if (sparse_header->magic != SPARSE_HEADER_MAGIC)
	{
		cmd_flash_emmc_img(arg, data, sz);
	}
	else
	{
		cmd_flash_emmc_sparse_img(arg, data, sz);
	}
	return;
}
Beispiel #28
0
void fb_mmc_erase(const char *cmd)
{
	int ret;
	struct blk_desc *dev_desc;
	disk_partition_t info;
	lbaint_t blks, blks_start, blks_size, grp_size;
	struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV);

	if (mmc == NULL) {
		error("invalid mmc device");
		fastboot_fail("invalid mmc device");
		return;
	}

	dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
	if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
		error("invalid mmc device");
		fastboot_fail("invalid mmc device");
		return;
	}

	ret = part_get_info_efi_by_name_or_alias(dev_desc, cmd, &info);
	if (ret) {
		error("cannot find partition: '%s'", cmd);
		fastboot_fail("cannot find partition");
		return;
	}

	/* Align blocks to erase group size to avoid erasing other partitions */
	grp_size = mmc->erase_grp_size;
	blks_start = (info.start + grp_size - 1) & ~(grp_size - 1);
	if (info.size >= grp_size)
		blks_size = (info.size - (blks_start - info.start)) &
				(~(grp_size - 1));
	else
		blks_size = 0;

	printf("Erasing blocks " LBAFU " to " LBAFU " due to alignment\n",
	       blks_start, blks_start + blks_size);

	blks = dev_desc->block_erase(dev_desc, blks_start, blks_size);
	if (blks != blks_size) {
		error("failed erasing from device %d", dev_desc->devnum);
		fastboot_fail("failed erasing from device");
		return;
	}

	printf("........ erased " LBAFU " bytes from '%s'\n",
	       blks_size * info.blksz, cmd);
	fastboot_okay("");
}
Beispiel #29
0
void cmd_oem_reboot2recovery(const char *arg, void *data, unsigned sz)
{
   extern void Set_RTC_Recovery_Mode(bool flag)__attribute__((weak));

   if(Set_RTC_Recovery_Mode)
   {
       Set_RTC_Recovery_Mode(1);
       fastboot_okay("");
       mtk_arch_reset(1); //bypass pwr key when reboot
   }
   else
   {
       fastboot_fail("Not support this function (need RTC porting)");
   }
}
Beispiel #30
0
static void getvar_partition_type(char *part_name, char *response)
{
	int r;
	struct blk_desc *dev_desc;
	disk_partition_t part_info;

	r = fastboot_mmc_get_part_info(part_name, &dev_desc, &part_info,
				       response);
	if (r >= 0) {
		r = fs_set_blk_dev_with_part(dev_desc, r);
		if (r < 0)
			fastboot_fail("failed to set partition", response);
		else
			fastboot_okay(fs_get_type_name(), response);
	}
}