Include u-boot-initial-env in SWU image and flash it

28 views
Skip to first unread message

Frieder Schrempf

unread,
Oct 26, 2022, 5:54:46 AM10/26/22
to swupdate
Hello everyone,

I'm wondering how to include the U-Boot environment created from "make u-boot-initial-env" into an SWU image so it can be flashed to the SPI NOR during the update process?

Writing it to the flash directly doesn't work as the u-boot-initial-env is not a flashable image (no header/CRC included).

Writing it via fw_setenv works, but how can I use the file from the swu-Image instead of the one from the local file system (/etc/u-boot-initial-env)?
Do I need to write a script and use "fw_setenv -f" or is there a better way?

Thanks for helping!
Frieder

Fabio Estevam

unread,
Oct 26, 2022, 6:13:21 AM10/26/22
to Frieder Schrempf, swupdate
Hi Frieder,
You could add it to your sw-description:

images: (
{
filename = "u-boot-initial-env";
sha256 = "@u-boot-initial-env";
type = "bootloader";
},
{
....

Then in your swu image.bb:

SWUPDATE_IMAGES += "u-boot-initial-env"

Regards,

Fabio Estevam

Stefano Babic

unread,
Oct 26, 2022, 6:18:01 AM10/26/22
to swup...@googlegroups.com
Hi Frieder,

On 26.10.22 11:54, Frieder Schrempf wrote:
> Hello everyone,
>
> I'm wondering how to include the U-Boot environment created from "make
> u-boot-initial-env" into an SWU image so it can be flashed to the SPI
> NOR during the update process?

The reason for u-boot-initial-env (and libubootenv) is to avoid any
hardware dependency, what we have using U-Boot's legacy tool. It is not
required at all that the file is stored into the SPI flash.

When system boots and no environment is in flash, the tools in
libubootenv (fw_setenv / fw_printenv, but SWUpdate, too) will use
u-boot-initial-env. In OE, u-boot-initial-env is installed via the
u-boot-env package.

>
> Writing it to the flash directly doesn't work as the u-boot-initial-env
> is not a flashable image (no header/CRC included).
>
> Writing it via fw_setenv works, but how can I use the file from the
> swu-Image instead of the one from the local file system
> (/etc/u-boot-initial-env)?
> Do I need to write a script and use "fw_setenv -f" or is there a better way?
>

In case you update U-Boot and you have a new "default" environment, the
following methods are often used:

1. Put u-boot-initial-env into the SWU and use the bootloader handler, like:

images: (
{
filename = "u-boot-initial-env";
type = "bootloader";
}
);

(this is more similar as what you want - it is like a fw_setenv -s
u-boot-initial-env")

2. Just break the CRC into environment copy. You can use "copyhandler"
or whatever you want. U-Boot will start with default environment, and in
user space /etc/u-boot-initial-env will be taken.

In any case, SWUpdate does not need as input a flashable environment
built with mkimage or mkenvimage. SWUpdate takes a plain ASCII like
u-boot-initial-env and creates the environment for U-Boot nvia libubootenv.

Best regards,
Stefano


> Thanks for helping!
> Frieder
>
> --
> 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 on the web visit
> https://groups.google.com/d/msgid/swupdate/91b3b9bf-5c80-4c86-8fd6-97ea4bcd4369n%40googlegroups.com <https://groups.google.com/d/msgid/swupdate/91b3b9bf-5c80-4c86-8fd6-97ea4bcd4369n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=====================================================================

Frieder Schrempf

unread,
Oct 26, 2022, 7:08:47 AM10/26/22
to swupdate
Hi Fabio and Stefano,

thanks  a lot for the fast help! Got it now.
I added the following and the environment gets set correctly.

images: (
           {
               filename = "u-boot-initial-env";
               type = "bootloader";
           }
 );

Now I want to alter a variable in the postinst script like this:

postinst)
     echo "call post"
     fw_setenv boot_targets mmc0

But this doesn't seem to work. After the update boot_targets is still mmc1.
Running "fw_setenv boot_targets mmc0" from the console manually works fine though.
Any ideas?

Stefano Babic

unread,
Oct 26, 2022, 7:18:53 AM10/26/22
to Frieder Schrempf, swupdate
Hi Frieder,

On 26.10.22 13:08, Frieder Schrempf wrote:
> Hi Fabio and Stefano,
>
> thanks  a lot for the fast help! Got it now.
> I added the following and the environment gets set correctly.
>
> images: (
>            {
>                filename = "u-boot-initial-env";
>                type = "bootloader";
>            }
>  );
>
> Now I want to alter a variable in the postinst script like this:
>
> postinst)
> echo"call post"
>      fw_setenv boot_targets mmc0
>

This is a bad idea. You are breaking the atomicity, because there are
two steps where the environment is set. Additionally, running shell
script is for security reason a bad idea.

> But this doesn't seem to work. After the update boot_targets is still mmc1.
> Running "fw_setenv boot_targets mmc0" from the console manually works
> fine though.
> Any ideas?

SWUpdate as design will save the environment in an atomic way, that
means all environment is simply computed and stored in a shot as last
step of an update. That is, after you postscript ran. Take into account
that a power-cut after you script ran can lead to a bricked device.

Instead of this, simply add a bootenv entry in sw-description:

bootenv: (
{
name = "boot_targets";
value = "mmc0";
});

Best regards,
Stefano Babic
> https://groups.google.com/d/msgid/swupdate/91b3b9bf-5c80-4c86-8fd6-97ea4bcd4369n%40googlegroups.com <https://groups.google.com/d/msgid/swupdate/91b3b9bf-5c80-4c86-8fd6-97ea4bcd4369n%40googlegroups.com> <https://groups.google.com/d/msgid/swupdate/91b3b9bf-5c80-4c86-8fd6-97ea4bcd4369n%40googlegroups.com?utm_medium=email&utm_source=footer <https://groups.google.com/d/msgid/swupdate/91b3b9bf-5c80-4c86-8fd6-97ea4bcd4369n%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> --
> =====================================================================
> DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, 82194 Groebenzell, Germany
> Phone: +49-8142-66989-53 <tel:+49%208142%206698953> Fax:
> +49-8142-66989-80 <tel:+49%208142%206698980> Email: sba...@denx.de
> =====================================================================
>
> --
> 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 on the web visit
> https://groups.google.com/d/msgid/swupdate/71526686-8c8a-4681-b0fc-b9c47015e24fn%40googlegroups.com <https://groups.google.com/d/msgid/swupdate/71526686-8c8a-4681-b0fc-b9c47015e24fn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Frieder Schrempf

unread,
Oct 26, 2022, 7:57:46 AM10/26/22
to swupdate
Stefano Babic schrieb am Mittwoch, 26. Oktober 2022 um 13:18:53 UTC+2:
Hi Frieder,

On 26.10.22 13:08, Frieder Schrempf wrote:
> Hi Fabio and Stefano,
>
> thanks  a lot for the fast help! Got it now.
> I added the following and the environment gets set correctly.
>
> images: (
>            {
>                filename = "u-boot-initial-env";
>                type = "bootloader";
>            }
>  );
>
> Now I want to alter a variable in the postinst script like this:
>
> postinst)
> echo"call post"
>      fw_setenv boot_targets mmc0
>

