aboutsummaryrefslogtreecommitdiff
path: root/tools/env
AgeCommit message (Collapse)Author
2024-07-15tools: Remove duplicate newlinesMarek Vasut
Drop all duplicate newlines. No functional change. Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
2024-01-05fw_env: autodetect NAND erase size and env sectorsAnthony Loiseau
As already done for NOR chips, if device ESIZE and ENVSECTORS static configurations are both zero, then autodetect them at runtime. Cc: Joe Hershberger <joe.hershberger@ni.com> cc: Stefan Agner <stefan@agner.ch> cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Signed-off-by: Anthony Loiseau <anthony.loiseau@allcircuits.com>
2024-01-05fw_env: keep calling read() until whole flash block is readRafał Miłecki
It's totally valid for read() to provide less bytes than requested maximum. It may happen if there is no more data available yet or source pushes data in small chunks. This actually happens when trying to read env data from NVMEM device. Kernel may provide NVMEM content in page size parts (like 4096 B). This fixes warnings like: Warning on /sys/bus/nvmem/devices/u-boot-env0/nvmem: Attempted to read 16384 bytes but got 4096 Warning on /sys/bus/nvmem/devices/u-boot-env0/nvmem: Attempted to read 12288 bytes but got 4096 Warning on /sys/bus/nvmem/devices/u-boot-env0/nvmem: Attempted to read 8192 bytes but got 4096 Since the main loop in flash_read_buf() is used to read blocks this patch adds a new nested one. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2024-01-05fw_env: rename variables holding env data contentRafał Miłecki
Rename "addr0" and "addr1" to "buf0" and "buf1" accordingly. Name "addr" suggests that variable contains a numeric value being some kind of address. Name "buf" is de facto a standard name for pointer to allocated memory for reading data to. While at it drop redundant checks for NULL before calling free(). Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2024-01-05fw_env: fix reading NVMEM device's "compatible" valueRafał Miłecki
Call to fread() was changed to check for return value. The problem is it can't be checked for returning 1 (as it is) to determine success. We call fread() with buffer size as "size" argument. Reading any "compatible" value shorter than buffer size will result in returning 0 even on success. Modify code to use fstat() to determine expected read length. This fixes regression that broke using fw_env with NVMEM devices. Fixes: c059a22b7776 ("tools: env: fw_env: Fix unused-result warning") Cc: Jaehoon Chung <jh80.chung@samsung.com> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2023-07-07Adjust gitignore for tools/generated/Tobias Deiminger
Tell git that auto-generated C sources are now exclusively expected under tools/generated/. Signed-off-by: Tobias Deiminger <tdmg@linutronix.de>
2023-04-25tools: env: update lock path in READMEJohn Keeping
Commit aeb40f1166e0 ("tools: env: use /run to store lockfile") updated the path to the lockfile but did not update the documentation to match. Use the new path in the documentation. Fixes: aeb40f1166 ("tools: env: use /run to store lockfile") Signed-off-by: John Keeping <john@metanate.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2023-04-06tools: env: use /run to store lockfileTim Lee
According this issue https://github.com/ppp-project/ppp/issues/339. Eventually, the dt-utils changed lock directory to fix missing /var/lock directory error then make dt-utils can run normally. We also have a similar issue with these two utilities fw_printenv and fw_setenv will failed when the directory /var/lock is non-existent. We have a custom linux distribution built with yocto (OpenBMC) that use systemd and it deprecated the /var/lock directory. More discussion in systemd/systemd#15668. Thus, we sync with community's solution for uboot/tools/env utilities: The current location /var/lock is considered legacy (at least by systemd). Just use /run to store the lockfile and append the usual .lock suffix. Tested: Verified /run/lock is now present and fw_printenv can work in OpenBMC. Signed-off-by: Tim Lee <timlee660101@gmail.com> Reviewed-by: Tom Rini <trini@konsulko.com>
2022-12-08tools: env: fw_env: Fix unused-result warningJaehoon Chung
Fix unused-result warning about fread. tools/env/fw_env.c: In function ‘find_nvmem_device’: tools/env/fw_env.c:1751:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result] 1751 | fread(buf, sizeof(buf), 1, fp); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
2022-09-29tools: env: Fix missing closedir in ubi_get_volnum_by_nameMiaoqian Lin
The function calls opendir() but missing the corresponding closedir() before exit the function. Add missing closedir() to fix it. Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
2022-07-08fw_env: add fallback to Linux's NVMEM based accessRafał Miłecki
A new DT binding for describing environment data block has been added in Linux's commit 5db1c2dbc04c ("dt-bindings: nvmem: add U-Boot environment variables binding"). Once we get a proper Linux NVMEM driver it'll be possible to use Linux's binary interface for user-space as documented in the: https://www.kernel.org/doc/html/latest/driver-api/nvmem.html This commits makes fw_env fallback to looking for a compatible NVMEM device in case config file isn't present. In a long term this may make config files redundant and avoid code (info) duplication. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2022-02-11fw_env: simplify logic & code paths in the fw_env_open()Rafał Miłecki
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-11fw_env: make flash_io() take buffer as an argumentRafał Miłecki
It's usually easier to understand code & follow it if all arguments are passed explicitly. Many coding styles also discourage using global variables. Behaviour of flash_io() was a bit unintuitive as it was writing to a buffer referenced in a global struct. That required developers to remember how it works and sometimes required hacking "environment" global struct variable to read data into a proper buffer. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
2021-12-20fw_setenv: Unbreak fw_setenv caused by buggy MEMISLOCKED useJoakim Tjernlund
Commit "fw_setenv: lock the flash only if it was locked before" checks for Locked status with uninitialized erase data. Address by moving the test for MEMISLOCKED. Fixes: 8a726b852502 ("fw_setenv: lock the flash only if it was locked before") Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com>
2021-09-02tools: env: Handle shorter read callsThibault Ferrante
On some cases, the actual number of bytes read can be shorter than what was requested. This can be handled gracefully by taking this difference into account instead of exiting. Signed-off-by: Thibault Ferrante <thibault.ferrante@gmail.com>
2021-01-22tools: env: return error if ubi_update_start() failsMartin Hundebøll
The UBI_IOCVOLUP ioctl can fail if exclusive access to the volume isn't obtained. If this happens, the flush operation doesn't return error, leaving the caller without knowledge of missing flush. Fix this by forwarding the error (-1) from ubi_update_start(). Fixes: 34255b92e6e ("tools: env: Add support for direct read/write UBI volumes") Signed-off-by: Martin Hundebøll <martin@geanix.com>
2020-08-05tools: env: Avoid an uninited warning with was_lockedSimon Glass
Set this variable to 0 to avoid a warning about an unused variable. This happens on gcc 7.5.0 for me. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-08-05tools: env: Fix printf() warning in fw_envSimon Glass
The printf() string produces a warning about %d not matching size_t. Fix it and put the format string on one line to avoid a checkpatch warning. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-31fw_setenv: lock the flash only if it was locked beforeIvan Mikhaylov
With current implementation of fw_setenv, it is always locks u-boot-env region if lock interface is implemented for such mtd device. You can not control lock of this region with fw_setenv, there is no option for it in config or in application itself. Because of this situation may happen problems like in this thread on xilinx forum: https://forums.xilinx.com/t5/Embedded-Linux/Flash-be-locked-after-use-fw-setenv-from-user-space /td-p/1027851 A short summary of that link is: some person has issue with some spi chip which has lock interface but doesn't locks properly which leads to lock of whole flash memory on lock of u-boot-env region. As resulted solution hack was added into spi-nor.c driver for this chip with lock disablement. Instead fix this problem by adding logic to fw_setenv only lock the flash if it was already locked when we attempted to use it. Signed-off-by: Ivan Mikhaylov <fr0st61te@gmail.com>
2020-06-02tools: fw_env: Fix warning when reading too littleHarald Seiler
When using CONFIG_ENV_IS_IN_FAT and the config-file specifies a size larger than what U-Boot wrote into the env-file, a confusing error message is shown: $ fw_printenv Read error on /boot/uboot.env: Success Fix this by showing a different error message when read returns too little data. Signed-off-by: Harald Seiler <hws@denx.de>
2020-05-25tools/env/fw_env.h: remove env.hRomain Naour
As reported by Nicolas Carrier on the Buildroot mailing list [1], there is a new build issue while building a program which interacts with the u-boot environment. This program uses the headers of the ubootenv library provided by uboot-tools. This is a recent change from uboot [2] adding "#include <env.h>" to fw_env.h. Adding env.h require a board configuration to build since it also include compiler.h (and others uboot internal includes). env.h include seems not needed since env_set() is not used in fw_env tool. Nicolas removed env.h from fw_env tool and fixed it's build issue. This problem is present since uboot v2019.10. [1] http://lists.busybox.net/pipermail/buildroot/2020-April/280307.html [2] https://gitlab.denx.de/u-boot/u-boot/-/commit/9fb625ce05539fe6876a59ce1dcadb76b33c6f6e Reported-by: Nicolas Carrier <nicolas.carrier@orolia.com> Signed-off-by: Romain Naour <romain.naour@gmail.com>
2020-04-27tools: fw_env: use erasesize from MEMGETINFO ioctlRasmus Villemoes
We have a board with several revisions. The older ones use a nor flash with 64k erase size, while the newer have a flash with 4k sectors. The environment size is 8k. Currently, we have to put a column containing 0x10000 (64k) in fw_env.config in order for it to work on the older boards. But that ends up wasting quite a lot of time on the newer boards that could just erase the 8k occupied by the environment - strace says the 64k erase takes 0.405 seconds. With this patch, as expected, that's about an 8-fold better, at 0.043 seconds. Having different fw_env.config files for the different revisions is highly impractical, and the correct information is already available right at our fingertips. So use the erasesize returned by the MEMGETINFO ioctl when the fourth and fifth columns (sector size and #sectors, respectively) are absent or contain 0, a case where the logic previously used to use the environment size as erase size (and consequently computed ENVSECTORS(dev) as 1). As I'm only testing this on a NOR flash, I'm only changing the logic for that case, though I think it should be possible for the other types as well. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2019-12-20fw_setenv: avoid writing environment when nothing has changedRasmus Villemoes
In the case where one deletes an already-non-existing variable, or sets a variable to the value it already has, there is no point in writing the environment back, thus reducing wear on the underlying storage device. In the case of redundant environments, if the two environments differ (e.g. because one is corrupt), make sure that any call of fw_setenv causes the two to become synchronized, even if the fw_setenv call does not change anything in the good copy. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2019-12-02crc32: Use the crc.h header for crc functionsSimon Glass
Drop inclusion of crc.h in common.h and use the correct header directly instead. With this we can drop the conflicting definition in fw_env.h and rely on the crc.h header, which is already included. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2019-09-24fw_env: fix build errorPierre-Jean Texier
The following error appears: tools/env/fw_env.c:1149:25: error: lvalue required as unary ‘&’ operand rc = write(fd, &ENV_REDUND_OBSOLETE, sizeof(ENV_REDUND_OBSOLETE)); Fixes: d3716dd ("env: Rename the redundancy flags") Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io> Tested-by: Joris Offouga <offougajoris@gmail.com> Tested-by: Heiko Schocher <hs@denx.de> Suggested-by: Heiko Schocher <hs@denx.de> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2019-09-24fw_env: remove duplicated definitionsPierre-Jean Texier
Since commit d3716dd ("env: Rename the redundancy flags"), the definitions of ENV_REDUND_OBSOLETE & ENV_REDUND_ACTIVE was moved to env.h. Fixes: tools/env/fw_env.c:122:22: error: ‘ENV_REDUND_ACTIVE’ redeclared as different kind of symbol static unsigned char ENV_REDUND_ACTIVE = 1; ^~~~~~~~~~~~~~~~~ In file included from tools/env/fw_env.c:13: include/env.h:63:2: note: previous definition of ‘ENV_REDUND_ACTIVE’ was here ENV_REDUND_ACTIVE = 1, ^~~~~~~~~~~~~~~~~ tools/env/fw_env.c:127:22: error: ‘ENV_REDUND_OBSOLETE’ redeclared as different kind of symbol static unsigned char ENV_REDUND_OBSOLETE; ^~~~~~~~~~~~~~~~~~~ In file included from tools/env/fw_env.c:13: include/env.h:62:2: note: previous definition of ‘ENV_REDUND_OBSOLETE’ was here ENV_REDUND_OBSOLETE = 0, Signed-off-by: Pierre-Jean Texier <pjtexier@koncepto.io> Tested-by: Joris Offouga <offougajoris@gmail.com> Tested-by: Heiko Schocher <hs@denx.de> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2019-08-11env: Rename the redundancy flagsSimon Glass
Add an ENV prefix to these two flags so that it is clear what they relate to. Also move them to env.h since they are part of the public API. Use an enum rather than a #define to tie them together. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-08-11env: Move env_set() to env.hSimon Glass
Move env_set() over to the new header file. Acked-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Simon Glass <sjg@chromium.org>
2019-06-20fw_env: Add missing write failure checkAlex Kiernan
If flash_write fails, whilst we propagate this up to our caller, we need to avoid swapping in the new file (if we're on a filesystem) in this case. Fixes: dbc34323796b ("tools: env: Implement atomic replace for filesystem") Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2019-05-05env: add missing newlinePhilip Molloy
Signed-off-by: Philip Molloy <philip@philipmolloy.com>
2019-04-26fw_env: Fix double freeBjörn Stenberg
addr0 is being freed twice, leading to segmentation fault Signed-off-by: Björn Stenberg <bjorn@haxx.se>
2018-09-10include/version.h: workaround sysroot inc orderMatt Weber
On some systems the host system or even the cross sysroot can contain a version.h. This leads to the wrong file being picked up and a PLAIN_VERSION undefined error. This workaround symlinks the version.h into the tool folder to allow reordering of search folders. Fixes http://autobuild.buildroot.net/results/770/7702d5df36a6532aafdbe6e9e62709bbfa058b54/build-end.log http://autobuild.buildroot.net/results/e34/e3401027d2fb3ce565ca9e2456a427afd3610a87/build-end.log ... additional can be found with these queries ... http://autobuild.buildroot.net/?reason=uboot-tools-2018.03 http://autobuild.buildroot.net/?reason=uboot-tools-2018.05 Upstream: pending Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
2018-07-01Revert "fw_printenv: Don't bail out directly after one env read error"Tom Rini
As pointed out by Wolfgang Denk, the problem with this fix is that while interactive users will see that we have found one part of the environment failed and are using the other, progmatic use will not see this and can lead to problems. Signed-off-by: Tom Rini <trini@konsulko.com>
2018-06-27fw_printenv: Don't bail out directly after one env read errorJoe Hershberger
When using a redundant environment a read error should simply mean to not use that copy instead of giving up completely. The other copy may be just fine. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Ioan-Adrian Ratiu <adrian.ratiu@ni.com>
2018-06-13u-boot: Fix several typosShyam Saini
's/environemnt/environment/' and 's/Environemnt/Environment/' Signed-off-by: Shyam Saini <shyam@amarulasolutions.com>
2018-06-13tools: env: Use getline rather than fgets when reading config/scriptAlex Kiernan
When reading the config file, or a script file, use getline rather than fgets so line lengths aren't limited by the size of a compiled in buffer (128 characters for config, 1024 for scripts). Rename 'dump' to 'line' so it's clear we're working with a line of text. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2018-05-07SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <trini@konsulko.com>
2018-04-10fw_printenv: Fix crash due to incorrect size for malloc'ed string.Kristian Amlie
Using sizeof gives the size of the pointer only, not the string. This could easily lead to crashes when using -l argument. Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>
2018-03-19tools: env: Implement atomic replace for filesystemAlex Kiernan
If the U-Boot environment is stored in a regular file and redundant operation isn't set, then write to a temporary file and perform an atomic rename. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2018-03-19tools: env: Refactor write path of flash_io()Alex Kiernan
Extract write path of flash_io() into a separate function. This patch should be a functional no-op. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com> Reviewed-by: Stefano Babic <sbabic@denx.de>
2018-03-19tools: env: Fix CamelCasing style violationAlex Kiernan
Replace HaveRedundEnv with have_redund_env to fix style violation. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2018-03-19tools: env: Pass through indentAlex Kiernan
Pass tools/env/fw_env.c through indent to correct style violations. This commit consists of only one non-whitespace change: tools/env/fw_env.c:549: error: do not use assignment in if condition Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2018-03-05tools/env: allow equal sign as key value separationStefan Agner
Treat the first equal sign as a key/value separation too. This makes the script files compatible with mkenvimage input file format. It won't support variables with equal signs anymore, but this seems not really like a loss. Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
2018-02-14Fix --noheader on fw_printenvAlex Kiernan
The single argument `--noheader' is expecting isn't taken from getopt parsing, but instead from the remaining argv arguments. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2018-01-28tools: remove unused retJelle van der Waa
Remove unused ret from fw_env_flush. Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-11-29tools: env: Add support for direct read/write UBI volumesS. Lockwood-Childs
Up to now we were able to read/write environment data from/to UBI volumes only indirectly by gluebi driver. This driver creates NAND MTD on top of UBI volumes, which is quite a workaroung for this use case. Add support for direct read/write UBI volumes in order to not use obsolete gluebi driver. Forward-ported from this patch: http://patchwork.ozlabs.org/patch/619305/ Original patch: Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com> Forward port: Signed-off-by: S. Lockwood-Childs <sjl@vctlabs.com>
2017-11-21env: Remove CONFIG_ENV_AES supportTom Rini
This support has been deprecated since v2017.09 due to security issues. We now remove this support. Signed-off-by: Tom Rini <trini@konsulko.com>
2017-11-06tools: env: allow to print U-Boot versionStefan Agner
The fw_env utility family has a default environment compiled in which ties it quite strongly to the U-Boot source/config it has been built with. Allow to display the U-Boot version it has been built with using the -v/--version argument. Signed-off-by: Stefan Agner <stefan.agner@toradex.com> Reviewed-by: Lukasz Majewski <lukma@denx.de>
2017-10-16tools: env: Add embedded.c to .gitignoreBin Meng
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2017-09-05env: Add 'envtools' target to 'make help'Simon Glass
The target is not currently mentioned anywhere. Add it to the help so people can find it. Signed-off-by: Simon Glass <sjg@chromium.org>