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

📄 cmd_nvedit.c

📁 source code of armboot for s3c4510
💻 C
📖 第 1 页 / 共 2 页
字号:
		printf ("## Error: environment overflow, \"%s\" deleted\n", name);		return 1;    }	    while ((*env = *name++) != '\0')      env++;    for (i=2; i<argc; ++i) 	{		char *val = argv[i];			*env = (i==2) ? '=' : ' ';		while ((*++env = *val++) != '\0');    }        /* end is marked with double '\0' */    *++env = '\0';        /* Update CRC */    bd->bi_env_crc = crc32(0, bd->bi_env_data, sizeof(bd->bi_env_data));    /*     * Some variables should be updated when the corresponding     * entry in the enviornment is changed     */        if (strcmp(argv[1],"ethaddr") == 0) 	{		char *s = argv[2];	/* always use only one arg */		char *e;				for (i=0; i<6; ++i) 		{	    	bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;	    	if (s) s = (*e) ? e+1 : e;		}		return 0;    }    if (strcmp(argv[1],"ipaddr") == 0) 	{		char *s = argv[2];	/* always use only one arg */		char *e;		bd->bi_ip_addr = 0;				for (i=0; i<4; ++i) 		{	    	ulong val = s ? simple_strtoul(s, &e, 10) : 0;	    	bd->bi_ip_addr <<= 8;	    	bd->bi_ip_addr  |= (val & 0xFF);	    	if (s) s = (*e) ? e+1 : e;		}		return 0;    }    if (strcmp(argv[1],"loadaddr") == 0) 	{		load_addr = simple_strtoul(argv[2], NULL, 16);		return 0;    }#if (CONFIG_COMMANDS & CFG_CMD_NET)    if (strcmp(argv[1],"bootfile") == 0) 	{		copy_filename (BootFile, argv[2], sizeof(BootFile));		return 0;    }#endif	/* CFG_CMD_NET */    return 0;}void setenv (bd_t * bd, char *varname, char *varvalue){    char *argv[4] = { "setenv", varname, varvalue, NULL };    _do_setenv (bd, 0, 3, argv);	//board_env_save(bd, bd->bi_env, sizeof(env_t));	// added by LAPUTA}int do_setenv (cmd_tbl_t * cmdtp, bd_t *  bd, int flag, int argc, char * argv []){    if (argc < 2) {	printf ("Usage:\n%s\n", cmdtp->usage);	return 1;    }    return _do_setenv (bd, flag, argc, argv);}/************************************************************************ * Prompt for environment variable */#if (CONFIG_COMMANDS & CFG_CMD_ASKENV)int do_askenv (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc,		char *argv[]){    extern char console_buffer[CFG_CBSIZE];    char message[CFG_CBSIZE];    int size = CFG_CBSIZE - 1;    int len;    char *local_args[4];        local_args[0] = argv[0];    local_args[1] = argv[1];    local_args[2] = NULL;    local_args[3] = NULL;        if (argc < 2) {	printf ("Usage:\n%s\n", cmdtp->usage);	return 1;    }    /* Check the syntax */    switch (argc) {    case 1:	printf ("Usage:\n%s\n", cmdtp->usage);	return 1;	    case 2:		/* askenv envname */	sprintf (message, "Please enter '%s':", argv[1]);	break;	    case 3:		/* askenv envname size */	sprintf (message, "Please enter '%s':", argv[1]);	size = simple_strtoul (argv[2], NULL, 10);	break;	    default:	/* askenv envname message1 ... messagen size */	{	    int i;	    int pos = 0;	    	    for (i = 2; i < argc - 1; i++) {		if (pos) {		    message[pos++] = ' ';		}		strcpy (message+pos, argv[i]);		pos += strlen(argv[i]);	    }	    message[pos] = '\0';	    size = simple_strtoul (argv[argc - 1], NULL, 10);	}    }        if (size >= CFG_CBSIZE)      size = CFG_CBSIZE - 1;    if (size <= 0)      return 1;    /* prompt for input */    len = readline (message);    if (size < len)      console_buffer[size] = '\0';    len = 2;    if (console_buffer[0] != '\0') {	local_args[2] = console_buffer;	len = 3;    }        // Continue calling setenv code    return _do_setenv (bd, flag, len, local_args);}#endif	/* CFG_CMD_ASKENV *//************************************************************************ * Look up variable from environment, * return address of storage for that variable, * or NULL if not found */char *getenv (bd_t * bd, uchar *name){    int i, nxt;        for (i=0; get_env_char(bd, i) != '\0'; i=nxt+1) 	{		int val;				for (nxt=i; get_env_char(bd, nxt) != '\0'; ++nxt) 		{			if (nxt >= sizeof(bd->bi_env_data)) 			{				return (NULL);			}		}		if ((val=envmatch(bd, name, i)) < 0)		  continue;		return (get_env_addr(bd, val));    }        return (NULL);}/************************************************************************ * Match a name / name=value pair * * s1 is either a simple 'name', or a 'name=value' pair. * i2 is the environment index for a 'name2=value2' pair. * If the names match, return the index for the value2, else NULL. */static int envmatch (bd_t *bd, uchar *s1, int i2){	while (*s1 == get_env_char(bd, i2++))		if (*s1++ == '=')			return(i2);	if (*s1 == '\0' && get_env_char(bd, i2-1) == '=')		return(i2);	return(-1);}#if (CONFIG_COMMANDS & CFG_CMD_ENV)int do_saveenv  (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[]){    return (board_env_save(bd, bd->bi_env, sizeof(env_t))) ? 1 : 0;}#endif	/* CFG_CMD_ENV */void env_init(bd_t *bd){    bd->bi_env = 0;}void env_relocate(bd_t *bd){    char *s, *e;    int reg;       bd->bi_env = malloc(sizeof(env_t));    if (board_env_copy(bd, bd->bi_env, sizeof(env_t)) < 0)    {		printf("*** Using default environment\n");		memcpy(bd->bi_env_data, default_environment, sizeof(default_environment));		bd->bi_env_crc = crc32(0, bd->bi_env_data, sizeof(bd->bi_env_data));    }        /* now initialise some variables */        /* MAC address */    s = getenv(bd, "ethaddr");    for (reg=0; reg<6; reg++)     {		bd->bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0;		if (s)			s = (*e) ? e+1 : e;	 }       /* IP address */    bd->bi_ip_addr = 0;    s = getenv(bd, "ipaddr");    for (reg=0; reg<4; ++reg) 	{            ulong val = s ? simple_strtoul(s, &e, 10) : 0;        bd->bi_ip_addr <<= 8;        bd->bi_ip_addr  |= (val & 0xFF);        if (s)	  		s = (*e) ? e+1 : e;    }        if ((s = getenv(bd, "loadaddr")) != NULL) 	{            load_addr = simple_strtoul(s, NULL, 16);    }// modified by choish #if defined(CONFIG_S3C2500) || defined(CONFIG_S3C2510)/* ICache, DCache, Write Buffer initialize 	*/	s = getenv(bd, "icache");	copy_filename(bd->bi_icache,s,sizeof(bd->bi_icache));	s = getenv(bd, "dcache");	copy_filename(bd->bi_dcache,s,sizeof(bd->bi_dcache));	s = getenv(bd, "wbuffer");	copy_filename(bd->bi_wbuffer,s,sizeof(bd->bi_wbuffer));#endif#if (CONFIG_COMMANDS & CFG_CMD_NET)    if ((s = getenv(bd, "bootfile")) != NULL) 	{            copy_filename (BootFile, s, sizeof(BootFile));    }#endif  /* CFG_CMD_NET */}#if defined(CONFIG_S3C2500) || defined(CONFIG_S3C2510)// by laputa startvoid reset_call(bd_t *bd){	unsigned long tmp;	disable_interrupts();	// supervisor mode	__asm__(			"mrs r0,cpsr\n"			"bic r0,r0,#0x1f\n"			"orr r0,r0,#0x13\n"			"msr cpsr,r0\n"			"ldr r0,=0x40000\n"			"mov pc,r0"		   );}void go_ram(bd_t *bd,int flag){	printf("load... and go \n");	run_command(getenv(bd,"bootcmd"),bd,flag);	reset_call(bd);	while(1);}int read_name_value(bd_t *bd,int *index_start,char *name,char *value){	int cnt;	int name_save=1;		// 1 = name save, 0 = value save	char tmp;				// one char save buffer	cnt = *index_start;		// index start count	if(!(tmp=get_env_char(bd,cnt)))		return 0;	for(;tmp;tmp=get_env_char(bd,++cnt))	{		if(name_save)		{			if(tmp=='=')			{				name_save = 0;		// after "=" is value set				continue;			}			*(name++)=tmp;			// name save		}		else			*(value++)=tmp;	}	*name=0;		// end of string	*value=0;	*index_start = ++cnt;		// next start index no.	return 1;}char *readenv(bd_t *bd,int cmd){	char *fev;	static int index_no;	static char name[30];	static char value[30];	switch(cmd)	{		case 0:			index_no = 0;		case 1:			if(!(read_name_value(bd,&index_no,name,value)))				return 0;			fev=name;			break;		case 2:			fev=value;			break;		default:			break;	}	return (char *)fev;		// return NAME or VALUE}void msg_arg(int argc, char *argv[]){    int n;    printf("do_saveenv argc = [%d] \n",argc);    for(n=0;n<argc;n++)        printf("do_saveenv argv[%d] = [%s] \n",n,argv[n]);}// end laputa#endif

⌨️ 快捷键说明

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