Skip to contentSkip to conversation

env: mmc: statically set the environment partition name

PATCH Superseded Emmanuel Di Fede 3 participants 4 messages Jun 13, 2023 – Jul 15, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 env: mmc: statically set the environment partition name

The new opt-out setting, CONFIG_ENV_MMC_PARTITION, statically sets the MMC environment partition name. Prior to this patch, the only way to declare this partition name was by creating a 'u-boot,mmc-env-partition' parameter in the device-tree's /config node.

This setting provides additional flexibility, particularly in cases where accessing the device-tree is not straightforward (e.g. QEMU).

If undeclared, the device-tree's setting will be used.

Cc Joe Hershberger <[email protected]>
Cc Patrick Delaunay <[email protected]>
---
 doc/device-tree-bindings/config.txt | 2 ++
 env/Kconfig                         | 8 ++++++++
 env/mmc.c                           | 9 +++++++--
 3 files changed, 17 insertions(+), 2 deletions(-)
doc/device-tree-bindings/config.txt +2 -0
index 3151778b2c..f50c68bbdc 100644
@@ -76,6 +76,8 @@ u-boot,mmc-env-partition (int)
 	precedence. In that case, only if the partition is not found,
 	mmc-env-offset* will be tried.
 
+	Note that CONFIG_ENV_MMC_PARTITION overrides this device-tree setting.
+
 u-boot,no-apm-finalize (bool)
 	For x86 devices running on coreboot, this tells U-Boot not to lock
 	down the Intel Management Engine (ME) registers. This allows U-Boot to
env/Kconfig +8 -0
index 2bbe4c466a..de38b00bd1 100644
@@ -659,6 +659,14 @@ config SYS_MMC_ENV_PART
 	  partition 0 or the first boot partition, which is 1 or some other defined
 	  partition.
 
+config ENV_MMC_PARTITION
+	string "mmc environment partition name"
+	depends on ENV_IS_IN_MMC
+	help
+	  MMC partition name used to save environment variables.
+	  If this variable is unset, u-boot will try to get the env partition name
+	  from the DTB's /config node.
+
 config ENV_MMC_USE_DT
 	bool "Read partition name and offset in DT"
 	depends on ENV_IS_IN_MMC && OF_CONTROL
env/mmc.c +7 -2
index 7a5836ad66..887df61fbe 100644
@@ -114,8 +114,13 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy)
 	if (IS_ENABLED(CONFIG_SYS_MMC_ENV_PART))
 		hwpart = mmc_get_env_part(mmc);
 
