fw_setenv: lock the flash only if it was locked before
authorIvan Mikhaylov <fr0st61te@gmail.com>
Fri, 10 Jul 2020 16:54:18 +0000 (19:54 +0300)
committerTom Rini <trini@konsulko.com>
Fri, 31 Jul 2020 14:13:00 +0000 (10:13 -0400)
commitdb82015929aeff6b58982a22d61ab8c5b87752f3
tree671af1a640f1fbb27f87a82685d8be9e632ee564
parentd045cbacf2529266bb312add023e12c0d400bf67
fw_setenv: lock the flash only if it was locked before

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>
tools/env/fw_env.c