software/drivers/sd8887/src/bluetooth/bt/bt_main.c
/**
 *  @brief This function dump firmware memory to file
 *
 *  @param phandle   A pointer to moal_handle
 *
 *  @return         N/A
 */
@brief This function dump firmware memory to file
@param phandle   A pointer to moal_handle

@return         N/A
@brief This function dump firmware memory to file @param phandle A pointer to moal_handle @return N / A
void
bt_dump_firmware_info_v2(bt_private *priv)
{
	int ret = 0;
	unsigned int reg, reg_start, reg_end;
	u8 *dbg_ptr = NULL;
	u8 dump_num = 0;
	u8 idx = 0;
	u8 doneflag = 0;
	rdwr_status stat;
	u8 i = 0;
	u8 read_reg = 0;
	u32 memory_size = 0;
	u8 path_name[64], file_name[32];
	u8 *end_ptr = NULL;
	u8 dbg_dump_start_reg = 0;
	u8 dbg_dump_end_reg = 0;
	if (!priv) {
		PRINTM(ERROR, "Could not dump firmwware info\n");
		return;
	}
	memset(path_name, 0, sizeof(path_name));
	strcpy((char *)path_name, "/data");
	PRINTM(MSG, "Create DUMP directory success:dir_name=%s\n", path_name);
	dbg_dump_start_reg = DEBUG_DUMP_START_REG;
	dbg_dump_end_reg = DEBUG_DUMP_END_REG;
	sbi_wakeup_firmware(priv);
	priv->fw_dump = TRUE;
	PRINTM(MSG, "==== DEBUG MODE OUTPUT START ====\n");
	if (RDWR_STATUS_FAILURE == bt_cmd52_rdwr_firmware(priv, doneflag))
		goto done;
	reg = dbg_dump_start_reg;
	ret = sd_read_reg(priv, reg, &dump_num);
	if (ret) {
		PRINTM(MSG, "SDIO READ MEM NUM ERR\n");
		goto done;
	}
	if (dump_num >
	    (sizeof(bt_mem_type_mapping_tbl) / sizeof(memory_type_mapping))) {
		PRINTM(MSG, "Invalid dump_num=%d\n", dump_num);
		return;
	}
	for (idx = 0; idx < dump_num; idx++) {
		if (RDWR_STATUS_FAILURE ==
		    bt_cmd52_rdwr_firmware(priv, doneflag))
			goto done;
		memory_size = 0;
		reg = dbg_dump_start_reg;
		for (i = 0; i < 4; i++) {
			ret = sd_read_reg(priv, reg, &read_reg);
			if (ret) {
				PRINTM(MSG, "SDIO READ ERR\n");
				goto done;
			}
			memory_size |= (read_reg << i * 8);
			reg++;
		}
		if (memory_size == 0) {
			PRINTM(MSG, "Firmware Dump Finished!\n");
			break;
		} else {
			PRINTM(MSG, "%s_SIZE=0x%x\n",
			       bt_mem_type_mapping_tbl[idx].mem_name,
			       memory_size);
			bt_mem_type_mapping_tbl[idx].mem_Ptr =
				vmalloc(memory_size + 1);
			if ((ret != BT_STATUS_SUCCESS) ||
			    !bt_mem_type_mapping_tbl[idx].mem_Ptr) {
				PRINTM(ERROR,
				       "Error: vmalloc %s buffer failed!!!\n",
				       bt_mem_type_mapping_tbl[idx].mem_name);
				goto done;
			}
			dbg_ptr = bt_mem_type_mapping_tbl[idx].mem_Ptr;
			end_ptr = dbg_ptr + memory_size;
		}
		doneflag = bt_mem_type_mapping_tbl[idx].done_flag;
		PRINTM(MSG, "Start %s output, please wait...\n",
		       bt_mem_type_mapping_tbl[idx].mem_name);
		do {
			stat = bt_cmd52_rdwr_firmware(priv, doneflag);
			if (RDWR_STATUS_FAILURE == stat)
				goto done;
			reg_start = dbg_dump_start_reg;
			reg_end = dbg_dump_end_reg;
			for (reg = reg_start; reg <= reg_end; reg++) {
				ret = sd_read_reg(priv, reg, dbg_ptr);
				if (ret) {
					PRINTM(MSG, "SDIO READ ERR\n");
					goto done;
				}
				if (dbg_ptr < end_ptr)
					dbg_ptr++;
				else
					PRINTM(MSG,
					       "pre-allocced buf is not enough\n");
			}
			if (RDWR_STATUS_DONE == stat) {
				PRINTM(MSG, "%s done:"
				       "size = 0x%x\n",
				       bt_mem_type_mapping_tbl[idx].mem_name,
				       (unsigned int)(dbg_ptr -
						      bt_mem_type_mapping_tbl
						      [idx].mem_Ptr));
				memset(file_name, 0, sizeof(file_name));
				snprintf((char *)file_name, sizeof(file_name),
					 "%s%s", "file_bt_",
					 bt_mem_type_mapping_tbl[idx].mem_name);
				if (BT_STATUS_SUCCESS !=
				    bt_save_dump_info_to_file((char *)path_name,
							      (char *)file_name,
							      bt_mem_type_mapping_tbl
							      [idx].mem_Ptr,
							      memory_size))
					PRINTM(MSG,
					       "Can't save dump file %s in %s\n",
					       file_name, path_name);
				vfree(bt_mem_type_mapping_tbl[idx].mem_Ptr);
				bt_mem_type_mapping_tbl[idx].mem_Ptr = NULL;
				break;
			}
		} while (1);
	}
	PRINTM(MSG, "==== DEBUG MODE OUTPUT END ====\n");
done:
	priv->fw_dump = FALSE;
	for (idx = 0; idx < dump_num; idx++) {
		if (bt_mem_type_mapping_tbl[idx].mem_Ptr) {
			vfree(bt_mem_type_mapping_tbl[idx].mem_Ptr);
			bt_mem_type_mapping_tbl[idx].mem_Ptr = NULL;
		}
	}
	PRINTM(MSG, "==== DEBUG MODE END ====\n");
	return;
}
void bt_dump_firmware_info_v2 ( bt_private * priv ) { int ret = 0 ; unsigned int reg , reg_start , reg_end ; u8 * dbg_ptr = NULL ; u8 dump_num = 0 ; u8 idx = 0 ; u8 doneflag = 0 ; rdwr_status stat ; u8 i = 0 ; u8 read_reg = 0 ; u32 memory_size = 0 ; u8 path_name [ 64 ] , file_name [ 32 ] ; u8 * end_ptr = NULL ; u8 dbg_dump_start_reg = 0 ; u8 dbg_dump_end_reg = 0 ; if ( ! priv ) { PRINTM ( ERROR , " \n " ) ; return ; } memset ( path_name , 0 , sizeof ( path_name ) ) ; strcpy ( ( char * ) path_name , " " ) ; PRINTM ( MSG , " \n " , path_name ) ; dbg_dump_start_reg = DEBUG_DUMP_START_REG ; dbg_dump_end_reg = DEBUG_DUMP_END_REG ; sbi_wakeup_firmware ( priv ) ; priv -> fw_dump = TRUE ; PRINTM ( MSG , " \n " ) ; if ( RDWR_STATUS_FAILURE == bt_cmd52_rdwr_firmware ( priv , doneflag ) ) goto done ; reg = dbg_dump_start_reg ; ret = sd_read_reg ( priv , reg , & dump_num ) ; if ( ret ) { PRINTM ( MSG , " \n " ) ; goto done ; } if ( dump_num > ( sizeof ( bt_mem_type_mapping_tbl ) / sizeof ( memory_type_mapping ) ) ) { PRINTM ( MSG , " \n " , dump_num ) ; return ; } for ( idx = 0 ; idx < dump_num ; idx ++ ) { if ( RDWR_STATUS_FAILURE == bt_cmd52_rdwr_firmware ( priv , doneflag ) ) goto done ; memory_size = 0 ; reg = dbg_dump_start_reg ; for ( i = 0 ; i < 4 ; i ++ ) { ret = sd_read_reg ( priv , reg , & read_reg ) ; if ( ret ) { PRINTM ( MSG , " \n " ) ; goto done ; } memory_size |= ( read_reg << i * 8 ) ; reg ++ ; } if ( memory_size == 0 ) { PRINTM ( MSG , " \n " ) ; break ; } else { PRINTM ( MSG , " \n " , bt_mem_type_mapping_tbl [ idx ] . mem_name , memory_size ) ; bt_mem_type_mapping_tbl [ idx ] . mem_Ptr = vmalloc ( memory_size + 1 ) ; if ( ( ret != BT_STATUS_SUCCESS ) || ! bt_mem_type_mapping_tbl [ idx ] . mem_Ptr ) { PRINTM ( ERROR , " \n " , bt_mem_type_mapping_tbl [ idx ] . mem_name ) ; goto done ; } dbg_ptr = bt_mem_type_mapping_tbl [ idx ] . mem_Ptr ; end_ptr = dbg_ptr + memory_size ; } doneflag = bt_mem_type_mapping_tbl [ idx ] . done_flag ; PRINTM ( MSG , " \n " , bt_mem_type_mapping_tbl [ idx ] . mem_name ) ; do { stat = bt_cmd52_rdwr_firmware ( priv , doneflag ) ; if ( RDWR_STATUS_FAILURE == stat ) goto done ; reg_start = dbg_dump_start_reg ; reg_end = dbg_dump_end_reg ; for ( reg = reg_start ; reg <= reg_end ; reg ++ ) { ret = sd_read_reg ( priv , reg , dbg_ptr ) ; if ( ret ) { PRINTM ( MSG , " \n " ) ; goto done ; } if ( dbg_ptr < end_ptr ) dbg_ptr ++ ; else PRINTM ( MSG , " \n " ) ; } if ( RDWR_STATUS_DONE == stat ) { PRINTM ( MSG , " " " \n " , bt_mem_type_mapping_tbl [ idx ] . mem_name , ( unsigned int ) ( dbg_ptr - bt_mem_type_mapping_tbl [ idx ] . mem_Ptr ) ) ; memset ( file_name , 0 , sizeof ( file_name ) ) ; snprintf ( ( char * ) file_name , sizeof ( file_name ) , " " , " " , bt_mem_type_mapping_tbl [ idx ] . mem_name ) ; if ( BT_STATUS_SUCCESS != bt_save_dump_info_to_file ( ( char * ) path_name , ( char * ) file_name , bt_mem_type_mapping_tbl [ idx ] . mem_Ptr , memory_size ) ) PRINTM ( MSG , " \n " , file_name , path_name ) ; vfree ( bt_mem_type_mapping_tbl [ idx ] . mem_Ptr ) ; bt_mem_type_mapping_tbl [ idx ] . mem_Ptr = NULL ; break ; } } while ( 1 ) ; } PRINTM ( MSG , " \n " ) ; done : priv -> fw_dump = FALSE ; for ( idx = 0 ; idx < dump_num ; idx ++ ) { if ( bt_mem_type_mapping_tbl [ idx ] . mem_Ptr ) { vfree ( bt_mem_type_mapping_tbl [ idx ] . mem_Ptr ) ; bt_mem_type_mapping_tbl [ idx ] . mem_Ptr = NULL ; } } PRINTM ( MSG , " \n " ) ; return ; }
@brief This function dump firmware memory to file
  @param phandle   A pointer to moal_handle
@brief This function dump firmware memory to file @param phandle A pointer to moal_handle
/* start dump fw memory */ /* read the number of the memories which will dump */ /* read the length of every memory which will dump */ /* end dump fw memory */