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

📄 verchk.c

📁 这是某个项目中使用的ARM7TDMI平台上ucos系统的bootloader
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
**  Copyright  (c)  2004,  UTStarcom, Inc.
**          All Rights Reserved.
**
**  Subsystem  : Platform support
**  File       : verchk.c
**  Created By : Sean Yang
**  Created On : 2005.01.21
**
**  Purpose:
**    check version and run it
**
****************************************************************************/

/****************************************************************************
* includes
****************************************************************************/


#include "common.h"
#include "zlib.h"
#include "../../sys/os/inc/bsp.h"
#include "../../sys/os/inc/ucos_ii.h"
#include "../../sys/hal/inc/hal_nvm.h"
#include "..\..\sys\drv\inc\drv_i2c.h"

/***************************************************************************
* extern functions
***************************************************************************/

/***************************************************************************
* Defines and Typedefs
***************************************************************************/

typedef unsigned char 	U8;
typedef unsigned short 	U16;
typedef unsigned int  	U32;

#define	FAILURE  	(-1)

#define EXT_SRAM_BASE  	0x00200000

#define BUFFER_BASE		0x00360000
#define BUFFER_LEN	    128*1024     /* output buffer length, may be changed according system capacity */                                                   	

#define FPGA_BASE       0x380000
#define FPGA_BUF_SIZE   0x20000

#define TRACE_BASE  	0x003A0000
#define TRACE_SIZE   	0x00060000    /* Trace area, 384K bytes */

#define REG_PIO_SET     0x007FF811
#define REG_PIO_DATA    0x007FF820

/* gzip flag byte */

#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
#define COMMENT      0x10 /* bit 4 set: file comment present */

#define LED_PLN_SW   2   /* program plane switch */
#define LED_ERR_1    3   /* e2prom operation fail */
#define LED_ERR_2    4   /* ram check error */
#define LED_ERR_3    5   /* 2 area boot counter are both > 3 */
#define LED_ERR_4    6   /* 1st area boot counter > 3, 2nd area check err */
#define LED_ERR_5    7   /* 2 area check both err */
#define LED_ERR_6    8   /* program unzip fail */
#define LED_ERR_7    9   /* flash operation fail */

/***************************************************************************
* Global and Local Data Definitions 
***************************************************************************/
/* extern functions */
extern void ak95_config_reg_data(void);
extern INT8 hal_sng_get_act_prog(sw_type_e sw_type, nvm_area_e *act_area);
extern INT8 hal_sng_get_boot_cnt(nvm_area_e area, UINT8 *cnt);
extern INT8 hal_sng_check_prog_sum(sw_type_e sw_type, nvm_area_e area);
extern INT8 hal_sng_get_prog_size(sw_type_e sw_type, nvm_area_e area, UINT32 *size);
extern INT8 hal_sng_get_prog_addr(sw_type_e sw_type, nvm_area_e area, UINT32 *addr);
extern INT8 hal_sng_set_act_prog(sw_type_e sw_type, nvm_area_e act_area);

/* Definitions for gzip functionality */

unzip_const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */

unsigned char *srcp; /* Variables for gzip functionality */
z_stream      d_stream; /* decompression stream */
unsigned char * buffer; /* Allocate enough memory for output buffer */

/* global variables produced by bin2carray */                                                              

unsigned char inbuf[50];	
unsigned int inbuf_num_bytes = sizeof(inbuf);		

void reset_watchdog(void)
{
 	U8 * regs;
 	U8 i;
 	
 	regs = (U8 *)REG_PIO_DATA;	/* output high level to PIO5 */
 	*regs = 0x20;

 	for (i=0; i<8;i++);

 	regs = (U8 *)REG_PIO_DATA;	/* output low level to PIO5 */
 	*regs = 0x00;
}

void boot_led_switch(U8 times)
{
    U32 loop_cnt1, loop_cnt2, loop_cnt3;
	unsigned char * led_ptr = (unsigned char *)0x007ff823;


    for (loop_cnt1 = 0; loop_cnt1 < times; loop_cnt1++)
    {
    	*led_ptr |= 0x02;	/* turn off */
        for (loop_cnt2 = 0; loop_cnt2 < 10; loop_cnt2++)
        {
            for(loop_cnt3 = 0; loop_cnt3 < 10000; loop_cnt3++) {}/* about 1.6s */
            reset_watchdog();
        }
		
    	*led_ptr &= ~0x02; /* turn on */
        for (loop_cnt2 = 0; loop_cnt2 < 10; loop_cnt2++)
        {
            for(loop_cnt3 = 0; loop_cnt3 < 10000; loop_cnt3++){} /* about 1.6s */
            reset_watchdog();
        }
    }
}

