[ERROR] Cannot read environment, using default

32 views
Skip to first unread message

Michael Glembotzki

unread,
Aug 12, 2025, 2:47:00 AMAug 12
to swupdate
I think this is in most cases no error. Especially on the very first startup:

[ERROR] : SWUPDATE failed [0] ERROR util.c : read_lines_notify : 1294 : Cannot read environment, using default

Can we change it to TRACE or DEBUG Level?

Best regards,
Michael

Stefano Babic

unread,
Aug 12, 2025, 3:13:07 AMAug 12
to Michael Glembotzki, swupdate
Hi Michael,
Well, it seems more a WARN.


Best regards,
Stefano

Michael Glembotzki

unread,
Sep 8, 2025, 3:32:13 AM (3 days ago) Sep 8
to swup...@googlegroups.com, Michael Glembotzki
Signed-off-by: Michael Glembotzki <Michael.G...@iris-sensing.com>
---
core/swupdate.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/core/swupdate.c b/core/swupdate.c
index eca29846..fa43361f 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -164,7 +164,7 @@ static void usage(char *programname)
" -l, --loglevel <level> : logging level\n"
" -L, --syslog : enable syslog logger\n"
#ifdef CONFIG_SIGNED_IMAGES
- " -6, --digest-provider <string> : the provider used to verify the update\n"
+ " --digest-provider <string> : the provider used to verify the update\n"
" -k, --key <public key file> : file with public key to verify images\n"
" --cert-purpose <purpose> : set expected certificate purpose\n"
" [emailProtection|codeSigning] (default: emailProtection)\n"
@@ -181,10 +181,10 @@ static void usage(char *programname)
#ifdef CONFIG_ENCRYPTED_IMAGES
" -K, --key-aes <key file> : the file contains the symmetric key to be used\n"
" to decrypt images\n"
- " -8, --decrypt-provider <string>: the provider used for decryption\n"
+ " --decrypt-provider <string>: the provider used for decryption\n"
#endif
#ifdef CONFIG_HASH_VERIFY
- " -7, --hash-provider <string> : the provider used to perform hashes\n"
+ " --hash-provider <string> : the provider used to perform hashes\n"
#endif
" -n, --dry-run : run SWUpdate without installing the software\n"
" -N, --no-downgrading <version> : not install a release older as <version>\n"
--
2.50.1

Michael Glembotzki

unread,
Sep 8, 2025, 3:33:44 AM (3 days ago) Sep 8
to swup...@googlegroups.com, Michael Glembotzki
In swupdate reading the default uboot env for the first time results in:

[ERROR] : SWUPDATE failed [0] ERROR util.c : read_lines_notify : 1294 :
Cannot read environment, using default

Because it's more of a warning than an error, and swupdate treats output
to stderr as an error, reduce serverity by logging to stdout.

