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

📄 badblockmanage.c

📁 Blob autotest.Used on xscale(badblockmanage function)
💻 C
字号:
#include <stdio.h>#include <string.h>#include "socket_base.h"char *next_cmd = "reboot";char str[] = "blob>";char rbuf[4096], rbuf_save[256];HTRANSINTERFACE handle;char *p_buf;int read_comp_comm(int i){	int ret = 0;	int readresult = 0;        int compresult = 0;	memset(rbuf, 0, 4096);        char *pdest = NULL;        int pos = 0;                do                {                        int k = 0, pos = 0;                        readresult = ReadPackage(rbuf, 4096, handle, 1, 3);                        if (readresult == 0)                        {                                printf("k:%d read %d bytes\n", k, readresult);                                goto kk;                        }                        printf("========Read Package is successfully==========\n");                        p_buf = rbuf;                        printf("To compare the string to see wheterh fvscaler or not\n");                        //for (i=0; i<readresult; i++)                        //{                                printf("p_buf= %s\n", p_buf);                                //compresult = strncmp(p_buf, "fCore:",6);                                pdest = strstr(p_buf, str);                                pos = pdest - p_buf + 1;                                if( pdest != NULL )                                {                                        printf( "%s found at position %d\n\n", str, pos);                                        int j = 1;                                        printf("get current fcore success\n");                                        pdest += 5;					switch (i)					{						case 1: 							j = strncmp(pdest, "blob>", 5);							break;						case 2:							j = strncmp(pdest, "Read flash from 0x60000, length 0x200000", 40);							break;						case 3:								j = strncmp(pdest, "tftp_cmd: file 'zImage' loaded", 30);                                                        break;						case 4:							j = strncmp(pdest, "Done", 4);                                		        break;						case 5:                                                        j = strncmp(pdest, "]#", 2);                                                        break;						default:							printf("i is error\n");					}							if (j == 0)                                        {                                                printf("The frist fvscaler info is succesful\n");                                        }                                        else                                        {                                                printf("The frist fvscaler info is fail\n");                                        }                                        compresult = 1;                                }                                else                                {                                        printf( "%s not found\n", str);                                        compresult = 0;                                };kk:                k++;                printf ("read package and get right comm content time: %d\n", k);		if (k > 10)		{			printf("Read package via COMM, Fail to get right content or read\n");			ret = 1;			break;				}				                } while ( (readresult == 0)||(compresult == 0));	return ret; }int main(int argc, char *argv[]){	//open network lclient	COMMANDPAR par1;	HTRANSINTERFACE cmdFile = NULL;	int result;	int ret = 0;	char cmdline[256];		par1.opMode=SOCKET_OP;	par1.socketAddr = malloc(30);	par1.socketAddr = "192.168.1.100:10000";	par1.endPoint = CLIENT;		if (par1.opMode == FILE_OP){		}else if (par1.opMode == SOCKET_OP){                cmdFile = OpenTransInterface(&par1);                if(cmdFile == NULL){                        fprintf(stderr, "Can not connect the server socket!\n");                        return -1;                }	}	printf("send commad:%s\n",next_cmd);		result  = SendPackage(next_cmd, 6, cmdFile);	if(result != 6){		printf("send problem\n");		ret = -1;		goto out1;	}	result = ReadPackage(cmdline, 4, cmdFile);//get the cmd	if(result != 4){		printf("read problem\n");		ret = -1;		goto out1;	}	printf("readpackage: %s\n", cmdline);	if (strncmp(cmdline, "Done",4) == 0)	{		printf("reboot success\n");	}			//finish reboot platform			COMMANDPAR par;	//HTRANSINTERFACE handle;	int last_result;	int i;	//char rbuf[4096], rbuf_save[256];	//char *p_buf;	char *mac_buf;	char *wbuf = malloc(256);	char *macaddr = malloc(20);	memset(macaddr, 0,20);	mac_buf = macaddr;	memset(rbuf, 0, 4096);	memset(rbuf_save, 0, 256);	par.opMode = COMM_OP;	par.commAddr = malloc(30);	par.commAddr = "/dev/ttyS0";	par.baudrate = malloc(15);	par.baudrate = "B38400";	par.endPoint = SERVER;	handle = OpenTransInterface(&par);	if(handle == NULL){		printf("Open Transfer interface failed\n");		return -1;	}	sleep(5);	printf("----Test platform can enter blob control interface----\n");	/* wait to enter blob command control interface*/	printf("echo anykey successed\n");	for (i=0; i<6; i++)	{		wbuf = "\n";		result = SendPackage(wbuf, 1, handle);		if(result != 1){			printf("Send problem\n");			ret = -1;			goto out;		}		sleep(1);	}		memset(rbuf, 0, 4096);		result = ReadPackage(rbuf, 20, handle, 1, 5);		printf("read %d bytes\n", result);		printf("read: %s\n", rbuf);		p_buf = rbuf;		for (i=0; i<result; i++)		{			if (strncmp(p_buf, "blob>",5) == 0)			{					printf("enter blob command control\n");				break;			}			p_buf++;			if(i== result-1)			{				printf("can not enter blob command control\n");				ret = -1;				goto out;			}		}		printf("----Set one good block to be bad block----\n");			wbuf = "set_badblk 3\n";		result = SendPackage(wbuf, 13, handle);		if(result != 13){			printf("Send problem\n");			ret = -1;			goto out;		}		result = read_comp_comm (1);		if(result != 0){                        printf("set_badblk 3 is fail\n");                        ret = -1;                        goto out;                }		wbuf = "nkernel\n";                result = SendPackage(wbuf, 8, handle);                if(result != 8){                        printf("Send problem\n");                        ret = -1;                        goto out;                }                result = read_comp_comm (2);                if(result != 0){                        printf("set_badblk 3 is fail\n");                        ret = -1;                        goto out;                }		wbuf = "boot\n";                result = SendPackage(wbuf, 5, handle);                if(result != 5){                        printf("Send problem\n");                        ret = -1;                        goto out;                }	 	sleep(30);                wbuf = "\n";                result = SendPackage(wbuf, 1, handle);                if(result != 1){                	printf("Send problem\n");                        ret = -1;                        goto out;                }        	result = ReadPackage(rbuf, 1024, handle, 1, 10);                printf("read %d bytes\n", result);                printf("read: %s\n", rbuf);		if (result == 0)		{			printf("Success: The system can not boot up from marked bad blcok\n");		}		else		{ 			printf("Fail:    The system can boot up from marked bad blcok\n");                        ret = -1;                        goto out;		}		/* Inform Windows PC to auto reboot DVK */		printf("send commad:%s\n",next_cmd);	        result  = SendPackage(next_cmd, 6, cmdFile);        	if(result != 6){                	printf("send problem\n");                	ret = -1;                	goto out1;        	}        	result = ReadPackage(cmdline, 4, cmdFile);//get the cmd        	if(result != 4){                	printf("read problem\n");                	ret = -1;                	goto out1;        	}        	printf("readpackage: %s\n", cmdline);        	if (strncmp(cmdline, "Done",4) == 0)        	{                	printf("reboot success\n");        	}		 printf("----Test use tftp to download zImage to SRAM----\n");	        // Re-download zImage to nandflash                wbuf = "tftp zImage\n";                result = SendPackage(wbuf, 12, handle);                if(result != 12){                        printf("Send problem\n");                        ret = -1;                        goto out;                }                result = read_comp_comm (3);                if(result != 0){                        printf("Download zImage to SRAM is fail\n");                        ret = -1;                        goto out;                }		printf("----Test write zImage to nand flash------\n");		wbuf = "nandwrite -j 0x80800000 0x60000 0x200000\n";                result = SendPackage(wbuf, 41, handle);                if(result != 41){                        printf("Send problem\n");                        ret = -1;                        goto out;                }		result = read_comp_comm (4);                if(result != 0){                        printf("Write zImage to NAND flash is fail\n");                        ret = -1;                        goto out;                }		wbuf = "nkernel\n";                result = SendPackage(wbuf, 8, handle);                if(result != 8){                        printf("Send problem\n");                        ret = -1;                        goto out;                }                result = read_comp_comm (2);                if(result != 0){                        printf("set_badblk 3 is fail\n");                        ret = -1;                        goto out;                }		wbuf = "boot\n";                result = SendPackage(wbuf, 5, handle);                if(result != 5){                        printf("Send problem\n");                        ret = -1;                        goto out;                }                sleep(30);		printf("Send Enter key to console\n");                wbuf = "\n";                result = SendPackage(wbuf, 1, handle);                if(result != 1){                        printf("Send problem\n");                        ret = -1;                        goto out;                }		result = read_comp_comm (5);                if(result != 0){                        printf("BOOT UP system is fail\n");                        ret = -1;                        goto out;                }	printf("------------------------------------------------------------------\n");	printf("------------------------------------------------------------------\n");	printf("------------------------------------------------------------------\n");	printf("------------------------------------------------------------------\n");	out:	if(handle != NULL){		CloseTransInterface(handle);		}		out1:    if(cmdFile != NULL)                CloseTransInterface(cmdFile);	return ret;}

⌨️ 快捷键说明

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