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

📄 cmdline.cpp

📁 linux下的jtag调试软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		return 1;	}	FILE *fp=fileManagerPtr->openFP(argv[1], "r");	if (fp)	{		// get file length		fseek(fp, 0, SEEK_END);		fileSize=ftell(fp);		fileSizeAligned = (fileSize&0x1) ? fileSize+1 : fileSize;		fclose(fp);		// prepare the command line to call 'enp.lnj'		char call[256];		//! \bug buffer overflow		sprintf(call, "flash/enp.lnj %s %x %x\n", 				argv[1],				address,				fileSize/2);		printf("calling: \"%s\"\n", call);		long long startTick=GetTick();		if (cmdLine.exec(call)) 			return 3;				cmdLine.exec("wait");		printf("Embedded flasher returned %d\n", pxa250Ptr->getSavePlace(0));		float duration= ((float)GetTick()-startTick)/1000.0f;		printf("done in %.3f s (%.3f KByte/s)\n", duration, fileSizeAligned/(duration*1000.0f));		return 0;	}	else		return 2;}int GetCmd::exec(int argc, char *argv[]){ 	assert(pxa250Ptr);	unsigned int address;	unsigned int size;	unsigned int *data;	if (argc < 2)	{		printf(getDescr());		return 1;	}	else if (argc == 2)	{		size = 1;	}	else	{		sscanf(argv[2], "%x", &size);	}	sscanf(argv[1], "%x", &address);	data = (unsigned int *)malloc(size*sizeof(unsigned int));	pxa250Ptr->getData(address, size, data);		for (unsigned i=0; i<size; i++)	{		printf("%08x : %08x\n", address+(i*4), data[i]);	}		free(data);		return 0;}int ExecCmd::exec(int argc, char *argv[]){	assert(pxa250Ptr);	unsigned int address;	unsigned int sp;	if (argc<2)	{		address=0xa0000000;		sp=0xa0000000+(64*1024*1024);	}	else if (argc<3)	{		sscanf(argv[1], "%x", &address);		sp=0xa0000000+(64*1024*1024);	}	else	{		sscanf(argv[1], "%x", &address);		sscanf(argv[2], "%x", &sp);	}	pxa250Ptr->execute(address, sp);	return 0;}int ExtBreakCmd::exec(int argc, char *argv[]) {	assert(pxa250Ptr);	pxa250Ptr->extBreak();	return 0;}int RebootCmd::exec(int argc, char *argv[]) {	assert(pxa250Ptr);	pxa250Ptr->reboot();	return 0;}int ContinueCmd::exec(int argc, char *argv[]) {	assert(pxa250Ptr);	pxa250Ptr->continueCmd();	return 0;}int RegisterCmd::exec(int argc, char *argv[]) {	assert(pxa250Ptr);	if (argc < 2) {		printf("%s",getDescr());		return 1;	}	unsigned int reg = strtoul(argv[1], 0, 10);	if (argc >= 3) {		// this is a write		unsigned int val = strtoul(argv[2], 0, 16);		return pxa250Ptr->setSavePlace(reg, val) ? 0 : 2;	} else {		// this is a read		unsigned int val = pxa250Ptr->getSavePlace(reg);		printf("Register %d = %08x (%d)\n", reg, val, val);		return 0;	}}int HwBreakCmd::exec(int argc, char *argv[]) {	if (argc < 2) {		printf("%s", getDescr());		return 1;	}	// activate or remove breakpoint ?	bool enable;	if (strcmp("on", argv[1]) == 0) {		enable = true;	} else {		if (strcmp("off", argv[1]) == 0)			enable = false;		else {			printf("%s", getDescr());			return 2;		}	}	// at what address ?	unsigned int addr;		if (argc >= 3)		addr = strtoul(argv[2], 0, 16);	else 		addr = pxa250Ptr->getSavePlace(15);	JTAGpxa250::Cp15Reg reg=JTAGpxa250::IBCR0;	if (argc >= 4) {		switch (argv[3][0]) {		case '0': reg = JTAGpxa250::IBCR0; break;		case '1': reg = JTAGpxa250::IBCR1; break;		default:			printf("%s", getDescr());			return 3;		}	} 	// now load the debug register	if (pxa250Ptr->setCp15DebugRegister(addr | ( enable ? 1 : 0), reg))		return 0;	else		return 4;}		int WaitCmd::exec(int argc, char *argv[]) {		while (!pxa250Ptr->targetReady()) {		usleep(100);		pxa250Ptr->pollForTX();	}	return 0;}	/////////////////////////////////////// CmdLine class implementation///////////////////////////////////////! Builds the vector of command objectsCmdLine::CmdLine() {	commands.push_back(new InitCmd());	commands.push_back(new CheckCmd());	commands.push_back(new StopCmd());	commands.push_back(new LoadICCmd());	commands.push_back(new QuitCmd());	commands.push_back(new ResetCmd());	commands.push_back(new BootCmd());	commands.push_back(new LoadCmd());	commands.push_back(new PutCmd());	commands.push_back(new GetCmd());	commands.push_back(new ExecCmd());	commands.push_back(new ExtBreakCmd());	commands.push_back(new ContinueCmd());	commands.push_back(new RebootCmd());	commands.push_back(new RegisterCmd());	commands.push_back(new HwBreakCmd());	commands.push_back(new HelpCmd(commands));	//commands.push_back(new EraseFlashCmd());	commands.push_back(new WaitCmd());	commands.push_back(new ProgramFlashCmd(*this));}//! delete all command objectsCmdLine::~CmdLine() {	std::vector<Command *>::iterator it;	for (it = commands.begin(); it != commands.end(); ++it) {		delete *it;		*it = 0;	}}/*! * Execute a command. If it's a script, skip comments and replace argument * passing. * Comments are replaced using \1, \2, etc. \0 is the name of the script. * * \param cmdLine the command line to execute, null-terminated. * * \param argc in case of a script execution, argc contains the number of * argument of the script command line. * * \param argv in case of a script execution, argv is an array of parameters. * \0, \1 .. \argc are replaced by these parameters. * * \return -1 if the command wants to quit. -2 == cmd not found. *  0 on success. */int CmdLine::exec(const char *cmdLine, int argc, char **argv) {	// copy the command line	char *cmd = strdup(cmdLine);	char *words[256];	int nbWords = splitString(cmd, words, 256, " \t\r\n");	assert(cmd);	assert(words);	// ignore comments and empty lines	if ((nbWords==0) || (words[0][0] == '#')) {		free(cmd);		return 0;	}	// parameters replacement and comment ignoring	for (int i=0; i< nbWords; i++) {		if (words[i][0] == '#') {			nbWords = i;			break;		} 		if (argc && words[i][0] == '\\' && isdigit(words[i][1])) {			long p = strtoul(words[i] + 1, 0, 10);			if (p < 0) p = 0;			if (p < argc)				words[i] = argv[p];		}	}	// search for a matching command	std::vector<Command *>::iterator it;	for (it = commands.begin(); it != commands.end(); ++it) {		if (strcmp((*it)->getName(), words[0]) == 0) {			int ret= (*it)->exec(nbWords, words);			free(cmd);			return ret;		}	}	// look for a script of the corresponding name	FILE *f = fileManagerPtr->openFP(words[0], "rt");	if (f) {		char line[256];		int ln=0;		while (fgets(line, sizeof(line), f)) {			ln++;			debugMessage(CMD_SCRIPT_DEBUG, "%s:%d: %s\n", words[0], ln, line);			int r=exec(line, nbWords, words);			if (r) {				printf("%s:%d: command returned %d\n", 						words[0], ln, r);				fclose(f);				free(cmd);				return -3;			}						}		fclose(f);		free(cmd);		return 0;	}	fprintf(stderr, "%s: command not found\n", words[0]);	free(cmd);	return -2;}int CmdLine::getNextToken(const char *string, const char *delim) {	for (int i=0; string[i]; i++) {		for (int c=0; delim[c]; c++) {			if (string[i] != delim[c])				return i;		}	}	return -1;}/*! *  Fill an array of char pointer, given an input string and a string of *  delimiters. In case of overflow, the end of the command line is dropped. * *  \param inputString input null terminated string, or 0. *  \param outputArray already allocated array with at least arraySize elements. *  \param arraySize number of elements of outputArray. *  \param delimiters null terminated string containing caracters that separates  *  	the words. *  \return the number of words found. */int CmdLine::splitString(char *inputString, char **outputArray, 			unsigned arraySize, const char *delimiters){	char *c;	unsigned arrayPos=0;	int inWord = 0;	if (!inputString) return 0;	for (c= inputString; *c; c++) {		if (index(delimiters, *c)) {			*c = 0;			inWord = 0;		} else {			if (!inWord && arrayPos < arraySize) {				inWord = 1;				outputArray[arrayPos++] = c;			}		}	}	return arrayPos;}

⌨️ 快捷键说明

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