-	/* look for the partition in mmc CONFIG_SYS_MMC_ENV_DEV */
-	str = ofnode_conf_read_str(dt_prop.partition);
+	if (IS_ENABLED(CONFIG_ENV_MMC_PARTITION)) {
+		str = CONFIG_ENV_MMC_PARTITION;
+	} else {
+		/* look for the partition in mmc CONFIG_SYS_MMC_ENV_DEV */
+		str = ofnode_conf_read_str(dt_prop.partition);
+	}
+
 	if (str) {
 		/* try to place the environment at end of the partition */
 		err = mmc_offset_try_partition(str, copy, &val);
Signature · 1 line
2.41.0
#1 lore raw

Hi,

Quoted 38 lines · Emmanuel Di Fede

The new opt-out setting, CONFIG_ENV_MMC_PARTITION, statically sets the MMC environment partition name. Prior to this patch, the only way to declare this partition name was by creating a 'u-boot,mmc-env-partition' parameter in the device-tree's /config node.

This setting provides additional flexibility, particularly in cases where accessing the device-tree is not straightforward (e.g. QEMU).

If undeclared, the device-tree's setting will be used.

Cc Joe Hershberger <[email protected]>
Cc Patrick Delaunay <[email protected]>
---
  doc/device-tree-bindings/config.txt | 2 ++
  env/Kconfig                         | 8 ++++++++
  env/mmc.c                           | 9 +++++++--
  3 files changed, 17 insertions(+), 2 deletions(-)
doc/device-tree-bindings/config.txt +2 -0
index 3151778b2c..f50c68bbdc 100644
@@ -76,6 +76,8 @@ u-boot,mmc-env-partition (int)
  	precedence. In that case, only if the partition is not found,
  	mmc-env-offset* will be tried.
 
+	Note that CONFIG_ENV_MMC_PARTITION overrides this device-tree setting.
+
  u-boot,no-apm-finalize (bool)
  	For x86 devices running on coreboot, this tells U-Boot not to lock
  	down the Intel Management Engine (ME) registers. This allows U-Boot to
env/Kconfig +0 -0
index 2bbe4c466a..de38b00bd1 100644
@@ -659,6 +659,14 @@ config SYS_MMC_ENV_PART
  	  partition 0 or the first boot partition, which is 1 or some other defined

env/Kconfig config SYS_MMC_ENV_PART · line 669

Quoted 10 lines
env/Kconfig +8 -0
  	  partition.
 
+config ENV_MMC_PARTITION
+	string "mmc environment partition name"
+	depends on ENV_IS_IN_MMC
+	help
+	  MMC partition name used to save environment variables.
+	  If this variable is unset, u-boot will try to get the env partition name
+	  from the DTB's /config node.
+

as it is sting this define is always activated => with default ""

if you want to test it with IS_ENABLED you need to add a other bolean config

I encounter the same issue several time

example: CONFIG_USE_DEFAULT_ENV_FILE/CONFIG_DEFAULT_ENV_FILE CONFIG_USE_BOOTCOMMAND / CONFIG_BOOTCOMMAND CONFIG_USE_BOOTARGS / CONFIG_BOOTARGS

sometthing like:

+config USE_ENV_MMC_PARTITION
+ boolean "use the mmc environment partition name"
+ depends on ENV_IS_IN_MMC

+config ENV_MMC_PARTITION
+ string "mmc environment partition name"
+ depends on USE_ENV_MMC_PARTITION
+ help

+	  MMC partition name used to save environment variables.
+	  If this variable is unset, u-boot will try to get the env partition name
+	  from the DTB's /config node.
Quoted 8 lines
env/Kconfig +0 -0
  config ENV_MMC_USE_DT
  	bool "Read partition name and offset in DT"
  	depends on ENV_IS_IN_MMC && OF_CONTROL
env/mmc.c +0 -0
index 7a5836ad66..887df61fbe 100644

env/mmc.c static inline s64 mmc_offset(struct mmc *mmc, int copy) · line 117

Quoted 6 lines
env/mmc.c +1 -2
@@ -114,8 +114,13 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy)
  	if (IS_ENABLED(CONFIG_SYS_MMC_ENV_PART))
  		hwpart = mmc_get_env_part(mmc);
 
-	/* look for the partition in mmc CONFIG_SYS_MMC_ENV_DEV */
-	str = ofnode_conf_read_str(dt_prop.partition);
+	if (IS_ENABLED(CONFIG_ENV_MMC_PARTITION)) {

see previous comment =>

if (IS_ENABLED(CONFIG_USE_ENV_MMC_PARTITION)) {

env/mmc.c static inline s64 mmc_offset(struct mmc *mmc, int copy) · line 122

Quoted 5 lines
env/mmc.c +5 -0
+		str = CONFIG_ENV_MMC_PARTITION;
+	} else {
+		/* look for the partition in mmc CONFIG_SYS_MMC_ENV_DEV */
+		str = ofnode_conf_read_str(dt_prop.partition);
+	}

I think it is can be simplified by using the macro with parameters

str = IS_ENABLED(CONFIG_USE_ENV_MMC_PARTITION,

                             CONFIG_ENV_MMC_PARTITION,

ofnode_conf_read_str(dt_prop.partition));

and that corrects a compilation issue when CONFIG_USE_ENV_MMC_PARTITION /  CONFIG_ENV_MMC_PARTITION are not defined

env/mmc.c static inline s64 mmc_offset(struct mmc *mmc, int copy) · line 126

Quoted 4 lines
env/mmc.c +1 -0
+
  	if (str) {
  		/* try to place the environment at end of the partition */
  		err = mmc_offset_try_partition(str, copy, &val);

Patrick

#2 lore raw

PATCH v2 1/1 env: mmc: statically set the environment partition name

The new opt-out setting, CONFIG_ENV_MMC_PARTITION, statically sets the MMC environment partition name. Prior to this patch, the only way to declare this partition name was by creating a 'u-boot,mmc-env-partition' parameter in the device-tree's /config node.

This setting provides additional flexibility, particularly in cases where accessing the device-tree is not straightforward (e.g. QEMU).

If undeclared, the device-tree's setting will be used.

Cc Joe Hershberger <[email protected]>
Cc Patrick Delaunay <[email protected]>

---
v2:
- Add CONFIG_USE_ENV_MMC_PARTITION
- Replace soft if(IS_DEFINED()) condition by pre-processor #if defined()

 doc/device-tree-bindings/config.txt |  2 ++
 env/Kconfig                         | 12 ++++++++++++
 env/mmc.c                           |  5 +++++
 3 files changed, 19 insertions(+)
doc/device-tree-bindings/config.txt +2 -0
index 3151778b2c..f50c68bbdc 100644
@@ -76,6 +76,8 @@ u-boot,mmc-env-partition (int)
 	precedence. In that case, only if the partition is not found,
 	mmc-env-offset* will be tried.
 
+	Note that CONFIG_ENV_MMC_PARTITION overrides this device-tree setting.
+
 u-boot,no-apm-finalize (bool)
 	For x86 devices running on coreboot, this tells U-Boot not to lock
 	down the Intel Management Engine (ME) registers. This allows U-Boot to
env/Kconfig +12 -0
index 2bbe4c466a..59a410447f 100644
@@ -659,6 +659,18 @@ config SYS_MMC_ENV_PART
 	  partition 0 or the first boot partition, which is 1 or some other defined
 	  partition.
 
+config USE_ENV_MMC_PARTITION
+	bool "use the mmc environment partition name"
+	depends on ENV_IS_IN_MMC
+
+config ENV_MMC_PARTITION
+	string "mmc environment partition name"
+	depends on USE_ENV_MMC_PARTITION
+	help
+	  MMC partition name used to save environment variables.
+	  If this variable is unset, u-boot will try to get the env partition name
+	  from the device-tree's /config node.
+
 config ENV_MMC_USE_DT
 	bool "Read partition name and offset in DT"
 	depends on ENV_IS_IN_MMC && OF_CONTROL
env/mmc.c +5 -0
index 7a5836ad66..cb14bbb58f 100644
@@ -114,8 +114,13 @@ static inline s64 mmc_offset(struct mmc *mmc, int copy)
 	if (IS_ENABLED(CONFIG_SYS_MMC_ENV_PART))
 		hwpart = mmc_get_env_part(mmc);
 
+#if defined(CONFIG_ENV_MMC_PARTITION)
+	str = CONFIG_ENV_MMC_PARTITION;
+#else
 	/* look for the partition in mmc CONFIG_SYS_MMC_ENV_DEV */
 	str = ofnode_conf_read_str(dt_prop.partition);
+#endif
+
 	if (str) {
 		/* try to place the environment at end of the partition */
 		err = mmc_offset_try_partition(str, copy, &val);
Signature · 1 line
2.41.0
#3 lore raw
Quoted 5 lines · Emmanuel Di Fede

The new opt-out setting, CONFIG_ENV_MMC_PARTITION, statically sets the MMC environment partition name. Prior to this patch, the only way to declare this partition name was by creating a 'u-boot,mmc-env-partition' parameter in the device-tree's /config node.

Quoted 8 lines

This setting provides additional flexibility, particularly in cases where accessing the device-tree is not straightforward (e.g. QEMU).

If undeclared, the device-tree's setting will be used.

Cc Joe Hershberger <[email protected]>
Cc Patrick Delaunay <[email protected]>

Applied to u-boot/master, thanks!

Signature · 1 line
Tom