[PATCH v3] env: spi: Fix gd->env_valid for the first write

E Shattow e at freeshell.de
Tue Sep 23 23:23:43 CEST 2025


On 9/22/25 11:47, Marek Vasut wrote:
> On 9/22/25 6:03 PM, Michal Simek wrote:
>> When both SPI environment locations are invalid (gd->env_valid ==
>> ENV_INVALID), the first call to saveenv writes to the primary location
>> and
>> sets the active flag. However, the logic for updating gd->env_valid
>> incorrectly sets it to ENV_REDUND, which does not match the actual
>> location
>> written. This causes the first two writes to target the same location,
>> and
>> alternation only begins after the second write.
>>
>> Update the logic to alternate gd->env_valid based on whether the last
>> write
>> was to the primary or redundant location, ensuring the first write sets
>> ENV_VALID and subsequent writes alternate as expected. This aligns
>> env_valid with the actual storage location and fixes the alternation
>> sequence from the first write.
>>
>> With this change, the "Valid environment" printout correctly reflects the
>> active location after each save, and the alternation between primary and
>> redundant locations works as intended from the start.
>>
>> Signed-off-by: Michal Simek <michal.simek at amd.com>
> 
> Reviewed-by: Marek Vasut <marek.vasut at mailbox.org>

Comments from
https://lore.kernel.org/u-boot/e436dd80-3693-472b-b9f6-5d27a8310397@freeshell.de/T/#m114473aa0a28a08b150aef2dbed028200472fdf2
linked here.  Nits about the grammar overloading of "alternation" which
could be improved.

Best regards,

-E


More information about the U-Boot mailing list