From: Wolfgang Denk Date: Thu, 30 Jan 2020 21:46:40 +0100 Subject: [U-Boot] [PATCH] tools: env: handle corrupted ubi volumes during sanity check In-Reply-To: <20191112190223.225956-1-martin@geanix.com> References: <20191112190223.225956-1-martin@geanix.com> Message-ID: <20200130204640.E5CD224065D@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Dear Martin, In message <20191112190223.225956-1-martin@geanix.com> you wrote: > A partially written ubi volume is marked as such by the kernel. Such a > mark causes the initial ubi sanity check to fail instead of falling back > to the redundant environment. >=20 > Fix this by special casing the EBADF return code from the UBI_IOCEBISMAP > ioctl, as this is only ever returned in case of a partially written > volume. The CRC checking will decide which environment to use anyways. I dislike this approach, sorry. > Signed-off-by: Martin Hundeb=C3=B8ll > --- > tools/env/fw_env.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) >=20 > diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c > index cfada0ee11..f7904ae036 100644 > --- a/tools/env/fw_env.c > +++ b/tools/env/fw_env.c > @@ -1608,7 +1608,13 @@ static int check_device_config(int dev) > =20 > if (IS_UBI(dev)) { > rc =3D ioctl(fd, UBI_IOCEBISMAP, &lnum); > - if (rc < 0) { > + if (rc < 0 && errno =3D=3D EBADF) { > + /* EBADF here means we are dealing with a partially > + * written UBI volume, Leave it for now to allow the > + * use of the redundant env. CRC checking will decide > + * which to use */ > + rc =3D 0; No, we have an error here, so we should report that error to the user at least. Saying "oh, this error is not an error" is wrong. Think especially of the case when there is no redundant environment at all! If you want to drop through to trying to read the other copy of the enviropnment (if there is one !!!) this needs to be implemented differently. Naked-by: Wolfgang Denk Best regards, Wolfgang Denk --=20 DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de There's an old proverb that says just about whatever you want it to.