/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
void usb_params_init(void)
{
	__u32 i;

	usb_clock_init();

	awxx_usb[0].index = 0;
	awxx_usb[0].reg_base = 	0x01c19000;
	awxx_usb[0].irq_no = 103;
	awxx_usb[0].drq_no = 0x04;

	awxx_usb[0].role = USB0_ROLE;  //USB_ROLE_HST; //USB_ROLE_UNK
	awxx_usb[0].speed = USB0_SPEED;

	if(awxx_usb[0].speed==USB_SPEED_HS)
	{
		awxx_usb[0].device.dev_desc   = USB_HS_BULK_DevDesc;
		awxx_usb[0].device.config_desc= USB_HS_BULK_ConfigDesc;
	}
	else
	{
		awxx_usb[0].device.dev_desc   = USB_FS_BULK_DevDesc;
		awxx_usb[0].device.config_desc= USB_FS_BULK_ConfigDesc;
	}
	for(i=0; i<4; i++)
	{
		awxx_usb[0].device.str_desc[i]   = USB_StrDec0[i];
	}

	awxx_usb[0].device.intf_desc  = USB_HS_BULK_ConfigDesc;
	awxx_usb[0].device.endp_desc  = USB_HS_BULK_ConfigDesc;
	awxx_usb[0].device.dev_qual   = USB_DevQual;
	awxx_usb[0].device.otg_desc   = USB_OTGDesc;

	//awxx_usb[0].device.MaxLUN = USB_MAX_LUN;
	//awxx_usb[0].device.MaxLUN = wBoot_part_count() - 1;
	awxx_usb[0].device.MaxLUN = wBoot_part_count(1) - 1;
	__inf("part count = %d\n", awxx_usb[0].device.MaxLUN + 1);

	//awxx_usb[0].device.bo_memory_base =   USB_BO_DEV0_MEM_BASE;                           // USB_BO_DEV0_MEM_BASE;
	//awxx_usb[0].device.bo_capacity = USB_DEV0_TOTAL_CAP;  //MB
	//awxx_usb[0].device.bo_seccnt = usb_get_capacity();                  //USB_DEV0_SEC_CNT;
	//awxx_usb[0].device.bo_bufbase = USB_BO_DEV0_BUF_BASE;	                                 //??
	awxx_usb[0].device.bo_memory_base = (__u32)wBoot_malloc(128 * 1024);		//use to storage user data
	awxx_usb[0].device.bo_bufbase = (__u32)wBoot_malloc(64 * 1024);				//use to usb ping-pang buffer

	awxx_usb[0].ep0_flag = 0;
	awxx_usb[0].ep0_xfer_state = USB_EP0_SETUP;

	//dma
	awxx_usb[0].dma = wBoot_dma_request(1);
	if(!awxx_usb[0].dma)
	{
		__inf("usb error: request dma fail\n");
	}
}
__u32 ShowBatteryCharge_init(int rate)
{
	bat_charge_show *battery_info = NULL;
	__s32 			 ret = 0, i;
	char             pic_name[32];

	/* 参数初始化 */
	if(!board_res.layer_hd)
    {
        return 0;
    }
    battery_info = wBoot_malloc(sizeof(bat_charge_show));
    if(!battery_info)
    {
    	return 0;
    }
    memset(battery_info, 0, sizeof(bat_charge_show));
    memset(pic_name, 0, 32);
    strcpy(pic_name, "c:\\os_show\\bat0.bmp");

	for(i=0;i<10;i++)
	{
		pic_name[14] = '0' + i;
		ret = Parse_Pic_BMP_ByPath(pic_name, &battery_info->battery[i], 0);
		if(ret != 0)
		{
			__inf("parser bmp file %s failed\n", pic_name);
			return 0;
		}
	}
	ret = Parse_Pic_BMP_ByPath("c:\\os_show\\bat10.bmp", &battery_info->battery[10], 0);
	if(ret != 0)
	{
		__inf("parser bmp file c:\\os_show\\bat10.bmp failed\n");
		return 0;
	}

	battery_info->PictureInfo.BitCount = battery_info->battery[0].BitCount;
	battery_info->PictureInfo.Height = battery_info->battery[0].Height;
	battery_info->PictureInfo.Width  = battery_info->battery[0].Width;
	battery_info->PictureInfo.BufferSize = battery_info->PictureInfo.Width * battery_info->PictureInfo.Height * 4;
	battery_info->PictureInfo.Buffer = wBoot_malloc(battery_info->PictureInfo.BufferSize);
	battery_info->PictureInfo.RowSize = battery_info->PictureInfo.Width * 4;
	battery_info->buffersize = battery_info->PictureInfo.BufferSize;
	if(!battery_info->PictureInfo.Buffer)
	{
		return 0;
	}
	memcpy(battery_info->PictureInfo.Buffer, battery_info->battery[0].Buffer, battery_info->PictureInfo.BufferSize);
	/* 显示图片 */
	battery_info->layer_para = ui_AllocLayerPara(&battery_info->PictureInfo);
	ShowLayer(board_res.layer_hd, battery_info->layer_para, board_res.display_source);

    return (__u32)battery_info;
}
Example #3
0
//------------------------------------------------------------------------------------------------------------
//
// 函数说明
//
//
// 参数说明
//
//
// 返回值
//
//
// 其他
//    无
//
//------------------------------------------------------------------------------------------------------------
__s32 script_patch(char *script_name, void *script_buf, __s32 boot_script_type)
{
    H_FILE script_file = NULL;
    int    ret = -1;
    char   *script_addr = NULL;
    int    script_len;

    //打开脚本文件,打不开则失败
    if(!script_name)
    {
        __wrn("the input script is empty\n");

        return -1;
    }
    script_file = wBoot_fopen(script_name, "rb");
    if(!script_file)
    {
        __wrn("unable to open script file %s\n", script_name);

        return -1;
    }
    //首先获取脚本的长度
    script_len = wBoot_flen(script_file);
    //读出脚本所有的内容
    script_addr = (char *)wBoot_malloc(script_len);
    if(!script_addr)
    {
        __wrn("unable to malloc memory for script\n");

        goto _err_out;
    }
    wBoot_fread(script_addr, 1, script_len, script_file);
    wBoot_fclose(script_file);
    script_file = NULL;
    //解析脚本,根据脚本类型作区别
    if(!boot_script_type)
    {
        ret = parser_script_os_sel(script_addr, script_len, script_buf);
    }
    if(ret)
    {
        __wrn("script is invalid\n");
    }

_err_out:
    //退出时候的处理
    if(script_addr)
    {
        wBoot_free(script_addr);
    }
    if(script_file)
    {
        wBoot_fclose(script_file);
        script_file = NULL;
    }

    return ret;
}
Example #4
0
/*
************************************************************************************************************
*
*                                             ui_show_data
*
*    函数名称:ui_show_data
*
*    参数列表:
*
*    返回值  :
*
*    说明    :在屏幕的某个位置显示传进的数据
*
*
************************************************************************************************************
*/
__hdle boot_ui_progressbar_create(int x1, int y1, int x2, int y2)
{
    progressbar_t *progress = NULL;
    int tmp;

    progress = wBoot_malloc(sizeof(progressbar_t));
    if(!progress)
    {
        __inf("boot ui: create progressbar failed\n");

        return NULL;
    }
    if(x1 > x2)
    {
        tmp = x1;
        x1 	= x2;
        x2  = tmp;
    }
    if(y1 > y2)
    {
        tmp = y1;
        y1 	= y2;
        y2  = tmp;
    }
    progress->x1 = x1;
    progress->x2 = x2;
    progress->y1 = y1;
    progress->y2 = y2;
    progress->width  = x2 - x1;
    progress->height = y2 - y1;
    progress->st_x	 = progress->pr_x = x1 + 1;
    progress->st_y	 = progress->pr_y = y1 + 1;
    progress->frame_color 	 = UI_BOOT_GUI_WHITE;
    progress->progress_color = UI_BOOT_GUI_GREEN;
    progress->progress_ratio = 0;
    progress->thick          = 1;
    progress->frame_color 	 = UI_BOOT_GUI_GREEN;
    progress->progress_color = UI_BOOT_GUI_RED;

    return (__hdle)progress;
}
/*
*******************************************************************************
*                     ui_AllocLayerPara
*
* Description:
*    初始化一个图层参数
*
* Parameters:
*    PictureInfo  :  input. 图片信息
*
* Return value:
*    返回图层参数
*
* note:
*    void
*
*******************************************************************************
*/
display_layer_info_t *ui_AllocLayerPara(Picture_t *PictureInfo)
{
	display_layer_info_t *layer_para = NULL;
	__u32 screen_width = 0;
	__u32 screen_height = 0;

	layer_para = (display_layer_info_t *)wBoot_malloc(sizeof(display_layer_info_t));
	if(layer_para == NULL)
	{
		DMSG_PANIC("ERR: wBoot_malloc failed\n");
		return NULL;
	}
	memset(layer_para, 0, sizeof(display_layer_info_t));
    /* 初始化图形参数 */
	screen_width  = De_GetSceenWidth();
	screen_height = De_GetSceenHeight();

    layer_para->fb.size.width 		= (PictureInfo->RowSize * 8) / PictureInfo->BitCount;
    layer_para->fb.addr[0] 			= (__u32)PictureInfo->Buffer;
    layer_para->fb.mode = DISP_MOD_INTERLEAVED;
    layer_para->fb.format = DISP_FORMAT_ARGB8888;
    layer_para->fb.br_swap = 0;
    layer_para->fb.seq = DISP_SEQ_ARGB;
    layer_para->ck_enable        = 0;
	layer_para->mode           = DISP_LAYER_WORK_MODE_NORMAL;
	layer_para->alpha_en       = 1;
	layer_para->alpha_val      = 0xff;
	layer_para->pipe           = 0;
	layer_para->src_win.x      = 0;
	layer_para->src_win.y      = 0;
	layer_para->src_win.width  = PictureInfo->Width;
	layer_para->src_win.height = PictureInfo->Height;
	layer_para->scn_win.x      = (screen_width - PictureInfo->Width) / 2;  	/* 居中 */
	layer_para->scn_win.y      = (screen_height - PictureInfo->Height) / 2;	/* 居中 */
	layer_para->scn_win.width  = PictureInfo->Width;
	layer_para->scn_win.height = PictureInfo->Height;

    return layer_para;
}
/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
int env_fetch_from_boot1(void)
{
	char *tmp_boot1 = NULL;
	int   ret = 0;

	tmp_boot1 = wBoot_malloc(512 * 1024);
	if(!tmp_boot1)
	{
		__inf("not enough memory to read boot1!\n");

		return 0;
	}
	else
	{
		if(Nand_Load_Boot1(tmp_boot1, 512 * 1024))
		{
			__inf("the boot1 in flash is bad!\n");

			return 0;
		}
		else
		{
			boot1_file_head_t  *tmp_boot1_head = (boot1_file_head_t *)tmp_boot1;
			char 			   *base = (char *)tmp_boot1_head->prvt_head.script_buf;
			int   			   i;
			dynamic_data_form  *dform;
			dynamic_boot_head  *dhead;

			dhead = (dynamic_boot_head *)base;
			if(strncmp(dhead->magic, "dynamic", sizeof("dynamic")))
			{
				__inf("dynamic data magic error\n");

				return 0;
			}
			base += sizeof(dynamic_boot_head);
			for(i=0;i<dhead->count;i++)
			{
				dform = (dynamic_data_form *)base;
				if(!strncmp(dform->name, "MAC", sizeof("MAC")))
				{
					char *buf0 = env_flash_dram_base+4;
					char *buf1 = base + sizeof(dynamic_data_form);
					int   j, k, l;

					__inf("dynamic data form1 find\n");
					strcpy(env_flash_dram_base, "mac=");

					k = 0;
					l = 0;
					for(j=0;j<5;j++)
					{
						buf0[k++] = buf1[l++];
						buf0[k++] = buf1[l++];
						buf0[k++] = ':';
					}
					buf0[k++] = buf1[l++];
					buf0[k++] = buf1[l++];
					buf0[k]   = '\0';
					ret = 1;
					env_exist = 2;

					break;
				}
				else if(!strncmp(dform->name, "mac_addr", sizeof("mac_addr")))
				{
					__inf("dynamic data form2 find\n");
					__inf("usedsize=%d\n", dform->usedsize>>2);

					{
						char *tm = base + sizeof(dynamic_data_form);
						int   p;

						for(p=0;p<4;p++)
						{
							__inf("%c %c %c %c %c %c %c %c\n", *(tm + 0), *(tm + 1), *(tm + 2), *(tm + 3), *(tm + 4), *(tm + 5), *(tm + 6), *(tm + 7));
							tm += 8;
						}
						__inf("\n");
					}

					memcpy(env_flash_dram_base, base + sizeof(dynamic_data_form), dform->usedsize);
					ret = 1;
					env_exist = 2;
				}
				base += dform->usedsize;
			}
		}
		wBoot_free(tmp_boot1);
	}
/*******************************************************************************
*函数名称: NAND_BadBlockScan
*函数原型:bad_blcok_scan(const boot_nand_para_t *nand_param)
*函数功能: 标记blk_num指定的块为坏块。
*入口参数: nand_param
*返 回 值: >0              编程操作成功
*          -1              编程操作失败
*备    注:
*******************************************************************************/
__s32 NAND_BadBlockScan(const boot_nand_para_t *nand_param)
{
	boot_flash_info_t info;
	struct boot_physical_param  para;

	__s32  i, j, k;
	__u32  page_with_bad_block, page_per_block;
	__s32  page_index[4];
	__u32  bad_block_cnt[8];
	__u32  bad_block_num = 0;
	__u32  good_block_num = 0;
	__s32  good_block_ratio = -1;
	__u32  chip;
	__u8   oob_buf[OOB_BUF_SIZE];
	__u8*  page_buf;
	__u32  die_skip_flag = (nand_param->OperationOpt)&(0x1<<11);
	__u32  block_cnt_of_die = (nand_param->BlkCntPerDie);

	for(i=0; i<8; i++)
	    bad_block_cnt[i] = 0;

	NAND_Print("Ready to scan bad blocks.\n");

    // get nand info to cal
	NAND_Print("nfb phy init ok.\n");
	if( NAND_GetFlashInfo( &info ) )
	    {
    		NAND_Print("get flash info failed.\n");
    		return -1;
    	}
	NAND_Print("Succeed in getting flash info.\n");

	//cal nand parameters
	//page_buf = (__u8*)(BAD_BLK_SCAN_BUF_ADR);
    page_buf = (__u8*)wBoot_malloc(32 * 1024);
    if(!page_buf)
    {
        NAND_Print("malloc memory for page buf fail\n");
        return -1;
    }

	page_with_bad_block = info.pagewithbadflag;
	page_per_block = info.blocksize/info.pagesize;

	//read the first, second, last, last-1 page for check bad blocks
	page_index[0] = 0;
	page_index[1] = 0xEE;
	page_index[2] = 0xEE;
	page_index[3] = 0xEE;

    switch(page_with_bad_block & 0x03)
    {
        case 0x00:
            //the bad block flag is in the first page, same as the logical information, just read 1 page is ok
            break;

        case 0x01:
            //the bad block flag is in the first page or the second page, need read the first page and the second page
            page_index[1] = 1;
            break;

        case 0x02:
            //the bad block flag is in the last page, need read the first page and the last page
            page_index[1] = page_per_block - 1;
            break;

        case 0x03:
            //the bad block flag is in the last 2 page, so, need read the first page, the last page and the last-1 page
            page_index[1] = page_per_block - 1;
            page_index[2] = page_per_block - 2;
            break;
    }

    //scan bad blocks
	for( i = 0;  i < info.chip_cnt;  i++ ){

		chip = _cal_real_chip( i, nand_param->ChipConnectInfo );
		NAND_Print("scan CE %u\n", chip);
		bad_block_cnt[chip] = 0;

		for( j = 0;  j < info.blk_cnt_per_chip;  j++ )
		{
			para.chip = chip;
			if(!die_skip_flag)
			    para.block = j;
			else
			    para.block = j%block_cnt_of_die + 2*block_cnt_of_die*(j/block_cnt_of_die);
			para.mainbuf = page_buf;
			para.oobbuf = oob_buf;

			for(k = 0; k<4; k++)
			{
				// read pages for check
				para.page = page_index[k];
				if(para.page == 0xEE)
				    continue;
				NAND_PhyRead(&para );

				// find bad blocks
				if(oob_buf[0] != 0xff)
				{
				    NAND_Print("find defined bad block in chip %u, block %u.\n", i, j);
					bad_block_cnt[chip]++;
                    break;
				}
			}
		}
	}

	// cal bad block num
	if(info.chip_cnt == 0x1)        //for one CE
    	{
    	    if(nand_param->ChipConnectInfo == 0x1)
    	        {
    	            bad_block_num = bad_block_cnt[0]<<1;
    	        }
    		else
    		    {
    		        NAND_Print("chip connect parameter %x error \n", nand_param->ChipConnectInfo);
    		        wBoot_free(page_buf);

        			return -1;
    		    }
    	}
	else if(info.chip_cnt == 2)     //for two CE
    	{
    		if(nand_param->ChipConnectInfo == 0x3)
    		    {
    			    bad_block_num = (bad_block_cnt[0] + bad_block_cnt[1])<<1;
    		    }
    		else if(nand_param->ChipConnectInfo == 0x5)
        		{
        			bad_block_num = (bad_block_cnt[0] + bad_block_cnt[2])<<1;
        		}
    		else if(nand_param->ChipConnectInfo == 0x81)
        		{
        			bad_block_num = (bad_block_cnt[0] + bad_block_cnt[7])<<1;
        		}
    		else
        		{
        			NAND_Print("chip connect parameter %x error \n", nand_param->ChipConnectInfo);
        			wBoot_free(page_buf);

        			return -1;
        		}
    	}
	else if(info.chip_cnt == 4)     //for four CE
	    {
    		if(nand_param->ChipConnectInfo == 0xf)
    		    {
    			    bad_block_num = max_badblk((bad_block_cnt[0] + bad_block_cnt[2]),(bad_block_cnt[1] + bad_block_cnt[3]))<<1;
    		    }
    		else if(nand_param->ChipConnectInfo == 0x55)
    		    {
    			    bad_block_num = max_badblk((bad_block_cnt[0] + bad_block_cnt[2]),(bad_block_cnt[4] + bad_block_cnt[6]))<<1;
    		    }
    		else
    		    {
    			    NAND_Print("chip connect parameter %x error \n",nand_param->ChipConnectInfo);
    			    wBoot_free(page_buf);

    			    return -1;
    		    }

	    }
	else if(info.chip_cnt == 8)     //for eight CE
	    {
    		if(nand_param->ChipConnectInfo == 0xff)
    		    {
        			bad_block_num = max_badblk((bad_block_cnt[0] + bad_block_cnt[2]),(bad_block_cnt[1] + bad_block_cnt[3]));
        			bad_block_num = 2*max_badblk(bad_block_num, max_badblk((bad_block_cnt[4] + bad_block_cnt[6]),(bad_block_cnt[5] + bad_block_cnt[7])));

        		}
    		else
    		    {
        			NAND_Print("chip connect parameter %x error \n",nand_param->ChipConnectInfo);
        			wBoot_free(page_buf);

        			return -1;
        		}
	    }
	else
	    {
	        NAND_Print("chip cnt parameter %x error \n",nand_param->ChipCnt);
	        wBoot_free(page_buf);

        	return -1;
	    }


	//cal good block num required per 1024 blocks
	good_block_num = (1024*(info.blk_cnt_per_chip - bad_block_num))/info.blk_cnt_per_chip -114;
    for(i=0; i<info.chip_cnt; i++)
    {
		chip = _cal_real_chip( i, nand_param->ChipConnectInfo );
		NAND_Print(" %d bad blocks in CE %u \n", bad_block_cnt[chip], chip);
	}
	NAND_Print("cal bad block num is %u \n", bad_block_num);
	NAND_Print("cal good block num is %u \n", good_block_num);

    //cal good block ratio
	for(i=0; i<10; i++)
	{
		if(good_block_num >= (nand_param->good_block_ratio - 32*i))
		    {
    			good_block_ratio = (nand_param->good_block_ratio - 32*i);
    			NAND_Print("good block ratio is %u \n",good_block_ratio);
    			break;
    		}
	}
    wBoot_free(page_buf);

 	return good_block_ratio;
}
/*
************************************************************************************************************************
*                       NAND_EraseChip
*
*Description: Erase chip, only erase the all 0x0 blocks
*
*Arguments  : connecnt info.
*
*Return     :   = 0     OK;
*               other  Fail.
************************************************************************************************************************
*/
__s32  NAND_EraseChip( const boot_nand_para_t *nand_param)
{
	boot_flash_info_t info;
	struct boot_physical_param  para_read;

	__s32  i,j,k,m;
	__s32  ret;
	__s32  cnt0, cnt1;
	__s32  mark_err_flag;
	__u32  bad_block_flag;
	__u32  page_with_bad_block, page_size, page_per_block;
	__s32  page_index[4];
	__u32  chip;
	__u8   oob_buf_read[OOB_BUF_SIZE];
	__u8*  page_buf_read;
	__s32  error_flag = 0;
	__s32  block_start;
	__u32  die_skip_flag = (nand_param->OperationOpt)&(0x1<<11);
	__u32  block_cnt_of_die = (nand_param->BlkCntPerDie);

    bad_block_scan_flag = 0;

    page_buf_read = (__u8*)wBoot_malloc(32 * 1024);
    if(!page_buf_read)
    {
        NAND_Print("malloc memory for page read fail\n");
        return -1;
    }
	NAND_Print("Ready to erase chip.\n");
	// get nand info to cal
	NAND_Print("nfb phy init ok.\n");
	if( NAND_GetFlashInfo( &info ) != 0 )
	{
		NAND_Print("get flash info failed.\n");
		wBoot_free(page_buf_read);
		return -1;
	}
	NAND_Print("Succeed in getting flash info.\n");

	page_size = 512*info.pagesize;
	page_with_bad_block = info.pagewithbadflag;
	page_per_block = info.blocksize/info.pagesize;
	NAND_Print("page size:%x, block size: %x, bad block position: %x.\n",page_size, page_per_block,page_with_bad_block);

    page_index[0] = 0;
	page_index[1] = 0xEE;
	page_index[2] = 0xEE;
	page_index[3] = 0xEE;

    switch(page_with_bad_block & 0x03)
    {
        case 0x00:
            //the bad block flag is in the first page, same as the logical information, just read 1 page is ok
            break;

        case 0x01:
            //the bad block flag is in the first page or the second page, need read the first page and the second page
            page_index[1] = 1;
            break;

        case 0x02:
            //the bad block flag is in the last page, need read the first page and the last page
            page_index[1] = page_per_block - 1;
            break;

        case 0x03:
            //the bad block flag is in the last 2 page, so, need read the first page, the last page and the last-1 page
            page_index[1] = page_per_block - 1;
            page_index[2] = page_per_block - 2;
            break;
    }

    NAND_Print("chip_cnt = %x, chip_connect = %x, rb_cnt = %x,  rb_connect = %x,  good_block_ratio =%x \n",nand_param->ChipCnt,nand_param->ChipConnectInfo,nand_param->RbCnt,nand_param->RbConnectInfo,nand_param->good_block_ratio);

	for( i = 0;  i < nand_param->ChipCnt;  i++ )
	{
	    //select chip
		chip = _cal_real_chip( i, nand_param->ChipConnectInfo );
        NAND_Print("erase chip %u \n", chip);

        //scan for bad blocks, only erase good block, all 0x00 blocks is defined bad blocks
		if(i == 0)
		{
			block_start = 7;
		}
		else
		{
			block_start = 0;
		}
		for( j = block_start;  j < info.blk_cnt_per_chip;  j++ )
		{
			para_read.chip = chip;
			if(!die_skip_flag)
			    para_read.block = j;
			else
			    para_read.block = j%block_cnt_of_die + 2*block_cnt_of_die*(j/block_cnt_of_die);
			para_read.mainbuf = page_buf_read;
			para_read.oobbuf = oob_buf_read;

			bad_block_flag = 0;

			for(k = 0; k<4; k++)
			{
				cnt0 =0;
				cnt1 =0;
				para_read.page = page_index[k];
				if( para_read.page== 0xEE)
				    break;

				ret = NAND_PhyRead(& para_read );

				//check the current block is a all 0x00 block
				#if 0
				for(m=0; m<8; m++)   //check user data, 8 byte
			    {
			        if(oob_buf_read[m] == ((__u8)0x0) )
			            cnt1++;
			        else
			            break;
			    }
				for(m=0; m<page_size; m++)  //check main data
				{
					if(page_buf_read[m] == ((__u8)0x0) )
						cnt0++;
					else
						break;
			    }

				if((cnt0 == page_size)&&(cnt1 == 8))
				{
					bad_block_flag = 1;
					NAND_Print("find a all 0x00 block %u\n", j);
					break;
				}
				#endif
				if(oob_buf_read[0] == 0x0)
				{
						bad_block_flag = 1;
						NAND_Print("find a bad block %u\n", j);
						break;
				}
			}

			if(bad_block_flag)
				continue;

			ret = NAND_PhyErase( &para_read );
			if( ret != 0 )
	    		{
	    		    NAND_Print("erasing block %u failed.\n", j );
			    	mark_err_flag = mark_bad_block( i, j );
	    		    if( mark_err_flag!= 0 )
	    		        {
        					error_flag++;
        					NAND_Print("error in marking bad block flag in chip %u, block %u, mark error flag %u.\n", i, j, mark_err_flag);
        				}
	    		}

    		}
	}

	NAND_Print("has cleared the chip.\n");
	if(error_flag)
		NAND_Print("the nand is Bad.\n");
	else
		NAND_Print("the nand is OK.\n");

    wBoot_free(page_buf_read);

	return 0;

}
/*
************************************************************************************************************************
*                       NAND_VersionCheck
*
*Description: Check the nand flash driver is current version
*
*Arguments  : void.
*
*Return     :   = 0  version match;
*                 1  version not match
*                -1  can't get invalid version info
************************************************************************************************************************
*/
__s32 NAND_VersionCheck(void)
{
	struct boot_physical_param boot0_readop_temp;
	struct boot_physical_param *boot0_readop = NULL;
	__u32 block_index;
	__u32 cnt1;
	__s32 version_match_flag = -1;
	//__u32 chip_type;
	__s32 i;
	__u8  oob_buf[32];
	__u32* main_data;
	__u8  nand_version[4];

    /********************************************************************************
    *   nand_version[2] = 0xFF;          //the sequnece mode version <
    *   nand_version[2] = 0x01;          //the first interleave mode version, care ecc
    *                                      2010-06-05
    *   nand_version[2] = 0x02;          //the current version, don't care ecc
    *                                      2010-07-13
    *   NOTE:  need update the nand version in update_boot0 at the same time
    ********************************************************************************/
    nand_version[0] = 0xff;     //bad block flag
    nand_version[1] = 0x00;     //reserved, set to 0x00
    nand_version[2] = NAND_VERSION_0;     //nand driver version 0, current vresion is 0x02
    nand_version[3] = NAND_VERSION_1;     //nand driver version 1, current vresion is 0x00

    NAND_Print("check nand version start.\n");
	NAND_Print("Current nand driver version is %x %x %x %x \n", nand_version[0], nand_version[1], nand_version[2], nand_version[3]);

    boot0_readop = &boot0_readop_temp;

	//init boot0_readop
	boot0_readop->block = 0x0;
	boot0_readop->chip = 0;
	boot0_readop->mainbuf = (void*)wBoot_malloc(32 * 1024);
    if(!boot0_readop->mainbuf)
    {
        NAND_Print("malloc memory for boot0 read operation fail\n");
        return -1;
    }

	boot0_readop->oobbuf = oob_buf;
	boot0_readop->page = 0;
	boot0_readop->sectorbitmap = 0;

    main_data = (__u32*)wBoot_malloc(32 * 1024);
    if(!main_data)
    {
        NAND_Print("malloc memory for main data fail\n");
        return -1;
    }

    //scan boot0 area blocks
	for(block_index=BOOT0_START_BLK_NUM;block_index<BOOT0_LAST_BLK_NUM + 1;block_index++)
	{

		boot0_readop->block = block_index;
		boot0_readop->page = 0;
		cnt1 = 0;

        NAND_PhyRead_1K(boot0_readop);

        //check the current block is a bad block
		if(oob_buf[0] != 0xFF)
	    {
			NAND_Print("block %u is bad block.\n",block_index);
			continue;
	    }


		//check the current block is a all 0xFF block
		for(i=0; i<256; i++)
		{
			if(*(main_data+i) == 0xffffffff)
				cnt1++;
		}

		if(cnt1 == 256)
	    {
			NAND_Print("block %u is cleared block.\n",block_index);
			continue;
	    }

	    if((oob_buf[1] == 0x00) || (oob_buf[1] == 0xFF))
	    {
	       NAND_Print("Media version is valid in block %u, version info is %x %x %x %x \n", block_index, oob_buf[0], oob_buf[1], oob_buf[2], oob_buf[3]);
	       if(oob_buf[2] == nand_version[2])
	       {
	            NAND_Print("nand driver version match ok in block %u.\n",block_index);
    		    version_match_flag = 0;
    		    break;
	       }
	       else
	       {
	            NAND_Print("nand driver version match fail in block %u.\n",block_index);
    		    version_match_flag = 1;
    		    break;
	       }

	    }
	    else
	    {
	        NAND_Print("Media version is invalid in block %uversion info is %x %x %x %x \n", block_index, oob_buf[0], oob_buf[1], oob_buf[2], oob_buf[3]);
	    }

	}

    if(block_index == (BOOT0_LAST_BLK_NUM + 1))
    {
         NAND_Print("can't find valid version info in boot blocks. \n");
         version_match_flag = -1;
    }

    wBoot_free(main_data);
	return version_match_flag;
}
/*******************************************************************************
*函数名称: mark_bad_block
*函数原型:mark_bad_block( __u32 chip_num, __u32 blk_num )
*函数功能: 标记blk_num指定的块为坏块。
*入口参数: chip_num           chip number
           blk_num            块号
*返 回 值: 0              编程操作成功
*          other          编程操作失败
*备    注:
*******************************************************************************/
static __s32 mark_bad_block( __u32 chip_num, __u32 blk_num)
{
    boot_flash_info_t info;
	struct boot_physical_param  para;
	__u8   oob_buf[OOB_BUF_SIZE];
	__u8*  page_buf;
	__s32  page_index[4];
    __u32  page_with_bad_block, page_per_block;
	__u32  i;
	__s32  mark_err_flag = -1;


	if( NAND_GetFlashInfo( &info ))
	{
		NAND_Print("get flash info failed.\n");
		return -1;
	}

	//cal nand parameters
	//page_buf = (__u8*)(MARK_BAD_BLK_BUF_ADR);
    page_buf = (__u8*)wBoot_malloc(32 * 1024);
    if(!page_buf)
    {
        NAND_Print("malloc memory for page buf fail\n");
        return -1;
    }

	page_with_bad_block = info.pagewithbadflag;
	page_per_block = info.blocksize/info.pagesize;

	//read the first, second, last, last-1 page for check bad blocks
	page_index[0] = 0;
	page_index[1] = 0xEE;
	page_index[2] = 0xEE;
	page_index[3] = 0xEE;

    switch(page_with_bad_block & 0x03)
    {
        case 0x00:
            //the bad block flag is in the first page, same as the logical information, just read 1 page is ok
            break;

        case 0x01:
            //the bad block flag is in the first page or the second page, need read the first page and the second page
            page_index[1] = 1;
            break;

        case 0x02:
            //the bad block flag is in the last page, need read the first page and the last page
            page_index[1] = page_per_block - 1;
            break;

        case 0x03:
            //the bad block flag is in the last 2 page, so, need read the first page, the last page and the last-1 page
            page_index[1] = page_per_block - 1;
            page_index[2] = page_per_block - 2;
            break;
    }

	for(i =0; i<4; i++)
	{
		oob_buf[0] = 0x0;
		oob_buf[1] = 0x1;
		oob_buf[2] = 0x2;
		oob_buf[3] = 0x3;
		oob_buf[4] = 0x89;
		oob_buf[5] = 0xab;
		oob_buf[6] = 0xcd;
		oob_buf[7] = 0xef;

		para.chip = chip_num;
		para.block = blk_num;
		para.page = page_index[i];
		para.mainbuf = page_buf;
		para.oobbuf = oob_buf;

		if(para.page == 0xEE)
		    continue;

        NAND_PhyWrite( &para );
        NAND_PhyRead( &para );

		if(oob_buf[0] !=0xff)
			mark_err_flag = 0;
	}

	wBoot_free(page_buf);

	return mark_err_flag;
}
Example #11
0
/*
*******************************************************************************
*                     ui_AllocLayerPara
*
* Description:
*    初始化一个图层参数
*
* Parameters:
*    PictureInfo  :  input. 图片信息
*
* Return value:
*    返回图层参数
*
* note:
*    void
*
*******************************************************************************
*/
display_layer_info_t *LCD_DisplayAllocLayerPara(void)
{
	display_layer_info_t *layer_para = NULL;
	__u32 screen_width = 0;
	__u32 screen_height = 0;
    __u32 buffer_size;

	layer_para = (display_layer_info_t *)wBoot_malloc(sizeof(display_layer_info_t));
	if(layer_para == NULL)
	{
		DMSG_PANIC("ERR: wBoot_malloc failed\n");
		return NULL;
	}
	memset(layer_para, 0, sizeof(display_layer_info_t));
    /* 初始化图形参数 */
	screen_width  = De_GetSceenWidth();
	screen_height = De_GetSceenHeight();
	//根据屏幕的大小,申请framebuffer的大小
	display_info.screen_width  = screen_width;
	display_info.screen_height = screen_height;
	buffer_size                = screen_width * screen_height * 4 * 2;

    display_info.screen_buf = wBoot_malloc(buffer_size);
    if(!display_info.screen_buf)
    {
        __wrn("LCD_DisplayAllocLayerPara: malloc memory for display buffer failed\n");

        wBoot_free(layer_para);

        return NULL;
    }

    memset(display_info.screen_buf, 0, buffer_size);

    layer_para->fb.size.width 		= screen_width;
    layer_para->fb.size.height 		= screen_height;
    layer_para->fb.addr[0] 			= (__u32)display_info.screen_buf;
    layer_para->fb.mode = DISP_MOD_INTERLEAVED;
    layer_para->fb.format = DISP_FORMAT_ARGB8888;
    layer_para->fb.br_swap = 0;
    layer_para->fb.seq = DISP_SEQ_ARGB;
    layer_para->ck_enable        = 0;
	layer_para->mode           = DISP_LAYER_WORK_MODE_NORMAL;
	layer_para->alpha_en       = 0;
	layer_para->alpha_val      = 0xff;
	layer_para->pipe           = 0;
	layer_para->src_win.x      = 0;
	layer_para->src_win.y      = 0;
	layer_para->src_win.width  = screen_width;
	layer_para->src_win.height = screen_height;
	layer_para->scn_win.x      = 0;
	layer_para->scn_win.y      = 0;
	layer_para->scn_win.width  = screen_width;
	layer_para->scn_win.height = screen_height;

    display_info.crt_addr = display_info.screen_buf;

    display_info.total_height = ((buffer_size / 4) / (screen_width)) / (WORD_SIZE);   //总的高度,可以显示的行数

    display_info.rest_screen_height  = display_info.total_height - 1;          //记录屏幕的剩余高度,行数, 剩余1行不用
    display_info.rest_display_height = screen_height/WORD_SIZE - 1;    //记录显示的剩余高度,行数,剩余1行不用
    display_info.rest_screen_width   = screen_width;                        //剩余宽度等于显示宽度, 像素单位
    display_info.current_height = 0;
    display_info.fb_addr        = display_info.screen_buf;
    display_info.x              = 0;
    display_info.y              = 0;

    return layer_para;
}
__s32 fetch_dynamic_data(char *buffer, int buffer_size)
{
	int		ret, i;
	H_FILE  index_file = NULL;
	H_FILE  data_file  = NULL;
	int     index_length;
	int     data_length;
	char    index_buffer[1024];
	char    *data_buffer;
	Dynamic_index  *dindex;
	char    data_file_name[32];
	Dyamic_head    *ddata;
	int		index_number;
	char    tmp_data_file_name[16];

	ret = -1;
//	if(wBoot_fsmount('Z'))		//其实是挂标准MBR的用户盘
//	{
//		__inf("log error: cant find user disk\n");
//
//		return;
//	}
	//打开索引文件
	index_file = wBoot_fopen("z:\\dynamic\\dindex.bin", "rb+");
	if(!index_file)
	{
		sprite_wrn("dynamic data error: cant find dynamic data index file\n");

		goto dynamic_data_err;
	}
	index_length = wBoot_flen(index_file);
	if(!index_length)
	{
		sprite_wrn("dynamic data error: dynamic data index file is bad\n");

		goto dynamic_data_err;
	}
	//读出索引数据
	memset(index_buffer, 0, 1024);
	wBoot_fread(index_buffer, 1, index_length, index_file);
	dindex = (Dynamic_index *)index_buffer;
	//校验索引数据
	if(memcmp(dindex->magic, "dynamic", sizeof("dynamic")))
	{
		sprite_wrn("dynamic data error: bad dynamic data index\n");

		goto dynamic_data_err;
	}
	//生成数据文件名称
	memset(data_file_name, 0, 32);
	strcpy(data_file_name, "z:\\dynamic\\");

	while(dindex->used_count < dindex->total_count)
	{
		dindex->used_count ++;
		dindex->err_times ++;
		memset(tmp_data_file_name, 0, 16);
		strcpy(tmp_data_file_name, dindex->last_file);
		index_number = 0;
		for(i=1;(i<8) && (tmp_data_file_name[i] != '.');i++)
		{
			index_number = index_number * 10 + (tmp_data_file_name[i] - '0');
		}
		//保存当前要查找的文件名
		strcpy(data_file_name + sizeof("z:\\dynamic\\") - 1, dindex->last_file);
		//生成新的索引文件名称
		index_number ++;
		for(i=7;i>0;i--)
		{
			tmp_data_file_name[i] = (index_number%10) + '0';
			index_number /= 10;
		}
		//回写到索引文件中(缓存)
		strcpy(dindex->last_file, tmp_data_file_name);
		//打开数据文件
		data_file = wBoot_fopen(data_file_name, "rb+");
		if(!data_file)
		{
			//对应的数据文件不存在
			sprite_wrn("dynamic data error: dynamic data file %s is not exist\n", data_file_name);
			data_file = NULL;

			continue;
		}
		data_length = wBoot_flen(data_file);
		if(!data_length)
		{
			sprite_wrn("dynamic data error: dynamic data file %s is bad\n", data_file_name);
			wBoot_fclose(data_file);
			data_file = NULL;

			continue;
		}
		data_buffer = wBoot_malloc(data_length);
		if(!data_buffer)
		{
			sprite_wrn("dynamic data error: not enough memory for dynamic data\n");

			goto dynamic_data_err;
		}
		wBoot_fread(data_buffer, 1, data_length, data_file);
		//检查数据的校验和
//		if(simple_check_data_valid(data_buffer, data_length))
//		{
//			sprite_wrn("dynamic data error: dynamic data checksum error\n");
//			wBoot_free(data_buffer);
//			data_buffer = NULL;
//			wBoot_fclose(data_file);
//			data_file = NULL;
//
//			continue;
//		}
		ddata = (Dyamic_head *)data_buffer;
		if(ddata->used)	//已经被使用过,切换下一个文件
		{
			wBoot_free(data_buffer);
			data_buffer = NULL;
			wBoot_fclose(data_file);
			data_file = NULL;
			wBoot_fclose(data_file);
		}
		else
		{
			ddata->used = 1;
			//取出所有数据
			dynamic_data_get(data_buffer, data_length, buffer, buffer_size);
			dindex->successed_times ++;
			dindex->err_times --;
			//保存回原文件
//			simple_data_checksum(data_buffer, data_length);
			wBoot_fseek(data_file, 0, 0);
			wBoot_write(data_buffer, 1, data_length, data_file);
			wBoot_fclose(data_file);

			break;
		}
	}
	//修改索引文件
	strcpy(dindex->last_file, tmp_data_file_name);
	wBoot_fseek(index_file, 0, 0);
	wBoot_write(index_buffer, 1, index_length, index_file);
	ret = 0;
	//完毕
dynamic_data_err:
	if(data_buffer)
	{
		wBoot_free(data_buffer);
	}
	if(data_file)
	{
		wBoot_fclose(data_file);
	}
	if(index_file)
	{
		wBoot_fclose(index_file);
	}

	return ret;
}
Example #13
0
/*
*******************************************************************************
*                     ShowPicture
*
* Description:
*   以图片的存储路径来显示一张图片
*
* Parameters:
*   Path    :  需要显示的图片路径,只支持BMP格
*   picture_group : 图片个数,最多同时有8个
*   show_way:  显示方式       参数保留,暂时不支持
*              要求所有图片的大小一致
* Return value:
*    0  :  成功
*   !0  :  失败
*
* note:
*   void
*
*******************************************************************************
*/
__hdle ShowMultiPicture(pic_name_info_t *pic_name_info, __u32 picture_group, __u32 show_way)
{
    __s32     ret;
    __u32     i, j = 0;
    __u32     tmp_left, tmp_top, tmp_width;
    char     *tmp_addr, *base_tmp_addr;
    char     *tmp_pic_addr;
    __u32     pic_width, pic_height;
    ui_show_multi_set_t  *pic_info = NULL;

    /* 参数初始化 */
    if(!board_res.layer_hd)
    {
        return (__hdle)0;
    }
	//寻找出所有的图片格式
	if(picture_group > 8)
	{
	    picture_group = 8;
	}
	pic_info = (ui_show_multi_set_t *)wBoot_malloc(sizeof(ui_show_multi_set_t));
	if(!pic_info)
	{
	    return (__hdle)0;
	}
	memset((void *)pic_info, 0, sizeof(ui_show_multi_set_t));
	pic_info->pic_total = picture_group;
	for(i=0;i<picture_group;i++)
	{
	    for(j=0;j<pic_name_info[i].valid_num;j++)
	    {
	        ret = Parse_Pic_BMP_ByPath(pic_name_info[i].name[j], &(pic_info->pic[i].PictureInfo[pic_info->pic[i].valid_num]), 0);
    	    if(ret)
            {
                __inf("decode %s bmp file failed\n", pic_name_info[i].name[j]);
            }
            else
            {
                pic_info->pic[i].valid_num ++;
            }
        }
	}
	//申请一个图层用于显示,并获取display buffer的地址
    pic_info->layer_para = ui_multi_AllocLayerPara((void *)&(pic_info->lcd_info), 0);
    //根据获取的用户数据,开始填充参数
    //暂时只做左右排列

    //按照从左到右摆放的方式,寻找每个编组的图应该在的位置
    pic_width    = pic_info->pic[0].PictureInfo[0].Width;
    pic_height   = pic_info->pic[0].PictureInfo[0].Height;

    tmp_top  = ( pic_info->lcd_info.lcd_height - pic_height)>>1;
    tmp_width= pic_info->lcd_info.lcd_width/picture_group;
    tmp_left = (tmp_width - pic_width)>>1;
    for(i=0;i<picture_group;i++)
    {
        pic_info->pic[i].left = tmp_left + i * tmp_width;
        pic_info->pic[i].top  = tmp_top;
    }
    //开始贴图,第一次
    base_tmp_addr = (char *)pic_info->lcd_info.display_buffer;
    base_tmp_addr += tmp_top * pic_info->lcd_info.lcd_width * 4;
    //开始一个图一个图的开始贴图
    for(i=0;i<picture_group;i++)
    {
        tmp_addr = base_tmp_addr + (pic_info->pic[i].left<<2);
        tmp_pic_addr = (char *)pic_info->pic[i].PictureInfo[0].Buffer;
        for(j=0;j<pic_height;j++)
        {
            memcpy(tmp_addr, tmp_pic_addr, pic_width << 2);
            tmp_addr += pic_info->lcd_info.lcd_width * 4;
            tmp_pic_addr += pic_width << 2;
        }
    }
	/* 显示图片 */
	ShowLayer(board_res.layer_hd, pic_info->layer_para, board_res.display_source);
    wBoot_timer_delay(50);

	return (__hdle)pic_info;
}
Example #14
0
/*
*******************************************************************************
*                     ui_AllocLayerPara
*
* Description:
*    初始化一个图层参数
*
* Parameters:
*    PictureInfo  :  input. 图片信息
*
* Return value:
*    返回图层参数
*
* note:
*    void
*
*******************************************************************************
*/
display_layer_info_t *ui_multi_AllocLayerPara(display_lcd_set_t  *lcd_info, __u32 address)
{
	display_layer_info_t *layer_para = NULL;
	__u32 screen_width = 0;
	__u32 screen_height = 0;
	__u32 buffer_size;

	layer_para = (display_layer_info_t *)wBoot_malloc(sizeof(display_layer_info_t));
	if(layer_para == NULL)
	{
		DMSG_PANIC("ERR: wBoot_malloc failed\n");
		return NULL;
	}
	memset(layer_para, 0, sizeof(display_layer_info_t));
    /* 初始化图形参数 */
	screen_width  = De_GetSceenWidth();
	screen_height = De_GetSceenHeight();
	//根据屏幕的大小,申请framebuffer的大小
	lcd_info->lcd_width  = screen_width;
	lcd_info->lcd_height = screen_height;
	buffer_size = screen_width * screen_height * 4;
	if(!address)
	{
        lcd_info->display_buffer = wBoot_malloc(buffer_size);
        if(!lcd_info->display_buffer)
        {
            __inf("multi displya fail: malloc memory for display buffer failed\n");

            wBoot_free(layer_para);
            return NULL;
        }
    }
    else
    {
        lcd_info->display_buffer = (__u32 *)address;
    }
    memset(lcd_info->display_buffer, 0, buffer_size);

    layer_para->fb.size.width 		= screen_width;
    layer_para->fb.size.height 		= screen_height;
    layer_para->fb.addr[0] 			= (__u32)lcd_info->display_buffer;
    layer_para->fb.mode = DISP_MOD_INTERLEAVED;
    layer_para->fb.format = DISP_FORMAT_ARGB8888;
    layer_para->fb.br_swap = 0;
    layer_para->fb.seq = DISP_SEQ_ARGB;
    layer_para->ck_enable        = 0;
	layer_para->mode           = DISP_LAYER_WORK_MODE_NORMAL;
	layer_para->alpha_en       = 1;
	layer_para->alpha_val      = 0xff;
	layer_para->pipe           = 0;
	layer_para->src_win.x      = 0;
	layer_para->src_win.y      = 0;
	layer_para->src_win.width  = screen_width;
	layer_para->src_win.height = screen_height;
	layer_para->scn_win.x      = 0;
	layer_para->scn_win.y      = 0;
	layer_para->scn_win.width  = screen_width;
	layer_para->scn_win.height = screen_height;

    return layer_para;
}
/*
************************************************************************************************************
*
*                                             function
*
*    函数名称:
*
*    参数列表:
*
*    返回值  :
*
*    说明    :
*
*
************************************************************************************************************
*/
int private_fetch_from_flash(void)
{
	char *mbr_buf;
	MBR  *mbr_info;
	int  crc, i;
	int  size, start;
	int  ret = -1;
    int s_type = 0;
	memset(mac_addr_store, 0, 32);
	env_flash_dram_base = (char *)ENV_FLASH_DRAM_ADDRESS;
	private_flash_dram_base = (char *)PRIVATE_FLASH_DRAM_ADDRESS;
#if 1
	if(sprite_flash_init(&s_type))
	{
		__inf("update flash env err: flash init\n");

		return -1;
	}
    mbr_buf=wBoot_malloc(MBR_SIZE*MBR_COPY_NUM);
    if(0 == mbr_buf)
    {
        __inf("update flash env err: malloc mbr buffer failed!\n");
        goto update_flash_env_err;
    }
	if(sprite_flash_read(0, MBR_SIZE*MBR_COPY_NUM/512, mbr_buf))
	{
		__inf("update flash env err: read flash error\n");

		goto update_flash_env_err;
	}
	for(i=0;i<MBR_COPY_NUM;i++)
	{
		mbr_info = (MBR *)(mbr_buf + i * MBR_SIZE);
		crc = calc_crc32((void *)&mbr_info->version, sizeof(MBR) - 4);
		if(crc == mbr_info->crc32)
		{
			break;
		}
	}
	if(4 == i)
	{
		ret = 0;
		__inf("update flash env err: cant find good flash mbr\n");
        wBoot_free(mbr_buf);
		goto update_flash_env_err;
	}
	for(i=0;i<mbr_info->PartCount;i++)
	{
		if(!strcmp("env", (const char *)mbr_info->array[i].name))
		{
			__inf("env part found\n");
			start = mbr_info->array[i].addrlo;
			size  = mbr_info->array[i].lenlo;
			memset(env_flash_dram_base, 0, size<<9);
			if(sprite_flash_read(start, size, env_flash_dram_base))
			{
				__inf("update flash env err: read env data error\n");
                wBoot_free(mbr_buf);
				goto update_flash_env_err;
			}
			env_exist = 1;
		}
		else if(!strcmp("private", (const char *)mbr_info->array[i].name))
		{
			__inf("private part found\n");
			start = mbr_info->array[i].addrlo;
			size  = mbr_info->array[i].lenlo;
			memset(private_flash_dram_base, 0, size<<9);
			if(sprite_flash_read(start, size, private_flash_dram_base))
			{
				__inf("update flash private err: read private data error\n");
                wBoot_free(mbr_buf);
				goto update_flash_env_err;
			}
			private_flash_flash_size = size<<9;
			private_exist = 1;
		}
	}
	ret = 0;

wBoot_free(mbr_buf);
update_flash_env_err:
	sprite_flash_exit(s_type);
#endif
//	if(!env_exist)		//如果在旧的环境变量中没有找到动态数据,则去boot1中寻找
//	{
//		ret = env_fetch_from_boot1();
//	}

	return ret;
}
Example #16
0
/*
*******************************************************************************
*                     BootMain
*
* Description:
*    BOOT主应用程序
*
* Parameters:
*    void
*
* Return value:
*    void
*
* note:
*    void
*
*******************************************************************************
*/
int BootMain(int argc, char **argv)
{
	__s32                 ret;
    int                   erase_flash;
	MBR					  mbr_info;
    boot_global_info_t   *global_info;

    DMSG_INFO("big firmware! here we go !\n");
	DMSG_INFO("Sprite start\n");
	{
		char ch;

		ch = wBoot_getc_delay( 1 );  // 27000000
	    __inf("%d\n", ch);

	    switch(ch)
	   	{
	   		case '1':
	   		{
	   			usb_start();
	    		usb_run();
	    		break;
	   		}
	   		case '2':
	   		{
	   			__inf("Jump to fel\n");
	   			wBoot_jump_fel( );
	   			break;
	   		}
	   		case '-':
	   		{
	   			__u32 dbg = 0x55;

	            __inf("hold\n");
		        while(dbg == 0x55);
		        break;
	   		}
	   		case '+':
	   		{
	   			force_debug = 1;
	        	break;
	   		}
	   		default:
	   			break;
	   	}
	}
	*(volatile unsigned int *)(0x1c20C00 + 0x118) = 0;
	*(volatile unsigned int *)(0x1c20C00 + 0x11C) = 3;
	//数据初始化
	memset(&board_res, 0, sizeof(boot_hardware_res));
    //申请内存,填充第一个启动脚本
    global_info = (boot_global_info_t *)wBoot_malloc(sizeof(boot_global_info_t));
    if(!global_info)
    {
        __wrn("unable to malloc memory for bootini\n");

        return -1;
    }
    //填充启动脚本
    memset(global_info, 0, sizeof(boot_global_info_t));
    ret = script_patch("c:\\boot.ini", global_info, 0);
    if(ret < 0)
    {
        __wrn("unable to parser boot.ini\n");

        return -1;
    }
    //初始化显示设备
    __inf("display init\n");
    cue = -1;
    if(boot_ui_init(global_info->display_device, global_info->display_mode) >= 0)
    {
    	//开启字符显示
    	__inf("char init\n");
    	boot_ui_char_init(0);
    	cue = 0;
    }
    sprite_led_init();
    sprite_wrn_init();
    //获取MBR信息
    __inf("mbr fetch\n");
	ret = card_mbr_info((void *)&mbr_info);
	if(ret < 0)
	{
		__wrn("unable to get mbr info\n");

        return -1;
	}
	boot_ui_check_device_open();
    
	ret = wBoot_script_parser_fetch("platform", "eraseflag", &erase_flash, 1);
	if((!ret) && (erase_flash))
	{
		erase_flash = 1;
	}
	else
	{
		erase_flash = 0;
	}
    
    //开始准备系统数据
    ret = card_sprite((void *)&mbr_info,erase_flash, cue);

	sprite_wrn_exit();
	sprite_led_exit(ret);
	if(!ret)
	{
		char	buffer[512];

		board_res.led_status[0] = CARD_SPRITE_SUCCESSED;
		sprite_wrn("CARD OK\n");

		__inf("get work mode\n");
		memset(buffer, 0, 512);
		wBoot_block_dread(15, 1, buffer);
		if(strcmp(buffer, "1234567890abcdefghijklmnopqrstuvwxyz"))
		{
			__inf("try to close\n");
			wBoot_timer_delay(3000);

			wBoot_power_set_off();
		}
		else
		{
			int ret;

			__inf("try to format\n");
			wBoot_timer_delay(500);
			ret = FormatDisk();
			__inf("format %d\n", ret);
			WATCHDOG_REG_MODE = 0x0;
			wBoot_timer_delay(500);
			WATCHDOG_REG_MODE = 0x3;
		}
	}
	else
	{
		board_res.led_status[0] = CARD_SPRITE_FAIL;
	}
	{
		__u32 dbg = 0x55;

		while(dbg == 0x55);
	}

    return 0;
}