Skip to contentSkip to conversation

tools: env: handle corrupted ubi volumes during sanity check

PATCH New Martin Hundebøll 2 participants 2 messages Nov 12, 2019 – Jan 30, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: env: handle corrupted ubi volumes during sanity check

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.

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.

---
 tools/env/fw_env.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/env/fw_env.c +7 -1
index cfada0ee11..f7904ae036 100644
@@ -1608,7 +1608,13 @@ static int check_device_config(int dev)
 
 	if (IS_UBI(dev)) {
 		rc = ioctl(fd, UBI_IOCEBISMAP, &lnum);
-		if (rc < 0) {
+		if (rc < 0 && errno == 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 = 0;
+		} else if (rc < 0) {
 			fprintf(stderr, "Cannot get UBI information for %s\n",
 				DEVNAME(dev));
 			goto err;
Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/1 tools: env: handle corrupted ubi volumes during sanity check

Dear Martin,

Quoted 7 lines · In message <[email protected]> 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.

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.

Quoted 10 lines
---
 tools/env/fw_env.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/env/fw_env.c +0 -0
index cfada0ee11..f7904ae036 100644

tools/env/fw_env.c static int check_device_config(int dev) · line 1616

Quoted 10 lines
tools/env/fw_env.c +6 -1
@@ -1608,7 +1608,13 @@ static int check_device_config(int dev)
 
 	if (IS_UBI(dev)) {
 		rc = ioctl(fd, UBI_IOCEBISMAP, &lnum);
-		if (rc < 0) {
+		if (rc < 0 && errno == 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 = 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.

Best regards,

Wolfgang Denk

Signature · 4 lines
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.