public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Patrick Delaunay <patrick.delaunay@st.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 2/3] env: introduce macro ENV_IS_IN_SOMEWHERE
Date: Thu, 3 Oct 2019 09:24:27 +0200	[thread overview]
Message-ID: <20191003072428.19197-3-patrick.delaunay@st.com> (raw)
In-Reply-To: <20191003072428.19197-1-patrick.delaunay@st.com>

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@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

  parent reply	other threads:[~2019-10-03  7:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03  7:24 [U-Boot] [PATCH v4 0/3] env: Add CONFIG_ENV_FULL_SUPPORT Patrick Delaunay
2019-10-03  7:24 ` [U-Boot] [PATCH v4 1/3] env: correct the check of env_flags_validate presence Patrick Delaunay
2019-10-03 13:18   ` Tom Rini
2019-10-03  7:24 ` Patrick Delaunay [this message]
2020-03-18 16:03   ` [PATCH v4 2/3] env: introduce macro ENV_IS_IN_SOMEWHERE Patrick DELAUNAY
2019-10-03  7:24 ` [U-Boot] [PATCH v4 3/3] env: Add CONFIG_ENV_FULL_SUPPORT Patrick Delaunay
2020-03-18 16:06   ` Patrick DELAUNAY
2019-10-07 17:56 ` [U-Boot] [PATCH v4 0/3] " Wolfgang Denk
2019-10-07 22:36   ` Tom Rini
2019-10-08 11:09     ` Wolfgang Denk
2019-10-14 14:46   ` Patrick DELAUNAY
2019-10-15  9:28     ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191003072428.19197-3-patrick.delaunay@st.com \
    --to=patrick.delaunay@st.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox