SMDK2440 boot code, base on vivi

源代码在线查看: command.c

软件大小: 282 K
上传用户: SLing2008
关键词: SMDK 2440 boot base
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*				 * vivi/lib/command.c: 				 *   - to support user commands on the boot loader				 *				 * Copyright (C) 2001 MIZI Research, Inc.				 *				 * This program is free software; you can redistribute it and/or modify				 * it under the terms of the GNU General Public License as published by				 * the Free Software Foundation; either version 2 of the License, or				 * (at your option) any later version.				 *				 * This program is distributed in the hope that it will be useful,				 * but WITHOUT ANY WARRANTY; without even the implied warranty of				 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the				 * GNU General Public License for more details.				 *				 * You should have received a copy of the GNU General Public License				 * along with this program; if not, write to the Free Software				 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA				 *				 *				 * Author: Janghoon Lyu 				 * Date  : $Date: 2004/01/10 09:11:50 $				 *				 * $Revision: 1.4 $				 *				 * 				 * History				 * 				 * 2001-12-23: Janghoon Lyu 				 *    - Initial code				 *    - Base on bootldr/bootldr.c 				 *				 * 2002-02-23: Janghoon Lyu 				 *    -  Add flash commands				 *				 * 2002-07-13: Janghoon Lyu 				 *    - 疙飞绢 备炼 函版				 *    - 滴 拌摸栏肺 疙犬窍霸 备盒				 *        - 皋牢, 辑宏				 *    - 皋牢 疙飞绢 殿废秦辑 荤侩窍档废.				 *    - 辑宏 疙飞绢绰 皋牢 疙飞绢啊 乐绰 镑俊辑 舅酒辑 荤侩窍档废				 *				 */								#include 				#include 				#include 				#include 				#include 								enum ParseState stackedState;				static user_command_t *cmd_list = NULL;								/*				 * Parse user command line				 */				void parseargs(char *argstr, int *argc_p, char **argv, char** resid)				{					int argc = 0;					char c;					enum ParseState lastState = PS_WHITESPACE;									/* tokenize the argstr */					while ((c = *argstr) != 0) {						enum ParseState newState;										if (c == ';' && lastState != PS_STRING && lastState != PS_ESCAPE)							break;										if (lastState == PS_ESCAPE) {							newState = stackedState;						} else if (lastState == PS_STRING) {							if (c == '"') {								newState = PS_WHITESPACE;								*argstr = 0;							} else {								newState = PS_STRING;							}						} else if ((c == ' ') || (c == '\t')) {							/* whitespace character */							*argstr = 0;							newState = PS_WHITESPACE;						} else if (c == '"') {							newState = PS_STRING;							*argstr++ = 0;							argv[argc++] = argstr;						} else if (c == '\\') {							stackedState = lastState;							newState = PS_ESCAPE;						} else {							/* token */							if (lastState == PS_WHITESPACE) {								argv[argc++] = argstr;							}							newState = PS_TOKEN;						}										lastState = newState;						argstr++;					}								#if 0 /* for debugging */					{						int i;						putLabeledWord("parseargs: argc=", argc);						for (i = 0; i < argc; i++) {							putstr("   ");							putstr(argv[i]);							putstr("\r\n");						}					}				#endif										argv[argc] = NULL;					if (argc_p != NULL)						*argc_p = argc;									if (*argstr == ';') {						*argstr++ = '\0';					}					*resid = argstr;				}								#if 0				/*				 * 鞘夸茄啊?				 */				void unparseargs(char *argstr, int argc, const char **argv)				{					int i;					for (i = 0; i < argc; i++) {						if (argv[i] != NULL) {							strcat(argstr, " ");							strcat(argstr, argv[i]);						}					}				}				#endif								/*				 * Genernal interface				 */								/*				 * For (main) commands				 */								/* add user command */				void add_command(user_command_t *cmd)				{					if (cmd_list == NULL) {						cmd_list = cmd;					} else {						cmd->next = cmd_list;						cmd_list = cmd;					}					/*printk("Registered '%s' command\n", cmd->name);*/				}								/* find command */				user_command_t *find_cmd(const char *cmdname)				{					user_command_t *curr;									/* do da string compare for the first offset character of cmdstr					  against each number of the cmdlist */					curr = cmd_list;					while(curr != NULL) {						if (strncmp(curr->name, cmdname, strlen(curr->name)) == 0)							return curr;						curr = curr->next;					}					return NULL;				}								/* execute a function */				void execcmd(int argc, const char **argv)				{					user_command_t *cmd = find_cmd(argv[0]);									if (cmd == NULL) {						printk("Could not found '%s' command\n", argv[0]);						printk("If you want to konw available commands, type 'help'\n"); 						return;					}					/*printk("execcmd: cmd=%s, argc=%d\n", argv[0], argc);*/									cmd->cmdfunc(argc, argv);				}								/* parse and execute a string */				void exec_string(char *buf)				{					int argc;					char *argv[128];					char *resid;									while (*buf) {						memset(argv, 0, sizeof(argv));						parseargs(buf, &argc, argv, &resid);						if (argc > 0)							execcmd(argc, (const char **)argv);						buf = resid;					}				}												/*				 * Define built-in commands				 */								/* help command */				void command_help(int argc, const char **argv)				{					int i;					user_command_t *tmp;									printk("Available built-in commands:\n");					tmp = cmd_list;					for (i = 0; tmp != NULL; i++) {						if ((i % 10) == 0) printk("\n\t");						printk("%s, ", tmp->name);						tmp = tmp->next;					}					printk("\n");				}								user_command_t help_cmd = {					"help",					command_help,					NULL				};												extern user_command_t boot_cmd;				extern user_command_t load_cmd;				extern user_command_t reset_cmd;				extern user_command_t call_cmd;				#ifdef CONFIG_MEMORY_CMD				extern user_command_t mem_cmd;				extern user_command_t dump_cmd;				#endif				#ifdef CONFIG_MEMORY_TEST				extern user_command_t memtst_cmd;				#endif				//extern user_command_t sleep_cmd;								/* Register basic user commands */				void				init_builtin_cmds(void)				{				#ifdef CONFIG_TEST					add_command(&test_cmd);				#endif					add_command(&reset_cmd);				#ifdef CONFIG_MEMORY_CMD					add_command(&mem_cmd);					add_command(&dump_cmd);				#endif					add_command(&load_cmd);					add_command(&call_cmd);					add_command(&boot_cmd);					add_command(&help_cmd);				#ifdef CONFIG_MEMORY_TEST					add_command(&memtst_cmd);				#endif					//add_command(&sleep_cmd);				}							

相关资源