Example #1
0
static int find_img_to_open(int md_id, MD_IMG_TYPE img_type, char active_file_path[], char active_post_fix[])
{
	char img_name[3][IMG_NAME_LEN];
	char full_path[IMG_PATH_LEN];
	int i;
	char post_fix[IMG_POSTFIX_LEN];
	char post_fix_ex[IMG_POSTFIX_LEN];
	struct file *filp = NULL;

	// Gen file name
	get_md_postfix(md_id, NULL, post_fix, post_fix_ex);

	if(img_type == IMG_MD){ // Gen MD image name
		snprintf(img_name[0], IMG_NAME_LEN, "modem_%s.img", post_fix); 
		snprintf(img_name[1], IMG_NAME_LEN, "modem_%s.img", post_fix_ex);
		snprintf(img_name[2], IMG_NAME_LEN, "%s", MOEDM_IMAGE_NAME); 
	} else if (img_type == IMG_DSP) { // Gen DSP image name
		snprintf(img_name[0], IMG_NAME_LEN, "dsp_%s.bin", post_fix); 
		snprintf(img_name[1], IMG_NAME_LEN, "dsp_%s.bin", post_fix_ex);
		snprintf(img_name[2], IMG_NAME_LEN, "%s", DSP_IMAGE_NAME);
	} else {
		CCCI_UTIL_ERR_MSG_WITH_ID(md_id, "Invalid img type%d\n", img_type);
		return -CCCI_ERR_INVALID_PARAM;
	}

	CCCI_UTIL_INF_MSG_WITH_ID(md_id, "Find img @CIP\n");
	for(i=0; i<3; i++) {
		CCCI_UTIL_INF_MSG_WITH_ID(md_id, "try to open %s\n", img_name[i]);
		snprintf(full_path, IMG_PATH_LEN, "%s%s", CONFIG_MODEM_FIRMWARE_CIP_PATH, img_name[i]);
		filp = filp_open(full_path, O_RDONLY, 0644);
		if (IS_ERR(filp)) {
			continue;
		} else { // Open image success
			snprintf(active_file_path, IMG_PATH_LEN, full_path);
			filp_close(filp, current->files);
			if(i==0) {
				snprintf(active_post_fix, IMG_POSTFIX_LEN, "%s", post_fix);
			} else if(i==1) {
				snprintf(active_post_fix, IMG_POSTFIX_LEN, "%s", post_fix_ex);
			} else {
				active_post_fix[0] = '\0';
			}
			return 0;
		}
	}

	CCCI_UTIL_INF_MSG_WITH_ID(md_id, "Find img @default\n");
	for(i=0; i<3; i++) {
		CCCI_UTIL_INF_MSG_WITH_ID(md_id, "try to open %s\n", img_name[i]);
		snprintf(full_path, IMG_PATH_LEN, "%s%s", CONFIG_MODEM_FIRMWARE_PATH, img_name[i]);
		filp = filp_open(full_path, O_RDONLY, 0644);
		if (IS_ERR(filp)) {
			continue;
		} else { // Open image success
			snprintf(active_file_path, IMG_PATH_LEN, full_path);
			filp_close(filp, current->files);
			if(i==0) {
				snprintf(active_post_fix, IMG_POSTFIX_LEN, "%s", post_fix);
			} else if(i==1) {
				snprintf(active_post_fix, IMG_POSTFIX_LEN, "%s", post_fix_ex);
			} else {
				active_post_fix[0] = '\0';
			}
			return 0;
		}
	}
	
	active_post_fix[0] = '\0';
	CCCI_UTIL_ERR_MSG_WITH_ID(md_id,"No Image file found\n");
	return -CCCI_ERR_LOAD_IMG_NOT_FOUND;
}
static int find_img_to_open(int md_id, MD_IMG_TYPE img_type, char active_file_path[], char active_post_fix[])
{
	char img_name[3][IMG_NAME_LEN];
	char full_path[IMG_PATH_LEN];
	int i;
	char post_fix[IMG_POSTFIX_LEN];
	char post_fix_ex[IMG_POSTFIX_LEN];
	struct file *filp = NULL;

	/* Gen file name */
	get_md_postfix(md_id, NULL, post_fix, post_fix_ex);

	if (img_type == IMG_MD) {	/* Gen MD image name */
		snprintf(img_name[0], IMG_NAME_LEN, "modem_%s.img", post_fix);
		snprintf(img_name[1], IMG_NAME_LEN, "modem_%s.img", post_fix_ex);
		snprintf(img_name[2], IMG_NAME_LEN, "%s", MOEDM_IMAGE_NAME);
	} else if (img_type == IMG_DSP) {	/* Gen DSP image name */
		snprintf(img_name[0], IMG_NAME_LEN, "dsp_%s.bin", post_fix);
		snprintf(img_name[1], IMG_NAME_LEN, "dsp_%s.bin", post_fix_ex);
		snprintf(img_name[2], IMG_NAME_LEN, "%s", DSP_IMAGE_NAME);
	} else {
		CCCI_UTIL_ERR_MSG_WITH_ID(md_id, "Invalid img type%d\n", img_type);
		return -CCCI_ERR_INVALID_PARAM;
	}

	CCCI_UTIL_DBG_MSG_WITH_ID(md_id, "Find img @CIP\n");
	for (i = 0; i < 3; i++) {
		CCCI_UTIL_DBG_MSG_WITH_ID(md_id, "try to open %s\n", img_name[i]);
		snprintf(full_path, IMG_PATH_LEN, "%s%s", CONFIG_MODEM_FIRMWARE_CIP_PATH, img_name[i]);
		filp = filp_open(full_path, O_RDONLY, 0644);
		if (IS_ERR(filp)) {
			continue;
		} else {	/* Open image success */
			snprintf(active_file_path, IMG_PATH_LEN, full_path);
			filp_close(filp, current->files);
			if (i == 0)
				snprintf(active_post_fix, IMG_POSTFIX_LEN, "%s", post_fix);
			else if (i == 1)
				snprintf(active_post_fix, IMG_POSTFIX_LEN, "%s", post_fix_ex);
			else
				active_post_fix[0] = '\0';
			return 0;
		}
	}

	CCCI_UTIL_DBG_MSG_WITH_ID(md_id, "Find img @default\n");
	for (i = 0; i < 3; i++) {
		CCCI_UTIL_DBG_MSG_WITH_ID(md_id, "try to open %s\n", img_name[i]);
		snprintf(full_path, IMG_PATH_LEN, "%s%s", CONFIG_MODEM_FIRMWARE_PATH, img_name[i]);
		filp = filp_open(full_path, O_RDONLY, 0644);
		if (IS_ERR(filp)) {
			continue;
		} else {	/* Open image success */
			snprintf(active_file_path, IMG_PATH_LEN, full_path);
			filp_close(filp, current->files);
			if (i == 0)
				snprintf(active_post_fix, IMG_POSTFIX_LEN, "%s", post_fix);
			else if (i == 1)
				snprintf(active_post_fix, IMG_POSTFIX_LEN, "%s", post_fix_ex);
			else
				active_post_fix[0] = '\0';
			return 0;
		}
	}

	active_post_fix[0] = '\0';
	CCCI_UTIL_ERR_MSG_WITH_ID(md_id, "No Image file found\n");
	{
		char title[100];
		char info[100];
		snprintf(title, sizeof(title), "MD%d image not exist:%s", md_id + 1, img_name[0]);
		snprintf(info, sizeof(info), "Modem %d image name: %s,please check CUSTOM_MODME in projectconfig.mk!",
			 md_id + 1, img_name[0]);
#if defined(CONFIG_MTK_AEE_FEATURE)
		aed_md_exception_api(NULL, 0, (const int *)info, sizeof(info), (const char *)title, DB_OPT_DEFAULT);
#endif
	}
	return -CCCI_ERR_LOAD_IMG_NOT_FOUND;
}