Exemple #1
0
static int bq27410_update_write(struct file *filp, const char __user *buff, unsigned long len, void *data)
{
	int ret = 0;
	char update_file[100];
	memset(update_file, 0, 100);

	if(copy_from_user(&update_file, buff, len))	
	{		
		return -EFAULT;	
	}

	update_file[len-1] = 0;
	ret = update_get_flen(update_file);
	if(ret == 0){
		printk("bq27410_update_write:update_get_flen error.\n");
		return -EFAULT;
	}

	mutex_lock(&g_bq27410_mutex);

	printk("update file: %d-[%s].\n", len, update_file);
	if(bq27410_update_flash_data(filp, update_file, len, data) < 0)
		ret = bq27410_update_flash_data(filp, update_file, len, data);

	mutex_unlock(&g_bq27410_mutex);

	if(ret)
	{
		//after update firmware ,restart the system.
		printk("%s,after update firmware ,restart the system.\n", __FUNCTION__);
		sys_sync();
		msleep(200);
		bq27410_update_flag = 3;
//		kernel_restart(NULL);
	}
	else{
		printk("bq27410_update_write:update failed.\n");
		bq27410_update_flag = 4;
	}
	return len;

}
Exemple #2
0
static void bq27410_battery_update_work(struct work_struct *work)
{
	struct file *filp;
	int retval;
	unsigned long len = sizeof(g_filename);
	struct bq27410_device_info *di = container_of(work, struct bq27410_device_info, work.work); 

	retval = update_get_flen(g_filename);
	if(retval == 0){
		printk("bq27410_battery_update_work:update_get_flen error.\n");
		return;
	}

	mutex_lock(&g_bq27410_mutex);
	retval = bq27410_update_flash_data(filp, g_filename, len, NULL);
	mutex_unlock(&g_bq27410_mutex);

	if(retval == 0)
	{
	#if UPDATE_FIRMWARE_RESTART
		printk("bq27410_battery_update_work ,update success,restart the system.\n");
		virtual_battery_enable = 0;
		//after update firmware ,restart the system.
		sys_sync();
		msleep(200);
		kernel_restart(NULL);

		return;
	#else
		printk("bq27410_battery_update_work ,update success.\n");
	#endif
	}
	else{
		printk("bq27410_battery_update_work:update failed.\n");
		return;
	}

	bq27410_write_batt_insert(g_client);
	msleep(2000);
	bq27410_write_batt_insert(g_client);
	
	INIT_DELAYED_WORK(&bq27410_di->work, bq27410_battery_work);
	schedule_delayed_work(&bq27410_di->work, bq27410_di->interval);
}