[U-Boot] [PATCH v4 2/3] env: introduce macro ENV_IS_IN_SOMEWHERE

Patrick Delaunay patrick.delaunay at st.com
Thu Oct 3 07:24:27 UTC 2019


This patch introduce a macro ENV_IS_IN_SOMEWHERE to check if the
the environment can be saved somewhere, in a storage medium,
without assumption on CONFIG$(SPL_TPL_)ENV_IS_NOWHERE.

Since the commit 208bd2b85ecc ("env: allow ENV_IS_NOWHERE with
other storage target"), it is allowed to activated ENV_IS_NOWHERE with
other CONFIG_IS_IN... in U-Boot.
It is only allowed for U-Boot but the remaining restriction in Kconfig
could also removed for SPL and TPL
(depends on !SPL_ENV_IS_NOWHERE / depends on !TPL_ENV_IS_NOWHERE).

This macro ENV_IS_IN_SOMEWHERE can be used in code to check if the
environment for U-Boot / SPL / TPL is really managed (at least one
CONFIG$(SPL_TPL_)ENV_IS_IN_.. is activated).

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
---
Hi,

For this patch,
I am not completely satisfied by the name "ENV_IS_IN_SOMEWHERE".

Perhaps other name will be less confusing:
 "ENV_IS_IN_XXX",
 "ENV_IS_IN_DEVICE",
 "ENV_IS_IN_STORAGE",
 "ENV_IS_IN_MEDIUM",
 "ENV_IS_IN_STORAGE_MEDIUM",
 "ENV_SAVE_SUPPORT" ...

But I don't found a perfect solution...

Any proposal  on other name is welcome.


Changes in v4: None
Changes in v3: None
Changes in v2:
- Add comment for ENV_IS_IN_SOMEWHERE

 cmd/nvedit.c  | 29 +++++++----------------------
 include/env.h | 23 +++++++++++++++++++++++
 2 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 1cb0bc1460..7a6ec5ae30 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -40,28 +40,13 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if	defined(CONFIG_ENV_IS_IN_EEPROM)	|| \
-	defined(CONFIG_ENV_IS_IN_FLASH)		|| \
-	defined(CONFIG_ENV_IS_IN_MMC)		|| \
-	defined(CONFIG_ENV_IS_IN_FAT)		|| \
-	defined(CONFIG_ENV_IS_IN_EXT4)		|| \
-	defined(CONFIG_ENV_IS_IN_NAND)		|| \
-	defined(CONFIG_ENV_IS_IN_NVRAM)		|| \
-	defined(CONFIG_ENV_IS_IN_ONENAND)	|| \
-	defined(CONFIG_ENV_IS_IN_SATA)		|| \
-	defined(CONFIG_ENV_IS_IN_SPI_FLASH)	|| \
-	defined(CONFIG_ENV_IS_IN_REMOTE)	|| \
-	defined(CONFIG_ENV_IS_IN_UBI)
-
-#define ENV_IS_IN_DEVICE
-
-#endif
-
-#if	!defined(ENV_IS_IN_DEVICE)		&& \
-	!defined(CONFIG_ENV_IS_NOWHERE)
+#if !defined(CONFIG_SPL_BUILD) || CONFIG_IS_ENABLED(ENV_SUPPORT)
+#if	!ENV_IS_IN_SOMEWHERE		&& \
+	!CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
 # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|MMC|FAT|EXT4|\
 NAND|NVRAM|ONENAND|SATA|SPI_FLASH|REMOTE|UBI} or CONFIG_ENV_IS_NOWHERE
 #endif
+#endif
 
 /*
  * Maximum expected input data size for import command
@@ -744,7 +729,7 @@ ulong env_get_ulong(const char *name, int base, ulong default_val)
 }
 
 #ifndef CONFIG_SPL_BUILD
-#if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE)
+#if defined(CONFIG_CMD_SAVEENV) && ENV_IS_IN_SOMEWHERE
 static int do_env_save(cmd_tbl_t *cmdtp, int flag, int argc,
 		       char * const argv[])
 {
@@ -1309,7 +1294,7 @@ static cmd_tbl_t cmd_env_sub[] = {
 #if defined(CONFIG_CMD_RUN)
 	U_BOOT_CMD_MKENT(run, CONFIG_SYS_MAXARGS, 1, do_run, "", ""),
 #endif
-#if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE)
+#if defined(CONFIG_CMD_SAVEENV) && ENV_IS_IN_SOMEWHERE
 	U_BOOT_CMD_MKENT(save, 1, 0, do_env_save, "", ""),
 #if defined(CONFIG_CMD_ERASEENV)
 	U_BOOT_CMD_MKENT(erase, 1, 0, do_env_erase, "", ""),
@@ -1392,7 +1377,7 @@ static char env_help_text[] =
 #if defined(CONFIG_CMD_RUN)
 	"env run var [...] - run commands in an environment variable\n"
 #endif
-#if defined(CONFIG_CMD_SAVEENV) && defined(ENV_IS_IN_DEVICE)
+#if defined(CONFIG_CMD_SAVEENV) && ENV_IS_IN_SOMEWHERE
 	"env save - save environment\n"
 #if defined(CONFIG_CMD_ERASEENV)
 	"env erase - erase environment\n"
diff --git a/include/env.h b/include/env.h
index a74a261337..bdf42e746a 100644
--- a/include/env.h
+++ b/include/env.h
@@ -35,6 +35,29 @@ struct env_clbk_tbl {
 			int flags);
 };
 
+/**
+ * ENV_IS_IN_SOMEWHERE - test if one storage medium is supported by enviromnent
+ *
+ * this helper macro allow to test if at a storage medium is supported by
+ * U-Boot enviromnent, so if one configuration of ENV_IS_IN_... is activated
+ * usage: #if ENV_IS_IN_SOMEWHERE
+ *
+ * WARNING: several storage medium can be activated at the same time
+ *          and ENV_IS_NOWHERE can be also activated as fallback
+ */
+#define ENV_IS_IN_SOMEWHERE \
+		(CONFIG_IS_ENABLED(ENV_IS_IN_EEPROM) || \
+		 CONFIG_IS_ENABLED(ENV_IS_IN_EXT4) || \
+		 CONFIG_IS_ENABLED(ENV_IS_IN_FAT) || \
+		 CONFIG_IS_ENABLED(ENV_IS_IN_FLASH) || \
+		 CONFIG_IS_ENABLED(ENV_IS_IN_MMC) || \
+		 CONFIG_IS_ENABLED(ENV_IS_IN_NAND) || \
+		 CONFIG_IS_ENABLED(ENV_IS_IN_NVRAM) || \
+		 CONFIG_IS_ENABLED(ENV_IS_IN_ONENAND) || \
+		 CONFIG_IS_ENABLED(ENV_IS_IN_REMOTE) || \
+		 CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH) || \
+		 CONFIG_IS_ENABLED(ENV_IS_IN_UBI))
+
 /*
  * Define a callback that can be associated with variables.
  * when associated through the ".callbacks" environment variable, the callback
-- 
2.17.1



More information about the U-Boot mailing list