summaryrefslogtreecommitdiff
path: root/tools/env/fw_env.c
AgeCommit message (Collapse)Author
2017-09-05env: Fix out of tree building of tools-allTom Rini
With the move of environment code from common/ to env/ a number of changes needed to be made to various make targets. We missed updating some of the files required for out of tree builds of the tools. Correct the 'environ' target to know that we need to work under tools/env/ still (not tools/environ/) and then update the wrappers in env_attr.c and env_flags.c to point to the new correct file. Reported-by: Peter Robinson <pbrobinson@gmail.com> Tested-by: Peter Robinson <pbrobinson@gmail.com> Signed-off-by: Tom Rini <trini@konsulko.com>
2017-09-03fix: fw_env: Prevent writing error message on special files, which don't ↵Lukasz Majewski
support fsync According to fsync specification [1] some special files (e.g., a pipe, FIFO, or socket) don't support synchronization and return either EROFS or EINVAL. On the linux side the sys_fsync -> do_fsync() checks if the requested file has f_op->fsync defined. If not it returns EINVAL [2]. This commit prevents writing error messages for files (devices), which do not support fsync(). [1] - http://man7.org/linux/man-pages/man2/fsync.2.html [2] - http://elixir.free-electrons.com/linux/v4.13-rc6/source/fs/sync.c#L183 Signed-off-by: Lukasz Majewski <lukma@denx.de> Acked-by: Michael Heimpold <mhei@heimpold.de>
2017-08-16env: Rename setenv() to env_set()Simon Glass
We are now using an env_ prefix for environment functions. Rename setenv() for consistency. Also add function comments in common.h. Suggested-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Simon Glass <sjg@chromium.org>
2017-07-22tools/fw_env: use fsync to ensure that data is physically storedMichael Heimpold
Closing a file descriptor does not guarantee that the data has been successfully saved to disk, as the kernel might defer the write. Signed-off-by: Michael Heimpold <mhei@heimpold.de>
2017-04-18tools/env: avoid memory leak in fw_setenvxypron.glpk@gmx.de
If realloc fails we should release the old buffer. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-04-12env: fix memory leak in fw_env routinesStefano Babic
fw_env_open allocates buffers to store the environment, but these buffers are never freed. This becomes quite nasty using the fw_ tools as library, because each access to the environment (even just reading a variable) generates a memory leak equal to the size of the environment. Fix this renaming fw_env_close() as fw_env_flush(), because the function really flushes the environment from RAM to storage, and add a fw_env_close function to free the allocated resources. Signed-off-by: Stefano Babic <sbabic@denx.de>
2017-04-12env: split fw_env.h in public and private partsStefano Babic
Move U-Boot private data into a separate file. This lets export fw_env.h to be used by external programs that want to change the environment using the library built in tools/env. Signed-off-by: Stefano Babic <sbabic@denx.de>
2016-11-28tools/env: fix environment alignment tests for block devicesMax Krummenacher
commit 183923d3e412500bdc597d1745e2fb6f7f679ec7 enforces that the environment must start at an erase block boundary. For block devices the sample fw_env.config does not mandate a erase block size for block devices. A missing setting defaults to the full env size. Depending on the environment location the alignment check now errors out for perfectly legal settings. Fix this by defaulting to the standard blocksize of 0x200 for environments stored in a block device. That keeps the fw_env.config files for block devices working even with that new check. Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
2016-10-07Suspected Spam: Do not open attachements![PATCH 4/6] tools/env: ↵Andreas Fenkart
flash_write_buf: enforce offset to be start of environment This allows to take advantage of the environment being block aligned. This is not a new constraint. Writes always start at the begin of the environment, since the header with CRC/length as there. Every environment modification requires updating the header Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-10-07tools/env: lookup dev_type directly from flash_read_buf/flash_write_bufAndreas Fenkart
flash_write_buf already looks up size/offset/#sector from struct envdev_s. It can look up mtd_type as well. Same applies to flash_read_buf. Makes the interface simpler Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-10-07tools/env: pass bad block offset by valueAndreas Fenkart
the offset is not modified by linux ioctl call see mtd_ioctl{drivers/mtd/mtdchar.c} Makes the interface less ambiguous, since the caller can now exclude a modification of blockstart Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-10-07tools/env: factor out environment_end functionAndreas Fenkart
instead of adhoc computation of the environment end, use a function with a proper name Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-08-20tools/env: soften warning about erase block alignmentAndreas Fenkart
addon 183923d3e MMC/SATA have no erase blocks, only blocks. Hence the warning about erase block alignment might be confusing in such environment. Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-08-20tools/env: return with error if redundant environments have unequal sizeAndreas Fenkart
For double buffering to work, the target buffer must always be big enough to hold all data. This can only be ensured if buffers are of equal size, otherwise one must be smaller and we risk data loss when copying from the bigger to the smaller buffer. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com> Reviewed-by: Tom Rini <trini@konsulko.com>
2016-08-15tools/env: ensure environment starts at erase block boundaryAndreas Fenkart
56086921 added support for unaligned environments access. U-boot itself does not support this: - env_nand.c fails when using an unaligned offset. It produces an error in nand_erase_opts{drivers/mtd/nand/nand_util.c} - in env_sf/env_flash the unused space at the end is preserved, but not in the beginning. block alignment is assumed - env_sata/env_mmc aligns offset/length to the block size of the underlying device. data is silently redirected to the beginning of a block There is seems no use case for unaligned environment. If there is some useful data at the beginning of the the block (e.g. end of u-boot) that would be very unsafe. If the redundant environments are hosted by the same erase block then that invalidates the idea of double buffering. It might be that unaligned access was allowed in the past, and that people with legacy u-boot are trapped. But at the time of 56086921 it wasn't supported and due to reasons above I guess it was never introduced. I prefer to remove that (unused) feature in favor of simplicity Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com> Acked-by: Stefan Agner <stefan.agner@toradex.com>
2016-07-26tools: env: Fix format warnings in debugMarcin Niestroj
Format warnings (-Wformat) were shown in printf() calls after defining DEBUG macro. Update format string and explicitly cast variables to suppress all warnings. Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2016-07-22tools/env: reuse fw_getenv in fw_printenv functionAndreas Fenkart
Try to avoid adhoc iteration of the environment. Reuse fw_getenv to find the variables that should be printed. Only use open-coded iteration when printing all variables. For backwards compatibility, keep emitting a newline when printing with value_only. Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-07-22tools/env: move envmatch further up in file to avoid forward declarationsAndreas Fenkart
forward declaration not needed when re-ordered Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-07-22tools/env: kernel-doc for fw_printenv, fw_getenv and fw_parse_scriptAndreas Fenkart
there are two groups of functions: - application ready tools: fw_setenv/fw_getenv/fw_parse_script these are used, when creating a single binary containing multiple tools (busybox like) - file access like: open/read/write/close above functions are implemented on top of these. applications can use those to modify several variables without creating a temporary batch script file tested with "./scripts/kernel-doc -html -v tools/env/fw_env.h" Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-07-22tools/env: allow negative offsetsStefan Agner
A negative value for the offset is treated as a backwards offset for from the end of the device/partition for block devices. This aligns the behavior of the config file with the syntax of CONFIG_ENV_OFFSET where the functionality has been introduced with commit 5c088ee841f9 ("env_mmc: allow negative CONFIG_ENV_OFFSET"). Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
2016-07-22tools/env: complete environment device config earlyStefan Agner
Currently flash_read completes a crucial part of the environment device configuration, the device type (mtd_type). This is rather confusing as flash_io calls flash_read conditionally, and one might think flash_write, which also makes use of mtd_type, gets called before flash_read. But since flash_io is always called with O_RDONLY first, this is not actually the case in reality. However, it is much cleaner to complete and verify the config early in parse_config. This also prepares the code for further extension. Signed-off-by: Stefan Agner <stefan.agner@toradex.com> Reviewed-by: Andreas Fenkart
2016-05-31tools/env: allow to pass NULL for environment optionsAndreas Fenkart
If users of the library are happy with the default, e.g. config file name. They can pass NULL as the opts pointer. This simplifies the transition of existing library users. FIXES a compile error. since common_args has been removed by a previous patch Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-05-27tools/env: no global variable sharing between application and libraryAndreas Fenkart
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-05-27tools/env: compute size of usable area only onceAndreas Fenkart
for double buffering to work, redundant buffers must have equal size Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-05-27tools/env: fw_printenv pass value_only as argumentAndreas Fenkart
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-05-27tools/env: pass key as argument to env_aes_cbc_cryptAndreas Fenkart
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-05-02tools: env: fix config file loading in env libraryAnatolij Gustschin
env library is broken as the config file pointer is only initialized in main(). When running in the env library parse_config() fails: Cannot parse config file '(null)': Bad address Ensure that config file pointer is always initialized. Signed-off-by: Anatolij Gustschin <agust@denx.de> Cc: Stefano Babic <sbabic@denx.de>
2016-03-27tools: env: bug: config structs must be defined in tools libraryAndreas Fenkart
fw_senten/fw_printenv can be compiled as a tools library, excluding the fw_env_main object. Reported-by: Stefano Babic <sbabic@denx.de> Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-03-26tools: env: fw_parse_script: simplify removal of newline/carriage returnAndreas Fenkart
fgets returns when the first '\n' is found Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-03-26tools: env: split fw_string_blank into skip_chars / skip_blanksAndreas Fenkart
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-03-26tools: env: fw_string_blank: return from loop when item foundAndreas Fenkart
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-03-26tools: env: replace WHITESPACE macro by isblankAndreas Fenkart
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-02-08tools: env: shift optind arguments and fix argument indicesAndreas Fenkart
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-02-08tools: env: parse aes key / suppress flag into argument structAndreas Fenkart
disabled original parsing, but not yet removed since the argument indexing needs to be fixed Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-02-08tools: env: make parse_aes_key statelessAndreas Fenkart
Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2016-02-08tools: env validate: pass values as 0-based arrayAndreas Fenkart
passing argv/argc can produce off-by-one errors Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
2015-12-14tools: env: include compiler.hPeter Robinson
With gcc 5.2 and later we get a bunch of "error: unknown type name" for 'uint8_t', 'uint32_t' and friends. Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
2015-11-18tools/env: allow config filename to be passed via command line argumentMichael Heimpold
When for example generating/manipulating SD card/eMMC images which contain U-Boot and its environment(s), it is handy to use a given configuration file instead of the compiled-in default one. And since the default configuration file is expected under /etc it's hard for an usual linux user account without special permissions to use fw_printenv/fw_setenv for this purpose. So allow to pass an optional filename via a new '-c' command line argument. Example: $ ln -s fw_printenv tools/env/fw_setenv $ cat fw_env.config test.img 0x20000 0x20000 test.img 0x40000 0x20000 $ tools/env/fw_printenv -c ./fw_env.config fdt_file fdt_file=imx28-duckbill.dtb $ tools/env/fw_setenv -c ./fw_env.config fdt_file imx28-duckbill-spi.dtb $ tools/env/fw_printenv -c ./fw_env.config fdt_file fdt_file=imx28-duckbill-spi.dtb Signed-off-by: Michael Heimpold <mhei@heimpold.de>
2015-05-08Fix musl buildJörg Krause
This patch fixes cross-compiling U-Boot tools with the musl C library: * including <sys/types.h> is needed for ulong * defining _GNU_SOURCE is needed for loff_t Tested for target at91sam9261ek_dataflash_cs3. Signed-off-by: Jörg Krause <joerg.krause@embedded.rocks> Cc: Tom Rini <trini@konsulko.com>
2014-11-07tools/env: Fix environment size and CRC on 64-bit hostsDominic Sacré
On architectures where 'long' is 64 bit, the u-boot environment as seen by the fw_env tools was missing 4 bytes. This patch fixes getenvsize(), and thus also ensures that the environment's CRC32 checksum is calculated correctly. Signed-off-by: Dominic Sacré <dominic.sacre@gmx.de> Cc: Wolfgang Denk <wd@denx.de> Cc: Tom Rini <trini@ti.com>
2014-05-09Merge branch 'u-boot/master'Albert ARIBAUD
Conflicts: drivers/net/Makefile (trivial merge)
2014-04-17fw_env.c: Switch get_config to use '%ms' in sscanfTom Rini
We currently limit ourself to 16 characters for the device name to read the environment from. This is insufficient for /dev/mmcblk0boot1 to work for example. Switch to '%ms' which gives us a dynamically allocated buffer instead. We're short lived enough to not bother free()ing the buffer. Signed-off-by: Tom Rini <trini@ti.com>
2014-03-21env: Implement support for AES encryption into fw_* toolsMarek Vasut
Implement support for encrypting/decrypting the environment block into the tools/env/fw_* tools. The cipher used is AES 128 CBC and the implementation depends solely on components internal to U-Boot. To allow building against the internal AES library, the library did need minor adjustments to not include U-Boot's headers which are not wanted to be included and define missing types. Signed-off-by: Marek Vasut <marex@denx.de>
2014-03-12fw_env: correct writes to devices with small erase blocksDustin Byford
Some NOR flash devices have a small erase block size. For example, the Micron N25Q512 can erase in 4K blocks. These devices expose a bug in fw_env.c where flash_write_buf() incorrectly calculates bytes written and attempts to write past the environment sectors. Luckily, a range check prevents any real damage, but this does cause fw_setenv to fail with an error. This change corrects the write length calculation. The bug was introduced with commit 56086921 from 2008 and only affects configurations where the erase block size is smaller than the total environment data size. Signed-off-by: Dustin Byford <dustin@cumulusnetworks.com>
2014-03-12fw_env: calculate default number of env sectorsDustin Byford
The assumed number of environment sectors (always 1) leads to an incorrect top_of_range calculation in fw.env.c when a flash device has an erase block size smaller than the environment data size (number of environment sectors > 1). This change updates the default number of environment sectors to at least cover the size of the environment. Also corrected a false statement about the number of sectors column in fw_env.config. Signed-off-by: Dustin Byford <dustin@cumulusnetworks.com>
2013-09-06fw_env: fix writing environment for mtd devicesOliver Metz
Signed-off-by: Oliver Metz <oliver@freetz.org> Tested-by: Luka Perkov <luka@openwrt.org>
2013-09-06fw_env: add redundant env support for MTD_ABSENTOliver Metz
Signed-off-by: Oliver Metz <oliver@freetz.org> Tested-by: Luka Perkov <luka@openwrt.org>
2013-07-24Add GPL-2.0+ SPDX-License-Identifier to source filesWolfgang Denk
Signed-off-by: Wolfgang Denk <wd@denx.de> [trini: Fixup common/cmd_io.c] Signed-off-by: Tom Rini <trini@ti.com>
2013-04-11env: Add redundant env support to UBI envJoe Hershberger
Allow the user to specify two UBI volumes to use for the environment Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
2013-04-11env: Add support for UBI environmentJoe Hershberger
UBI is a better place for the environment on NAND devices because it handles wear-leveling and bad blocks. Gluebi is needed in Linux to access the env as an MTD partition. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>