Esempio n. 1
0
static void flash_monitor_write2flash(void)
{
	int lockfd;
	char version[32];
	flash_monitor_task_t *task = dma_flash_monitor.task;

	lockfd = flash_write_lock();
	sem_wait(&dma_flash_monitor.task_lock);
	while(task){
		if(task->status == FLASH_STATUS_DIRTY){
			flash_op_t *p_flash_op = NULL;
			/* changed */
			fprintf(stdout, "F:%s:%d, write flash from srouce dir(%s)->%s\n", 
				__FUNCTION__, __LINE__, task->mdir, task->ofile);
			task->status = FLASH_STATUS_WRITTING;
			/* erase the flash */
			p_flash_op = create_flash_op();	
			flash_op_erase(p_flash_op, task->ofile, NULL);
			destroy_flash_op(&p_flash_op);
			securesoho_get_curversion(version);
			mkconfig_translate_config_dir_to_file(task->mdir, 
					task->ofile, CONF_PRODUCT, version);
			task->status = FLASH_STATUS_CLEAN;		
		}
		task = task->next;
	}
	sem_post(&dma_flash_monitor.task_lock);
	flash_write_unlock(lockfd);
}
Esempio n. 2
0
void flash_monitor_add_task(const char *mdir, const char *ofile)
{
	flash_monitor_task_t *task;
	int lockfd;

	lockfd = flash_write_lock();
	if(mdir && ofile){
		sem_wait(&dma_flash_monitor.task_lock);
		task = flash_monitor_get_task(ofile);
		if(task){
			fprintf(stdout, "%s,%d,	 we have the task(%s,%s)\n",
				__FUNCTION__, __LINE__, mdir, ofile);
		}else{
			fprintf(stdout, "%s,%d, add a new task(%s,%s)\n", 
				__FUNCTION__, __LINE__, mdir, ofile);
			task=(flash_monitor_task_t*)malloc(sizeof(flash_monitor_task_t));
			memset(task, '\0', sizeof(flash_monitor_task_t));
			task->mdir = strdup(mdir);
			task->ofile = strdup(ofile);
			task->status = FLASH_STATUS_CLEAN;
			task->CRC = get_dir_crc(mdir);
			set_saved_dir_crc(task->mdir, task->CRC);
			/* add the task */
			task->next = dma_flash_monitor.task;
			dma_flash_monitor.task = task;
		}
		sem_post(&dma_flash_monitor.task_lock);
	}
	flash_write_unlock(lockfd);
}
Esempio n. 3
0
static int flash_monitor_update_status()
{
	int lockfd;
	int changed=0;
	flash_monitor_task_t *task, *task_base;

	task_base = dma_flash_monitor.task;
	task = task_base;

	lockfd = flash_write_lock();
	sem_wait(&dma_flash_monitor.task_lock);
	while(task){
		unsigned long crc=0;
		crc = get_dir_crc(task->mdir);
		task->CRC = get_saved_dir_crc(task->mdir);
		if(crc != task->CRC){
			/* changed */
			if(changed==0) 
			changed = 1;
			task->status = FLASH_STATUS_DIRTY;
		}
		task = task->next;
	}
	task = task_base;
	while(task){
		unsigned long crc=0;
		crc = get_dir_crc(task->mdir);
		task->CRC = get_saved_dir_crc(task->mdir);
		if(crc != task->CRC){
			/* changed */
			task->CRC = crc;
			set_saved_dir_crc(task->mdir, task->CRC);
		}
		task = task->next;
	}
	sem_post(&dma_flash_monitor.task_lock);
	flash_write_unlock(lockfd);
	return changed;
}
Esempio n. 4
0
int flash_write(struct target *target, struct image *image,
		uint32_t *written, int erase)
{
	return flash_write_unlock(target, image, written, erase, false);
}