summaryrefslogtreecommitdiff
path: root/tools/env/fw_env.c
Commit message (Collapse)AuthorAgeLines
* tools: env: Fix format warnings in debugMarcin Niestroj2016-07-26-7/+10
| | | | | | | | | | 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>
* tools/env: reuse fw_getenv in fw_printenv functionAndreas Fenkart2016-07-22-27/+17
| | | | | | | | | | 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>
* tools/env: move envmatch further up in file to avoid forward declarationsAndreas Fenkart2016-07-22-20/+18
| | | | | | | forward declaration not needed when re-ordered Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools/env: kernel-doc for fw_printenv, fw_getenv and fw_parse_scriptAndreas Fenkart2016-07-22-1/+1
| | | | | | | | | | | | | | | 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>
* tools/env: allow negative offsetsStefan Agner2016-07-22-9/+30
| | | | | | | | | | 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>
* tools/env: complete environment device config earlyStefan Agner2016-07-22-50/+60
| | | | | | | | | | | | | | | 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
* tools/env: allow to pass NULL for environment optionsAndreas Fenkart2016-05-31-3/+24
| | | | | | | | | | 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>
* tools/env: no global variable sharing between application and libraryAndreas Fenkart2016-05-27-27/+23
| | | | Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools/env: compute size of usable area only onceAndreas Fenkart2016-05-27-14/+18
| | | | | | for double buffering to work, redundant buffers must have equal size Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools/env: fw_printenv pass value_only as argumentAndreas Fenkart2016-05-27-3/+3
| | | | Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools/env: pass key as argument to env_aes_cbc_cryptAndreas Fenkart2016-05-27-6/+9
| | | | Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools: env: fix config file loading in env libraryAnatolij Gustschin2016-05-02-0/+3
| | | | | | | | | | | | 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>
* tools: env: bug: config structs must be defined in tools libraryAndreas Fenkart2016-03-27-0/+4
| | | | | | | | 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>
* tools: env: fw_parse_script: simplify removal of newline/carriage returnAndreas Fenkart2016-03-26-6/+4
| | | | | | fgets returns when the first '\n' is found Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools: env: split fw_string_blank into skip_chars / skip_blanksAndreas Fenkart2016-03-26-9/+14
| | | | Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools: env: fw_string_blank: return from loop when item foundAndreas Fenkart2016-03-26-5/+2
| | | | Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools: env: replace WHITESPACE macro by isblankAndreas Fenkart2016-03-26-4/+3
| | | | Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools: env: shift optind arguments and fix argument indicesAndreas Fenkart2016-02-08-43/+11
| | | | Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools: env: parse aes key / suppress flag into argument structAndreas Fenkart2016-02-08-52/+12
| | | | | | | disabled original parsing, but not yet removed since the argument indexing needs to be fixed Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools: env: make parse_aes_key statelessAndreas Fenkart2016-02-08-6/+6
| | | | Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools: env validate: pass values as 0-based arrayAndreas Fenkart2016-02-08-4/+7
| | | | | | passing argv/argc can produce off-by-one errors Signed-off-by: Andreas Fenkart <andreas.fenkart@digitalstrom.com>
* tools: env: include compiler.hPeter Robinson2015-12-13-0/+1
| | | | | | | 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>
* tools/env: allow config filename to be passed via command line argumentMichael Heimpold2015-11-18-2/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix musl buildJörg Krause2015-05-08-0/+2
| | | | | | | | | | | 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>
* tools/env: Fix environment size and CRC on 64-bit hostsDominic Sacré2014-11-07-1/+1
| | | | | | | | | | | 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>
* Merge branch 'u-boot/master'Albert ARIBAUD2014-05-09-2/+127
|\ | | | | | | | | | | | | Conflicts: drivers/net/Makefile (trivial merge)
| * env: Implement support for AES encryption into fw_* toolsMarek Vasut2014-03-21-2/+127
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* | fw_env.c: Switch get_config to use '%ms' in sscanfTom Rini2014-04-17-5/+8
|/ | | | | | | | | | 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>
* fw_env: correct writes to devices with small erase blocksDustin Byford2014-03-12-2/+2
| | | | | | | | | | | | | | | | | 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>
* fw_env: calculate default number of env sectorsDustin Byford2014-03-12-6/+8
| | | | | | | | | | | | | | | 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>
* fw_env: fix writing environment for mtd devicesOliver Metz2013-09-06-28/+42
| | | | | Signed-off-by: Oliver Metz <oliver@freetz.org> Tested-by: Luka Perkov <luka@openwrt.org>
* fw_env: add redundant env support for MTD_ABSENTOliver Metz2013-09-06-0/+3
| | | | | Signed-off-by: Oliver Metz <oliver@freetz.org> Tested-by: Luka Perkov <luka@openwrt.org>
* Add GPL-2.0+ SPDX-License-Identifier to source filesWolfgang Denk2013-07-24-17/+1
| | | | | | Signed-off-by: Wolfgang Denk <wd@denx.de> [trini: Fixup common/cmd_io.c] Signed-off-by: Tom Rini <trini@ti.com>
* env: Add redundant env support to UBI envJoe Hershberger2013-04-11-0/+3
| | | | | | Allow the user to specify two UBI volumes to use for the environment Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* env: Add support for UBI environmentJoe Hershberger2013-04-11-1/+2
| | | | | | | | | 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>
* env: Allow accessing non-mtd devicesLubomir Rintel2013-03-11-10/+24
| | | | | | | In certain cases, memory device is present as flat file or block device (via mmc or mtdblock layer). Do not attempt MTD operations against it. Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
* fw_env: fix type of lenMike Frysinger2012-12-19-1/+2
| | | | | | | | | | | This variable is assigned by a size_t, and is printed that way, but is incorrectly declared as an int. Which means we get warnings: fw_env.c: In function 'fw_setenv': fw_env.c:409:5: warning: format '%zu' expects argument of type 'size_t', but argument 3 has type 'int' [-Wformat] Signed-off-by: Mike Frysinger <vapier@gentoo.org> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* env: Handle write-once ethaddr and serial# genericallyJoe Hershberger2012-12-13-17/+0
| | | | | | | Use the variable access flags to implement the protection for ethaddr and serial# instead of hard-coding them. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* env: Add support for access control to .flagsJoe Hershberger2012-12-13-4/+70
| | | | | | Add support for read-only, write-once, and change-default. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* tools/env: Add environment variable flags supportJoe Hershberger2012-12-13-0/+9
| | | | | | | | | | | | | | Currently just validates variable types as decimal, hexidecimal, boolean, ip address, and mac address. Call env_acl_validate_setenv_params() from setenv() in fw_env.c. If the entry is not found in the env .flags, then look in the static one. This allows the env to override the static definitions, but prevents the need to have every definition in the environment distracting you. Need to build in _ctype for isdigit for Linux. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* env: cosmetic: Consilidate the default env definitionJoe Hershberger2012-10-19-96/+2
| | | | | | | There used to be a huge structure duplicated 3 times in the source. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Signed-off-by: Tom Rini <trini@ti.com>
* tools/env: Improve debug printsJoe Hershberger2012-10-16-5/+22
| | | | | | | Provide more information when using redundant environments Consistently print debug info to stderr Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* tools/env: Fix variable delete operationJoe Hershberger2012-10-16-2/+3
| | | | | | | Fix crash introduced by a073d63a36524453a817ab029fad5b188f46127e when attempting to delete a variable. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* tools/env: Fix build failure from missing header includeJoe Hershberger2012-10-15-0/+1
| | | | | | | | | | This was introduced in: 8679d0ffdcc0beafea8e6942c0c67cf859afa18e - COMMON: Use __stringify() instead of MK_STR() The header is now needed since common.h is not included in this tool. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* env: Check for NULL pointer in envmatch()Joe Hershberger2012-10-15-0/+2
| | | | | | | If the pointer passed into envmatch() is NULL, return -1 instead of crashing. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* tools/env: Don't call env_init() in fw_getenv()Joe Hershberger2012-10-15-3/+0
| | | | | | We will only call fw_getenv when the env has already been initialized. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* tools/env: Remove unneeded complexityJoe Hershberger2012-10-15-20/+13
| | | | | | | | | The length included the name length, and then it was subtracted back out on each use. Now we don't include it in the first place. Also realloc as we process arguments and eliminate memset. Use memcpy instead of manually copying each byte. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* tools/env: Use a board-specific default envJoe Hershberger2012-10-15-15/+13
| | | | | | | | | | | | | | | | | | | Originally added in aa701b94336b358798d676eef12a7b90bdac23f5 Before this patch, there was a hard-coded env that was used as default if the env in flash is detected as invalid. Now this tool (compiled for a given board) will share the default env with the u-boot for the board. Fix include of config.h Need to define "TEXT_BASE" when building the fw_env tool so that the default env will be correct for environments which use it. Define __ASSEMBLY__ when calling #include <config.h> so that we only get #defines (all we're interested in). Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* COMMON: Use __stringify() instead of MK_STR()Marek Vasut2012-10-15-20/+17
| | | | | | | | | Kill multiple occurances and redeclaration of MK_STR in favor of __stringify(). Signed-off-by: Marek Vasut <marex@denx.de> Cc: Wolfgang Denk <wd@denx.de> Signed-off-by: Tom Rini <trini@ti.com>
* fw_env: Add env vars describing U-Boot target boardBenoît Thébaudeau2012-09-18-0/+11
| | | | | | | | Commit 5e724ca did the same thing for env_common and env_embedded, but forgot fw_env. Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com> Cc: Wolfgang Denk <wd@denx.de>