Re: [PATCH v2] Allow usage of default environment without environment file storage

2019-12-11 Thread Sascha Hauer
On Mon, Dec 09, 2019 at 11:49:28AM +0100, Albert Schwarzkopf wrote:
> Currently, the default environment is only used when the
> barebox environment on the persistent store is not valid
> or when ENVFS_FLAGS_FORCE_BUILT_IN is set in the super block.
> 
> However, ENVFS_FLAGS_FORCE_BUILT_IN can be cleared and the
> environmnet variables in the persistent store will be
> used again. This may not be desirable.
> 
> This patch allows building CONFIG_DEFAULT_ENVIRONMENT
> independent of CONFIG_ENV_HANDLING. This can be useful
> if you never want to load or write values from the
> persistent store and you only need to read environment variables
> from your default environment.
> 
> If CONFIG_ENV_HANDLING is not set, a message will be printed to the
> user indicating that changes to non-volatile variables won't be
> persisted.
> 
> Move envfs functions that are needed when CONFIG_DEFAULT_ENVIRONMENT
> and/or CONFIG_ENV_HANDLING is set to a new file common/envfs-core.c.
> 
> Signed-off-by: Albert Schwarzkopf 
> ---

Applied, thanks

Sascha

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2] Allow usage of default environment without environment file storage

2019-12-09 Thread Albert Schwarzkopf
Currently, the default environment is only used when the
barebox environment on the persistent store is not valid
or when ENVFS_FLAGS_FORCE_BUILT_IN is set in the super block.

However, ENVFS_FLAGS_FORCE_BUILT_IN can be cleared and the
environmnet variables in the persistent store will be
used again. This may not be desirable.

This patch allows building CONFIG_DEFAULT_ENVIRONMENT
independent of CONFIG_ENV_HANDLING. This can be useful
if you never want to load or write values from the
persistent store and you only need to read environment variables
from your default environment.

If CONFIG_ENV_HANDLING is not set, a message will be printed to the
user indicating that changes to non-volatile variables won't be
persisted.

Move envfs functions that are needed when CONFIG_DEFAULT_ENVIRONMENT
and/or CONFIG_ENV_HANDLING is set to a new file common/envfs-core.c.

Signed-off-by: Albert Schwarzkopf 
---
v2: instead of introducing new #ifdefs, move functions
to new file common/envfs-core.c which contains the functions that we 
need when CONFIG_ENV_HANDLING and/or CONFIG_DEFAULT_ENVIRONMENT is set. 
Change scripts/bareboxenv.c to use common/envfs-core.c.
---
 commands/nv.c|   5 ++
 common/Kconfig   |  24 +++---
 common/Makefile  |   3 +-
 common/envfs-core.c  | 197 +++
 common/environment.c | 172 -
 common/globalvar.c   |  16 ++--
 common/startup.c |  24 --
 include/envfs.h  |   5 ++
 scripts/bareboxenv.c |   1 +
 9 files changed, 250 insertions(+), 197 deletions(-)
 create mode 100644 common/envfs-core.c

diff --git a/commands/nv.c b/commands/nv.c
index 01c25a108..315019345 100644
--- a/commands/nv.c
+++ b/commands/nv.c
@@ -50,6 +50,11 @@ static int do_nv(int argc, char *argv[])
}
 
if (do_save) {
+   if (!IS_ENABLED(CONFIG_ENV_HANDLING)) {
+   printf("Error: Current configuration does not support 
saving variables\n");
+   return COMMAND_ERROR;
+   }
+
return nvvar_save();
}
 
diff --git a/common/Kconfig b/common/Kconfig
index cafaadb3d..05b961be7 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -174,19 +174,19 @@ config GLOBALVAR
 
 config NVVAR
bool "Non volatile global environment variables support"
-   default y if !SHELL_NONE
+   default y if !SHELL_NONE && ENV_HANDLING
depends on GLOBALVAR
-   depends on ENV_HANDLING
select FNMATCH
help
  Non volatile environment variables begin with "nv.". They behave like
- global variables above, but their values are saved in the environment
- storage with 'saveenv' and thus are persistent over restarts. nv 
variables
- are coupled with global variables of the same name. Setting "nv.foo" 
results
- in "global.foo" changed also (but not the other way round: setting 
"global.foo"
- leaves "nv.foo" untouched). The idea is that nv variables can store 
defaults
- while global variables can be changed during runtime without changing 
the
- default.
+ global variables above, but when CONFIG_ENV_HANDLING is enabled, they
+ can be stored in the environment storage with 'saveenv' and thus
+ persisted over restarts. nv variables are coupled with global
+ variables of the same name. Setting "nv.foo" results in "global.foo"
+ changed also (but not the other way round: setting "global.foo" leaves
+ "nv.foo" untouched). The idea is that nv variables can store defaults
+ while global variables can be changed during runtime without changing
+ the default.
 
 menu "memory layout"
 
@@ -805,12 +805,12 @@ config ENV_HANDLING
 
 config DEFAULT_ENVIRONMENT
bool
-   default y
-   depends on ENV_HANDLING
+   default y if ENV_HANDLING
prompt "Compile in default environment"
help
  Enabling this option will give you a default environment when
- the environment found in the environment sector is invalid
+ the environment found in the environment sector is invalid or when
+ CONFIG_ENV_HANDLING is not enabled.
 
 choice
prompt "default compression for in-barebox binaries"
diff --git a/common/Makefile b/common/Makefile
index a284655fc..03617e67b 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -25,7 +25,8 @@ obj-$(CONFIG_CONSOLE_FULL)+= console.o
 obj-$(CONFIG_CONSOLE_SIMPLE)   += console_simple.o
 obj-y  += console_countdown.o
 obj-pbl-$(CONFIG_DDR_SPD)  += ddr_spd.o
-obj-$(CONFIG_ENV_HANDLING) += environment.o
+obj-$(CONFIG_ENV_HANDLING) += environment.o envfs-core.o
+obj-$(CONFIG_DEFAULT_ENVIRONMENT) += envfs-core.o
 obj-$(CONFIG_ENVIRONMENT_VARIABLES) += env.o
 obj-$(CONFIG_FILETYPE) += filetype.o
 CFLAGS_filetype.o = -I$(srctree)/arch/
diff --git a/common/envfs-core.c b/common/envfs-core.c
new