2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-05-16 09:10:35 +00:00
|
|
|
/*
|
New implementation for internal handling of environment variables.
Motivation:
* Old environment code used a pessimizing implementation:
- variable lookup used linear search => slow
- changed/added variables were added at the end, i. e. most
frequently used variables had the slowest access times => slow
- each setenv() would calculate the CRC32 checksum over the whole
environment block => slow
* "redundant" envrionment was locked down to two copies
* No easy way to implement features like "reset to factory defaults",
or to select one out of several pre-defined (previously saved) sets
of environment settings ("profiles")
* No easy way to import or export environment settings
======================================================================
API Changes:
- Variable names starting with '#' are no longer allowed
I didn't find any such variable names being used; it is highly
recommended to follow standard conventions and start variable names
with an alphanumeric character
- "printenv" will now print a backslash at the end of all but the last
lines of a multi-line variable value.
Multi-line variables have never been formally defined, allthough
there is no reason not to use them. Now we define rules how to deal
with them, allowing for import and export.
- Function forceenv() and the related code in saveenv() was removed.
At the moment this is causing build problems for the only user of
this code (schmoogie - which has no entry in MAINTAINERS); may be
fixed later by implementing the "env set -f" feature.
Inconsistencies:
- "printenv" will '\\'-escape the '\n' in multi-line variables, while
"printenv var" will not do that.
======================================================================
Advantages:
- "printenv" output much better readable (sorted)
- faster!
- extendable (additional variable properties can be added)
- new, powerful features like "factory reset" or easy switching
between several different environment settings ("profiles")
Disadvantages:
- Image size grows by typically 5...7 KiB (might shrink a bit again on
systems with redundant environment with a following patch series)
======================================================================
Implemented:
- env command with subcommands:
- env print [arg ...]
same as "printenv": print environment
- env set [-f] name [arg ...]
same as "setenv": set (and delete) environment variables
["-f" - force setting even for read-only variables - not
implemented yet.]
- end delete [-f] name
not implemented yet
["-f" - force delete even for read-only variables]
- env save
same as "saveenv": save environment
- env export [-t | -b | -c] addr [size]
export internal representation (hash table) in formats usable for
persistent storage or processing:
-t: export as text format; if size is given, data will be
padded with '\0' bytes; if not, one terminating '\0'
will be added (which is included in the "filesize"
setting so you can for exmple copy this to flash and
keep the termination).
-b: export as binary format (name=value pairs separated by
'\0', list end marked by double "\0\0")
-c: export as checksum protected environment format as
used for example by "saveenv" command
addr: memory address where environment gets stored
size: size of output buffer
With "-c" and size is NOT given, then the export command will
format the data as currently used for the persistent storage,
i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
prepend a valid CRC32 checksum and, in case of resundant
environment, a "current" redundancy flag. If size is given, this
value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
checksum and redundancy flag will be inserted.
With "-b" and "-t", always only the real data (including a
terminating '\0' byte) will be written; here the optional size
argument will be used to make sure not to overflow the user
provided buffer; the command will abort if the size is not
sufficient. Any remainign space will be '\0' padded.
On successful return, the variable "filesize" will be set.
Note that filesize includes the trailing/terminating '\0'
byte(s).
Usage szenario: create a text snapshot/backup of the current
settings:
=> env export -t 100000
=> era ${backup_addr} +${filesize}
=> cp.b 100000 ${backup_addr} ${filesize}
Re-import this snapshot, deleting all other settings:
=> env import -d -t ${backup_addr}
- env import [-d] [-t | -b | -c] addr [size]
import external format (text or binary) into hash table,
optionally deleting existing values:
-d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
-t: assume text format; either "size" must be given or the
text data must be '\0' terminated
-b: assume binary format ('\0' separated, "\0\0" terminated)
-c: assume checksum protected environment format
addr: memory address to read from
size: length of input data; if missing, proper '\0'
termination is mandatory
- env default -f
reset default environment: drop all environment settings and load
default environment
- env ask name [message] [size]
same as "askenv": ask for environment variable
- env edit name
same as "editenv": edit environment variable
- env run
same as "run": run commands in an environment variable
======================================================================
TODO:
- drop default env as implemented now; provide a text file based
initialization instead (eventually using several text files to
incrementally build it from common blocks) and a tool to convert it
into a binary blob / object file.
- It would be nice if we could add wildcard support for environment
variables; this is needed for variable name auto-completion,
but it would also be nice to be able to say "printenv ip*" or
"printenv *addr*"
- Some boards don't link any more due to the grown code size:
DU405, canyonlands, sequoia, socrates.
=> cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Stefan Roese <sr@denx.de>,
Heiko Schocher <hs@denx.de>
- Dropping forceenv() causes build problems on schmoogie
=> cc: Sergey Kubushyn <ksi@koi8.net>
- Build tested on PPC and ARM only; runtime tested with NOR and NAND
flash only => needs testing!!
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Cc: Stefan Roese <sr@denx.de>,
Cc: Heiko Schocher <hs@denx.de>
Cc: Sergey Kubushyn <ksi@koi8.net>
2010-06-20 21:33:59 +00:00
|
|
|
* (C) Copyright 2000-2010
|
2008-05-16 09:10:35 +00:00
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Andreas Heppel <aheppel@sysgo.de>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2008 Atmel Corporation
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2017-05-17 23:18:03 +00:00
|
|
|
#include <dm.h>
|
2008-05-16 09:10:35 +00:00
|
|
|
#include <environment.h>
|
2008-12-11 11:23:37 +00:00
|
|
|
#include <malloc.h>
|
2014-10-14 05:41:55 +00:00
|
|
|
#include <spi.h>
|
2008-05-16 09:10:35 +00:00
|
|
|
#include <spi_flash.h>
|
New implementation for internal handling of environment variables.
Motivation:
* Old environment code used a pessimizing implementation:
- variable lookup used linear search => slow
- changed/added variables were added at the end, i. e. most
frequently used variables had the slowest access times => slow
- each setenv() would calculate the CRC32 checksum over the whole
environment block => slow
* "redundant" envrionment was locked down to two copies
* No easy way to implement features like "reset to factory defaults",
or to select one out of several pre-defined (previously saved) sets
of environment settings ("profiles")
* No easy way to import or export environment settings
======================================================================
API Changes:
- Variable names starting with '#' are no longer allowed
I didn't find any such variable names being used; it is highly
recommended to follow standard conventions and start variable names
with an alphanumeric character
- "printenv" will now print a backslash at the end of all but the last
lines of a multi-line variable value.
Multi-line variables have never been formally defined, allthough
there is no reason not to use them. Now we define rules how to deal
with them, allowing for import and export.
- Function forceenv() and the related code in saveenv() was removed.
At the moment this is causing build problems for the only user of
this code (schmoogie - which has no entry in MAINTAINERS); may be
fixed later by implementing the "env set -f" feature.
Inconsistencies:
- "printenv" will '\\'-escape the '\n' in multi-line variables, while
"printenv var" will not do that.
======================================================================
Advantages:
- "printenv" output much better readable (sorted)
- faster!
- extendable (additional variable properties can be added)
- new, powerful features like "factory reset" or easy switching
between several different environment settings ("profiles")
Disadvantages:
- Image size grows by typically 5...7 KiB (might shrink a bit again on
systems with redundant environment with a following patch series)
======================================================================
Implemented:
- env command with subcommands:
- env print [arg ...]
same as "printenv": print environment
- env set [-f] name [arg ...]
same as "setenv": set (and delete) environment variables
["-f" - force setting even for read-only variables - not
implemented yet.]
- end delete [-f] name
not implemented yet
["-f" - force delete even for read-only variables]
- env save
same as "saveenv": save environment
- env export [-t | -b | -c] addr [size]
export internal representation (hash table) in formats usable for
persistent storage or processing:
-t: export as text format; if size is given, data will be
padded with '\0' bytes; if not, one terminating '\0'
will be added (which is included in the "filesize"
setting so you can for exmple copy this to flash and
keep the termination).
-b: export as binary format (name=value pairs separated by
'\0', list end marked by double "\0\0")
-c: export as checksum protected environment format as
used for example by "saveenv" command
addr: memory address where environment gets stored
size: size of output buffer
With "-c" and size is NOT given, then the export command will
format the data as currently used for the persistent storage,
i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
prepend a valid CRC32 checksum and, in case of resundant
environment, a "current" redundancy flag. If size is given, this
value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
checksum and redundancy flag will be inserted.
With "-b" and "-t", always only the real data (including a
terminating '\0' byte) will be written; here the optional size
argument will be used to make sure not to overflow the user
provided buffer; the command will abort if the size is not
sufficient. Any remainign space will be '\0' padded.
On successful return, the variable "filesize" will be set.
Note that filesize includes the trailing/terminating '\0'
byte(s).
Usage szenario: create a text snapshot/backup of the current
settings:
=> env export -t 100000
=> era ${backup_addr} +${filesize}
=> cp.b 100000 ${backup_addr} ${filesize}
Re-import this snapshot, deleting all other settings:
=> env import -d -t ${backup_addr}
- env import [-d] [-t | -b | -c] addr [size]
import external format (text or binary) into hash table,
optionally deleting existing values:
-d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
-t: assume text format; either "size" must be given or the
text data must be '\0' terminated
-b: assume binary format ('\0' separated, "\0\0" terminated)
-c: assume checksum protected environment format
addr: memory address to read from
size: length of input data; if missing, proper '\0'
termination is mandatory
- env default -f
reset default environment: drop all environment settings and load
default environment
- env ask name [message] [size]
same as "askenv": ask for environment variable
- env edit name
same as "editenv": edit environment variable
- env run
same as "run": run commands in an environment variable
======================================================================
TODO:
- drop default env as implemented now; provide a text file based
initialization instead (eventually using several text files to
incrementally build it from common blocks) and a tool to convert it
into a binary blob / object file.
- It would be nice if we could add wildcard support for environment
variables; this is needed for variable name auto-completion,
but it would also be nice to be able to say "printenv ip*" or
"printenv *addr*"
- Some boards don't link any more due to the grown code size:
DU405, canyonlands, sequoia, socrates.
=> cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Stefan Roese <sr@denx.de>,
Heiko Schocher <hs@denx.de>
- Dropping forceenv() causes build problems on schmoogie
=> cc: Sergey Kubushyn <ksi@koi8.net>
- Build tested on PPC and ARM only; runtime tested with NOR and NAND
flash only => needs testing!!
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Cc: Stefan Roese <sr@denx.de>,
Cc: Heiko Schocher <hs@denx.de>
Cc: Sergey Kubushyn <ksi@koi8.net>
2010-06-20 21:33:59 +00:00
|
|
|
#include <search.h>
|
|
|
|
#include <errno.h>
|
2016-01-26 07:06:42 +00:00
|
|
|
#include <dm/device-internal.h>
|
2008-05-16 09:10:35 +00:00
|
|
|
|
2008-09-10 20:48:06 +00:00
|
|
|
#ifndef CONFIG_ENV_SPI_BUS
|
2017-02-01 13:51:47 +00:00
|
|
|
# define CONFIG_ENV_SPI_BUS CONFIG_SF_DEFAULT_BUS
|
2008-05-16 09:10:35 +00:00
|
|
|
#endif
|
2008-09-10 20:48:06 +00:00
|
|
|
#ifndef CONFIG_ENV_SPI_CS
|
2017-02-01 13:51:47 +00:00
|
|
|
# define CONFIG_ENV_SPI_CS CONFIG_SF_DEFAULT_CS
|
2008-05-16 09:10:35 +00:00
|
|
|
#endif
|
2008-09-10 20:48:06 +00:00
|
|
|
#ifndef CONFIG_ENV_SPI_MAX_HZ
|
2017-02-01 13:51:47 +00:00
|
|
|
# define CONFIG_ENV_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED
|
2008-05-16 09:10:35 +00:00
|
|
|
#endif
|
2008-09-10 20:48:06 +00:00
|
|
|
#ifndef CONFIG_ENV_SPI_MODE
|
2017-02-01 13:51:47 +00:00
|
|
|
# define CONFIG_ENV_SPI_MODE CONFIG_SF_DEFAULT_MODE
|
2008-05-16 09:10:35 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-03 18:21:58 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
|
|
|
#define CMD_SAVEENV
|
2017-12-14 12:07:08 +00:00
|
|
|
#define INITENV
|
2017-08-03 18:21:58 +00:00
|
|
|
#endif
|
|
|
|
|
2010-04-23 15:22:55 +00:00
|
|
|
#ifdef CONFIG_ENV_OFFSET_REDUND
|
2017-08-03 18:21:58 +00:00
|
|
|
#ifdef CMD_SAVEENV
|
2011-11-07 01:14:08 +00:00
|
|
|
static ulong env_offset = CONFIG_ENV_OFFSET;
|
|
|
|
static ulong env_new_offset = CONFIG_ENV_OFFSET_REDUND;
|
2017-08-03 18:21:58 +00:00
|
|
|
#endif
|
2010-04-23 15:22:55 +00:00
|
|
|
|
2011-11-07 01:14:08 +00:00
|
|
|
#define ACTIVE_FLAG 1
|
|
|
|
#define OBSOLETE_FLAG 0
|
2010-10-27 09:06:20 +00:00
|
|
|
#endif /* CONFIG_ENV_OFFSET_REDUND */
|
2010-04-23 15:22:55 +00:00
|
|
|
|
2008-05-16 09:10:35 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
static struct spi_flash *env_flash;
|
|
|
|
|
2017-04-08 09:59:31 +00:00
|
|
|
static int setup_flash_device(void)
|
2010-04-23 15:22:55 +00:00
|
|
|
{
|
2016-01-26 07:06:42 +00:00
|
|
|
#ifdef CONFIG_DM_SPI_FLASH
|
|
|
|
struct udevice *new;
|
2017-04-08 09:59:31 +00:00
|
|
|
int ret;
|
2016-01-26 07:06:42 +00:00
|
|
|
|
2016-07-06 04:34:28 +00:00
|
|
|
/* speed and mode will be read from DT */
|
2016-01-26 07:06:42 +00:00
|
|
|
ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
|
2018-08-29 13:34:52 +00:00
|
|
|
CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE,
|
|
|
|
&new);
|
2016-01-26 07:06:42 +00:00
|
|
|
if (ret) {
|
2018-06-24 16:16:57 +00:00
|
|
|
set_default_env("spi_flash_probe_bus_cs() failed", 0);
|
2017-08-03 18:22:17 +00:00
|
|
|
return ret;
|
2016-01-26 07:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
env_flash = dev_get_uclass_priv(new);
|
|
|
|
#else
|
2010-04-23 15:22:55 +00:00
|
|
|
|
|
|
|
if (!env_flash) {
|
2010-10-27 09:06:20 +00:00
|
|
|
env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS,
|
|
|
|
CONFIG_ENV_SPI_CS,
|
|
|
|
CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
|
|
|
|
if (!env_flash) {
|
2018-06-24 16:16:57 +00:00
|
|
|
set_default_env("spi_flash_probe() failed", 0);
|
2017-08-03 18:22:17 +00:00
|
|
|
return -EIO;
|
2010-10-27 09:06:20 +00:00
|
|
|
}
|
2010-04-23 15:22:55 +00:00
|
|
|
}
|
2016-01-26 07:06:42 +00:00
|
|
|
#endif
|
2017-04-08 09:59:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_ENV_OFFSET_REDUND)
|
2017-08-03 18:21:58 +00:00
|
|
|
#ifdef CMD_SAVEENV
|
2017-08-03 18:22:01 +00:00
|
|
|
static int env_sf_save(void)
|
2017-04-08 09:59:31 +00:00
|
|
|
{
|
|
|
|
env_t env_new;
|
|
|
|
char *saved_buffer = NULL, flag = OBSOLETE_FLAG;
|
2017-04-08 09:59:34 +00:00
|
|
|
u32 saved_size, saved_offset, sector;
|
2017-04-08 09:59:31 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = setup_flash_device();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-04-23 15:22:55 +00:00
|
|
|
|
2014-03-05 18:59:50 +00:00
|
|
|
ret = env_export(&env_new);
|
|
|
|
if (ret)
|
2017-08-03 18:22:17 +00:00
|
|
|
return -EIO;
|
2013-04-05 18:55:21 +00:00
|
|
|
env_new.flags = ACTIVE_FLAG;
|
New implementation for internal handling of environment variables.
Motivation:
* Old environment code used a pessimizing implementation:
- variable lookup used linear search => slow
- changed/added variables were added at the end, i. e. most
frequently used variables had the slowest access times => slow
- each setenv() would calculate the CRC32 checksum over the whole
environment block => slow
* "redundant" envrionment was locked down to two copies
* No easy way to implement features like "reset to factory defaults",
or to select one out of several pre-defined (previously saved) sets
of environment settings ("profiles")
* No easy way to import or export environment settings
======================================================================
API Changes:
- Variable names starting with '#' are no longer allowed
I didn't find any such variable names being used; it is highly
recommended to follow standard conventions and start variable names
with an alphanumeric character
- "printenv" will now print a backslash at the end of all but the last
lines of a multi-line variable value.
Multi-line variables have never been formally defined, allthough
there is no reason not to use them. Now we define rules how to deal
with them, allowing for import and export.
- Function forceenv() and the related code in saveenv() was removed.
At the moment this is causing build problems for the only user of
this code (schmoogie - which has no entry in MAINTAINERS); may be
fixed later by implementing the "env set -f" feature.
Inconsistencies:
- "printenv" will '\\'-escape the '\n' in multi-line variables, while
"printenv var" will not do that.
======================================================================
Advantages:
- "printenv" output much better readable (sorted)
- faster!
- extendable (additional variable properties can be added)
- new, powerful features like "factory reset" or easy switching
between several different environment settings ("profiles")
Disadvantages:
- Image size grows by typically 5...7 KiB (might shrink a bit again on
systems with redundant environment with a following patch series)
======================================================================
Implemented:
- env command with subcommands:
- env print [arg ...]
same as "printenv": print environment
- env set [-f] name [arg ...]
same as "setenv": set (and delete) environment variables
["-f" - force setting even for read-only variables - not
implemented yet.]
- end delete [-f] name
not implemented yet
["-f" - force delete even for read-only variables]
- env save
same as "saveenv": save environment
- env export [-t | -b | -c] addr [size]
export internal representation (hash table) in formats usable for
persistent storage or processing:
-t: export as text format; if size is given, data will be
padded with '\0' bytes; if not, one terminating '\0'
will be added (which is included in the "filesize"
setting so you can for exmple copy this to flash and
keep the termination).
-b: export as binary format (name=value pairs separated by
'\0', list end marked by double "\0\0")
-c: export as checksum protected environment format as
used for example by "saveenv" command
addr: memory address where environment gets stored
size: size of output buffer
With "-c" and size is NOT given, then the export command will
format the data as currently used for the persistent storage,
i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
prepend a valid CRC32 checksum and, in case of resundant
environment, a "current" redundancy flag. If size is given, this
value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
checksum and redundancy flag will be inserted.
With "-b" and "-t", always only the real data (including a
terminating '\0' byte) will be written; here the optional size
argument will be used to make sure not to overflow the user
provided buffer; the command will abort if the size is not
sufficient. Any remainign space will be '\0' padded.
On successful return, the variable "filesize" will be set.
Note that filesize includes the trailing/terminating '\0'
byte(s).
Usage szenario: create a text snapshot/backup of the current
settings:
=> env export -t 100000
=> era ${backup_addr} +${filesize}
=> cp.b 100000 ${backup_addr} ${filesize}
Re-import this snapshot, deleting all other settings:
=> env import -d -t ${backup_addr}
- env import [-d] [-t | -b | -c] addr [size]
import external format (text or binary) into hash table,
optionally deleting existing values:
-d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
-t: assume text format; either "size" must be given or the
text data must be '\0' terminated
-b: assume binary format ('\0' separated, "\0\0" terminated)
-c: assume checksum protected environment format
addr: memory address to read from
size: length of input data; if missing, proper '\0'
termination is mandatory
- env default -f
reset default environment: drop all environment settings and load
default environment
- env ask name [message] [size]
same as "askenv": ask for environment variable
- env edit name
same as "editenv": edit environment variable
- env run
same as "run": run commands in an environment variable
======================================================================
TODO:
- drop default env as implemented now; provide a text file based
initialization instead (eventually using several text files to
incrementally build it from common blocks) and a tool to convert it
into a binary blob / object file.
- It would be nice if we could add wildcard support for environment
variables; this is needed for variable name auto-completion,
but it would also be nice to be able to say "printenv ip*" or
"printenv *addr*"
- Some boards don't link any more due to the grown code size:
DU405, canyonlands, sequoia, socrates.
=> cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Stefan Roese <sr@denx.de>,
Heiko Schocher <hs@denx.de>
- Dropping forceenv() causes build problems on schmoogie
=> cc: Sergey Kubushyn <ksi@koi8.net>
- Build tested on PPC and ARM only; runtime tested with NOR and NAND
flash only => needs testing!!
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Cc: Stefan Roese <sr@denx.de>,
Cc: Heiko Schocher <hs@denx.de>
Cc: Sergey Kubushyn <ksi@koi8.net>
2010-06-20 21:33:59 +00:00
|
|
|
|
2017-08-03 18:21:56 +00:00
|
|
|
if (gd->env_valid == ENV_VALID) {
|
2010-10-27 09:06:20 +00:00
|
|
|
env_new_offset = CONFIG_ENV_OFFSET_REDUND;
|
|
|
|
env_offset = CONFIG_ENV_OFFSET;
|
|
|
|
} else {
|
|
|
|
env_new_offset = CONFIG_ENV_OFFSET;
|
|
|
|
env_offset = CONFIG_ENV_OFFSET_REDUND;
|
|
|
|
}
|
|
|
|
|
2010-04-23 15:22:55 +00:00
|
|
|
/* Is the sector larger than the env (i.e. embedded) */
|
|
|
|
if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
|
|
|
|
saved_size = CONFIG_ENV_SECT_SIZE - CONFIG_ENV_SIZE;
|
|
|
|
saved_offset = env_new_offset + CONFIG_ENV_SIZE;
|
2015-08-17 07:59:49 +00:00
|
|
|
saved_buffer = memalign(ARCH_DMA_MINALIGN, saved_size);
|
2010-04-23 15:22:55 +00:00
|
|
|
if (!saved_buffer) {
|
2017-08-03 18:22:17 +00:00
|
|
|
ret = -ENOMEM;
|
2010-04-23 15:22:55 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
ret = spi_flash_read(env_flash, saved_offset,
|
|
|
|
saved_size, saved_buffer);
|
|
|
|
if (ret)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2017-04-08 09:59:34 +00:00
|
|
|
sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE);
|
2010-04-23 15:22:55 +00:00
|
|
|
|
|
|
|
puts("Erasing SPI flash...");
|
|
|
|
ret = spi_flash_erase(env_flash, env_new_offset,
|
|
|
|
sector * CONFIG_ENV_SECT_SIZE);
|
|
|
|
if (ret)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
puts("Writing to SPI flash...");
|
|
|
|
|
2010-10-27 09:06:20 +00:00
|
|
|
ret = spi_flash_write(env_flash, env_new_offset,
|
2013-04-05 18:55:21 +00:00
|
|
|
CONFIG_ENV_SIZE, &env_new);
|
2010-04-23 15:22:55 +00:00
|
|
|
if (ret)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
|
|
|
|
ret = spi_flash_write(env_flash, saved_offset,
|
|
|
|
saved_size, saved_buffer);
|
|
|
|
if (ret)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-11-07 01:14:08 +00:00
|
|
|
ret = spi_flash_write(env_flash, env_offset + offsetof(env_t, flags),
|
2013-04-05 18:55:21 +00:00
|
|
|
sizeof(env_new.flags), &flag);
|
2010-10-27 09:06:20 +00:00
|
|
|
if (ret)
|
|
|
|
goto done;
|
2010-04-23 15:22:55 +00:00
|
|
|
|
|
|
|
puts("done\n");
|
|
|
|
|
2017-08-03 18:21:56 +00:00
|
|
|
gd->env_valid = gd->env_valid == ENV_REDUND ? ENV_VALID : ENV_REDUND;
|
2010-10-27 09:06:20 +00:00
|
|
|
|
2011-03-29 02:35:14 +00:00
|
|
|
printf("Valid environment: %d\n", (int)gd->env_valid);
|
2010-10-27 09:06:20 +00:00
|
|
|
|
2010-04-23 15:22:55 +00:00
|
|
|
done:
|
|
|
|
if (saved_buffer)
|
|
|
|
free(saved_buffer);
|
2011-11-07 01:14:08 +00:00
|
|
|
|
2010-04-23 15:22:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2017-08-03 18:21:58 +00:00
|
|
|
#endif /* CMD_SAVEENV */
|
2010-04-23 15:22:55 +00:00
|
|
|
|
2017-08-03 18:22:17 +00:00
|
|
|
static int env_sf_load(void)
|
2010-04-23 15:22:55 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2018-01-31 13:47:13 +00:00
|
|
|
int read1_fail, read2_fail;
|
|
|
|
env_t *tmp_env1, *tmp_env2;
|
2010-04-23 15:22:55 +00:00
|
|
|
|
2015-08-17 07:59:49 +00:00
|
|
|
tmp_env1 = (env_t *)memalign(ARCH_DMA_MINALIGN,
|
|
|
|
CONFIG_ENV_SIZE);
|
|
|
|
tmp_env2 = (env_t *)memalign(ARCH_DMA_MINALIGN,
|
|
|
|
CONFIG_ENV_SIZE);
|
New implementation for internal handling of environment variables.
Motivation:
* Old environment code used a pessimizing implementation:
- variable lookup used linear search => slow
- changed/added variables were added at the end, i. e. most
frequently used variables had the slowest access times => slow
- each setenv() would calculate the CRC32 checksum over the whole
environment block => slow
* "redundant" envrionment was locked down to two copies
* No easy way to implement features like "reset to factory defaults",
or to select one out of several pre-defined (previously saved) sets
of environment settings ("profiles")
* No easy way to import or export environment settings
======================================================================
API Changes:
- Variable names starting with '#' are no longer allowed
I didn't find any such variable names being used; it is highly
recommended to follow standard conventions and start variable names
with an alphanumeric character
- "printenv" will now print a backslash at the end of all but the last
lines of a multi-line variable value.
Multi-line variables have never been formally defined, allthough
there is no reason not to use them. Now we define rules how to deal
with them, allowing for import and export.
- Function forceenv() and the related code in saveenv() was removed.
At the moment this is causing build problems for the only user of
this code (schmoogie - which has no entry in MAINTAINERS); may be
fixed later by implementing the "env set -f" feature.
Inconsistencies:
- "printenv" will '\\'-escape the '\n' in multi-line variables, while
"printenv var" will not do that.
======================================================================
Advantages:
- "printenv" output much better readable (sorted)
- faster!
- extendable (additional variable properties can be added)
- new, powerful features like "factory reset" or easy switching
between several different environment settings ("profiles")
Disadvantages:
- Image size grows by typically 5...7 KiB (might shrink a bit again on
systems with redundant environment with a following patch series)
======================================================================
Implemented:
- env command with subcommands:
- env print [arg ...]
same as "printenv": print environment
- env set [-f] name [arg ...]
same as "setenv": set (and delete) environment variables
["-f" - force setting even for read-only variables - not
implemented yet.]
- end delete [-f] name
not implemented yet
["-f" - force delete even for read-only variables]
- env save
same as "saveenv": save environment
- env export [-t | -b | -c] addr [size]
export internal representation (hash table) in formats usable for
persistent storage or processing:
-t: export as text format; if size is given, data will be
padded with '\0' bytes; if not, one terminating '\0'
will be added (which is included in the "filesize"
setting so you can for exmple copy this to flash and
keep the termination).
-b: export as binary format (name=value pairs separated by
'\0', list end marked by double "\0\0")
-c: export as checksum protected environment format as
used for example by "saveenv" command
addr: memory address where environment gets stored
size: size of output buffer
With "-c" and size is NOT given, then the export command will
format the data as currently used for the persistent storage,
i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
prepend a valid CRC32 checksum and, in case of resundant
environment, a "current" redundancy flag. If size is given, this
value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
checksum and redundancy flag will be inserted.
With "-b" and "-t", always only the real data (including a
terminating '\0' byte) will be written; here the optional size
argument will be used to make sure not to overflow the user
provided buffer; the command will abort if the size is not
sufficient. Any remainign space will be '\0' padded.
On successful return, the variable "filesize" will be set.
Note that filesize includes the trailing/terminating '\0'
byte(s).
Usage szenario: create a text snapshot/backup of the current
settings:
=> env export -t 100000
=> era ${backup_addr} +${filesize}
=> cp.b 100000 ${backup_addr} ${filesize}
Re-import this snapshot, deleting all other settings:
=> env import -d -t ${backup_addr}
- env import [-d] [-t | -b | -c] addr [size]
import external format (text or binary) into hash table,
optionally deleting existing values:
-d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
-t: assume text format; either "size" must be given or the
text data must be '\0' terminated
-b: assume binary format ('\0' separated, "\0\0" terminated)
-c: assume checksum protected environment format
addr: memory address to read from
size: length of input data; if missing, proper '\0'
termination is mandatory
- env default -f
reset default environment: drop all environment settings and load
default environment
- env ask name [message] [size]
same as "askenv": ask for environment variable
- env edit name
same as "editenv": edit environment variable
- env run
same as "run": run commands in an environment variable
======================================================================
TODO:
- drop default env as implemented now; provide a text file based
initialization instead (eventually using several text files to
incrementally build it from common blocks) and a tool to convert it
into a binary blob / object file.
- It would be nice if we could add wildcard support for environment
variables; this is needed for variable name auto-completion,
but it would also be nice to be able to say "printenv ip*" or
"printenv *addr*"
- Some boards don't link any more due to the grown code size:
DU405, canyonlands, sequoia, socrates.
=> cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Stefan Roese <sr@denx.de>,
Heiko Schocher <hs@denx.de>
- Dropping forceenv() causes build problems on schmoogie
=> cc: Sergey Kubushyn <ksi@koi8.net>
- Build tested on PPC and ARM only; runtime tested with NOR and NAND
flash only => needs testing!!
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Cc: Stefan Roese <sr@denx.de>,
Cc: Heiko Schocher <hs@denx.de>
Cc: Sergey Kubushyn <ksi@koi8.net>
2010-06-20 21:33:59 +00:00
|
|
|
if (!tmp_env1 || !tmp_env2) {
|
2018-06-24 16:16:57 +00:00
|
|
|
set_default_env("malloc() failed", 0);
|
2017-08-03 18:22:17 +00:00
|
|
|
ret = -EIO;
|
2011-03-29 02:35:14 +00:00
|
|
|
goto out;
|
2010-04-23 15:22:55 +00:00
|
|
|
}
|
|
|
|
|
2017-04-08 09:59:32 +00:00
|
|
|
ret = setup_flash_device();
|
|
|
|
if (ret)
|
2011-03-29 02:35:14 +00:00
|
|
|
goto out;
|
2010-04-23 15:22:55 +00:00
|
|
|
|
2018-01-31 13:47:13 +00:00
|
|
|
read1_fail = spi_flash_read(env_flash, CONFIG_ENV_OFFSET,
|
|
|
|
CONFIG_ENV_SIZE, tmp_env1);
|
|
|
|
read2_fail = spi_flash_read(env_flash, CONFIG_ENV_OFFSET_REDUND,
|
|
|
|
CONFIG_ENV_SIZE, tmp_env2);
|
New implementation for internal handling of environment variables.
Motivation:
* Old environment code used a pessimizing implementation:
- variable lookup used linear search => slow
- changed/added variables were added at the end, i. e. most
frequently used variables had the slowest access times => slow
- each setenv() would calculate the CRC32 checksum over the whole
environment block => slow
* "redundant" envrionment was locked down to two copies
* No easy way to implement features like "reset to factory defaults",
or to select one out of several pre-defined (previously saved) sets
of environment settings ("profiles")
* No easy way to import or export environment settings
======================================================================
API Changes:
- Variable names starting with '#' are no longer allowed
I didn't find any such variable names being used; it is highly
recommended to follow standard conventions and start variable names
with an alphanumeric character
- "printenv" will now print a backslash at the end of all but the last
lines of a multi-line variable value.
Multi-line variables have never been formally defined, allthough
there is no reason not to use them. Now we define rules how to deal
with them, allowing for import and export.
- Function forceenv() and the related code in saveenv() was removed.
At the moment this is causing build problems for the only user of
this code (schmoogie - which has no entry in MAINTAINERS); may be
fixed later by implementing the "env set -f" feature.
Inconsistencies:
- "printenv" will '\\'-escape the '\n' in multi-line variables, while
"printenv var" will not do that.
======================================================================
Advantages:
- "printenv" output much better readable (sorted)
- faster!
- extendable (additional variable properties can be added)
- new, powerful features like "factory reset" or easy switching
between several different environment settings ("profiles")
Disadvantages:
- Image size grows by typically 5...7 KiB (might shrink a bit again on
systems with redundant environment with a following patch series)
======================================================================
Implemented:
- env command with subcommands:
- env print [arg ...]
same as "printenv": print environment
- env set [-f] name [arg ...]
same as "setenv": set (and delete) environment variables
["-f" - force setting even for read-only variables - not
implemented yet.]
- end delete [-f] name
not implemented yet
["-f" - force delete even for read-only variables]
- env save
same as "saveenv": save environment
- env export [-t | -b | -c] addr [size]
export internal representation (hash table) in formats usable for
persistent storage or processing:
-t: export as text format; if size is given, data will be
padded with '\0' bytes; if not, one terminating '\0'
will be added (which is included in the "filesize"
setting so you can for exmple copy this to flash and
keep the termination).
-b: export as binary format (name=value pairs separated by
'\0', list end marked by double "\0\0")
-c: export as checksum protected environment format as
used for example by "saveenv" command
addr: memory address where environment gets stored
size: size of output buffer
With "-c" and size is NOT given, then the export command will
format the data as currently used for the persistent storage,
i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
prepend a valid CRC32 checksum and, in case of resundant
environment, a "current" redundancy flag. If size is given, this
value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
checksum and redundancy flag will be inserted.
With "-b" and "-t", always only the real data (including a
terminating '\0' byte) will be written; here the optional size
argument will be used to make sure not to overflow the user
provided buffer; the command will abort if the size is not
sufficient. Any remainign space will be '\0' padded.
On successful return, the variable "filesize" will be set.
Note that filesize includes the trailing/terminating '\0'
byte(s).
Usage szenario: create a text snapshot/backup of the current
settings:
=> env export -t 100000
=> era ${backup_addr} +${filesize}
=> cp.b 100000 ${backup_addr} ${filesize}
Re-import this snapshot, deleting all other settings:
=> env import -d -t ${backup_addr}
- env import [-d] [-t | -b | -c] addr [size]
import external format (text or binary) into hash table,
optionally deleting existing values:
-d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
-t: assume text format; either "size" must be given or the
text data must be '\0' terminated
-b: assume binary format ('\0' separated, "\0\0" terminated)
-c: assume checksum protected environment format
addr: memory address to read from
size: length of input data; if missing, proper '\0'
termination is mandatory
- env default -f
reset default environment: drop all environment settings and load
default environment
- env ask name [message] [size]
same as "askenv": ask for environment variable
- env edit name
same as "editenv": edit environment variable
- env run
same as "run": run commands in an environment variable
======================================================================
TODO:
- drop default env as implemented now; provide a text file based
initialization instead (eventually using several text files to
incrementally build it from common blocks) and a tool to convert it
into a binary blob / object file.
- It would be nice if we could add wildcard support for environment
variables; this is needed for variable name auto-completion,
but it would also be nice to be able to say "printenv ip*" or
"printenv *addr*"
- Some boards don't link any more due to the grown code size:
DU405, canyonlands, sequoia, socrates.
=> cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Stefan Roese <sr@denx.de>,
Heiko Schocher <hs@denx.de>
- Dropping forceenv() causes build problems on schmoogie
=> cc: Sergey Kubushyn <ksi@koi8.net>
- Build tested on PPC and ARM only; runtime tested with NOR and NAND
flash only => needs testing!!
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Cc: Stefan Roese <sr@denx.de>,
Cc: Heiko Schocher <hs@denx.de>
Cc: Sergey Kubushyn <ksi@koi8.net>
2010-06-20 21:33:59 +00:00
|
|
|
|
2018-01-31 13:47:13 +00:00
|
|
|
ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2,
|
|
|
|
read2_fail);
|
2010-04-23 15:22:55 +00:00
|
|
|
|
|
|
|
spi_flash_free(env_flash);
|
|
|
|
env_flash = NULL;
|
|
|
|
out:
|
New implementation for internal handling of environment variables.
Motivation:
* Old environment code used a pessimizing implementation:
- variable lookup used linear search => slow
- changed/added variables were added at the end, i. e. most
frequently used variables had the slowest access times => slow
- each setenv() would calculate the CRC32 checksum over the whole
environment block => slow
* "redundant" envrionment was locked down to two copies
* No easy way to implement features like "reset to factory defaults",
or to select one out of several pre-defined (previously saved) sets
of environment settings ("profiles")
* No easy way to import or export environment settings
======================================================================
API Changes:
- Variable names starting with '#' are no longer allowed
I didn't find any such variable names being used; it is highly
recommended to follow standard conventions and start variable names
with an alphanumeric character
- "printenv" will now print a backslash at the end of all but the last
lines of a multi-line variable value.
Multi-line variables have never been formally defined, allthough
there is no reason not to use them. Now we define rules how to deal
with them, allowing for import and export.
- Function forceenv() and the related code in saveenv() was removed.
At the moment this is causing build problems for the only user of
this code (schmoogie - which has no entry in MAINTAINERS); may be
fixed later by implementing the "env set -f" feature.
Inconsistencies:
- "printenv" will '\\'-escape the '\n' in multi-line variables, while
"printenv var" will not do that.
======================================================================
Advantages:
- "printenv" output much better readable (sorted)
- faster!
- extendable (additional variable properties can be added)
- new, powerful features like "factory reset" or easy switching
between several different environment settings ("profiles")
Disadvantages:
- Image size grows by typically 5...7 KiB (might shrink a bit again on
systems with redundant environment with a following patch series)
======================================================================
Implemented:
- env command with subcommands:
- env print [arg ...]
same as "printenv": print environment
- env set [-f] name [arg ...]
same as "setenv": set (and delete) environment variables
["-f" - force setting even for read-only variables - not
implemented yet.]
- end delete [-f] name
not implemented yet
["-f" - force delete even for read-only variables]
- env save
same as "saveenv": save environment
- env export [-t | -b | -c] addr [size]
export internal representation (hash table) in formats usable for
persistent storage or processing:
-t: export as text format; if size is given, data will be
padded with '\0' bytes; if not, one terminating '\0'
will be added (which is included in the "filesize"
setting so you can for exmple copy this to flash and
keep the termination).
-b: export as binary format (name=value pairs separated by
'\0', list end marked by double "\0\0")
-c: export as checksum protected environment format as
used for example by "saveenv" command
addr: memory address where environment gets stored
size: size of output buffer
With "-c" and size is NOT given, then the export command will
format the data as currently used for the persistent storage,
i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
prepend a valid CRC32 checksum and, in case of resundant
environment, a "current" redundancy flag. If size is given, this
value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
checksum and redundancy flag will be inserted.
With "-b" and "-t", always only the real data (including a
terminating '\0' byte) will be written; here the optional size
argument will be used to make sure not to overflow the user
provided buffer; the command will abort if the size is not
sufficient. Any remainign space will be '\0' padded.
On successful return, the variable "filesize" will be set.
Note that filesize includes the trailing/terminating '\0'
byte(s).
Usage szenario: create a text snapshot/backup of the current
settings:
=> env export -t 100000
=> era ${backup_addr} +${filesize}
=> cp.b 100000 ${backup_addr} ${filesize}
Re-import this snapshot, deleting all other settings:
=> env import -d -t ${backup_addr}
- env import [-d] [-t | -b | -c] addr [size]
import external format (text or binary) into hash table,
optionally deleting existing values:
-d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
-t: assume text format; either "size" must be given or the
text data must be '\0' terminated
-b: assume binary format ('\0' separated, "\0\0" terminated)
-c: assume checksum protected environment format
addr: memory address to read from
size: length of input data; if missing, proper '\0'
termination is mandatory
- env default -f
reset default environment: drop all environment settings and load
default environment
- env ask name [message] [size]
same as "askenv": ask for environment variable
- env edit name
same as "editenv": edit environment variable
- env run
same as "run": run commands in an environment variable
======================================================================
TODO:
- drop default env as implemented now; provide a text file based
initialization instead (eventually using several text files to
incrementally build it from common blocks) and a tool to convert it
into a binary blob / object file.
- It would be nice if we could add wildcard support for environment
variables; this is needed for variable name auto-completion,
but it would also be nice to be able to say "printenv ip*" or
"printenv *addr*"
- Some boards don't link any more due to the grown code size:
DU405, canyonlands, sequoia, socrates.
=> cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Stefan Roese <sr@denx.de>,
Heiko Schocher <hs@denx.de>
- Dropping forceenv() causes build problems on schmoogie
=> cc: Sergey Kubushyn <ksi@koi8.net>
- Build tested on PPC and ARM only; runtime tested with NOR and NAND
flash only => needs testing!!
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Cc: Stefan Roese <sr@denx.de>,
Cc: Heiko Schocher <hs@denx.de>
Cc: Sergey Kubushyn <ksi@koi8.net>
2010-06-20 21:33:59 +00:00
|
|
|
free(tmp_env1);
|
|
|
|
free(tmp_env2);
|
2017-08-03 18:22:17 +00:00
|
|
|
|
|
|
|
return ret;
|
2010-04-23 15:22:55 +00:00
|
|
|
}
|
|
|
|
#else
|
2017-08-03 18:21:58 +00:00
|
|
|
#ifdef CMD_SAVEENV
|
2017-08-03 18:22:01 +00:00
|
|
|
static int env_sf_save(void)
|
2008-05-16 09:10:35 +00:00
|
|
|
{
|
2017-04-08 09:59:34 +00:00
|
|
|
u32 saved_size, saved_offset, sector;
|
2014-03-05 18:59:50 +00:00
|
|
|
char *saved_buffer = NULL;
|
2011-11-07 01:14:08 +00:00
|
|
|
int ret = 1;
|
2013-04-05 18:55:21 +00:00
|
|
|
env_t env_new;
|
2016-01-26 07:06:42 +00:00
|
|
|
|
2017-04-08 09:59:31 +00:00
|
|
|
ret = setup_flash_device();
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-05-16 09:10:35 +00:00
|
|
|
|
2008-12-11 11:23:37 +00:00
|
|
|
/* Is the sector larger than the env (i.e. embedded) */
|
|
|
|
if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
|
|
|
|
saved_size = CONFIG_ENV_SECT_SIZE - CONFIG_ENV_SIZE;
|
|
|
|
saved_offset = CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE;
|
|
|
|
saved_buffer = malloc(saved_size);
|
2011-11-07 01:14:08 +00:00
|
|
|
if (!saved_buffer)
|
2008-12-11 11:23:37 +00:00
|
|
|
goto done;
|
2011-11-07 01:14:08 +00:00
|
|
|
|
2010-10-27 09:06:20 +00:00
|
|
|
ret = spi_flash_read(env_flash, saved_offset,
|
|
|
|
saved_size, saved_buffer);
|
2008-12-11 11:23:37 +00:00
|
|
|
if (ret)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2014-03-05 18:59:50 +00:00
|
|
|
ret = env_export(&env_new);
|
|
|
|
if (ret)
|
2010-10-27 09:06:20 +00:00
|
|
|
goto done;
|
|
|
|
|
2017-04-08 09:59:34 +00:00
|
|
|
sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE);
|
|
|
|
|
2008-05-16 09:10:35 +00:00
|
|
|
puts("Erasing SPI flash...");
|
2010-10-27 09:06:20 +00:00
|
|
|
ret = spi_flash_erase(env_flash, CONFIG_ENV_OFFSET,
|
|
|
|
sector * CONFIG_ENV_SECT_SIZE);
|
2008-12-11 11:23:37 +00:00
|
|
|
if (ret)
|
|
|
|
goto done;
|
2008-05-16 09:10:35 +00:00
|
|
|
|
|
|
|
puts("Writing to SPI flash...");
|
2010-10-27 09:06:20 +00:00
|
|
|
ret = spi_flash_write(env_flash, CONFIG_ENV_OFFSET,
|
2013-04-05 18:55:21 +00:00
|
|
|
CONFIG_ENV_SIZE, &env_new);
|
2008-12-11 11:23:37 +00:00
|
|
|
if (ret)
|
|
|
|
goto done;
|
2008-05-16 09:10:35 +00:00
|
|
|
|
2008-12-11 11:23:37 +00:00
|
|
|
if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
|
2010-10-27 09:06:20 +00:00
|
|
|
ret = spi_flash_write(env_flash, saved_offset,
|
|
|
|
saved_size, saved_buffer);
|
2008-12-11 11:23:37 +00:00
|
|
|
if (ret)
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2008-05-16 09:10:35 +00:00
|
|
|
puts("done\n");
|
2008-12-11 11:23:37 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (saved_buffer)
|
|
|
|
free(saved_buffer);
|
2011-11-07 01:14:08 +00:00
|
|
|
|
2008-12-11 11:23:37 +00:00
|
|
|
return ret;
|
2008-05-16 09:10:35 +00:00
|
|
|
}
|
2017-08-03 18:21:58 +00:00
|
|
|
#endif /* CMD_SAVEENV */
|
2008-05-16 09:10:35 +00:00
|
|
|
|
2017-08-03 18:22:17 +00:00
|
|
|
static int env_sf_load(void)
|
2008-05-16 09:10:35 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2014-01-24 07:50:07 +00:00
|
|
|
char *buf = NULL;
|
2008-05-16 09:10:35 +00:00
|
|
|
|
2015-08-17 07:59:49 +00:00
|
|
|
buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE);
|
2017-04-08 09:59:33 +00:00
|
|
|
if (!buf) {
|
2018-06-24 16:16:57 +00:00
|
|
|
set_default_env("malloc() failed", 0);
|
2017-08-03 18:22:17 +00:00
|
|
|
return -EIO;
|
New implementation for internal handling of environment variables.
Motivation:
* Old environment code used a pessimizing implementation:
- variable lookup used linear search => slow
- changed/added variables were added at the end, i. e. most
frequently used variables had the slowest access times => slow
- each setenv() would calculate the CRC32 checksum over the whole
environment block => slow
* "redundant" envrionment was locked down to two copies
* No easy way to implement features like "reset to factory defaults",
or to select one out of several pre-defined (previously saved) sets
of environment settings ("profiles")
* No easy way to import or export environment settings
======================================================================
API Changes:
- Variable names starting with '#' are no longer allowed
I didn't find any such variable names being used; it is highly
recommended to follow standard conventions and start variable names
with an alphanumeric character
- "printenv" will now print a backslash at the end of all but the last
lines of a multi-line variable value.
Multi-line variables have never been formally defined, allthough
there is no reason not to use them. Now we define rules how to deal
with them, allowing for import and export.
- Function forceenv() and the related code in saveenv() was removed.
At the moment this is causing build problems for the only user of
this code (schmoogie - which has no entry in MAINTAINERS); may be
fixed later by implementing the "env set -f" feature.
Inconsistencies:
- "printenv" will '\\'-escape the '\n' in multi-line variables, while
"printenv var" will not do that.
======================================================================
Advantages:
- "printenv" output much better readable (sorted)
- faster!
- extendable (additional variable properties can be added)
- new, powerful features like "factory reset" or easy switching
between several different environment settings ("profiles")
Disadvantages:
- Image size grows by typically 5...7 KiB (might shrink a bit again on
systems with redundant environment with a following patch series)
======================================================================
Implemented:
- env command with subcommands:
- env print [arg ...]
same as "printenv": print environment
- env set [-f] name [arg ...]
same as "setenv": set (and delete) environment variables
["-f" - force setting even for read-only variables - not
implemented yet.]
- end delete [-f] name
not implemented yet
["-f" - force delete even for read-only variables]
- env save
same as "saveenv": save environment
- env export [-t | -b | -c] addr [size]
export internal representation (hash table) in formats usable for
persistent storage or processing:
-t: export as text format; if size is given, data will be
padded with '\0' bytes; if not, one terminating '\0'
will be added (which is included in the "filesize"
setting so you can for exmple copy this to flash and
keep the termination).
-b: export as binary format (name=value pairs separated by
'\0', list end marked by double "\0\0")
-c: export as checksum protected environment format as
used for example by "saveenv" command
addr: memory address where environment gets stored
size: size of output buffer
With "-c" and size is NOT given, then the export command will
format the data as currently used for the persistent storage,
i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
prepend a valid CRC32 checksum and, in case of resundant
environment, a "current" redundancy flag. If size is given, this
value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
checksum and redundancy flag will be inserted.
With "-b" and "-t", always only the real data (including a
terminating '\0' byte) will be written; here the optional size
argument will be used to make sure not to overflow the user
provided buffer; the command will abort if the size is not
sufficient. Any remainign space will be '\0' padded.
On successful return, the variable "filesize" will be set.
Note that filesize includes the trailing/terminating '\0'
byte(s).
Usage szenario: create a text snapshot/backup of the current
settings:
=> env export -t 100000
=> era ${backup_addr} +${filesize}
=> cp.b 100000 ${backup_addr} ${filesize}
Re-import this snapshot, deleting all other settings:
=> env import -d -t ${backup_addr}
- env import [-d] [-t | -b | -c] addr [size]
import external format (text or binary) into hash table,
optionally deleting existing values:
-d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
-t: assume text format; either "size" must be given or the
text data must be '\0' terminated
-b: assume binary format ('\0' separated, "\0\0" terminated)
-c: assume checksum protected environment format
addr: memory address to read from
size: length of input data; if missing, proper '\0'
termination is mandatory
- env default -f
reset default environment: drop all environment settings and load
default environment
- env ask name [message] [size]
same as "askenv": ask for environment variable
- env edit name
same as "editenv": edit environment variable
- env run
same as "run": run commands in an environment variable
======================================================================
TODO:
- drop default env as implemented now; provide a text file based
initialization instead (eventually using several text files to
incrementally build it from common blocks) and a tool to convert it
into a binary blob / object file.
- It would be nice if we could add wildcard support for environment
variables; this is needed for variable name auto-completion,
but it would also be nice to be able to say "printenv ip*" or
"printenv *addr*"
- Some boards don't link any more due to the grown code size:
DU405, canyonlands, sequoia, socrates.
=> cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Stefan Roese <sr@denx.de>,
Heiko Schocher <hs@denx.de>
- Dropping forceenv() causes build problems on schmoogie
=> cc: Sergey Kubushyn <ksi@koi8.net>
- Build tested on PPC and ARM only; runtime tested with NOR and NAND
flash only => needs testing!!
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Cc: Stefan Roese <sr@denx.de>,
Cc: Heiko Schocher <hs@denx.de>
Cc: Sergey Kubushyn <ksi@koi8.net>
2010-06-20 21:33:59 +00:00
|
|
|
}
|
2008-05-16 09:10:35 +00:00
|
|
|
|
2017-04-08 09:59:33 +00:00
|
|
|
ret = setup_flash_device();
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
New implementation for internal handling of environment variables.
Motivation:
* Old environment code used a pessimizing implementation:
- variable lookup used linear search => slow
- changed/added variables were added at the end, i. e. most
frequently used variables had the slowest access times => slow
- each setenv() would calculate the CRC32 checksum over the whole
environment block => slow
* "redundant" envrionment was locked down to two copies
* No easy way to implement features like "reset to factory defaults",
or to select one out of several pre-defined (previously saved) sets
of environment settings ("profiles")
* No easy way to import or export environment settings
======================================================================
API Changes:
- Variable names starting with '#' are no longer allowed
I didn't find any such variable names being used; it is highly
recommended to follow standard conventions and start variable names
with an alphanumeric character
- "printenv" will now print a backslash at the end of all but the last
lines of a multi-line variable value.
Multi-line variables have never been formally defined, allthough
there is no reason not to use them. Now we define rules how to deal
with them, allowing for import and export.
- Function forceenv() and the related code in saveenv() was removed.
At the moment this is causing build problems for the only user of
this code (schmoogie - which has no entry in MAINTAINERS); may be
fixed later by implementing the "env set -f" feature.
Inconsistencies:
- "printenv" will '\\'-escape the '\n' in multi-line variables, while
"printenv var" will not do that.
======================================================================
Advantages:
- "printenv" output much better readable (sorted)
- faster!
- extendable (additional variable properties can be added)
- new, powerful features like "factory reset" or easy switching
between several different environment settings ("profiles")
Disadvantages:
- Image size grows by typically 5...7 KiB (might shrink a bit again on
systems with redundant environment with a following patch series)
======================================================================
Implemented:
- env command with subcommands:
- env print [arg ...]
same as "printenv": print environment
- env set [-f] name [arg ...]
same as "setenv": set (and delete) environment variables
["-f" - force setting even for read-only variables - not
implemented yet.]
- end delete [-f] name
not implemented yet
["-f" - force delete even for read-only variables]
- env save
same as "saveenv": save environment
- env export [-t | -b | -c] addr [size]
export internal representation (hash table) in formats usable for
persistent storage or processing:
-t: export as text format; if size is given, data will be
padded with '\0' bytes; if not, one terminating '\0'
will be added (which is included in the "filesize"
setting so you can for exmple copy this to flash and
keep the termination).
-b: export as binary format (name=value pairs separated by
'\0', list end marked by double "\0\0")
-c: export as checksum protected environment format as
used for example by "saveenv" command
addr: memory address where environment gets stored
size: size of output buffer
With "-c" and size is NOT given, then the export command will
format the data as currently used for the persistent storage,
i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
prepend a valid CRC32 checksum and, in case of resundant
environment, a "current" redundancy flag. If size is given, this
value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
checksum and redundancy flag will be inserted.
With "-b" and "-t", always only the real data (including a
terminating '\0' byte) will be written; here the optional size
argument will be used to make sure not to overflow the user
provided buffer; the command will abort if the size is not
sufficient. Any remainign space will be '\0' padded.
On successful return, the variable "filesize" will be set.
Note that filesize includes the trailing/terminating '\0'
byte(s).
Usage szenario: create a text snapshot/backup of the current
settings:
=> env export -t 100000
=> era ${backup_addr} +${filesize}
=> cp.b 100000 ${backup_addr} ${filesize}
Re-import this snapshot, deleting all other settings:
=> env import -d -t ${backup_addr}
- env import [-d] [-t | -b | -c] addr [size]
import external format (text or binary) into hash table,
optionally deleting existing values:
-d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
-t: assume text format; either "size" must be given or the
text data must be '\0' terminated
-b: assume binary format ('\0' separated, "\0\0" terminated)
-c: assume checksum protected environment format
addr: memory address to read from
size: length of input data; if missing, proper '\0'
termination is mandatory
- env default -f
reset default environment: drop all environment settings and load
default environment
- env ask name [message] [size]
same as "askenv": ask for environment variable
- env edit name
same as "editenv": edit environment variable
- env run
same as "run": run commands in an environment variable
======================================================================
TODO:
- drop default env as implemented now; provide a text file based
initialization instead (eventually using several text files to
incrementally build it from common blocks) and a tool to convert it
into a binary blob / object file.
- It would be nice if we could add wildcard support for environment
variables; this is needed for variable name auto-completion,
but it would also be nice to be able to say "printenv ip*" or
"printenv *addr*"
- Some boards don't link any more due to the grown code size:
DU405, canyonlands, sequoia, socrates.
=> cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Stefan Roese <sr@denx.de>,
Heiko Schocher <hs@denx.de>
- Dropping forceenv() causes build problems on schmoogie
=> cc: Sergey Kubushyn <ksi@koi8.net>
- Build tested on PPC and ARM only; runtime tested with NOR and NAND
flash only => needs testing!!
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Cc: Stefan Roese <sr@denx.de>,
Cc: Heiko Schocher <hs@denx.de>
Cc: Sergey Kubushyn <ksi@koi8.net>
2010-06-20 21:33:59 +00:00
|
|
|
ret = spi_flash_read(env_flash,
|
|
|
|
CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, buf);
|
|
|
|
if (ret) {
|
2018-06-24 16:16:57 +00:00
|
|
|
set_default_env("spi_flash_read() failed", 0);
|
2017-04-08 09:59:33 +00:00
|
|
|
goto err_read;
|
New implementation for internal handling of environment variables.
Motivation:
* Old environment code used a pessimizing implementation:
- variable lookup used linear search => slow
- changed/added variables were added at the end, i. e. most
frequently used variables had the slowest access times => slow
- each setenv() would calculate the CRC32 checksum over the whole
environment block => slow
* "redundant" envrionment was locked down to two copies
* No easy way to implement features like "reset to factory defaults",
or to select one out of several pre-defined (previously saved) sets
of environment settings ("profiles")
* No easy way to import or export environment settings
======================================================================
API Changes:
- Variable names starting with '#' are no longer allowed
I didn't find any such variable names being used; it is highly
recommended to follow standard conventions and start variable names
with an alphanumeric character
- "printenv" will now print a backslash at the end of all but the last
lines of a multi-line variable value.
Multi-line variables have never been formally defined, allthough
there is no reason not to use them. Now we define rules how to deal
with them, allowing for import and export.
- Function forceenv() and the related code in saveenv() was removed.
At the moment this is causing build problems for the only user of
this code (schmoogie - which has no entry in MAINTAINERS); may be
fixed later by implementing the "env set -f" feature.
Inconsistencies:
- "printenv" will '\\'-escape the '\n' in multi-line variables, while
"printenv var" will not do that.
======================================================================
Advantages:
- "printenv" output much better readable (sorted)
- faster!
- extendable (additional variable properties can be added)
- new, powerful features like "factory reset" or easy switching
between several different environment settings ("profiles")
Disadvantages:
- Image size grows by typically 5...7 KiB (might shrink a bit again on
systems with redundant environment with a following patch series)
======================================================================
Implemented:
- env command with subcommands:
- env print [arg ...]
same as "printenv": print environment
- env set [-f] name [arg ...]
same as "setenv": set (and delete) environment variables
["-f" - force setting even for read-only variables - not
implemented yet.]
- end delete [-f] name
not implemented yet
["-f" - force delete even for read-only variables]
- env save
same as "saveenv": save environment
- env export [-t | -b | -c] addr [size]
export internal representation (hash table) in formats usable for
persistent storage or processing:
-t: export as text format; if size is given, data will be
padded with '\0' bytes; if not, one terminating '\0'
will be added (which is included in the "filesize"
setting so you can for exmple copy this to flash and
keep the termination).
-b: export as binary format (name=value pairs separated by
'\0', list end marked by double "\0\0")
-c: export as checksum protected environment format as
used for example by "saveenv" command
addr: memory address where environment gets stored
size: size of output buffer
With "-c" and size is NOT given, then the export command will
format the data as currently used for the persistent storage,
i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
prepend a valid CRC32 checksum and, in case of resundant
environment, a "current" redundancy flag. If size is given, this
value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
checksum and redundancy flag will be inserted.
With "-b" and "-t", always only the real data (including a
terminating '\0' byte) will be written; here the optional size
argument will be used to make sure not to overflow the user
provided buffer; the command will abort if the size is not
sufficient. Any remainign space will be '\0' padded.
On successful return, the variable "filesize" will be set.
Note that filesize includes the trailing/terminating '\0'
byte(s).
Usage szenario: create a text snapshot/backup of the current
settings:
=> env export -t 100000
=> era ${backup_addr} +${filesize}
=> cp.b 100000 ${backup_addr} ${filesize}
Re-import this snapshot, deleting all other settings:
=> env import -d -t ${backup_addr}
- env import [-d] [-t | -b | -c] addr [size]
import external format (text or binary) into hash table,
optionally deleting existing values:
-d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
-t: assume text format; either "size" must be given or the
text data must be '\0' terminated
-b: assume binary format ('\0' separated, "\0\0" terminated)
-c: assume checksum protected environment format
addr: memory address to read from
size: length of input data; if missing, proper '\0'
termination is mandatory
- env default -f
reset default environment: drop all environment settings and load
default environment
- env ask name [message] [size]
same as "askenv": ask for environment variable
- env edit name
same as "editenv": edit environment variable
- env run
same as "run": run commands in an environment variable
======================================================================
TODO:
- drop default env as implemented now; provide a text file based
initialization instead (eventually using several text files to
incrementally build it from common blocks) and a tool to convert it
into a binary blob / object file.
- It would be nice if we could add wildcard support for environment
variables; this is needed for variable name auto-completion,
but it would also be nice to be able to say "printenv ip*" or
"printenv *addr*"
- Some boards don't link any more due to the grown code size:
DU405, canyonlands, sequoia, socrates.
=> cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Stefan Roese <sr@denx.de>,
Heiko Schocher <hs@denx.de>
- Dropping forceenv() causes build problems on schmoogie
=> cc: Sergey Kubushyn <ksi@koi8.net>
- Build tested on PPC and ARM only; runtime tested with NOR and NAND
flash only => needs testing!!
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Cc: Stefan Roese <sr@denx.de>,
Cc: Heiko Schocher <hs@denx.de>
Cc: Sergey Kubushyn <ksi@koi8.net>
2010-06-20 21:33:59 +00:00
|
|
|
}
|
2008-05-16 09:10:35 +00:00
|
|
|
|
New implementation for internal handling of environment variables.
Motivation:
* Old environment code used a pessimizing implementation:
- variable lookup used linear search => slow
- changed/added variables were added at the end, i. e. most
frequently used variables had the slowest access times => slow
- each setenv() would calculate the CRC32 checksum over the whole
environment block => slow
* "redundant" envrionment was locked down to two copies
* No easy way to implement features like "reset to factory defaults",
or to select one out of several pre-defined (previously saved) sets
of environment settings ("profiles")
* No easy way to import or export environment settings
======================================================================
API Changes:
- Variable names starting with '#' are no longer allowed
I didn't find any such variable names being used; it is highly
recommended to follow standard conventions and start variable names
with an alphanumeric character
- "printenv" will now print a backslash at the end of all but the last
lines of a multi-line variable value.
Multi-line variables have never been formally defined, allthough
there is no reason not to use them. Now we define rules how to deal
with them, allowing for import and export.
- Function forceenv() and the related code in saveenv() was removed.
At the moment this is causing build problems for the only user of
this code (schmoogie - which has no entry in MAINTAINERS); may be
fixed later by implementing the "env set -f" feature.
Inconsistencies:
- "printenv" will '\\'-escape the '\n' in multi-line variables, while
"printenv var" will not do that.
======================================================================
Advantages:
- "printenv" output much better readable (sorted)
- faster!
- extendable (additional variable properties can be added)
- new, powerful features like "factory reset" or easy switching
between several different environment settings ("profiles")
Disadvantages:
- Image size grows by typically 5...7 KiB (might shrink a bit again on
systems with redundant environment with a following patch series)
======================================================================
Implemented:
- env command with subcommands:
- env print [arg ...]
same as "printenv": print environment
- env set [-f] name [arg ...]
same as "setenv": set (and delete) environment variables
["-f" - force setting even for read-only variables - not
implemented yet.]
- end delete [-f] name
not implemented yet
["-f" - force delete even for read-only variables]
- env save
same as "saveenv": save environment
- env export [-t | -b | -c] addr [size]
export internal representation (hash table) in formats usable for
persistent storage or processing:
-t: export as text format; if size is given, data will be
padded with '\0' bytes; if not, one terminating '\0'
will be added (which is included in the "filesize"
setting so you can for exmple copy this to flash and
keep the termination).
-b: export as binary format (name=value pairs separated by
'\0', list end marked by double "\0\0")
-c: export as checksum protected environment format as
used for example by "saveenv" command
addr: memory address where environment gets stored
size: size of output buffer
With "-c" and size is NOT given, then the export command will
format the data as currently used for the persistent storage,
i. e. it will use CONFIG_ENV_SECT_SIZE as output block size and
prepend a valid CRC32 checksum and, in case of resundant
environment, a "current" redundancy flag. If size is given, this
value will be used instead of CONFIG_ENV_SECT_SIZE; again, CRC32
checksum and redundancy flag will be inserted.
With "-b" and "-t", always only the real data (including a
terminating '\0' byte) will be written; here the optional size
argument will be used to make sure not to overflow the user
provided buffer; the command will abort if the size is not
sufficient. Any remainign space will be '\0' padded.
On successful return, the variable "filesize" will be set.
Note that filesize includes the trailing/terminating '\0'
byte(s).
Usage szenario: create a text snapshot/backup of the current
settings:
=> env export -t 100000
=> era ${backup_addr} +${filesize}
=> cp.b 100000 ${backup_addr} ${filesize}
Re-import this snapshot, deleting all other settings:
=> env import -d -t ${backup_addr}
- env import [-d] [-t | -b | -c] addr [size]
import external format (text or binary) into hash table,
optionally deleting existing values:
-d: delete existing environment before importing;
otherwise overwrite / append to existion definitions
-t: assume text format; either "size" must be given or the
text data must be '\0' terminated
-b: assume binary format ('\0' separated, "\0\0" terminated)
-c: assume checksum protected environment format
addr: memory address to read from
size: length of input data; if missing, proper '\0'
termination is mandatory
- env default -f
reset default environment: drop all environment settings and load
default environment
- env ask name [message] [size]
same as "askenv": ask for environment variable
- env edit name
same as "editenv": edit environment variable
- env run
same as "run": run commands in an environment variable
======================================================================
TODO:
- drop default env as implemented now; provide a text file based
initialization instead (eventually using several text files to
incrementally build it from common blocks) and a tool to convert it
into a binary blob / object file.
- It would be nice if we could add wildcard support for environment
variables; this is needed for variable name auto-completion,
but it would also be nice to be able to say "printenv ip*" or
"printenv *addr*"
- Some boards don't link any more due to the grown code size:
DU405, canyonlands, sequoia, socrates.
=> cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Stefan Roese <sr@denx.de>,
Heiko Schocher <hs@denx.de>
- Dropping forceenv() causes build problems on schmoogie
=> cc: Sergey Kubushyn <ksi@koi8.net>
- Build tested on PPC and ARM only; runtime tested with NOR and NAND
flash only => needs testing!!
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Matthias Fuchs <matthias.fuchs@esd-electronics.com>,
Cc: Stefan Roese <sr@denx.de>,
Cc: Heiko Schocher <hs@denx.de>
Cc: Sergey Kubushyn <ksi@koi8.net>
2010-06-20 21:33:59 +00:00
|
|
|
ret = env_import(buf, 1);
|
2018-01-31 13:47:10 +00:00
|
|
|
if (!ret)
|
2017-08-03 18:21:56 +00:00
|
|
|
gd->env_valid = ENV_VALID;
|
2017-04-08 09:59:33 +00:00
|
|
|
|
|
|
|
err_read:
|
2008-05-16 09:10:35 +00:00
|
|
|
spi_flash_free(env_flash);
|
|
|
|
env_flash = NULL;
|
2017-04-08 09:59:33 +00:00
|
|
|
out:
|
|
|
|
free(buf);
|
2017-08-03 18:22:17 +00:00
|
|
|
|
|
|
|
return ret;
|
2008-05-16 09:10:35 +00:00
|
|
|
}
|
2010-04-23 15:22:55 +00:00
|
|
|
#endif
|
2008-05-16 09:10:35 +00:00
|
|
|
|
2018-11-05 18:01:15 +00:00
|
|
|
#ifdef CONFIG_ENV_ADDR
|
|
|
|
__weak void *env_sf_get_env_addr(void)
|
|
|
|
{
|
|
|
|
return (void *)CONFIG_ENV_ADDR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-12-14 12:07:08 +00:00
|
|
|
#if defined(INITENV) && defined(CONFIG_ENV_ADDR)
|
|
|
|
static int env_sf_init(void)
|
|
|
|
{
|
2018-11-05 18:01:15 +00:00
|
|
|
env_t *env_ptr = (env_t *)env_sf_get_env_addr();
|
2017-12-14 12:07:08 +00:00
|
|
|
|
|
|
|
if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
|
|
|
|
gd->env_addr = (ulong)&(env_ptr->data);
|
|
|
|
gd->env_valid = 1;
|
|
|
|
} else {
|
|
|
|
gd->env_addr = (ulong)&default_environment[0];
|
|
|
|
gd->env_valid = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-08-03 18:21:58 +00:00
|
|
|
U_BOOT_ENV_LOCATION(sf) = {
|
|
|
|
.location = ENVL_SPI_FLASH,
|
2017-08-03 18:22:03 +00:00
|
|
|
ENV_NAME("SPI Flash")
|
2017-08-03 18:22:01 +00:00
|
|
|
.load = env_sf_load,
|
2017-08-03 18:21:58 +00:00
|
|
|
#ifdef CMD_SAVEENV
|
2017-08-03 18:22:01 +00:00
|
|
|
.save = env_save_ptr(env_sf_save),
|
2017-08-03 18:21:58 +00:00
|
|
|
#endif
|
2017-12-14 12:07:08 +00:00
|
|
|
#if defined(INITENV) && defined(CONFIG_ENV_ADDR)
|
|
|
|
.init = env_sf_init,
|
|
|
|
#endif
|
2017-08-03 18:21:58 +00:00
|
|
|
};
|