/****************************************************************************
**
**  FUNCTION NAME: open_gzip
**
**  Description:
**   	check the header information.
**
**  Argument        Type   					IO           Description
**  ------------- -------- -- ---------------------------------
**  src			       	U8 *    				I 				input header pointer
**  length			   U32      			 	I 				the whole compressed data's length
**  process_length		U32 *					I/O			stat the length  of data which has been dealt with.
**  Global Variables:
**			(1).d_stream.
**  RETURN VALUE: 	BOOL			TRUE/FALSE
**						  TRUE: header information is correct.
**						  FALSE:header information is worng.
**
**   HISTORY (Recommended but Optional):
**
**    Programmer           Date	     Description of Revision
**    -------------------- ---------- ------------------------------
**   Pengliang               2/2/2005
**
****************************************************************************/

U32 open_gzip (U8 *src , U32 length , U32 *process_length)
{
	unsigned char flags;
	int err;
	
	if(length >inbuf_num_bytes )
	{
		memcpy((U8 *)inbuf , (U8 *)src, inbuf_num_bytes); 
		*process_length +=  inbuf_num_bytes;
	}		
	else 
	{
		memcpy(inbuf , src, length); 
		*process_length +=  length;
	}
	
	srcp = &inbuf[0];	/* get the start address of FPGA structure */

	/* check for gzip signature */
	if(srcp[0] == gz_magic[0] &&
     srcp[1] == gz_magic[1] &&
     srcp[2] == Z_DEFLATED)
	{
		/* process (skip) gzip header */
		flags = srcp[3];
		srcp += 10; /* skip header & time, xflags and OS code */
		if((flags & ORIG_NAME) != 0)	/* skip the original file name */ 
		{
			while (*srcp++ != 0);
		}
		if((flags & COMMENT) != 0)	/* skip the .gz file comment */
		{
			while (*srcp++ != 0);
		}
		if((flags & HEAD_CRC) != 0)	/* skip the header crc */
		{	
			srcp += 2;
		}
		
		err = inflateInit2(&d_stream, -MAX_WBITS);

		/* set in/out buffer */ 
		d_stream.next_in   = srcp;		/* start address of compressed data */
		d_stream.avail_in  = inbuf_num_bytes - (srcp - inbuf);	/* size of data */
		d_stream.next_out  = buffer;      /* start address of output data buffer */
		d_stream.avail_out = BUFFER_LEN;	/* output buffer length */

		return SUCCESS ;
	}
	else
	{
		return FAILURE;
	}
}

/****************************************************************************
**
**  FUNCTION NAME: more_gzip
**
**  Description:
**   	decompress data process..
**
**  Argument        Type   					IO           Description
**  ------------- -------- -- ---------------------------------
**  buf			       	void *    				O 				output buffer pointer
**  len			      		U32      			 	I 				   buffer's length
**  flg						U8 *						O					all data decompressing's end flag:0x01: end, 0x02:error happen.
**  Global Variables:
**			(1).d_stream.
**  RETURN VALUE: 	rv_t			SUCCESS/FAILURE value
**						  SUCCESS
**						  FAILURE
**
**   HISTORY (Recommended but Optional):
**
**    Programmer           Date	     Description of Revision
**    -------------------- ---------- ------------------------------
**   Pengliang               2/2/2005
**
**  NOTE: calling function must check "*flg" value.
****************************************************************************/

U32 more_gzip (void *buf, U32  len , U8 *flg ) 
{
	int    err = 0;

	d_stream.next_out  = buf;
	d_stream.avail_out = len;
	if((err = inflate(&d_stream, Z_PARTIAL_FLUSH)) == Z_STREAM_END) 
	{
		*flg = 1;
	}
	else
	{
	    if(err != Z_OK)
	    {
			*flg = 0x02;/*means decompressing error*/
	    }
	}
	return (len - d_stream.avail_out);
}

/****************************************************************************
**
**  FUNCTION NAME: unzip_ver
**
**  Description:
**   the main function of decompress .gz data.
**
**  Argument        Type   					IO           Description
**  ------------- -------- -- ---------------------------------
**  src			       	U8 *    				I  					source adresspointer
**  dest			      	U8*      			 	O 				destination adress pointer
**  length				U32 					I					source data length.
**  Global Variables:
**			(1).buffer[];
**			(2).inbuf_num_bytes.
**			(3).inbuf[].
**			(4).d_stream.
**  RETURN VALUE: 	rtn_val			decompressing data 's length/FAILURE 
**						 
**
**   HISTORY (Recommended but Optional):
**
**    Programmer           Date	     Description of Revision
**    -------------------- ---------- ------------------------------

⌨️ 快捷键说明

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