⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 verchk.c

📁 这是某个项目中使用的ARM7TDMI平台上ucos系统的bootloader
💻 C
📖 第 1 页 / 共 2 页
字号:
**   Pengliang               2/2/2005
**
**
**  NOTE: if decompressing is correct , it will return the decompressing data length; if decompressing is error,
**    			it will return "FAILURE". so calling function must check this return_value.
**
****************************************************************************/

U32 unzip_ver(U8 * src, U8 * dest, U32 length)
{
	U32 rtn_val = 0;	/* the length of inflated file */
	U32  len = 0;	
	U32 process_len =0;
	U8  end_flg =0;
	
	if(FAILURE == open_gzip(src , length , &process_len))
	{
		return FAILURE;
	}
	
	do                                 
	{
		reset_watchdog();
	
		/*len : output data length , buffer: output data buffer*/
		len = more_gzip(buffer, BUFFER_LEN , &end_flg);    
		if(end_flg == 0x02)
		{
			return FAILURE;
		}
		
		if (len > 0)
		{
			/*copy the decompressing data into dest[] buffer.*/
			memcpy((U8 *)&dest[rtn_val] , (U8 *)buffer, len);     
			rtn_val += len;	
		}
		/*judge  "returning loop" condition.*/
		if(end_flg ==1)
		{
			break;
		}
		
			/*copy the compressing  data into inbuf[] buffer.*/
		if((length - process_len )> inbuf_num_bytes)
		{
			memcpy((U8 *)inbuf, (U8 *)&src[process_len] , inbuf_num_bytes );			
			d_stream.next_in = inbuf;
			d_stream.avail_in  = inbuf_num_bytes;
			process_len += inbuf_num_bytes; 
		}
		else
		{
			memcpy(inbuf, &src[process_len] , length - process_len );
			d_stream.next_in = inbuf;
			d_stream.avail_in  = (length - process_len );		
			process_len += (length - process_len ); 
			end_flg  = 1;
		}		
		
	}	while (1);

 return  rtn_val ;

}

/****************************************************************************
**
**  FUNCTION NAME: check_version
**
**  Description:
**   	check version on Flash if ok or not.
**		if version of active plane is ok, then unzip version of active plane from Flash to SRAM.
**		otherwise, check version of standby plane.
**		if version of standby plane is ok, then unzip version of standby version from Flash to SRAM,
**		and set current standby plane to active plane.
**		otherwise, reset system.
**
**  Argument       		 Type   									IO     Description
**  ------------- -------- -- ---------------------------------
**
**  Global Variables:
**	
**  Return Value: N/A
**						  
**   HISTORY (Recommended but Optional):
**
**    Programmer           Date	     Description of Revision
**    -------------------- ---------- ------------------------------
**    Sean Yang				2004.01.28 	Initial Writing
****************************************************************************/

