u-boot/tools/env
Rafał Miłecki 07c79dd5fd fw_env: simplify logic & code paths in the fw_env_open()
Environment variables can be stored in two formats:
1. Single entry with header containing CRC32
2. Two entries with extra flags field in each entry header

For that reason fw_env_open() has two main code paths and there are
pointers for CRC32/flags/data.

Previous implementation was a bit hard to follow:
1. It was checking for used format twice (in reversed order each time)
2. It was setting "environment" global struct fields to some temporary
   values that required extra comments explaining it

This change simplifies that code:
1. It introduces two clear code paths
2. It sets "environment" global struct fields values only once it really
   knows them

To be fair there are *two* crc32() calls now and an extra pointer
variable but that should be cheap enough and worth it.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2022-02-11 11:29:23 -05:00
..
.gitignore tools: env: Add embedded.c to .gitignore 2017-10-16 09:42:51 -04:00
crc32.c tools: convert makefiles to kbuild style 2014-02-19 11:07:49 -05:00
ctype.c tools: convert makefiles to kbuild style 2014-02-19 11:07:49 -05:00
env_attr.c env: Fix out of tree building of tools-all 2017-09-05 15:59:47 -04:00
env_flags.c env: Fix out of tree building of tools-all 2017-09-05 15:59:47 -04:00
fw_env.c fw_env: simplify logic & code paths in the fw_env_open() 2022-02-11 11:29:23 -05:00
fw_env.config tools: env: Add support for direct read/write UBI volumes 2017-11-29 22:30:50 -05:00
fw_env.h tools/env/fw_env.h: remove env.h 2020-05-25 11:54:53 -04:00
fw_env_main.c env: Move env_set() to env.h 2019-08-11 16:43:41 -04:00
fw_env_private.h SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
linux_string.c tools: convert makefiles to kbuild style 2014-02-19 11:07:49 -05:00
Makefile include/version.h: workaround sysroot inc order 2018-09-10 20:20:34 -04:00
README env: Add 'envtools' target to 'make help' 2017-09-05 20:34:09 -04:00

This is a demo implementation of a Linux command line tool to access
the U-Boot's environment variables.

In order to cross-compile fw_printenv, run
    make CROSS_COMPILE=<your cross-compiler prefix> envtools
in the root directory of the U-Boot distribution. For example,
    make CROSS_COMPILE=arm-linux- envtools

You should then create a symlink from fw_setenv to fw_printenv. They use
the same program and its function depends on its basename.

For the run-time utility configuration uncomment the line
#define CONFIG_FILE  "/etc/fw_env.config"
in fw_env.h.

For building against older versions of the MTD headers (meaning before
v2.6.8-rc1) it is required to pass the argument "MTD_VERSION=old" to
make.

See comments in the fw_env.config file for definitions for the
particular board.

Configuration can also be done via #defines in the fw_env.h file. The
following lines are relevant:

#define HAVE_REDUND	/* For systems with 2 env sectors */
#define DEVICE1_NAME	"/dev/mtd1"
#define DEVICE2_NAME	"/dev/mtd2"
#define DEVICE1_OFFSET    0x0000
#define ENV1_SIZE         0x4000
#define DEVICE1_ESIZE     0x4000
#define DEVICE1_ENVSECTORS     2
#define DEVICE2_OFFSET    0x0000
#define ENV2_SIZE         0x4000
#define DEVICE2_ESIZE     0x4000
#define DEVICE2_ENVSECTORS     2

Un-define HAVE_REDUND, if you want to use the utilities on a system
that does not have support for redundant environment enabled.
If HAVE_REDUND is undefined, DEVICE2_NAME is ignored,
as is ENV2_SIZE and DEVICE2_ESIZE.

The DEVICEx_NAME constants define which MTD character devices are to
be used to access the environment.

The DEVICEx_OFFSET constants define the environment offset within the
MTD character device.

ENVx_SIZE defines the size in bytes taken by the environment, which
may be less then flash sector size, if the environment takes less
then 1 sector.

DEVICEx_ESIZE defines the size of the first sector in the flash
partition where the environment resides.

DEVICEx_ENVSECTORS defines the number of sectors that may be used for
this environment instance. On NAND this is used to limit the range
within which bad blocks are skipped, on NOR it is not used.

To prevent losing changes to the environment and to prevent confusing the MTD
drivers, a lock file at /var/lock/fw_printenv.lock is used to serialize access
to the environment.