Skip to contentSkip to conversation

env: Exit tools when invalid CRC found

PATCH New Molloy 4 participants 6 messages Apr 3, 2019 – Nov 25, 2019

lore
Share & tools
lore

Molloy

#0 lore raw

PATCH 1/1 env: Exit tools when invalid CRC found

fw_setenv and fw_printenv currently print a warning and use a default environment compiled into the binary when an invalid CRC is found. This modifies the default behavior to print an error and exit. This is especially important when calling the tools from a script since the script depends on the exit code of the tool to know something went wrong.

If the default environment is desired it should be read explicitly by the caller. A better model is to store a default environment as a separate binary or text file rather than storing it in the executable.

---
 tools/env/fw_env.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
tools/env/fw_env.c +0 -1
index a5d75958e1..ef33e9e1be 100644
@@ -1438,9 +1438,8 @@ int fw_env_open(struct env_opts *opts)
 	if (!have_redund_env) {
 		if (!crc0_ok) {
 			fprintf(stderr,
-				"Warning: Bad CRC, using default

environment\n");
- memcpy(environment.data, default_environment,
- sizeof(default_environment));
+ "Invalid CRC found in environment\n");
+ return -1;
}
} else {
flag0 = *environment.flags;
@@ -1500,10 +1499,8 @@ int fw_env_open(struct env_opts *opts)
dev_current = 1;
} else if (!crc0_ok && !crc1_ok) {
fprintf(stderr,
- "Warning: Bad CRC, using default
environment\n");
- memcpy(environment.data, default_environment,
- sizeof(default_environment));
- dev_current = 0;
+ "Invalid CRC found in both redundant
environments\n");
+ return -1;
} else {
switch (environment.flag_scheme) { case FLAG_BOOLEAN:

Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 env: Exit tools when invalid CRC found

Quoted 7 lines · Philip

fw_setenv and fw_printenv currently print a warning and use a default environment compiled into the binary when an invalid CRC is found. This modifies the default behavior to print an error and exit. This is especially important when calling the tools from a script since the script depends on the exit code of the tool to know something went wrong.

Quoted 5 lines

If the default environment is desired it should be read explicitly by the caller. A better model is to store a default environment as a separate binary or text file rather than storing it in the executable.

Conceptually, yes, this is correct. However, the behavior in question has been deployed for so long that I don't feel that we can change it at this point, so I'm going to NAK this. Sorry.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190505/1dba6435/attachment.sig>
#2 lore raw

PATCH 1/1 env: Exit tools when invalid CRC found

Quoted 5 lines · Tom Rini

Conceptually, yes, this is correct. However, the behavior in question
has been deployed for so long that I don't feel that we can change it at
this point, so I'm going to NAK this. Sorry.

I certainly understand that constraint even though it has caused a fair amount of trouble. For a little more context please see an e-mail I sent to the Buildroot mailing list.[1]

How about as a compromise fw_printenv still prints the same output, but it returns an exit code > 0 when doing so?

Best,
Phil

[1]:
http://lists.busybox.net/pipermail/buildroot/2019-April/246761.html

#3 lore raw

PATCH 1/1 env: Exit tools when invalid CRC found

Hi Tom,

Quoted 7 lines · Philip
Quoted 5 lines · Tom Rini

Conceptually, yes, this is correct. However, the behavior in question
has been deployed for so long that I don't feel that we can change it at
this point, so I'm going to NAK this. Sorry.

Quoted 6 lines

I certainly understand that constraint even though it has caused a fair amount of trouble. For a little more context please see an e-mail I sent to the Buildroot mailing list.[1]

How about as a compromise fw_printenv still prints the same output, but it returns an exit code > 0 when doing so?

Are you worried about the change to the exit code here? Are you thinking there are some utilities that depend on it not erroring in this case?

If so, perhaps we can add a switch to the utility to have it actually error in this case. If that's not a concern, maybe we can do it without a switch.

It would also be great to hear wdenx input.

Thanks,
-Joe

Quoted 11 lines

Best,
Phil

[1]:
http://lists.busybox.net/pipermail/buildroot/2019-April/246761.html

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

#4 lore raw

PATCH 1/1 env: Exit tools when invalid CRC found

Quoted 21 lines · Joe Hershberger

Hi Tom,

Quoted 7 lines · Philip
Quoted 5 lines · Tom Rini

Conceptually, yes, this is correct. However, the behavior in question
has been deployed for so long that I don't feel that we can change it at
this point, so I'm going to NAK this. Sorry.

Quoted 6 lines

I certainly understand that constraint even though it has caused a fair amount of trouble. For a little more context please see an e-mail I sent to the Buildroot mailing list.[1]

How about as a compromise fw_printenv still prints the same output, but it returns an exit code > 0 when doing so?

Are you worried about the change to the exit code here? Are you thinking there are some utilities that depend on it not erroring in this case?

Quoted 5 lines

If so, perhaps we can add a switch to the utility to have it actually error in this case. If that's not a concern, maybe we can do it without a switch.

It would also be great to hear wdenx input.

Yes, my concern is scripts that either explicitly or implicitly depend
on the current behavior. Making a new behavior with a flag seems fine
to me.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191119/d7f4b930/attachment.sig>
#5 lore raw

PATCH 1/1 env: Exit tools when invalid CRC found

In reply to Joe Hershberger

Dear Joe,

Quoted 20 lines · In message <CANr=Z=bccLDfjRwUOLMdy+11JA8ZO9+rP2mWZS=_kL_+wMSnyw@mail.gmail.com>…
Quoted 7 lines · Philip
Quoted 5 lines · Tom Rini

Conceptually, yes, this is correct. However, the behavior in question
has been deployed for so long that I don't feel that we can change it at
this point, so I'm going to NAK this. Sorry.

Quoted 6 lines

I certainly understand that constraint even though it has caused a fair amount of trouble. For a little more context please see an e-mail I sent to the Buildroot mailing list.[1]

How about as a compromise fw_printenv still prints the same output, but it returns an exit code > 0 when doing so?

Are you worried about the change to the exit code here? Are you thinking there are some utilities that depend on it not erroring in this case?

Quoted 5 lines

If so, perhaps we can add a switch to the utility to have it actually error in this case. If that's not a concern, maybe we can do it without a switch.

It would also be great to hear wdenx input.

The current behaviour of the fw_env tools corresponds to what U-Boot proper is doing: if there is a CRC error, it will fall back to the default environment, and continue. This is well known (and hopefully documented) behaviour. we have no idea how many existing use cases would break if we change the default behaviour of the fw_env tools.

However, I agree that it is also a valid request to be able to recognize such CRC errors and handle them differently> I can see two different appraoches to implement this:

1) Add a new option to fw_env to return a specfic error code in this case (say 2 to be able to differentiate between such a "soft" error and "hard" I/O errors or such).

2) Implement a new "fw_test" command which just checks if the environment has a valid CRC and provides this information as return code.

Give existing usage of the fw_end tools I tend to prefer 2), which does not change existing behaviour and only adds new functionality instead.

Best regards,

Wolfgang Denk

Signature · 5 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
Let the programmers be many and the managers few -- then all will  be
productive.               -- Geoffrey James, "The Tao of Programming"