Skip to contentSkip to conversation

default environment append from kconfig

DISCUSSION Francesco Dolcini 4 participants 8 messages Aug 9, 2022 – Aug 10, 2022

lore
Share & tools
lore
#0 lore raw

Hello all,
is there any kconfig mechanism in u-boot to append environment variable to the default one?

I am aware of CONFIG_USE_DEFAULT_ENV_FILE, but this will completely replace it, looking into the code I was not able to find anything, but I wonder if something from this
https://lore.kernel.org/all/[email protected]/
can be used.

Francesco

#1 lore raw
Quoted 4 lines · Francesco Dolcini

Hello all,
is there any kconfig mechanism in u-boot to append environment variable to the default one?

Well, despite the name, CONFIG_EXTRA_ENV_SETTINGS is not settable via kconfig, but only from board header file. And while it works, it's rather cumbersome to maintain that macro expanding to a string with all the embedded \0 and the required \ continuations etc.

Quoted 2 lines

I am aware of CONFIG_USE_DEFAULT_ENV_FILE, but this will completely replace it, looking into the code I was not able to find anything,

You could select CONFIG_ENV_IMPORT_FDT, then populate the /config/environment/ devicetree node with the key/value pairs you want.

This can for example be done via the <board>-u-boot.dtsi file, or if you're using an in-tree board with in-tree .dts, and just want to maintain your own .config and environment out of tree, you could additionally set CONFIG_DEVICE_TREE_INCLUDES to point at a .dtsi which just has that

/ {

  config {
    environment {
      foo = "bar";
    };

};
};

(that was exactly a use case I had in mind for CONFIG_DEVICE_TREE_INCLUDES, as can be seen in the commit log for a77f468099).

Rasmus

#2 lore raw
Quoted 18 lines · Rasmus Villemoes
Quoted 2 lines · Francesco Dolcini

I am aware of CONFIG_USE_DEFAULT_ENV_FILE, but this will completely replace it, looking into the code I was not able to find anything,

You could select CONFIG_ENV_IMPORT_FDT, then populate the /config/environment/ devicetree node with the key/value pairs you want.

This can for example be done via the <board>-u-boot.dtsi file, or if you're using an in-tree board with in-tree .dts, and just want to maintain your own .config and environment out of tree, you could additionally set CONFIG_DEVICE_TREE_INCLUDES to point at a .dtsi which just has that

/ {

  config {
    environment {
      foo = "bar";
    };
Quoted 6 lines

};
};

(that was exactly a use case I had in mind for CONFIG_DEVICE_TREE_INCLUDES, as can be seen in the commit log for a77f468099).

Thanks Rasmus, it looks pretty helpful, I'll give it a try.

Francesco

#3 lore raw
In reply to Rasmus Villemoes
Quoted 10 lines · Rasmus Villemoes
Quoted 4 lines · Francesco Dolcini

Hello all,
is there any kconfig mechanism in u-boot to append environment variable to the default one?

Well, despite the name, CONFIG_EXTRA_ENV_SETTINGS is not settable via kconfig, but only from board header file. And while it works, it's rather cumbersome to maintain that macro expanding to a string with all the embedded \0 and the required \ continuations etc.

I just want to chime in here to note that the biggest blocker to removing CONFIG_EXTRA_ENV_SETTINGS and migrating it to board.env files is how to handle, exactly, distroboot support. Aside from that, whatever is done in CONFIG_EXTRA_ENV_SETTINGS can be done in the .env file (unless there's some other fancy macro work being done that I've missed).

Signature · 1 line
Tom
#4 lore raw

Hi Tom,

Quoted 8 lines · Tom Rini
Quoted 6 lines · Rasmus Villemoes
Quoted 4 lines · Francesco Dolcini

Hello all,
is there any kconfig mechanism in u-boot to append environment variable to the default one?

Quoted 8 lines
Quoted 4 lines

Well, despite the name, CONFIG_EXTRA_ENV_SETTINGS is not settable via kconfig, but only from board header file. And while it works, it's rather cumbersome to maintain that macro expanding to a string with all the embedded \0 and the required \ continuations etc.

I just want to chime in here to note that the biggest blocker to removing CONFIG_EXTRA_ENV_SETTINGS and migrating it to board.env files is how to handle, exactly, distroboot support. Aside from that,

I will get back to that before long.

Quoted 6 lines

whatever is done in CONFIG_EXTRA_ENV_SETTINGS can be done in the .env file (unless there's some other fancy macro work being done that I've missed).

--
Tom

Regards,
SImon

#5 lore raw
In reply to Francesco Dolcini
Quoted 9 lines · Francesco Dolcini

Hello all,
is there any kconfig mechanism in u-boot to append environment variable to the default one?

I am aware of CONFIG_USE_DEFAULT_ENV_FILE, but this will completely replace it, looking into the code I was not able to find anything, but I wonder if something from this
https://lore.kernel.org/all/[email protected]/
can be used.

Yes, you can use the series above, which has been merged for some time, to append to the environment via board/../<board>/<board>.env and you can look at the existing .env files for examples of how it works.

Signature · 1 line
Tom
#6 lore raw
Quoted 11 lines · Tom Rini
Quoted 9 lines · Francesco Dolcini

Hello all,
is there any kconfig mechanism in u-boot to append environment variable to the default one?

I am aware of CONFIG_USE_DEFAULT_ENV_FILE, but this will completely replace it, looking into the code I was not able to find anything, but I wonder if something from this
https://lore.kernel.org/all/[email protected]/
can be used.

Quoted 3 lines

Yes, you can use the series above, which has been merged for some time, to append to the environment via board/../<board>/<board>.env and you can look at the existing .env files for examples of how it works.

Am I wrong or this just override the whole environment? My need here is to just add|override some env variables to the default env to an in-tree u-boot board from an out-of-tree configuration.

Think about a specific network or boot configuration, for example.

Francesco

#7 lore raw
Quoted 12 lines · Francesco Dolcini
Quoted 11 lines · Tom Rini
Quoted 9 lines · Francesco Dolcini

Hello all,
is there any kconfig mechanism in u-boot to append environment variable to the default one?

I am aware of CONFIG_USE_DEFAULT_ENV_FILE, but this will completely replace it, looking into the code I was not able to find anything, but I wonder if something from this
https://lore.kernel.org/all/[email protected]/
can be used.

Quoted 8 lines
Quoted 3 lines

Yes, you can use the series above, which has been merged for some time, to append to the environment via board/../<board>/<board>.env and you can look at the existing .env files for examples of how it works.

Am I wrong or this just override the whole environment? My need here is to just add|override some env variables to the default env to an in-tree u-boot board from an out-of-tree configuration.

Think about a specific network or boot configuration, for example.

It doesn't override the whole environment. As of the link you posted, it did override all of (or rather, conflicted with) CONFIG_EXTRA_ENV_SETTINGS, but I changed that more recently as it was hindering adoption of the feature overall.

Signature · 1 line
Tom