diff options
| author | Wolfgang Denk <wd@denx.de> | 2010-09-28 23:30:47 +0200 | 
|---|---|---|
| committer | Wolfgang Denk <wd@denx.de> | 2010-09-28 23:30:47 +0200 | 
| commit | 2e6e1772c0e34871769be4aef79748fe3e47d953 (patch) | |
| tree | 00e4e19d7bccd2a1cd5753854ff4c2b8a26bebb0 /common/env_common.c | |
| parent | 1e4e5ef0469050f014aee1204dae8a9ab6053e49 (diff) | |
| parent | 3df61957938586c512c17e72d83551d190400981 (diff) | |
| download | olio-uboot-2014.01-2e6e1772c0e34871769be4aef79748fe3e47d953.tar.xz olio-uboot-2014.01-2e6e1772c0e34871769be4aef79748fe3e47d953.zip | |
Merge branch 'next' of /home/wd/git/u-boot/next
Conflicts:
	include/ppc4xx.h
Signed-off-by: Wolfgang Denk <wd@denx.de>
Diffstat (limited to 'common/env_common.c')
| -rw-r--r-- | common/env_common.c | 128 | 
1 files changed, 63 insertions, 65 deletions
| diff --git a/common/env_common.c b/common/env_common.c index 460309bee..a415ef8ef 100644 --- a/common/env_common.c +++ b/common/env_common.c @@ -1,10 +1,10 @@  /* - * (C) Copyright 2000-2002 + * (C) Copyright 2000-2010   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.   *   * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>   * Andreas Heppel <aheppel@sysgo.de> - + *   * See file CREDITS for list of people who contributed to this   * project.   * @@ -28,17 +28,12 @@  #include <command.h>  #include <environment.h>  #include <linux/stddef.h> +#include <search.h> +#include <errno.h>  #include <malloc.h>  DECLARE_GLOBAL_DATA_PTR; -#undef DEBUG_ENV -#ifdef DEBUG_ENV -#define DEBUGF(fmt,args...) printf(fmt ,##args) -#else -#define DEBUGF(fmt,args...) -#endif -  extern env_t *env_ptr;  extern void env_relocate_spec (void); @@ -134,33 +129,22 @@ uchar default_environment[] = {  	"\0"  }; -void env_crc_update (void) -{ -	env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE); -} -  static uchar env_get_char_init (int index)  {  	uchar c;  	/* if crc was bad, use the default environment */  	if (gd->env_valid) -	{  		c = env_get_char_spec(index); -	} else { +	else  		c = default_environment[index]; -	}  	return (c);  }  uchar env_get_char_memory (int index)  { -	if (gd->env_valid) { -		return ( *((uchar *)(gd->env_addr + index)) ); -	} else { -		return ( default_environment[index] ); -	} +	return *env_get_addr(index);  }  uchar env_get_char (int index) @@ -178,70 +162,84 @@ uchar env_get_char (int index)  uchar *env_get_addr (int index)  { -	if (gd->env_valid) { -		return ( ((uchar *)(gd->env_addr + index)) ); -	} else { -		return (&default_environment[index]); -	} +	if (gd->env_valid) +		return (uchar *)(gd->env_addr + index); +	else +		return &default_environment[index];  } -void set_default_env(void) +void set_default_env(const char *s)  {  	if (sizeof(default_environment) > ENV_SIZE) { -		puts ("*** Error - default environment is too large\n\n"); +		puts("*** Error - default environment is too large\n\n");  		return;  	} -	memset(env_ptr, 0, sizeof(env_t)); -	memcpy(env_ptr->data, default_environment, -	       sizeof(default_environment)); -#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT -	env_ptr->flags = 0xFF; -#endif -	env_crc_update (); -	gd->env_valid = 1; +	if (s) { +		if (*s == '!') { +			printf("*** Warning - %s, " +				"using default environment\n\n", +				s+1); +		} else { +			puts(s); +		} +	} else { +		puts("Using default environment\n\n"); +	} + +	if (himport((char *)default_environment, +		    sizeof(default_environment), '\0', 0) == 0) { +		error("Environment import failed: errno = %d\n", errno); +	} +	gd->flags |= GD_FLG_ENV_READY;  } -void env_relocate (void) +/* + * Check if CRC is valid and (if yes) import the environment. + * Note that "buf" may or may not be aligned. + */ +int env_import(const char *buf, int check)  { -#ifndef CONFIG_RELOC_FIXUP_WORKS -	DEBUGF ("%s[%d] offset = 0x%lx\n", __FUNCTION__,__LINE__, -		gd->reloc_off); -#endif +	env_t *ep = (env_t *)buf; -#ifdef ENV_IS_EMBEDDED -	/* -	 * The environment buffer is embedded with the text segment, -	 * just relocate the environment pointer -	 */ -#ifndef CONFIG_RELOC_FIXUP_WORKS -	env_ptr = (env_t *)((ulong)env_ptr + gd->reloc_off); -#endif -	DEBUGF ("%s[%d] embedded ENV at %p\n", __FUNCTION__,__LINE__,env_ptr); -#else -	/* -	 * We must allocate a buffer for the environment -	 */ -	env_ptr = (env_t *)malloc (CONFIG_ENV_SIZE); -	DEBUGF ("%s[%d] malloced ENV at %p\n", __FUNCTION__,__LINE__,env_ptr); -#endif +	if (check) { +		uint32_t crc; + +		memcpy(&crc, &ep->crc, sizeof(crc)); + +		if (crc32(0, ep->data, ENV_SIZE) != crc) { +			set_default_env("!bad CRC"); +			return 0; +		} +	} + +	if (himport((char *)ep->data, ENV_SIZE, '\0', 0)) { +		gd->flags |= GD_FLG_ENV_READY; +		return 1; +	} +	error("Cannot import environment: errno = %d\n", errno); + +	set_default_env("!import failed"); + +	return 0; +} + +void env_relocate (void) +{  	if (gd->env_valid == 0) {  #if defined(CONFIG_ENV_IS_NOWHERE)	/* Environment not changable */ -		puts ("Using default environment\n\n"); +		set_default_env(NULL);  #else -		puts ("*** Warning - bad CRC, using default environment\n\n");  		show_boot_progress (-60);  #endif -		set_default_env(); -	} -	else { +		set_default_env("!bad CRC"); +	} else {  		env_relocate_spec ();  	} -	gd->env_addr = (ulong)&(env_ptr->data);  } -#ifdef CONFIG_AUTO_COMPLETE +#if 0 /* need to reimplement - def CONFIG_AUTO_COMPLETE */  int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf)  {  	int i, nxt, len, vallen, found; |