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>
|
2019-08-01 15:47:00 +00:00
|
|
|
#include <env.h>
|
2019-08-02 15:44:25 +00:00
|
|
|
#include <env_internal.h>
|
2020-05-10 17:39:54 +00:00
|
|
|
#include <flash.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>
|
2020-05-10 17:39:54 +00:00
|
|
|
#include <uuid.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2016-01-26 07:06:42 +00:00
|
|
|
#include <dm/device-internal.h>
|
2019-11-14 19:57:16 +00:00
|
|
|
#include <u-boot/crc.h>
|
2008-05-16 09:10:35 +00:00
|
|
|
|
2017-08-03 18:21:58 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
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
|
2011-11-07 01:14:08 +00:00
|
|
|
static ulong env_offset = CONFIG_ENV_OFFSET;
|
|
|
|
static ulong env_new_offset = CONFIG_ENV_OFFSET_REDUND;
|
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
|
|
|
{
|
2020-06-04 15:11:53 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_SPI_FLASH)
|
2016-01-26 07:06:42 +00:00
|
|
|
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) {
|
2019-08-01 15:47:00 +00:00
|
|
|
env_set_default("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
|
2020-05-13 11:02:42 +00:00
|
|
|
if (env_flash)
|
|
|
|
spi_flash_free(env_flash);
|
2010-04-23 15:22:55 +00:00
|
|
|
|
2020-05-13 11:02:42 +00:00
|
|
|
env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
|
|
|
|
CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
|
2010-04-23 15:22:55 +00:00
|
|
|
if (!env_flash) {
|
2020-05-13 11:02:42 +00:00
|
|
|
env_set_default("spi_flash_probe() failed", 0);
|
|
|
|
return -EIO;
|
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:22:01 +00:00
|
|
|
static int env_sf_save(void)
|
2017-04-08 09:59:31 +00:00
|
|
|
{
|
|
|
|
env_t env_new;
|
2019-08-01 15:47:08 +00:00
|
|
|
char *saved_buffer = NULL, flag = ENV_REDUND_OBSOLETE;
|
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;
|
2019-08-01 15:47:08 +00:00
|
|
|
env_new.flags = ENV_REDUND_ACTIVE;
|
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;
|
|
|
|
}
|
2019-03-13 11:15:45 +00:00
|
|
|
ret = spi_flash_read(env_flash, saved_offset,
|
|
|
|
saved_size, saved_buffer);
|
2010-04-23 15:22:55 +00:00
|
|
|
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
|
|
|
|
2021-01-04 13:41:31 +00:00
|
|
|
done:
|
2010-04-23 15:22:55 +00:00
|
|
|
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: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) {
|
2019-08-01 15:47:00 +00:00
|
|
|
env_set_default("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
|
|
|
|
2019-03-13 11:15:45 +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,
|
2020-07-07 18:51:35 +00:00
|
|
|
read2_fail, H_EXTERNAL);
|
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: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
|
|
|
|
2019-03-13 11:15:45 +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
|
|
|
|
2021-01-04 13:41:31 +00:00
|
|
|
done:
|
2008-12-11 11:23:37 +00:00
|
|
|
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: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) {
|
2019-08-01 15:47:00 +00:00
|
|
|
env_set_default("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;
|
|
|
|
|
2019-03-13 11:15:45 +00:00
|
|
|
ret = spi_flash_read(env_flash,
|
|
|
|
CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, buf);
|
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 (ret) {
|
2019-08-01 15:47:00 +00:00
|
|
|
env_set_default("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
|
|
|
|
2020-07-07 18:51:35 +00:00
|
|
|
ret = env_import(buf, 1, H_EXTERNAL);
|
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
|
|
|
|
2019-11-19 01:02:10 +00:00
|
|
|
#if CONFIG_ENV_ADDR != 0x0
|
2018-11-05 18:01:15 +00:00
|
|
|
__weak void *env_sf_get_env_addr(void)
|
|
|
|
{
|
|
|
|
return (void *)CONFIG_ENV_ADDR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-11-19 01:02:10 +00:00
|
|
|
#if defined(INITENV) && (CONFIG_ENV_ADDR != 0x0)
|
2020-10-10 08:28:05 +00:00
|
|
|
/*
|
|
|
|
* check if Environment on CONFIG_ENV_ADDR is valid.
|
|
|
|
*/
|
|
|
|
static int env_sf_init_addr(void)
|
2017-12-14 12:07:08 +00:00
|
|
|
{
|
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
|
|
|
|
|
2020-10-10 08:28:05 +00:00
|
|
|
#if defined(CONFIG_ENV_SPI_EARLY)
|
|
|
|
/*
|
|
|
|
* early load environment from SPI flash (before relocation)
|
|
|
|
* and check if it is valid.
|
|
|
|
*/
|
|
|
|
static int env_sf_init_early(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int read1_fail;
|
|
|
|
int read2_fail;
|
|
|
|
int crc1_ok;
|
|
|
|
env_t *tmp_env2 = NULL;
|
|
|
|
env_t *tmp_env1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if malloc is not ready yet, we cannot use
|
|
|
|
* this part yet.
|
|
|
|
*/
|
|
|
|
if (!gd->malloc_limit)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
tmp_env1 = (env_t *)memalign(ARCH_DMA_MINALIGN,
|
|
|
|
CONFIG_ENV_SIZE);
|
|
|
|
if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
|
|
|
|
tmp_env2 = (env_t *)memalign(ARCH_DMA_MINALIGN,
|
|
|
|
CONFIG_ENV_SIZE);
|
|
|
|
|
|
|
|
if (!tmp_env1 || !tmp_env2)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = setup_flash_device();
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
read1_fail = spi_flash_read(env_flash, CONFIG_ENV_OFFSET,
|
|
|
|
CONFIG_ENV_SIZE, tmp_env1);
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT)) {
|
|
|
|
read2_fail = spi_flash_read(env_flash,
|
|
|
|
CONFIG_ENV_OFFSET_REDUND,
|
|
|
|
CONFIG_ENV_SIZE, tmp_env2);
|
|
|
|
ret = env_check_redund((char *)tmp_env1, read1_fail,
|
|
|
|
(char *)tmp_env2, read2_fail);
|
|
|
|
|
|
|
|
if (ret == -EIO || ret == -ENOMSG)
|
|
|
|
goto err_read;
|
|
|
|
|
|
|
|
if (gd->env_valid == ENV_VALID)
|
|
|
|
gd->env_addr = (unsigned long)&tmp_env1->data;
|
|
|
|
else
|
|
|
|
gd->env_addr = (unsigned long)&tmp_env2->data;
|
|
|
|
} else {
|
|
|
|
if (read1_fail)
|
|
|
|
goto err_read;
|
|
|
|
|
|
|
|
crc1_ok = crc32(0, tmp_env1->data, ENV_SIZE) ==
|
|
|
|
tmp_env1->crc;
|
|
|
|
if (!crc1_ok)
|
|
|
|
goto err_read;
|
|
|
|
|
|
|
|
/* if valid -> this is our env */
|
|
|
|
gd->env_valid = ENV_VALID;
|
|
|
|
gd->env_addr = (unsigned long)&tmp_env1->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err_read:
|
|
|
|
spi_flash_free(env_flash);
|
|
|
|
env_flash = NULL;
|
|
|
|
free(tmp_env1);
|
|
|
|
if (IS_ENABLED(CONFIG_SYS_REDUNDAND_ENVIRONMENT))
|
|
|
|
free(tmp_env2);
|
|
|
|
out:
|
|
|
|
/* env is not valid. always return 0 */
|
|
|
|
gd->env_valid = ENV_INVALID;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int env_sf_init(void)
|
|
|
|
{
|
|
|
|
#if defined(INITENV) && (CONFIG_ENV_ADDR != 0x0)
|
|
|
|
return env_sf_init_addr();
|
|
|
|
#elif defined(CONFIG_ENV_SPI_EARLY)
|
|
|
|
return env_sf_init_early();
|
|
|
|
#endif
|
|
|
|
/*
|
2020-11-03 14:22:36 +00:00
|
|
|
* return here -ENOENT, so env_init()
|
|
|
|
* can set the init bit and later if no
|
|
|
|
* other Environment storage is defined
|
|
|
|
* can set the default environment
|
2020-10-10 08:28:05 +00:00
|
|
|
*/
|
2020-11-03 14:22:36 +00:00
|
|
|
return -ENOENT;
|
2020-10-10 08:28:05 +00:00
|
|
|
}
|
|
|
|
|
2017-08-03 18:21:58 +00:00
|
|
|
U_BOOT_ENV_LOCATION(sf) = {
|
|
|
|
.location = ENVL_SPI_FLASH,
|
2020-07-28 09:51:16 +00:00
|
|
|
ENV_NAME("SPIFlash")
|
2017-08-03 18:22:01 +00:00
|
|
|
.load = env_sf_load,
|
env/sf.c: honour CONFIG_SPL_SAVEENV
Deciding whether to compile the env_sf_save() function based solely on
CONFIG_SPL_BUILD is wrong: For U-Boot proper, it leads to a build
warning in case CONFIG_CMD_SAVEENV=n (because the initialization of
the .save member is guarded by CONFIG_CMD_SAVEENV, while the
env_sf_save() function is built if !CONFIG_SPL_BUILD - and even
without the CONFIG_CMD_SAVEENV guard, the env_save_ptr() macro would
just expand to NULL, with no reference to env_sf_save visible to the
compiler). And for SPL, when one selects CONFIG_SPL_SAVEENV, one
obviously expects to actually be able to save the environment.
The compiler warning can be fixed by using a "<something> ?
env_sf_save : NULL" construction instead of a macro that just eats its
argument and expands to NULL. That way, if <something> is false,
env_sf_save gets eliminated as dead code, but the compiler still sees
the reference to it.
For <something>, we can use CONFIG_IS_ENABLED(SAVEENV), which is true
precisely:
- For U-Boot proper, when CONFIG_CMD_SAVEENV is set (because
CONFIG_SAVEENV is a hidden config symbol that gets set if and only
if CONFIG_CMD_SAVEENV is set).
- For SPL, when CONFIG_SPL_SAVEENV is set.
As a bonus, this also removes quite a few preprocessor conditionals.
This has been run-time tested on a mpc8309-derived board to verify
that saving the environment does indeed work in SPL with these patches
applied.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2020-03-26 23:02:00 +00:00
|
|
|
.save = CONFIG_IS_ENABLED(SAVEENV) ? ENV_SAVE_PTR(env_sf_save) : NULL,
|
2017-12-14 12:07:08 +00:00
|
|
|
.init = env_sf_init,
|
2017-08-03 18:21:58 +00:00
|
|
|
};
|