summaryrefslogtreecommitdiff
path: root/env/flash.c
AgeCommit message (Collapse)Author
9 daysenv: flash: add catch-all for unrecognized flags in env_flash_init()Neil Berkman
When both environment copies have valid CRCs but the flag bytes do not match any recognized pair, env_flash_init() falls through without setting gd->env_addr or gd->env_valid. This is a problem because: 1. env_init() then sets gd->env_addr = &default_environment (in RAM). 2. In env_flash_load(), the pointer comparison gd->env_addr != &flash_addr->data evaluates true (RAM != flash), triggering the pointer swap that selects the secondary copy. 3. The repair logic writes OBSOLETE (0x00) to the non-active flag but cannot promote the other flag from 0x00 to ACTIVE (0x01) because NOR flash requires a sector erase to set bits. Both copies end up with flag=0x00. 4. On every subsequent boot, flag1 == flag2 triggers the ENV_REDUND path, printing a spurious "recovered successfully" warning until an explicit saveenv erases and rewrites the sectors. The recognized flag values are ACTIVE (0x01), OBSOLETE (0x00), and erased (0xFF). Of the 256 possible flag values, the existing chain of if/else-if handles only three: 253 of 256 values fall through without setting gd->env_addr. Combined with 0x00 (already stuck on NOR), 254 of 256 values eventually reach the persistent-warning state. Other env backends (SPI flash, NAND, MMC) handle this through env_check_redund() in env/common.c, which uses a numeric comparison of the flags as a serial counter and always reaches a decision. The CFI flash backend is the only one that uses its own flag-matching logic. Add a catch-all else clause that defaults to the primary copy with ENV_REDUND status, matching the existing behavior for the flag1==flag2 case. This ensures gd->env_addr is always set, preventing the unintended pointer swap. The condition is recoverable via saveenv. Signed-off-by: Neil Berkman <[email protected]> Reproducer: https://gist.github.com/neilberkman/4155612a7942d3f510f204eb85e61943 The SPI flash backend (env/sf.c) has a related but distinct issue: it retained legacy boolean save semantics but its load path now uses the common serial-number logic in env_check_redund(), creating an inconsistency under interrupted updates. That has wider implications for fw_env.c and would need separate discussion.
2024-10-11global: Use CONFIG_XPL_BUILD instead of CONFIG_SPL_BUILDSimon Glass
Complete this rename for all directories outside arch/ board/ drivers/ and include/ Use the new symbol to refer to any 'SPL' build, including TPL and VPL Signed-off-by: Simon Glass <[email protected]>
2024-05-20Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"Tom Rini
As part of bringing the master branch back in to next, we need to allow for all of these changes to exist here. Reported-by: Jonas Karlman <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2024-05-19Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""Tom Rini
When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"' I failed to notice that b4 noticed it was based on next and so took that as the base commit and merged that part of next to master. This reverts commit c8ffd1356d42223cbb8c86280a083cc3c93e6426, reversing changes made to 2ee6f3a5f7550de3599faef9704e166e5dcace35. Reported-by: Jonas Karlman <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2024-05-06env: Remove <common.h> and add needed includesTom Rini
Remove <common.h> from all "env/" files and when needed add missing include files directly. Signed-off-by: Tom Rini <[email protected]>
2022-08-04Audit <flash.h> inclusionTom Rini
A large number of files include <flash.h> as it used to be how various SPI flash related functions were found, or for other reasons entirely. In order to migrate some further CONFIG symbols to Kconfig we need to not include flash.h in cases where we don't have a NOR flash of some sort enabled. Furthermore, in cases where we are in common code and it doesn't make sense to try and further refactor the code itself in to new files we need to guard this inclusion. Signed-off-by: Tom Rini <[email protected]>
2021-10-31env: flash: Cosmetic fixMarek Behún
Change tab to space in env_flash_init(). Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-10-31env: flash: Let generic env_init() assign default environmentMarek Behún
env_flash_init() (both implementations) assigns default environment if ENV_INVALID, but this is done in the generic env_init() function, which calls this initializer, so drop it from here. Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-10-26env: superfluous check before free()Heinrich Schuchardt
Free() checks if its argument in NULL. There is no need for the caller to do the same. Signed-off-by: Heinrich Schuchardt <[email protected]>
2021-02-02common: Drop asm/global_data.h from common headerSimon Glass
Move this out of the common header and include it only where needed. In a number of cases this requires adding "struct udevice;" to avoid adding another large header or in other cases replacing / adding missing header files that had been pulled in, very indirectly. Finally, we have a few cases where we did not need to include <asm/global_data.h> at all, so remove that include. Signed-off-by: Simon Glass <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2020-07-31env: Discern environment coming from external storageMarek Vasut
Add another custom environment flag which discerns environment coming from external storage from environment set by U-Boot itself. Signed-off-by: Marek Vasut <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2020-05-18common: Drop log.h from common headerSimon Glass
Move this header out of the common header. Signed-off-by: Simon Glass <[email protected]>
2020-01-17common: Move flash_perror() to flash.hSimon Glass
This function belongs more in flash.h than common.h so move it. Also remove the space before the bracket in some calls. Signed-off-by: Simon Glass <[email protected]>
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 <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2019-11-20env: Remove useless CONFIG_ENV_SIZE_REDUND and fix ENV_IS_REDUND checkTom Rini
We have CONFIG_ENV_SIZE_IS_REDUND but don't really use it. We have one board where we can simply multiple CONFIG_ENV_SIZE by two for the same result. The other place where we could but were not previously using this is for where env_internal.h checks for if we should set ENV_IS_EMBEDDED. This seems like the most likely use, historically, of the variable, but it was not used. Add logic to check for this now. Cc: Wolfgang Denk <[email protected]> Cc: Joe Hershberger <[email protected]> Signed-off-by: Tom Rini <[email protected]> Reviewed-by: Simon Glass <[email protected]> Acked-by: Joe Hershberger <[email protected]>
2019-08-11env: Rename environment.h to env_internal.hSimon Glass
This file contains lots of internal details about the environment. Most code can include env.h instead, calling the functions there as needed. Rename this file and add a comment at the top to indicate its internal nature. Signed-off-by: Simon Glass <[email protected]> Acked-by: Joe Hershberger <[email protected]> Reviewed-by: Simon Goldschmidt <[email protected]> [trini: Fixup apalis-tk1.c] Signed-off-by: Tom Rini <[email protected]>
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 <[email protected]>
2019-08-11env: Move env_valid to env.hSimon Glass
This enum is somewhat widely used to determine if the environment is valid or not. Move it to the common environment header file. Signed-off-by: Simon Glass <[email protected]> Acked-by: Joe Hershberger <[email protected]>
2019-08-11env: Rename environment to embedded_environmentSimon Glass
The name 'environment' is widely used in U-Boot so is not a very useful name of a variable. Rename it to better indicate its purpose. Signed-off-by: Simon Glass <[email protected]> Acked-by: Joe Hershberger <[email protected]> Reviewed-by: Simon Goldschmidt <[email protected]>
2018-12-04env: allow flash and nand env driver to compile togetherRajesh Bhagat
Define env_ptr as static in flash and nand env driver to allow these to compile together. Signed-off-by: Rajesh Bhagat <[email protected]> Reviewed-by: York Sun <[email protected]>
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 <[email protected]>
2018-02-01env: make env drivers propagate env_import return valueSimon Goldschmidt
For multiple env drivers to correctly implement fallback when one environment fails to load (e.g. crc error), the return value of env_import has to be propagated by all env driver's load function. Without this change, the first driver that succeeds to load an environment with an invalid CRC return 0 (success) and no other drivers are checked. Signed-off-by: Simon Goldschmidt <[email protected]> Acked-by: Maxime Ripard <[email protected]>
2017-08-20env: Replace all open-coded gd->env_valid values with ENV_ flagsSimon Glass
Some of these were missed in the conversion. Signed-off-by: Simon Glass <[email protected]>
2017-08-16env: Adjust the load() method to return an errorSimon Glass
The load() methods have inconsistent behaviour on error. Some of them load an empty default environment. Some load an environment containing an error message. Others do nothing. As a step in the right direction, have the method return an error code. Then the caller could handle this itself in a consistent way. Signed-off-by: Simon Glass <[email protected]>
2017-08-15env: Drop the env_name_spec globalSimon Glass
Add a name to the driver and use that instead of the global variable declared by each driver. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2017-08-15env: Switch over to use environment location driversSimon Glass
Move over to use a the master implementation of the location drivers, with each method calling out to the appropriate driver. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2017-08-15env: Create a location driver for each locationSimon Glass
Set up a location driver for each supported environment location. At present this just points to the global functions and is not used. A later patch will switch this over to use private functions in each driver. There are several special cases here in various drivers to handle peculiarities of certain boards: 1. Some boards define CONFIG_ENV_IS_IN_FAT and CONFIG_SPL_ENV_SUPPORT but do not actually load the environment in SPL. The env load code was optimised out before but with the driver, it is not. Therefore a special case is added to env/fat.c. The correct fix (depending on board testing might be to disable CONFIG_SPL_ENV_SUPPORT. 2. A similar situations happens with CONFIG_ENV_IS_IN_FLASH. Some boards do not actually load the environment in SPL, so to reduce code size we need to drop that code. A similar fix may be possible with these boards, or it may be possible to adjust the environment CONFIG settings. Added to the above is that the CONFIG_SPL_ENV_SUPPORT option does not apply when the environment is in flash. Obviously the above has been discovered through painful and time-consuming trial and error. Hopefully board maintainers can take a look and figure out what is actually needed. Signed-off-by: Simon Glass <[email protected]>
2017-08-15env: Add an enum for environment stateSimon Glass
At present we have three states for the environment, numbered 0, 1 and 2. Add an enum to record this to avoid open-coded values. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2017-08-15Move environment files from common/ to env/Simon Glass
About a quarter of the files in common/ relate to the environment. It seems better to put these into their own subdirectory and remove the prefix. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>