This is a bad idea. You are breaking the atomicity, because there are
two steps where the environment is set. Additionally, running shell
script is for security reason a bad idea.

Ok
 

> But this doesn't seem to work. After the update boot_targets is still mmc1.
> Running "fw_setenv boot_targets mmc0" from the console manually works
> fine though.
> Any ideas?

SWUpdate as design will save the environment in an atomic way, that
means all environment is simply computed and stored in a shot as last
step of an update. That is, after you postscript ran. Take into account
that a power-cut after you script ran can lead to a bricked device.

Ok, I see.
 

Instead of this, simply add a bootenv entry in sw-description:

bootenv: (
{
name = "boot_targets";
value = "mmc0";
});

But is it possible to use bootenv to override a default env from the same file?
I now have the following, but the boot_targets variable is still set to mmc1 as in the initial env after running the update.

images: (
   {
     filename = "u-boot-initial-env";
     type = "bootloader";
   }
);

Stefano Babic

unread,
Oct 26, 2022, 8:23:40 AM10/26/22
to Frieder Schrempf, swupdate
Hi Frieder,
The behavior is undefined because you have twice the same variable with
different values, and you arev asking to apply both of them (remember:
for SWUpdate, environment is applied just once at the end of the
update). You should drop boot_targets from u-boot-initial-env, or set to
the desired value before putting it into the SWU.

Best regards,
Stefano

Frieder Schrempf

unread,
Oct 26, 2022, 9:17:28 AM10/26/22
to swupdate
Ok, maybe it would be a useful feature to be able to override the env from the bootloader handler with values in bootenv. But for now I think I can get along without this.
Thanks for your help!
Reply all
Reply to author
Forward
0 new messages