parent
3b8b5282c8
commit
b0c5815f03
|
@ -1,566 +0,0 @@
|
|||
/*
|
||||
* (C) Copyright 2000-2002
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**************************************************************************
|
||||
*
|
||||
* Support for persistent environment data
|
||||
*
|
||||
* The "environment" is stored as a list of '\0' terminated
|
||||
* "name=value" strings. The end of the list is marked by a double
|
||||
* '\0'. New entries are always added at the end. Deleting an entry
|
||||
* shifts the remaining entries to the front. Replacing an entry is a
|
||||
* combination of deleting the old value and adding the new one.
|
||||
*
|
||||
* The environment is preceeded by a 32 bit CRC over the data part.
|
||||
*
|
||||
**************************************************************************
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <command.h>
|
||||
#include <environment.h>
|
||||
#include <watchdog.h>
|
||||
#include <serial.h>
|
||||
#include <linux/stddef.h>
|
||||
#include <asm/byteorder.h>
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_NET)
|
||||
#include <net.h>
|
||||
#endif
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
#if !defined(CFG_ENV_IS_IN_NVRAM) && \
|
||||
!defined(CFG_ENV_IS_IN_EEPROM) && \
|
||||
!defined(CFG_ENV_IS_IN_FLASH) && \
|
||||
!defined(CFG_ENV_IS_IN_NAND) && \
|
||||
!defined(CFG_ENV_IS_NOWHERE)
|
||||
# error Define one of CFG_ENV_IS_IN_{NVRAM|EEPROM|FLASH|NOWHERE}
|
||||
#endif
|
||||
|
||||
#define XMK_STR(x) #x
|
||||
#define MK_STR(x) XMK_STR(x)
|
||||
|
||||
/************************************************************************
|
||||
************************************************************************/
|
||||
|
||||
/* Function that returns a character from the environment */
|
||||
extern uchar (*env_get_char)(int);
|
||||
|
||||
/* Function that returns a pointer to a value from the environment */
|
||||
/* (Only memory version supported / needed). */
|
||||
extern uchar *env_get_addr(int);
|
||||
|
||||
/* Function that updates CRC of the enironment */
|
||||
extern void env_crc_update (void);
|
||||
|
||||
/************************************************************************
|
||||
************************************************************************/
|
||||
|
||||
static int envmatch (uchar *, int);
|
||||
|
||||
/*
|
||||
* Table with supported baudrates (defined in config_xyz.h)
|
||||
*/
|
||||
static const unsigned long baudrate_table[] = CFG_BAUDRATE_TABLE;
|
||||
#define N_BAUDRATES (sizeof(baudrate_table) / sizeof(baudrate_table[0]))
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Command interface: print one or all environment variables
|
||||
*/
|
||||
|
||||
int do_printenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||
{
|
||||
int i, j, k, nxt;
|
||||
int rcode = 0;
|
||||
|
||||
if (argc == 1) { /* Print all env variables */
|
||||
for (i=0; env_get_char(i) != '\0'; i=nxt+1) {
|
||||
for (nxt=i; env_get_char(nxt) != '\0'; ++nxt)
|
||||
;
|
||||
for (k=i; k<nxt; ++k)
|
||||
putc(env_get_char(k));
|
||||
putc ('\n');
|
||||
|
||||
if (ctrlc()) {
|
||||
puts ("\n ** Abort\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nEnvironment size: %d/%d bytes\n", i, ENV_SIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i=1; i<argc; ++i) { /* print single env variables */
|
||||
char *name = argv[i];
|
||||
|
||||
k = -1;
|
||||
|
||||
for (j=0; env_get_char(j) != '\0'; j=nxt+1) {
|
||||
|
||||
for (nxt=j; env_get_char(nxt) != '\0'; ++nxt)
|
||||
;
|
||||
k = envmatch((uchar *)name, j);
|
||||
if (k < 0) {
|
||||
continue;
|
||||
}
|
||||
puts (name);
|
||||
putc ('=');
|
||||
while (k < nxt)
|
||||
putc(env_get_char(k++));
|
||||
putc ('\n');
|
||||
break;
|
||||
}
|
||||
if (k < 0) {
|
||||
printf ("## Error: \"%s\" not defined\n", name);
|
||||
rcode ++;
|
||||
}
|
||||
}
|
||||
return rcode;
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Set a new environment variable,
|
||||
* or replace or delete an existing one.
|
||||
*
|
||||
* This function will ONLY work with a in-RAM copy of the environment
|
||||
*/
|
||||
|
||||
int _do_setenv (int flag, int argc, char *argv[])
|
||||
{
|
||||
int i, len, oldval;
|
||||
uchar *env, *nxt = NULL;
|
||||
char *name;
|
||||
|
||||
uchar *env_data = env_get_addr(0);
|
||||
|
||||
if (!env_data) /* need copy in RAM */
|
||||
return 1;
|
||||
|
||||
name = argv[1];
|
||||
|
||||
if (strchr(name, '=')) {
|
||||
printf ("## Error: illegal character '=' in variable name \"%s\"\n", name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* search if variable with this name already exists
|
||||
*/
|
||||
oldval = -1;
|
||||
for (env=env_data; *env; env=nxt+1) {
|
||||
for (nxt=env; *nxt; ++nxt)
|
||||
;
|
||||
if ((oldval = envmatch((uchar *)name, env-env_data)) >= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete any existing definition
|
||||
*/
|
||||
if (oldval >= 0) {
|
||||
#ifndef CONFIG_ENV_OVERWRITE
|
||||
|
||||
/*
|
||||
* Ethernet Address and serial# can be set only once,
|
||||
* ver is readonly.
|
||||
*/
|
||||
if ( (strcmp (name, "serial#") == 0) ||
|
||||
((strcmp (name, "ethaddr") == 0)
|
||||
#if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR)
|
||||
&& (strcmp ((char *)env_get_addr(oldval),MK_STR(CONFIG_ETHADDR)) != 0)
|
||||
#endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */
|
||||
) ) {
|
||||
printf ("Can't overwrite \"%s\"\n", name);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Switch to new baudrate if new baudrate is supported
|
||||
*/
|
||||
if (strcmp(argv[1],"baudrate") == 0) {
|
||||
int baudrate = simple_strtoul(argv[2], NULL, 10);
|
||||
int i;
|
||||
for (i=0; i<N_BAUDRATES; ++i) {
|
||||
if (baudrate == baudrate_table[i])
|
||||
break;
|
||||
}
|
||||
if (i == N_BAUDRATES) {
|
||||
printf ("## Baudrate %d bps not supported\n",
|
||||
baudrate);
|
||||
return 1;
|
||||
}
|
||||
printf ("## Switch baudrate to %d bps and press ENTER ...\n",
|
||||
baudrate);
|
||||
udelay(50000);
|
||||
gd->baudrate = baudrate;
|
||||
#if defined(CONFIG_PPC) || defined(CONFIG_MCF52x2)
|
||||
gd->bd->bi_baudrate = baudrate;
|
||||
#endif
|
||||
|
||||
serial_setbrg ();
|
||||
udelay(50000);
|
||||
for (;;) {
|
||||
if (getc() == '\r')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (*++nxt == '\0') {
|
||||
if (env > env_data) {
|
||||
env--;
|
||||
} else {
|
||||
*env = '\0';
|
||||
}
|
||||
} else {
|
||||
for (;;) {
|
||||
*env = *nxt++;
|
||||
if ((*env == '\0') && (*nxt == '\0'))
|
||||
break;
|
||||
++env;
|
||||
}
|
||||
}
|
||||
*++env = '\0';
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_MULTI
|
||||
if (strncmp(name, "eth", 3) == 0) {
|
||||
char *end;
|
||||
int num = simple_strtoul(name+3, &end, 10);
|
||||
|
||||
if (strcmp(end, "addr") == 0) {
|
||||
eth_set_enetaddr(num, argv[2]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Delete only ? */
|
||||
if ((argc < 3) || argv[2] == NULL) {
|
||||
env_crc_update ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Append new definition at the end
|
||||
*/
|
||||
for (env=env_data; *env || *(env+1); ++env)
|
||||
;
|
||||
if (env > env_data)
|
||||
++env;
|
||||
/*
|
||||
* Overflow when:
|
||||
* "name" + "=" + "val" +"\0\0" > ENV_SIZE - (env-env_data)
|
||||
*/
|
||||
len = strlen(name) + 2;
|
||||
/* add '=' for first arg, ' ' for all others */
|
||||
for (i=2; i<argc; ++i) {
|
||||
len += strlen(argv[i]) + 1;
|
||||
}
|
||||
if (len > (&env_data[ENV_SIZE]-env)) {
|
||||
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 */
|
||||
env_crc_update ();
|
||||
|
||||
/*
|
||||
* Some variables should be updated when the corresponding
|
||||
* entry in the enviornment is changed
|
||||
*/
|
||||
|
||||
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 (char *varname, char *varvalue)
|
||||
{
|
||||
char *argv[4] = { "setenv", varname, varvalue, NULL };
|
||||
_do_setenv (0, 3, argv);
|
||||
}
|
||||
|
||||
int do_setenv ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf ("Usage:\n%s\n", cmdtp->usage);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return _do_setenv (flag, argc, argv);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Prompt for environment variable
|
||||
*/
|
||||
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_ASKENV)
|
||||
int do_askenv ( cmd_tbl_t *cmdtp, 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);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
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 (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 (char *name)
|
||||
{
|
||||
int i, nxt;
|
||||
|
||||
WATCHDOG_RESET();
|
||||
|
||||
for (i=0; env_get_char(i) != '\0'; i=nxt+1) {
|
||||
int val;
|
||||
|
||||
for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) {
|
||||
if (nxt >= CFG_ENV_SIZE) {
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
if ((val=envmatch((uchar *)name, i)) < 0)
|
||||
continue;
|
||||
return ((char *)env_get_addr(val));
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int getenv_r (char *name, char *buf, unsigned len)
|
||||
{
|
||||
int i, nxt;
|
||||
|
||||
for (i=0; env_get_char(i) != '\0'; i=nxt+1) {
|
||||
int val, n;
|
||||
|
||||
for (nxt=i; env_get_char(nxt) != '\0'; ++nxt) {
|
||||
if (nxt >= CFG_ENV_SIZE) {
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
if ((val=envmatch((uchar *)name, i)) < 0)
|
||||
continue;
|
||||
/* found; copy out */
|
||||
n = 0;
|
||||
while ((len > n++) && (*buf++ = env_get_char(val++)) != '\0')
|
||||
;
|
||||
if (len == n)
|
||||
*buf = '\0';
|
||||
return (n);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#if defined(CFG_ENV_IS_IN_NVRAM) || defined(CFG_ENV_IS_IN_EEPROM) || \
|
||||
((CONFIG_COMMANDS & (CFG_CMD_ENV|CFG_CMD_FLASH)) == \
|
||||
(CFG_CMD_ENV|CFG_CMD_FLASH)) || \
|
||||
((CONFIG_COMMANDS & (CFG_CMD_ENV|CFG_CMD_NAND)) == \
|
||||
(CFG_CMD_ENV|CFG_CMD_NAND))
|
||||
int do_saveenv (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||
{
|
||||
extern char * env_name_spec;
|
||||
|
||||
printf ("Saving Environment to %s...\n", env_name_spec);
|
||||
|
||||
return (saveenv() ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* 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 (uchar *s1, int i2)
|
||||
{
|
||||
|
||||
while (*s1 == env_get_char(i2++))
|
||||
if (*s1++ == '=')
|
||||
return(i2);
|
||||
if (*s1 == '\0' && env_get_char(i2-1) == '=')
|
||||
return(i2);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************/
|
||||
|
||||
U_BOOT_CMD(
|
||||
printenv, CFG_MAXARGS, 1, do_printenv,
|
||||
"printenv- print environment variables\n",
|
||||
"\n - print values of all environment variables\n"
|
||||
"printenv name ...\n"
|
||||
" - print value of environment variable 'name'\n"
|
||||
);
|
||||
|
||||
U_BOOT_CMD(
|
||||
setenv, CFG_MAXARGS, 0, do_setenv,
|
||||
"setenv - set environment variables\n",
|
||||
"name value ...\n"
|
||||
" - set environment variable 'name' to 'value ...'\n"
|
||||
"setenv name\n"
|
||||
" - delete environment variable 'name'\n"
|
||||
);
|
||||
|
||||
#if defined(CFG_ENV_IS_IN_NVRAM) || defined(CFG_ENV_IS_IN_EEPROM) || \
|
||||
((CONFIG_COMMANDS & (CFG_CMD_ENV|CFG_CMD_FLASH)) == \
|
||||
(CFG_CMD_ENV|CFG_CMD_FLASH)) || \
|
||||
((CONFIG_COMMANDS & (CFG_CMD_ENV|CFG_CMD_NAND)) == \
|
||||
(CFG_CMD_ENV|CFG_CMD_NAND))
|
||||
U_BOOT_CMD(
|
||||
saveenv, 1, 0, do_saveenv,
|
||||
"saveenv - save environment variables to persistent storage\n",
|
||||
NULL
|
||||
);
|
||||
|
||||
#endif /* CFG_CMD_ENV */
|
||||
|
||||
#if (CONFIG_COMMANDS & CFG_CMD_ASKENV)
|
||||
|
||||
U_BOOT_CMD(
|
||||
askenv, CFG_MAXARGS, 1, do_askenv,
|
||||
"askenv - get environment variables from stdin\n",
|
||||
"name [message] [size]\n"
|
||||
" - get environment variable 'name' from stdin (max 'size' chars)\n"
|
||||
"askenv name\n"
|
||||
" - get environment variable 'name' from stdin\n"
|
||||
"askenv name size\n"
|
||||
" - get environment variable 'name' from stdin (max 'size' chars)\n"
|
||||
"askenv name [message] size\n"
|
||||
" - display 'message' string and get environment variable 'name'"
|
||||
"from stdin (max 'size' chars)\n"
|
||||
);
|
||||
#endif /* CFG_CMD_ASKENV */
|
||||
|
||||
int do_run (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
|
||||
U_BOOT_CMD(
|
||||
run, CFG_MAXARGS, 1, do_run,
|
||||
"run - run commands in an environment variable\n",
|
||||
"var [...]\n"
|
||||
" - run the commands in the environment variable(s) 'var'\n"
|
||||
);
|
|
@ -1,300 +0,0 @@
|
|||
/*
|
||||
* (C) Copyright 2000-2002
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <command.h>
|
||||
#include <environment.h>
|
||||
#include <linux/stddef.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#ifdef CONFIG_SHOW_BOOT_PROGRESS
|
||||
# include <status_led.h>
|
||||
# define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
|
||||
#else
|
||||
# define SHOW_BOOT_PROGRESS(arg)
|
||||
#endif
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
#ifdef CONFIG_AMIGAONEG3SE
|
||||
extern void enable_nvram(void);
|
||||
extern void disable_nvram(void);
|
||||
#endif
|
||||
|
||||
#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);
|
||||
extern uchar env_get_char_spec(int);
|
||||
|
||||
static uchar env_get_char_init (int index);
|
||||
uchar (*env_get_char)(int) = env_get_char_init;
|
||||
|
||||
/************************************************************************
|
||||
* Default settings to be used when no valid environment is found
|
||||
*/
|
||||
#define XMK_STR(x) #x
|
||||
#define MK_STR(x) XMK_STR(x)
|
||||
|
||||
uchar default_environment[] = {
|
||||
#ifdef CONFIG_BOOTARGS
|
||||
"bootargs=" CONFIG_BOOTARGS "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_BOOTCOMMAND
|
||||
"bootcmd=" CONFIG_BOOTCOMMAND "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_RAMBOOTCOMMAND
|
||||
"ramboot=" CONFIG_RAMBOOTCOMMAND "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_NFSBOOTCOMMAND
|
||||
"nfsboot=" CONFIG_NFSBOOTCOMMAND "\0"
|
||||
#endif
|
||||
#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
|
||||
"bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0"
|
||||
#endif
|
||||
#if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)
|
||||
"baudrate=" MK_STR(CONFIG_BAUDRATE) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_LOADS_ECHO
|
||||
"loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ETHADDR
|
||||
"ethaddr=" MK_STR(CONFIG_ETHADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ETH1ADDR
|
||||
"eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ETH2ADDR
|
||||
"eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ETH3ADDR
|
||||
"eth3addr=" MK_STR(CONFIG_ETH3ADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_IPADDR
|
||||
"ipaddr=" MK_STR(CONFIG_IPADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_SERVERIP
|
||||
"serverip=" MK_STR(CONFIG_SERVERIP) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_PREBOOT
|
||||
"preboot=" CONFIG_PREBOOT "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ROOTPATH
|
||||
"rootpath=" MK_STR(CONFIG_ROOTPATH) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_GATEWAYIP
|
||||
"gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_NETMASK
|
||||
"netmask=" MK_STR(CONFIG_NETMASK) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_HOSTNAME
|
||||
"hostname=" MK_STR(CONFIG_HOSTNAME) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_BOOTFILE
|
||||
"bootfile=" MK_STR(CONFIG_BOOTFILE) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_LOADADDR
|
||||
"loadaddr=" MK_STR(CONFIG_LOADADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_CLOCKS_IN_MHZ
|
||||
"clocks_in_mhz=1\0"
|
||||
#endif
|
||||
#if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0)
|
||||
"pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_EXTRA_ENV_SETTINGS
|
||||
CONFIG_EXTRA_ENV_SETTINGS
|
||||
#endif
|
||||
"\0"
|
||||
};
|
||||
|
||||
#if defined(CFG_ENV_IS_IN_NAND) /* Environment is in Nand Flash */
|
||||
int default_environment_size = sizeof(default_environment);
|
||||
#endif
|
||||
|
||||
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 {
|
||||
c = default_environment[index];
|
||||
}
|
||||
|
||||
return (c);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_AMIGAONEG3SE
|
||||
uchar env_get_char_memory (int index)
|
||||
{
|
||||
uchar retval;
|
||||
enable_nvram();
|
||||
if (gd->env_valid) {
|
||||
retval = ( *((uchar *)(gd->env_addr + index)) );
|
||||
} else {
|
||||
retval = ( default_environment[index] );
|
||||
}
|
||||
disable_nvram();
|
||||
return retval;
|
||||
}
|
||||
#else
|
||||
uchar env_get_char_memory (int index)
|
||||
{
|
||||
if (gd->env_valid) {
|
||||
return ( *((uchar *)(gd->env_addr + index)) );
|
||||
} else {
|
||||
return ( default_environment[index] );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
uchar *env_get_addr (int index)
|
||||
{
|
||||
if (gd->env_valid) {
|
||||
return ( ((uchar *)(gd->env_addr + index)) );
|
||||
} else {
|
||||
return (&default_environment[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void env_relocate (void)
|
||||
{
|
||||
DEBUGF ("%s[%d] offset = 0x%lx\n", __FUNCTION__,__LINE__,
|
||||
gd->reloc_off);
|
||||
|
||||
#ifdef CONFIG_AMIGAONEG3SE
|
||||
enable_nvram();
|
||||
#endif
|
||||
|
||||
#ifdef ENV_IS_EMBEDDED
|
||||
/*
|
||||
* The environment buffer is embedded with the text segment,
|
||||
* just relocate the environment pointer
|
||||
*/
|
||||
env_ptr = (env_t *)((ulong)env_ptr + gd->reloc_off);
|
||||
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 (CFG_ENV_SIZE);
|
||||
DEBUGF ("%s[%d] malloced ENV at %p\n", __FUNCTION__,__LINE__,env_ptr);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* After relocation to RAM, we can always use the "memory" functions
|
||||
*/
|
||||
env_get_char = env_get_char_memory;
|
||||
|
||||
if (gd->env_valid == 0) {
|
||||
#if defined(CONFIG_GTH) || defined(CFG_ENV_IS_NOWHERE) /* Environment not changable */
|
||||
puts ("Using default environment\n\n");
|
||||
#else
|
||||
puts ("*** Warning - bad CRC, using default environment\n\n");
|
||||
SHOW_BOOT_PROGRESS (-1);
|
||||
#endif
|
||||
|
||||
if (sizeof(default_environment) > ENV_SIZE)
|
||||
{
|
||||
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 CFG_REDUNDAND_ENVIRONMENT
|
||||
env_ptr->flags = 0xFF;
|
||||
#endif
|
||||
env_crc_update ();
|
||||
gd->env_valid = 1;
|
||||
}
|
||||
else {
|
||||
env_relocate_spec ();
|
||||
}
|
||||
gd->env_addr = (ulong)&(env_ptr->data);
|
||||
|
||||
#ifdef CONFIG_AMIGAONEG3SE
|
||||
disable_nvram();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CONFIG_AUTO_COMPLETE
|
||||
int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf)
|
||||
{
|
||||
int i, nxt, len, vallen, found;
|
||||
const char *lval, *rval;
|
||||
|
||||
found = 0;
|
||||
cmdv[0] = NULL;
|
||||
|
||||
len = strlen(var);
|
||||
/* now iterate over the variables and select those that match */
|
||||
for (i=0; env_get_char(i) != '\0'; i=nxt+1) {
|
||||
|
||||
for (nxt=i; env_get_char(nxt) != '\0'; ++nxt)
|
||||
;
|
||||
|
||||
lval = (char *)env_get_addr(i);
|
||||
rval = strchr(lval, '=');
|
||||
if (rval != NULL) {
|
||||
vallen = rval - lval;
|
||||
rval++;
|
||||
} else
|
||||
vallen = strlen(lval);
|
||||
|
||||
if (len > 0 && (vallen < len || memcmp(lval, var, len) != 0))
|
||||
continue;
|
||||
|
||||
if (found >= maxv - 2 || bufsz < vallen + 1) {
|
||||
cmdv[found++] = "...";
|
||||
break;
|
||||
}
|
||||
cmdv[found++] = buf;
|
||||
memcpy(buf, lval, vallen); buf += vallen; bufsz -= vallen;
|
||||
*buf++ = '\0'; bufsz--;
|
||||
}
|
||||
|
||||
cmdv[found] = NULL;
|
||||
return found;
|
||||
}
|
||||
#endif
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* (C) Copyright 2000-2002
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
|
||||
#if defined(CFG_ENV_IS_IN_EEPROM) /* Environment is in EEPROM */
|
||||
|
||||
#include <command.h>
|
||||
#include <environment.h>
|
||||
#include <linux/stddef.h>
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
env_t *env_ptr = NULL;
|
||||
|
||||
char * env_name_spec = "EEPROM";
|
||||
|
||||
extern uchar (*env_get_char)(int);
|
||||
extern uchar env_get_char_memory (int index);
|
||||
|
||||
|
||||
uchar env_get_char_spec (int index)
|
||||
{
|
||||
uchar c;
|
||||
|
||||
eeprom_read (CFG_DEF_EEPROM_ADDR,
|
||||
CFG_ENV_OFFSET+index+offsetof(env_t,data),
|
||||
&c, 1);
|
||||
|
||||
return (c);
|
||||
}
|
||||
|
||||
void env_relocate_spec (void)
|
||||
{
|
||||
eeprom_read (CFG_DEF_EEPROM_ADDR,
|
||||
CFG_ENV_OFFSET,
|
||||
(uchar*)env_ptr,
|
||||
CFG_ENV_SIZE);
|
||||
}
|
||||
|
||||
int saveenv(void)
|
||||
{
|
||||
return eeprom_write (CFG_DEF_EEPROM_ADDR,
|
||||
CFG_ENV_OFFSET,
|
||||
(uchar *)env_ptr,
|
||||
CFG_ENV_SIZE);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Initialize Environment use
|
||||
*
|
||||
* We are still running from ROM, so data use is limited
|
||||
* Use a (moderately small) buffer on the stack
|
||||
*/
|
||||
int env_init(void)
|
||||
{
|
||||
ulong crc, len, new;
|
||||
unsigned off;
|
||||
uchar buf[64];
|
||||
|
||||
eeprom_init (); /* prepare for EEPROM read/write */
|
||||
|
||||
/* read old CRC */
|
||||
eeprom_read (CFG_DEF_EEPROM_ADDR,
|
||||
CFG_ENV_OFFSET+offsetof(env_t,crc),
|
||||
(uchar *)&crc, sizeof(ulong));
|
||||
|
||||
new = 0;
|
||||
len = ENV_SIZE;
|
||||
off = offsetof(env_t,data);
|
||||
while (len > 0) {
|
||||
int n = (len > sizeof(buf)) ? sizeof(buf) : len;
|
||||
|
||||
eeprom_read (CFG_DEF_EEPROM_ADDR, CFG_ENV_OFFSET+off, buf, n);
|
||||
new = crc32 (new, buf, n);
|
||||
len -= n;
|
||||
off += n;
|
||||
}
|
||||
|
||||
if (crc == new) {
|
||||
gd->env_addr = offsetof(env_t,data);
|
||||
gd->env_valid = 1;
|
||||
} else {
|
||||
gd->env_addr = 0;
|
||||
gd->env_valid = 0;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif /* CFG_ENV_IS_IN_EEPROM */
|
|
@ -1,378 +0,0 @@
|
|||
/*
|
||||
* (C) Copyright 2000-2002
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* #define DEBUG */
|
||||
|
||||
#include <common.h>
|
||||
|
||||
#if defined(CFG_ENV_IS_IN_FLASH) /* Environment is in Flash */
|
||||
|
||||
#include <command.h>
|
||||
#include <environment.h>
|
||||
#include <linux/stddef.h>
|
||||
#include <malloc.h>
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
#if ((CONFIG_COMMANDS&(CFG_CMD_ENV|CFG_CMD_FLASH)) == (CFG_CMD_ENV|CFG_CMD_FLASH))
|
||||
#define CMD_SAVEENV
|
||||
#elif defined(CFG_ENV_ADDR_REDUND)
|
||||
#error Cannot use CFG_ENV_ADDR_REDUND without CFG_CMD_ENV & CFG_CMD_FLASH
|
||||
#endif
|
||||
|
||||
#if defined(CFG_ENV_SIZE_REDUND) && (CFG_ENV_SIZE_REDUND < CFG_ENV_SIZE)
|
||||
#error CFG_ENV_SIZE_REDUND should not be less then CFG_ENV_SIZE
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_INFERNO
|
||||
# ifdef CFG_ENV_ADDR_REDUND
|
||||
#error CFG_ENV_ADDR_REDUND is not implemented for CONFIG_INFERNO
|
||||
# endif
|
||||
#endif
|
||||
|
||||
char * env_name_spec = "Flash";
|
||||
|
||||
static env_t *flash_addr = (env_t *)CFG_ENV_ADDR;
|
||||
|
||||
#ifdef ENV_IS_EMBEDDED
|
||||
|
||||
extern uchar environment[];
|
||||
env_t *env_ptr = (env_t *)(&environment[0]);
|
||||
|
||||
#else /* ! ENV_IS_EMBEDDED */
|
||||
|
||||
env_t *env_ptr = (env_t *)CFG_ENV_ADDR;
|
||||
|
||||
#endif /* ENV_IS_EMBEDDED */
|
||||
|
||||
#ifdef CFG_ENV_ADDR_REDUND
|
||||
static env_t *flash_addr_new = (env_t *)CFG_ENV_ADDR_REDUND;
|
||||
|
||||
/* CFG_ENV_ADDR is supposed to be on sector boundary */
|
||||
static ulong end_addr = CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1;
|
||||
static ulong end_addr_new = CFG_ENV_ADDR_REDUND + CFG_ENV_SECT_SIZE - 1;
|
||||
|
||||
#define ACTIVE_FLAG 1
|
||||
#define OBSOLETE_FLAG 0
|
||||
#endif /* CFG_ENV_ADDR_REDUND */
|
||||
|
||||
extern uchar default_environment[];
|
||||
extern int default_environment_size;
|
||||
|
||||
|
||||
uchar env_get_char_spec (int index)
|
||||
{
|
||||
return ( *((uchar *)(gd->env_addr + index)) );
|
||||
}
|
||||
|
||||
#ifdef CFG_ENV_ADDR_REDUND
|
||||
|
||||
int env_init(void)
|
||||
{
|
||||
int crc1_ok = 0, crc2_ok = 0;
|
||||
|
||||
uchar flag1 = flash_addr->flags;
|
||||
uchar flag2 = flash_addr_new->flags;
|
||||
|
||||
ulong addr_default = (ulong)&default_environment[0];
|
||||
ulong addr1 = (ulong)&(flash_addr->data);
|
||||
ulong addr2 = (ulong)&(flash_addr_new->data);
|
||||
|
||||
crc1_ok = (crc32(0, flash_addr->data, ENV_SIZE) == flash_addr->crc);
|
||||
crc2_ok = (crc32(0, flash_addr_new->data, ENV_SIZE) == flash_addr_new->crc);
|
||||
|
||||
if (crc1_ok && ! crc2_ok) {
|
||||
gd->env_addr = addr1;
|
||||
gd->env_valid = 1;
|
||||
} else if (! crc1_ok && crc2_ok) {
|
||||
gd->env_addr = addr2;
|
||||
gd->env_valid = 1;
|
||||
} else if (! crc1_ok && ! crc2_ok) {
|
||||
gd->env_addr = addr_default;
|
||||
gd->env_valid = 0;
|
||||
} else if (flag1 == ACTIVE_FLAG && flag2 == OBSOLETE_FLAG) {
|
||||
gd->env_addr = addr1;
|
||||
gd->env_valid = 1;
|
||||
} else if (flag1 == OBSOLETE_FLAG && flag2 == ACTIVE_FLAG) {
|
||||
gd->env_addr = addr2;
|
||||
gd->env_valid = 1;
|
||||
} else if (flag1 == flag2) {
|
||||
gd->env_addr = addr1;
|
||||
gd->env_valid = 2;
|
||||
} else if (flag1 == 0xFF) {
|
||||
gd->env_addr = addr1;
|
||||
gd->env_valid = 2;
|
||||
} else if (flag2 == 0xFF) {
|
||||
gd->env_addr = addr2;
|
||||
gd->env_valid = 2;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef CMD_SAVEENV
|
||||
int saveenv(void)
|
||||
{
|
||||
char *saved_data = NULL;
|
||||
int rc = 1;
|
||||
char flag = OBSOLETE_FLAG, new_flag = ACTIVE_FLAG;
|
||||
#if CFG_ENV_SECT_SIZE > CFG_ENV_SIZE
|
||||
ulong up_data = 0;
|
||||
#endif
|
||||
|
||||
debug ("Protect off %08lX ... %08lX\n",
|
||||
(ulong)flash_addr, end_addr);
|
||||
|
||||
if (flash_sect_protect (0, (ulong)flash_addr, end_addr)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
debug ("Protect off %08lX ... %08lX\n",
|
||||
(ulong)flash_addr_new, end_addr_new);
|
||||
|
||||
if (flash_sect_protect (0, (ulong)flash_addr_new, end_addr_new)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
#if CFG_ENV_SECT_SIZE > CFG_ENV_SIZE
|
||||
up_data = (end_addr_new + 1 - ((long)flash_addr_new + CFG_ENV_SIZE));
|
||||
debug ("Data to save 0x%x\n", up_data);
|
||||
if (up_data) {
|
||||
if ((saved_data = malloc(up_data)) == NULL) {
|
||||
printf("Unable to save the rest of sector (%ld)\n",
|
||||
up_data);
|
||||
goto Done;
|
||||
}
|
||||
memcpy(saved_data,
|
||||
(void *)((long)flash_addr_new + CFG_ENV_SIZE), up_data);
|
||||
debug ("Data (start 0x%x, len 0x%x) saved at 0x%x\n",
|
||||
(long)flash_addr_new + CFG_ENV_SIZE,
|
||||
up_data, saved_data);
|
||||
}
|
||||
#endif
|
||||
puts ("Erasing Flash...");
|
||||
debug (" %08lX ... %08lX ...",
|
||||
(ulong)flash_addr_new, end_addr_new);
|
||||
#warning saveenv is broken
|
||||
// if (flash_sect_erase ((ulong)flash_addr_new, end_addr_new)) {
|
||||
// goto Done;
|
||||
// }
|
||||
|
||||
puts ("Writing to Flash... ");
|
||||
debug (" %08lX ... %08lX ...",
|
||||
(ulong)&(flash_addr_new->data),
|
||||
sizeof(env_ptr->data)+(ulong)&(flash_addr_new->data));
|
||||
if ((rc = flash_write((char *)env_ptr->data,
|
||||
(ulong)&(flash_addr_new->data),
|
||||
sizeof(env_ptr->data))) ||
|
||||
(rc = flash_write((char *)&(env_ptr->crc),
|
||||
(ulong)&(flash_addr_new->crc),
|
||||
sizeof(env_ptr->crc))) ||
|
||||
(rc = flash_write(&flag,
|
||||
(ulong)&(flash_addr->flags),
|
||||
sizeof(flash_addr->flags))) ||
|
||||
(rc = flash_write(&new_flag,
|
||||
(ulong)&(flash_addr_new->flags),
|
||||
sizeof(flash_addr_new->flags))))
|
||||
{
|
||||
flash_perror (rc);
|
||||
goto Done;
|
||||
}
|
||||
puts ("done\n");
|
||||
|
||||
#if CFG_ENV_SECT_SIZE > CFG_ENV_SIZE
|
||||
if (up_data) { /* restore the rest of sector */
|
||||
debug ("Restoring the rest of data to 0x%x len 0x%x\n",
|
||||
(long)flash_addr_new + CFG_ENV_SIZE, up_data);
|
||||
if (flash_write(saved_data,
|
||||
(long)flash_addr_new + CFG_ENV_SIZE,
|
||||
up_data)) {
|
||||
flash_perror(rc);
|
||||
goto Done;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
{
|
||||
env_t * etmp = flash_addr;
|
||||
ulong ltmp = end_addr;
|
||||
|
||||
flash_addr = flash_addr_new;
|
||||
flash_addr_new = etmp;
|
||||
|
||||
end_addr = end_addr_new;
|
||||
end_addr_new = ltmp;
|
||||
}
|
||||
|
||||
rc = 0;
|
||||
Done:
|
||||
|
||||
if (saved_data)
|
||||
free (saved_data);
|
||||
/* try to re-protect */
|
||||
// (void) flash_sect_protect (1, (ulong)flash_addr, end_addr);
|
||||
// (void) flash_sect_protect (1, (ulong)flash_addr_new, end_addr_new);
|
||||
|
||||
return rc;
|
||||
}
|
||||
#endif /* CMD_SAVEENV */
|
||||
|
||||
#else /* ! CFG_ENV_ADDR_REDUND */
|
||||
|
||||
int env_init(void)
|
||||
{
|
||||
if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
|
||||
gd->env_addr = (ulong)&(env_ptr->data);
|
||||
gd->env_valid = 1;
|
||||
return(0);
|
||||
}
|
||||
gd->env_addr = (ulong)&default_environment[0];
|
||||
gd->env_valid = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef CMD_SAVEENV
|
||||
|
||||
int saveenv(void)
|
||||
{
|
||||
int len, rc;
|
||||
ulong end_addr;
|
||||
ulong flash_sect_addr;
|
||||
#if defined(CFG_ENV_SECT_SIZE) && (CFG_ENV_SECT_SIZE > CFG_ENV_SIZE)
|
||||
ulong flash_offset;
|
||||
uchar env_buffer[CFG_ENV_SECT_SIZE];
|
||||
#else
|
||||
uchar *env_buffer = (uchar *)env_ptr;
|
||||
#endif /* CFG_ENV_SECT_SIZE */
|
||||
int rcode = 0;
|
||||
|
||||
#if defined(CFG_ENV_SECT_SIZE) && (CFG_ENV_SECT_SIZE > CFG_ENV_SIZE)
|
||||
|
||||
flash_offset = ((ulong)flash_addr) & (CFG_ENV_SECT_SIZE-1);
|
||||
flash_sect_addr = ((ulong)flash_addr) & ~(CFG_ENV_SECT_SIZE-1);
|
||||
|
||||
debug ( "copy old content: "
|
||||
"sect_addr: %08lX env_addr: %08lX offset: %08lX\n",
|
||||
flash_sect_addr, (ulong)flash_addr, flash_offset);
|
||||
|
||||
/* copy old contents to temporary buffer */
|
||||
memcpy (env_buffer, (void *)flash_sect_addr, CFG_ENV_SECT_SIZE);
|
||||
|
||||
/* copy current environment to temporary buffer */
|
||||
memcpy ((uchar *)((unsigned long)env_buffer + flash_offset),
|
||||
env_ptr,
|
||||
CFG_ENV_SIZE);
|
||||
|
||||
len = CFG_ENV_SECT_SIZE;
|
||||
#else
|
||||
flash_sect_addr = (ulong)flash_addr;
|
||||
len = CFG_ENV_SIZE;
|
||||
#endif /* CFG_ENV_SECT_SIZE */
|
||||
|
||||
#ifndef CONFIG_INFERNO
|
||||
end_addr = flash_sect_addr + len - 1;
|
||||
#else
|
||||
/* this is the last sector, and the size is hardcoded here */
|
||||
/* otherwise we will get stack problems on loading 128 KB environment */
|
||||
end_addr = flash_sect_addr + 0x20000 - 1;
|
||||
#endif
|
||||
|
||||
debug ("Protect off %08lX ... %08lX\n",
|
||||
(ulong)flash_sect_addr, end_addr);
|
||||
|
||||
// if (flash_sect_protect (0, flash_sect_addr, end_addr))
|
||||
// return 1;
|
||||
|
||||
puts ("Erasing Flash...");
|
||||
// if (flash_sect_erase (flash_sect_addr, end_addr))
|
||||
// return 1;
|
||||
|
||||
puts ("Writing to Flash... ");
|
||||
rc = flash_write((char *)env_buffer, flash_sect_addr, len);
|
||||
if (rc != 0) {
|
||||
flash_perror (rc);
|
||||
rcode = 1;
|
||||
} else {
|
||||
puts ("done\n");
|
||||
}
|
||||
|
||||
/* try to re-protect */
|
||||
// (void) flash_sect_protect (1, flash_sect_addr, end_addr);
|
||||
return rcode;
|
||||
}
|
||||
|
||||
#endif /* CMD_SAVEENV */
|
||||
|
||||
#endif /* CFG_ENV_ADDR_REDUND */
|
||||
|
||||
void env_relocate_spec (void)
|
||||
{
|
||||
#if !defined(ENV_IS_EMBEDDED) || defined(CFG_ENV_ADDR_REDUND)
|
||||
#ifdef CFG_ENV_ADDR_REDUND
|
||||
if (gd->env_addr != (ulong)&(flash_addr->data)) {
|
||||
env_t * etmp = flash_addr;
|
||||
ulong ltmp = end_addr;
|
||||
|
||||
flash_addr = flash_addr_new;
|
||||
flash_addr_new = etmp;
|
||||
|
||||
end_addr = end_addr_new;
|
||||
end_addr_new = ltmp;
|
||||
}
|
||||
|
||||
if (flash_addr_new->flags != OBSOLETE_FLAG &&
|
||||
crc32(0, flash_addr_new->data, ENV_SIZE) ==
|
||||
flash_addr_new->crc) {
|
||||
char flag = OBSOLETE_FLAG;
|
||||
|
||||
gd->env_valid = 2;
|
||||
flash_sect_protect (0, (ulong)flash_addr_new, end_addr_new);
|
||||
flash_write(&flag,
|
||||
(ulong)&(flash_addr_new->flags),
|
||||
sizeof(flash_addr_new->flags));
|
||||
flash_sect_protect (1, (ulong)flash_addr_new, end_addr_new);
|
||||
}
|
||||
|
||||
if (flash_addr->flags != ACTIVE_FLAG &&
|
||||
(flash_addr->flags & ACTIVE_FLAG) == ACTIVE_FLAG) {
|
||||
char flag = ACTIVE_FLAG;
|
||||
|
||||
gd->env_valid = 2;
|
||||
flash_sect_protect (0, (ulong)flash_addr, end_addr);
|
||||
flash_write(&flag,
|
||||
(ulong)&(flash_addr->flags),
|
||||
sizeof(flash_addr->flags));
|
||||
flash_sect_protect (1, (ulong)flash_addr, end_addr);
|
||||
}
|
||||
|
||||
if (gd->env_valid == 2)
|
||||
puts ("*** Warning - some problems detected "
|
||||
"reading environment; recovered successfully\n\n");
|
||||
#endif /* CFG_ENV_ADDR_REDUND */
|
||||
memcpy (env_ptr, (void*)flash_addr, CFG_ENV_SIZE);
|
||||
#endif /* ! ENV_IS_EMBEDDED || CFG_ENV_ADDR_REDUND */
|
||||
}
|
||||
|
||||
#endif /* CFG_ENV_IS_IN_FLASH */
|
|
@ -1,305 +0,0 @@
|
|||
/*
|
||||
* (C) Copyright 2004
|
||||
* Jian Zhang, Texas Instruments, jzhang@ti.com.
|
||||
|
||||
* (C) Copyright 2000-2006
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/* #define DEBUG */
|
||||
|
||||
#include <common.h>
|
||||
|
||||
#if defined(CFG_ENV_IS_IN_NAND) /* Environment is in Nand Flash */
|
||||
|
||||
#include <command.h>
|
||||
#include <environment.h>
|
||||
#include <linux/stddef.h>
|
||||
#include <malloc.h>
|
||||
#include <nand.h>
|
||||
|
||||
#if ((CONFIG_COMMANDS&(CFG_CMD_ENV|CFG_CMD_NAND)) == (CFG_CMD_ENV|CFG_CMD_NAND))
|
||||
#define CMD_SAVEENV
|
||||
#elif defined(CFG_ENV_OFFSET_REDUND)
|
||||
#error Cannot use CFG_ENV_OFFSET_REDUND without CFG_CMD_ENV & CFG_CMD_NAND
|
||||
#endif
|
||||
|
||||
#if defined(CFG_ENV_SIZE_REDUND) && (CFG_ENV_SIZE_REDUND != CFG_ENV_SIZE)
|
||||
#error CFG_ENV_SIZE_REDUND should be the same as CFG_ENV_SIZE
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_INFERNO
|
||||
#error CONFIG_INFERNO not supported yet
|
||||
#endif
|
||||
|
||||
int nand_legacy_rw (struct nand_chip* nand, int cmd,
|
||||
size_t start, size_t len,
|
||||
size_t * retlen, u_char * buf);
|
||||
|
||||
/* info for NAND chips, defined in drivers/nand/nand.c */
|
||||
extern nand_info_t nand_info[];
|
||||
|
||||
/* references to names in env_common.c */
|
||||
extern uchar default_environment[];
|
||||
extern int default_environment_size;
|
||||
|
||||
char * env_name_spec = "NAND";
|
||||
|
||||
|
||||
#ifdef ENV_IS_EMBEDDED
|
||||
extern uchar environment[];
|
||||
env_t *env_ptr = (env_t *)(&environment[0]);
|
||||
#else /* ! ENV_IS_EMBEDDED */
|
||||
env_t *env_ptr = 0;
|
||||
#endif /* ENV_IS_EMBEDDED */
|
||||
|
||||
|
||||
/* local functions */
|
||||
#if !defined(ENV_IS_EMBEDDED)
|
||||
static void use_default(void);
|
||||
#endif
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
uchar env_get_char_spec (int index)
|
||||
{
|
||||
return ( *((uchar *)(gd->env_addr + index)) );
|
||||
}
|
||||
|
||||
|
||||
/* this is called before nand_init()
|
||||
* so we can't read Nand to validate env data.
|
||||
* Mark it OK for now. env_relocate() in env_common.c
|
||||
* will call our relocate function which will does
|
||||
* the real validation.
|
||||
*
|
||||
* When using a NAND boot image (like sequoia_nand), the environment
|
||||
* can be embedded or attached to the U-Boot image in NAND flash. This way
|
||||
* the SPL loads not only the U-Boot image from NAND but also the
|
||||
* environment.
|
||||
*/
|
||||
int env_init(void)
|
||||
{
|
||||
#if defined(ENV_IS_EMBEDDED)
|
||||
ulong total;
|
||||
int crc1_ok = 0, crc2_ok = 0;
|
||||
env_t *tmp_env1, *tmp_env2;
|
||||
|
||||
total = CFG_ENV_SIZE;
|
||||
|
||||
tmp_env1 = env_ptr;
|
||||
tmp_env2 = (env_t *)((ulong)env_ptr + CFG_ENV_SIZE);
|
||||
|
||||
crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
|
||||
crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
|
||||
|
||||
if (!crc1_ok && !crc2_ok)
|
||||
gd->env_valid = 0;
|
||||
else if(crc1_ok && !crc2_ok)
|
||||
gd->env_valid = 1;
|
||||
else if(!crc1_ok && crc2_ok)
|
||||
gd->env_valid = 2;
|
||||
else {
|
||||
/* both ok - check serial */
|
||||
if(tmp_env1->flags == 255 && tmp_env2->flags == 0)
|
||||
gd->env_valid = 2;
|
||||
else if(tmp_env2->flags == 255 && tmp_env1->flags == 0)
|
||||
gd->env_valid = 1;
|
||||
else if(tmp_env1->flags > tmp_env2->flags)
|
||||
gd->env_valid = 1;
|
||||
else if(tmp_env2->flags > tmp_env1->flags)
|
||||
gd->env_valid = 2;
|
||||
else /* flags are equal - almost impossible */
|
||||
gd->env_valid = 1;
|
||||
}
|
||||
|
||||
if (gd->env_valid == 1)
|
||||
env_ptr = tmp_env1;
|
||||
else if (gd->env_valid == 2)
|
||||
env_ptr = tmp_env2;
|
||||
#else /* ENV_IS_EMBEDDED */
|
||||
gd->env_addr = (ulong)&default_environment[0];
|
||||
gd->env_valid = 1;
|
||||
#endif /* ENV_IS_EMBEDDED */
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef CMD_SAVEENV
|
||||
/*
|
||||
* The legacy NAND code saved the environment in the first NAND device i.e.,
|
||||
* nand_dev_desc + 0. This is also the behaviour using the new NAND code.
|
||||
*/
|
||||
#ifdef CFG_ENV_OFFSET_REDUND
|
||||
int saveenv(void)
|
||||
{
|
||||
ulong total;
|
||||
int ret = 0;
|
||||
|
||||
env_ptr->flags++;
|
||||
total = CFG_ENV_SIZE;
|
||||
|
||||
if(gd->env_valid == 1) {
|
||||
puts ("Erasing redundant Nand...");
|
||||
if (nand_erase(&nand_info[0],
|
||||
CFG_ENV_OFFSET_REDUND, CFG_ENV_SIZE))
|
||||
return 1;
|
||||
puts ("Writing to redundant Nand... ");
|
||||
ret = nand_write(&nand_info[0], CFG_ENV_OFFSET_REDUND, &total,
|
||||
(u_char*) env_ptr);
|
||||
} else {
|
||||
puts ("Erasing Nand...");
|
||||
if (nand_erase(&nand_info[0],
|
||||
CFG_ENV_OFFSET, CFG_ENV_SIZE))
|
||||
return 1;
|
||||
|
||||
puts ("Writing to Nand... ");
|
||||
ret = nand_write(&nand_info[0], CFG_ENV_OFFSET, &total,
|
||||
(u_char*) env_ptr);
|
||||
}
|
||||
if (ret || total != CFG_ENV_SIZE)
|
||||
return 1;
|
||||
|
||||
puts ("done\n");
|
||||
gd->env_valid = (gd->env_valid == 2 ? 1 : 2);
|
||||
return ret;
|
||||
}
|
||||
#else /* ! CFG_ENV_OFFSET_REDUND */
|
||||
int saveenv(void)
|
||||
{
|
||||
ulong total;
|
||||
int ret = 0;
|
||||
|
||||
puts ("Erasing Nand...");
|
||||
if (nand_erase(&nand_info[0], CFG_ENV_OFFSET, CFG_ENV_SIZE))
|
||||
return 1;
|
||||
|
||||
puts ("Writing to Nand... ");
|
||||
total = CFG_ENV_SIZE;
|
||||
ret = nand_write(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr);
|
||||
if (ret || total != CFG_ENV_SIZE)
|
||||
return 1;
|
||||
|
||||
puts ("done\n");
|
||||
return ret;
|
||||
}
|
||||
#endif /* CFG_ENV_OFFSET_REDUND */
|
||||
#endif /* CMD_SAVEENV */
|
||||
|
||||
#ifdef CFG_ENV_OFFSET_REDUND
|
||||
void env_relocate_spec (void)
|
||||
{
|
||||
#if !defined(ENV_IS_EMBEDDED)
|
||||
ulong total;
|
||||
int crc1_ok = 0, crc2_ok = 0;
|
||||
env_t *tmp_env1, *tmp_env2;
|
||||
|
||||
total = CFG_ENV_SIZE;
|
||||
|
||||
tmp_env1 = (env_t *) malloc(CFG_ENV_SIZE);
|
||||
tmp_env2 = (env_t *) malloc(CFG_ENV_SIZE);
|
||||
|
||||
nand_read(&nand_info[0], CFG_ENV_OFFSET, &total,
|
||||
(u_char*) tmp_env1);
|
||||
nand_read(&nand_info[0], CFG_ENV_OFFSET_REDUND, &total,
|
||||
(u_char*) tmp_env2);
|
||||
|
||||
crc1_ok = (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc);
|
||||
crc2_ok = (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc);
|
||||
|
||||
if(!crc1_ok && !crc2_ok)
|
||||
return use_default();
|
||||
else if(crc1_ok && !crc2_ok)
|
||||
gd->env_valid = 1;
|
||||
else if(!crc1_ok && crc2_ok)
|
||||
gd->env_valid = 2;
|
||||
else {
|
||||
/* both ok - check serial */
|
||||
if(tmp_env1->flags == 255 && tmp_env2->flags == 0)
|
||||
gd->env_valid = 2;
|
||||
else if(tmp_env2->flags == 255 && tmp_env1->flags == 0)
|
||||
gd->env_valid = 1;
|
||||
else if(tmp_env1->flags > tmp_env2->flags)
|
||||
gd->env_valid = 1;
|
||||
else if(tmp_env2->flags > tmp_env1->flags)
|
||||
gd->env_valid = 2;
|
||||
else /* flags are equal - almost impossible */
|
||||
gd->env_valid = 1;
|
||||
|
||||
}
|
||||
|
||||
free(env_ptr);
|
||||
if(gd->env_valid == 1) {
|
||||
env_ptr = tmp_env1;
|
||||
free(tmp_env2);
|
||||
} else {
|
||||
env_ptr = tmp_env2;
|
||||
free(tmp_env1);
|
||||
}
|
||||
|
||||
#endif /* ! ENV_IS_EMBEDDED */
|
||||
}
|
||||
#else /* ! CFG_ENV_OFFSET_REDUND */
|
||||
/*
|
||||
* The legacy NAND code saved the environment in the first NAND device i.e.,
|
||||
* nand_dev_desc + 0. This is also the behaviour using the new NAND code.
|
||||
*/
|
||||
void env_relocate_spec (void)
|
||||
{
|
||||
#if !defined(ENV_IS_EMBEDDED)
|
||||
ulong total;
|
||||
int ret;
|
||||
|
||||
total = CFG_ENV_SIZE;
|
||||
ret = nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr);
|
||||
if (ret || total != CFG_ENV_SIZE)
|
||||
return use_default();
|
||||
|
||||
if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
|
||||
return use_default();
|
||||
#endif /* ! ENV_IS_EMBEDDED */
|
||||
}
|
||||
#endif /* CFG_ENV_OFFSET_REDUND */
|
||||
|
||||
#if !defined(ENV_IS_EMBEDDED)
|
||||
static void use_default()
|
||||
{
|
||||
puts ("*** Warning - bad CRC or NAND, using default environment\n\n");
|
||||
|
||||
if (default_environment_size > CFG_ENV_SIZE){
|
||||
puts ("*** Error - default environment is too large\n\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset (env_ptr, 0, sizeof(env_t));
|
||||
memcpy (env_ptr->data,
|
||||
default_environment,
|
||||
default_environment_size);
|
||||
env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
|
||||
gd->env_valid = 1;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CFG_ENV_IS_IN_NAND */
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* (C) Copyright 2000-2002
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
|
||||
#if defined(CFG_ENV_IS_NOWHERE) /* Environment is nowhere */
|
||||
|
||||
#include <command.h>
|
||||
#include <environment.h>
|
||||
#include <linux/stddef.h>
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
env_t *env_ptr = NULL;
|
||||
|
||||
extern uchar default_environment[];
|
||||
extern int default_environment_size;
|
||||
|
||||
|
||||
void env_relocate_spec (void)
|
||||
{
|
||||
}
|
||||
|
||||
uchar env_get_char_spec (int index)
|
||||
{
|
||||
return ( *((uchar *)(gd->env_addr + index)) );
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Initialize Environment use
|
||||
*
|
||||
* We are still running from ROM, so data use is limited
|
||||
*/
|
||||
int env_init(void)
|
||||
{
|
||||
gd->env_addr = (ulong)&default_environment[0];
|
||||
gd->env_valid = 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif /* CFG_ENV_IS_NOWHERE) */
|
|
@ -1,163 +0,0 @@
|
|||
/*
|
||||
* (C) Copyright 2000-2002
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/*
|
||||
* 09-18-2001 Andreas Heppel, Sysgo RTS GmbH <aheppel@sysgo.de>
|
||||
*
|
||||
* It might not be possible in all cases to use 'memcpy()' to copy
|
||||
* the environment to NVRAM, as the NVRAM might not be mapped into
|
||||
* the memory space. (I.e. this is the case for the BAB750). In those
|
||||
* cases it might be possible to access the NVRAM using a different
|
||||
* method. For example, the RTC on the BAB750 is accessible in IO
|
||||
* space using its address and data registers. To enable usage of
|
||||
* NVRAM in those cases I invented the functions 'nvram_read()' and
|
||||
* 'nvram_write()', which will be activated upon the configuration
|
||||
* #define CFG_NVRAM_ACCESS_ROUTINE. Note, that those functions are
|
||||
* strongly dependent on the used HW, and must be redefined for each
|
||||
* board that wants to use them.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
#ifdef CFG_ENV_IS_IN_NVRAM /* Environment is in NVRAM */
|
||||
|
||||
#include <command.h>
|
||||
#include <environment.h>
|
||||
#include <linux/stddef.h>
|
||||
|
||||
#ifdef CFG_NVRAM_ACCESS_ROUTINE
|
||||
extern void *nvram_read(void *dest, const long src, size_t count);
|
||||
extern void nvram_write(long dest, const void *src, size_t count);
|
||||
env_t *env_ptr = NULL;
|
||||
#else
|
||||
env_t *env_ptr = (env_t *)CFG_ENV_ADDR;
|
||||
#endif
|
||||
|
||||
char * env_name_spec = "NVRAM";
|
||||
|
||||
extern uchar default_environment[];
|
||||
extern int default_environment_size;
|
||||
|
||||
extern uchar (*env_get_char)(int);
|
||||
extern uchar env_get_char_memory (int index);
|
||||
|
||||
#ifdef CONFIG_AMIGAONEG3SE
|
||||
uchar env_get_char_spec (int index)
|
||||
{
|
||||
#ifdef CFG_NVRAM_ACCESS_ROUTINE
|
||||
uchar c;
|
||||
|
||||
nvram_read(&c, CFG_ENV_ADDR+index, 1);
|
||||
|
||||
return c;
|
||||
#else
|
||||
uchar retval;
|
||||
enable_nvram();
|
||||
retval = *((uchar *)(gd->env_addr + index));
|
||||
disable_nvram();
|
||||
return retval;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
uchar env_get_char_spec (int index)
|
||||
{
|
||||
#ifdef CFG_NVRAM_ACCESS_ROUTINE
|
||||
uchar c;
|
||||
|
||||
nvram_read(&c, CFG_ENV_ADDR+index, 1);
|
||||
|
||||
return c;
|
||||
#else
|
||||
return *((uchar *)(gd->env_addr + index));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void env_relocate_spec (void)
|
||||
{
|
||||
#if defined(CFG_NVRAM_ACCESS_ROUTINE)
|
||||
nvram_read(env_ptr, CFG_ENV_ADDR, CFG_ENV_SIZE);
|
||||
#else
|
||||
memcpy (env_ptr, (void*)CFG_ENV_ADDR, CFG_ENV_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
int saveenv (void)
|
||||
{
|
||||
int rcode = 0;
|
||||
#ifdef CONFIG_AMIGAONEG3SE
|
||||
enable_nvram();
|
||||
#endif
|
||||
#ifdef CFG_NVRAM_ACCESS_ROUTINE
|
||||
nvram_write(CFG_ENV_ADDR, env_ptr, CFG_ENV_SIZE);
|
||||
#else
|
||||
if (memcpy ((char *)CFG_ENV_ADDR, env_ptr, CFG_ENV_SIZE) == NULL)
|
||||
rcode = 1 ;
|
||||
#endif
|
||||
#ifdef CONFIG_AMIGAONEG3SE
|
||||
udelay(10000);
|
||||
disable_nvram();
|
||||
#endif
|
||||
return rcode;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Initialize Environment use
|
||||
*
|
||||
* We are still running from ROM, so data use is limited
|
||||
*/
|
||||
int env_init (void)
|
||||
{
|
||||
#ifdef CONFIG_AMIGAONEG3SE
|
||||
enable_nvram();
|
||||
#endif
|
||||
#if defined(CFG_NVRAM_ACCESS_ROUTINE)
|
||||
ulong crc;
|
||||
uchar data[ENV_SIZE];
|
||||
nvram_read (&crc, CFG_ENV_ADDR, sizeof(ulong));
|
||||
nvram_read (data, CFG_ENV_ADDR+sizeof(ulong), ENV_SIZE);
|
||||
|
||||
if (crc32(0, data, ENV_SIZE) == crc) {
|
||||
gd->env_addr = (ulong)CFG_ENV_ADDR + sizeof(long);
|
||||
#else
|
||||
if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
|
||||
gd->env_addr = (ulong)&(env_ptr->data);
|
||||
#endif
|
||||
gd->env_valid = 1;
|
||||
} else {
|
||||
gd->env_addr = (ulong)&default_environment[0];
|
||||
gd->env_valid = 0;
|
||||
}
|
||||
#ifdef CONFIG_AMIGAONEG3SE
|
||||
disable_nvram();
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif /* CFG_ENV_IS_IN_NVRAM */
|
|
@ -1,211 +0,0 @@
|
|||
/*
|
||||
* (C) Copyright 2001
|
||||
* Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
|
||||
*
|
||||
* See file CREDITS for list of people who contributed to this
|
||||
* project.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
#define __ASSEMBLY__ /* Dirty trick to get only #defines */
|
||||
#endif
|
||||
#define __ASM_STUB_PROCESSOR_H__ /* don't include asm/processor. */
|
||||
#include <config.h>
|
||||
#undef __ASSEMBLY__
|
||||
#include <environment.h>
|
||||
|
||||
/*
|
||||
* Handle HOSTS that have prepended
|
||||
* crap on symbol names, not TARGETS.
|
||||
*/
|
||||
#if defined(__APPLE__)
|
||||
/* Leading underscore on symbols */
|
||||
# define SYM_CHAR "_"
|
||||
#else /* No leading character on symbols */
|
||||
# define SYM_CHAR
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Generate embedded environment table
|
||||
* inside U-Boot image, if needed.
|
||||
*/
|
||||
#if defined(ENV_IS_EMBEDDED)
|
||||
/*
|
||||
* Only put the environment in it's own section when we are building
|
||||
* U-Boot proper. The host based program "tools/envcrc" does not need
|
||||
* a seperate section. Note that ENV_CRC is only defined when building
|
||||
* U-Boot itself.
|
||||
*/
|
||||
#if (defined(CONFIG_CMI) || \
|
||||
defined(CONFIG_FADS) || \
|
||||
defined(CONFIG_HYMOD) || \
|
||||
defined(CONFIG_ICU862) || \
|
||||
defined(CONFIG_R360MPI) || \
|
||||
defined(CONFIG_TQM8xxL) || \
|
||||
defined(CONFIG_RRVISION) || \
|
||||
defined(CONFIG_TRAB) || \
|
||||
defined(CONFIG_PPCHAMELEONEVB) || \
|
||||
defined(CONFIG_M5271EVB) || \
|
||||
defined(CONFIG_IDMR) || \
|
||||
defined(CONFIG_NAND_U_BOOT)) && \
|
||||
defined(ENV_CRC) /* Environment embedded in U-Boot .ppcenv section */
|
||||
/* XXX - This only works with GNU C */
|
||||
# define __PPCENV__ __attribute__ ((section(".ppcenv")))
|
||||
# define __PPCTEXT__ __attribute__ ((section(".text")))
|
||||
|
||||
#elif defined(USE_HOSTCC) /* Native for 'tools/envcrc' */
|
||||
# define __PPCENV__ /*XXX DO_NOT_DEL_THIS_COMMENT*/
|
||||
# define __PPCTEXT__ /*XXX DO_NOT_DEL_THIS_COMMENT*/
|
||||
|
||||
#else /* Environment is embedded in U-Boot's .text section */
|
||||
/* XXX - This only works with GNU C */
|
||||
# define __PPCENV__ __attribute__ ((section(".text")))
|
||||
# define __PPCTEXT__ __attribute__ ((section(".text")))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macros to generate global absolutes.
|
||||
*/
|
||||
#define GEN_SYMNAME(str) SYM_CHAR #str
|
||||
#define GEN_VALUE(str) #str
|
||||
#define GEN_ABS(name, value) \
|
||||
asm (".globl " GEN_SYMNAME(name)); \
|
||||
asm (GEN_SYMNAME(name) " = " GEN_VALUE(value))
|
||||
|
||||
/*
|
||||
* Macros to transform values
|
||||
* into environment strings.
|
||||
*/
|
||||
#define XMK_STR(x) #x
|
||||
#define MK_STR(x) XMK_STR(x)
|
||||
|
||||
/*
|
||||
* Check to see if we are building with a
|
||||
* computed CRC. Otherwise define it as ~0.
|
||||
*/
|
||||
#if !defined(ENV_CRC)
|
||||
# define ENV_CRC ~0
|
||||
#endif
|
||||
|
||||
env_t environment __PPCENV__ = {
|
||||
ENV_CRC, /* CRC Sum */
|
||||
#ifdef CFG_REDUNDAND_ENVIRONMENT
|
||||
1, /* Flags: valid */
|
||||
#endif
|
||||
{
|
||||
#if defined(CONFIG_BOOTARGS)
|
||||
"bootargs=" CONFIG_BOOTARGS "\0"
|
||||
#endif
|
||||
#if defined(CONFIG_BOOTCOMMAND)
|
||||
"bootcmd=" CONFIG_BOOTCOMMAND "\0"
|
||||
#endif
|
||||
#if defined(CONFIG_RAMBOOTCOMMAND)
|
||||
"ramboot=" CONFIG_RAMBOOTCOMMAND "\0"
|
||||
#endif
|
||||
#if defined(CONFIG_NFSBOOTCOMMAND)
|
||||
"nfsboot=" CONFIG_NFSBOOTCOMMAND "\0"
|
||||
#endif
|
||||
#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
|
||||
"bootdelay=" MK_STR(CONFIG_BOOTDELAY) "\0"
|
||||
#endif
|
||||
#if defined(CONFIG_BAUDRATE) && (CONFIG_BAUDRATE >= 0)
|
||||
"baudrate=" MK_STR(CONFIG_BAUDRATE) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_LOADS_ECHO
|
||||
"loads_echo=" MK_STR(CONFIG_LOADS_ECHO) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ETHADDR
|
||||
"ethaddr=" MK_STR(CONFIG_ETHADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ETH1ADDR
|
||||
"eth1addr=" MK_STR(CONFIG_ETH1ADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ETH2ADDR
|
||||
"eth2addr=" MK_STR(CONFIG_ETH2ADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ETH3ADDR
|
||||
"eth3addr=" MK_STR(CONFIG_ETH3ADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ETHPRIME
|
||||
"ethprime=" CONFIG_ETHPRIME "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_IPADDR
|
||||
"ipaddr=" MK_STR(CONFIG_IPADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_SERVERIP
|
||||
"serverip=" MK_STR(CONFIG_SERVERIP) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_ROOTPATH
|
||||
"rootpath=" MK_STR(CONFIG_ROOTPATH) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_GATEWAYIP
|
||||
"gatewayip=" MK_STR(CONFIG_GATEWAYIP) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_NETMASK
|
||||
"netmask=" MK_STR(CONFIG_NETMASK) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_HOSTNAME
|
||||
"hostname=" MK_STR(CONFIG_HOSTNAME) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_BOOTFILE
|
||||
"bootfile=" MK_STR(CONFIG_BOOTFILE) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_LOADADDR
|
||||
"loadaddr=" MK_STR(CONFIG_LOADADDR) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_PREBOOT
|
||||
"preboot=" CONFIG_PREBOOT "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_CLOCKS_IN_MHZ
|
||||
"clocks_in_mhz=" "1" "\0"
|
||||
#endif
|
||||
#if defined(CONFIG_PCI_BOOTDELAY) && (CONFIG_PCI_BOOTDELAY > 0)
|
||||
"pcidelay=" MK_STR(CONFIG_PCI_BOOTDELAY) "\0"
|
||||
#endif
|
||||
#ifdef CONFIG_EXTRA_ENV_SETTINGS
|
||||
CONFIG_EXTRA_ENV_SETTINGS
|
||||
#endif
|
||||
"\0" /* Term. env_t.data with 2 NULs */
|
||||
}
|
||||
};
|
||||
#ifdef CFG_ENV_ADDR_REDUND
|
||||
env_t redundand_environment __PPCENV__ = {
|
||||
0, /* CRC Sum: invalid */
|
||||
0, /* Flags: invalid */
|
||||
{
|
||||
"\0"
|
||||
}
|
||||
};
|
||||
#endif /* CFG_ENV_ADDR_REDUND */
|
||||
|
||||
/*
|
||||
* These will end up in the .text section
|
||||
* if the environment strings are embedded
|
||||
* in the image. When this is used for
|
||||
* tools/envcrc, they are placed in the
|
||||
* .data/.sdata section.
|
||||
*
|
||||
*/
|
||||
unsigned long env_size __PPCTEXT__ = sizeof(env_t);
|
||||
|
||||
/*
|
||||
* Add in absolutes.
|
||||
*/
|
||||
GEN_ABS(env_offset, CFG_ENV_OFFSET);
|
||||
|
||||
#endif /* ENV_IS_EMBEDDED */
|
Loading…
Reference in New Issue