Signed-off-by: Michael Glembotzki <Michael.G...@iris-sensing.com>
---
src/fw_printenv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/fw_printenv.c b/src/fw_printenv.c
index ef95b32..ceed065 100644
--- a/src/fw_printenv.c
+++ b/src/fw_printenv.c
@@ -160,7 +160,7 @@ int main (int argc, char **argv) {
defenvfile = DEFAULT_ENV_FILE;

if ((ret = libuboot_open(ctx)) < 0) {
- fprintf(stderr, "Cannot read environment, using default\n");
+ fprintf(stdout, "Cannot read environment, using default\n");
if ((ret = libuboot_load_file(ctx, defenvfile)) < 0) {
fprintf(stderr, "Cannot read default environment from file\n");
exit (ret);
--
2.50.1

Stefano Babic

unread,
Sep 8, 2025, 5:37:40 AM (3 days ago) Sep 8
to Michael Glembotzki, swup...@googlegroups.com, Michael Glembotzki
Reviewed-by: Stefano Babic <stefan...@swupdate.org>

Stefano Babic

unread,
Sep 8, 2025, 5:44:43 AM (3 days ago) Sep 8
to Michael Glembotzki, swup...@googlegroups.com, Michael Glembotzki
Hi Michael,

On 9/8/25 09:33, Michael Glembotzki wrote:
> In swupdate reading the default uboot env for the first time results in:
>
> [ERROR] : SWUPDATE failed [0] ERROR util.c : read_lines_notify : 1294 :
> Cannot read environment, using default
>
> Because it's more of a warning than an error, and swupdate treats output
> to stderr as an error, reduce serverity by logging to stdout.
>

There is a reason for this. If the output is sent to stdout, it breaks
scripts because the returned strings contain this output.


> Signed-off-by: Michael Glembotzki <Michael.G...@iris-sensing.com>
> ---
> src/fw_printenv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/fw_printenv.c b/src/fw_printenv.c
> index ef95b32..ceed065 100644
> --- a/src/fw_printenv.c
> +++ b/src/fw_printenv.c
> @@ -160,7 +160,7 @@ int main (int argc, char **argv) {
> defenvfile = DEFAULT_ENV_FILE;
>
> if ((ret = libuboot_open(ctx)) < 0) {
> - fprintf(stderr, "Cannot read environment, using default\n");
> + fprintf(stdout, "Cannot read environment, using default\n");
> if ((ret = libuboot_load_file(ctx, defenvfile)) < 0) {
> fprintf(stderr, "Cannot read default environment from file\n");
> exit (ret);

Best regards,
Stefano Babic

Michael Glembotzki

unread,
Sep 8, 2025, 7:11:39 AM (3 days ago) Sep 8
to swupdate
Hi Stefano,

Stefano Babic schrieb am Montag, 8. September 2025 um 11:44:43 UTC+2:
Hi Michael,

On 9/8/25 09:33, Michael Glembotzki wrote:
> In swupdate reading the default uboot env for the first time results in:
>
> [ERROR] : SWUPDATE failed [0] ERROR util.c : read_lines_notify : 1294 :
> Cannot read environment, using default
>
> Because it's more of a warning than an error, and swupdate treats output
> to stderr as an error, reduce serverity by logging to stdout.
>

There is a reason for this. If the output is sent to stdout, it breaks
scripts because the returned strings contain this output.
But, using default values does not exit. It exits only if there is also no defenvfile.

Our use case is calling fw_printenv in the pre_post_inst.c and an error is shown,
but for fresh devices this is no errror.

Another idea is to change

RECOVERY_STATUS status = level == ERRORLEVEL ? FAILURE : RUN;
swupdate_notify(status, "%s", level, lines[index]);

in swupdate/core/util.c to

swupdate_notify(RUN, "%s", level, lines[index]);

but this feels even worse. Or shall we use different exit values in libubootenv?
Do you have a better idea to fix make the error / warn lesser strict?

Best regards,
Michael

Stefano Babic

unread,
Sep 8, 2025, 7:39:53 AM (3 days ago) Sep 8
to Michael Glembotzki, swupdate
Hi Michael,

On 08.09.25 13:11, Michael Glembotzki wrote:
> Hi Stefano,
>
> Stefano Babic schrieb am Montag, 8. September 2025 um 11:44:43 UTC+2:
>
> Hi Michael,
>
> On 9/8/25 09:33, Michael Glembotzki wrote:
> > In swupdate reading the default uboot env for the first time
> results in:
> >
> > [ERROR] : SWUPDATE failed [0] ERROR util.c : read_lines_notify :
> 1294 :
> > Cannot read environment, using default
> >
> > Because it's more of a warning than an error, and swupdate treats
> output
> > to stderr as an error, reduce serverity by logging to stdout.
> >
>
> There is a reason for this. If the output is sent to stdout, it breaks
> scripts because the returned strings contain this output.
>
> But, using default values does not exit. It exits only if there is also
> no defenvfile.
>
> Our use case is calling fw_printenv in the pre_post_inst.c and an error
> is shown,

Mmmhhh....where is this file ?

> but for fresh devices this is no errror.
>

In fact, SWUpdate raises a WARN.

https://github.com/sbabic/swupdate/blob/master/bootloader/uboot.c#L57

> Another idea is to change
>
> RECOVERY_STATUS status = level == ERRORLEVEL ? FAILURE : RUN;
> swupdate_notify(status, "%s", level, lines[index]);
>

I am lost: SWUpdate does not fw_printenv, because it makes usage of the
library. This allows full control.

> in swupdate/core/util.c to
>
> swupdate_notify(RUN, "%s", level, lines[index]);

This has nothing to do, and this code is to exec any external command.

>
> but this feels even worse. Or shall we use different exit values in
> libubootenv?

The output is just a warning - helpful for testing. But it doesn't mean
there is an issue. A fresh board hasn't environment in flash, and the
string happens.

> Do you have a better idea to fix make the error / warn lesser strict?
>

I am missing the real issue, because this is just writing a string and
doesn't change the exit code, as it shouldn't do because with a default
environment, everything is fine.

Is pre_post_inst.c part of your application ? Where is coming from ? If
it is, why do not use the library instead of fw_printenv ?

Best regards,
Stefano

> > Signed-off-by: Michael Glembotzki <Michael.G...@iris-sensing.com>
> > ---
> > src/fw_printenv.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/fw_printenv.c b/src/fw_printenv.c
> > index ef95b32..ceed065 100644
> > --- a/src/fw_printenv.c
> > +++ b/src/fw_printenv.c
> > @@ -160,7 +160,7 @@ int main (int argc, char **argv) {
> > defenvfile = DEFAULT_ENV_FILE;
> >
> > if ((ret = libuboot_open(ctx)) < 0) {
> > - fprintf(stderr, "Cannot read environment, using default\n");
> > + fprintf(stdout, "Cannot read environment, using default\n");
> > if ((ret = libuboot_load_file(ctx, defenvfile)) < 0) {
> > fprintf(stderr, "Cannot read default environment from file\n");
> > exit (ret);
>
> Best regards,
> Stefano Babic
>
> --
> You received this message because you are subscribed to the Google
> Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swupdate+u...@googlegroups.com
> <mailto:swupdate+u...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/
> swupdate/1ae0b6b9-4160-4990-87f0-bd992fe218d9n%40googlegroups.com
> <https://groups.google.com/d/msgid/swupdate/1ae0b6b9-4160-4990-87f0-
> bd992fe218d9n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Michael Glembotzki

unread,
Sep 8, 2025, 9:03:38 AM (3 days ago) Sep 8
to swupdate
Okay, I got something mixed up. Before installing, we check whether the previous installation has already been completed with:

preupdatecmd = "if [ \"$(fw_printenv upgrade_available | cut -d= -f2)\" = 1 ]; then exit 1; fi;"

This then leads to this error message:

[DEBUG] : SWUPDATE running :  [preupdatecmd] : Running Pre-update command
[ERROR] : SWUPDATE failed [0] ERROR util.c : read_lines_notify : 1283 : Cannot read environment, using default

There was another fw_printenv call in our pre_post_inst.sh script. I originally thought that was the cause of the error.
But, as you already wrote, that's not where the error is coming from. Is is/was a warning:

[WARN ] : SWUPDATE running :  [bootloader_initialize] : Cannot read environment, using default

We could redirect the error message on startup like: fw_printenv upgrade_available 2>&1

Best regards,
Michael

Stefano Babic

unread,
Sep 8, 2025, 9:17:42 AM (3 days ago) Sep 8
to Michael Glembotzki, swupdate
Hi Michael,

On 9/8/25 15:03, Michael Glembotzki wrote:
> Okay, I got something mixed up. Before installing, we check whether the
> previous installation has already been completed with:
>
> preupdatecmd = "if [ \"$(fw_printenv upgrade_available | cut -d= -f2)\"
> = 1 ]; then exit 1; fi;"
>

The best way to do this is to set a hook in sw-description

embedded-script ="
require ('swupdate')

function test_upgrade_available(image)
upgrade = swupdate.get_bootenv('upgrade_available')

if upgrade then
return false,image
else
return true,image
end
end";

....

images:(
....

{
filename = .....;
hook = "test_upgrade_available";
}


> This then leads to this error message:
>
> [DEBUG] : SWUPDATE running :  [preupdatecmd] : Running Pre-update command
> [ERROR] : SWUPDATE failed [0] ERROR util.c : read_lines_notify : 1283 :
> Cannot read environment, using default
>
> There was another fw_printenv call in our pre_post_inst.sh script. I
> originally thought that was the cause of the error.
> But, as you already wrote, that's not where the error is coming from. Is
> is/was a warning:
>
> [WARN ] : SWUPDATE running :  [bootloader_initialize] : Cannot read
> environment, using default

>
> We could redirect the error message on startup like: fw_printenv
> upgrade_available 2>&1
>

Best regards,
Stefano
> uboot.c#L57 <https://github.com/sbabic/swupdate/blob/master/
> bootloader/uboot.c#L57>
> <https://groups.google.com/d/msgid/>
> > swupdate/1ae0b6b9-4160-4990-87f0-bd992fe218d9n%40googlegroups.com
> <http://40googlegroups.com>
> > <https://groups.google.com/d/msgid/
> swupdate/1ae0b6b9-4160-4990-87f0- <https://groups.google.com/d/
> msgid/swupdate/1ae0b6b9-4160-4990-87f0->
> > bd992fe218d9n%40googlegroups.com?
> utm_medium=email&utm_source=footer <http://40googlegroups.com?
> utm_medium=email&utm_source=footer>>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swupdate+u...@googlegroups.com
> <mailto:swupdate+u...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/
> swupdate/5f305b7c-6094-469c-8364-c72fe876ce4en%40googlegroups.com
> <https://groups.google.com/d/msgid/swupdate/5f305b7c-6094-469c-8364-
> c72fe876ce4en%40googlegroups.com?utm_medium=email&utm_source=footer>.

Reply all
Reply to author
Forward
0 new messages