void check_version(void)
{
	U8 * src;
	U8 * dest;
	nvm_area_e act_plane;
	U32 ver_size;
	U8 boot_count;
	U8 switch_flag = 0;
	unsigned char * led_ptr = (unsigned char *)0x007ff823; /* not set control pin because has set in boot_init.c */

	*led_ptr &= ~0x02; /* turn on */
    	
	ak95_config_reg_data();
	i2c_init();

	/* get active plane of version */

	if (hal_sng_get_act_prog(AP_PRG, &act_plane) != OK)
	{
	    boot_led_switch(LED_ERR_1);
		while(1);	/* reset system */
    }

	/* clear the boot counter when cold boot */
	
	if (hal_sng_is_coldboot() != OK)
	{
    	if (hal_sng_set_boot_cnt(PRG_AREA_1, 0) != OK ||
    	    hal_sng_set_boot_cnt(PRG_AREA_2, 0) != OK )
    	{
    	    boot_led_switch(LED_ERR_1);
    		while(1);	/* reset system */
        }
	}
	
	/* get fail count of version */

	if (hal_sng_get_boot_cnt(act_plane, &boot_count) != OK)
	{
	    boot_led_switch(LED_ERR_1);
		while(1);	/* reset system */
    }

	/* running version count add 1, if running normal of CPU version, it will be clear */
	
	if (hal_sng_set_boot_cnt(act_plane, boot_count + 1) != OK)
	{
	    boot_led_switch(LED_ERR_1);
		while(1);	/* reset system */
    }

	/* running version count is great than 3 times, modify active plane */
	
	if (boot_count > 3)
	{
		if (PRG_AREA_1 == act_plane)
			act_plane = PRG_AREA_2;
		else
			act_plane = PRG_AREA_1;
			
		switch_flag = 1;
		
		/* get fail count of version */
	
		if (hal_sng_get_boot_cnt(act_plane, &boot_count) != OK)
    	{
    	    boot_led_switch(LED_ERR_1);
    		while(1);	/* reset system */
        }

    	/* running version count add 1, if running normal of CPU version, it will be clear */

    	if (hal_sng_set_boot_cnt(act_plane, boot_count + 1) != OK)
    	{
    	    boot_led_switch(LED_ERR_1);
    		while(1);	/* reset system */
        }
        
		/* running version count is great than 3 times, reset system */
		
		if (boot_count > 3)
    	{
    	    boot_led_switch(LED_ERR_3);
    		while(1);	/* reset system */
        }
	}

	/* check version of active plane */
	if (hal_sng_check_prog_sum(AP_PRG, act_plane) != OK) 
	{
		if (1 == switch_flag)
    	{
    	    boot_led_switch(LED_ERR_4);
    		while(1);	/* reset system */
        }
		
		/* check error, modify active plane */
		
		if (PRG_AREA_1 == act_plane)
			act_plane = PRG_AREA_2;
		else
			act_plane = PRG_AREA_1;

		switch_flag = 1;
		
    	/* running version count add 1, if running normal of CPU version, it will be clear */
    	if (hal_sng_get_boot_cnt(act_plane, &boot_count) != OK)
    	{
    	    boot_led_switch(LED_ERR_1);
    		while(1);	/* reset system */
        }   	
    	if (hal_sng_set_boot_cnt(act_plane, boot_count + 1) != OK)
    	{
    	    boot_led_switch(LED_ERR_1);
    		while(1);	/* reset system */
        }
        
		/* check version of standby plane */

		if (hal_sng_check_prog_sum(AP_PRG, act_plane) != OK) 
    	{
    	    boot_led_switch(LED_ERR_5);
    		while(1);	/* reset system */
        }
	}
	
	/* get version size */
	
	if (hal_sng_get_prog_size(AP_PRG, act_plane, &ver_size) != OK)
	{
	    boot_led_switch(LED_ERR_7);
		while(1);	/* reset system */
    }

	/* set address of source and destination, then unzip version from Flash to SRAM */

	if (hal_sng_get_prog_addr(AP_PRG, act_plane, (U32 *)&src) != OK)
	{
	    boot_led_switch(LED_ERR_7);
		while(1);	/* reset system */
    }

	/* unzip version, from FLASH to SRAM */

	dest = (U8 *)EXT_SRAM_BASE;
	buffer = (U8 *)BUFFER_BASE;

	if (unzip_ver(src, dest, ver_size) == FAILURE)
	{
	    boot_led_switch(LED_ERR_6);
		while(1);	/* reset system */
    }
    
	ver_size = 0;
	src = 0;
	if (hal_sng_get_prog_size(FPGA_PRG, act_plane, &ver_size) != OK)
	{
	    boot_led_switch(LED_ERR_7);
		while(1);	/* reset system */
    }

	if (hal_sng_get_prog_addr(FPGA_PRG, act_plane, (U32 *)&src) != OK)
	{
	    boot_led_switch(LED_ERR_7);
		while(1);	/* reset system */
    }

	dest = (U8 *)FPGA_BASE;
	buffer = (U8 *)BUFFER_BASE;
    memset(buffer, 0, FPGA_BUF_SIZE);
	if (unzip_ver(src, dest, ver_size) == FAILURE)
	{
	    boot_led_switch(LED_ERR_6);
		while(1);	/* reset system */
    }
	
	/* set boot plane */
	
	if (hal_sng_set_act_prog(AP_PRG, act_plane) != OK)
	{
	    boot_led_switch(LED_ERR_1);
		while(1);	/* reset system */
    }

    if (1 == switch_flag)
    {
        boot_led_switch(LED_PLN_SW);
    }
		
	*led_ptr |= 0x02;	/* turn off */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -