Skip to contentSkip to conversation

env: mmc/fat/ext4: make sure that the MMC sub-system is initialized before using it

PATCH New Faiz Abbas 4 participants 6 messages Feb 2, 2018 – Feb 8, 2018

lore
Share & tools
lore

Faiz Abbas

author
#0 lore raw

PATCH 1/1 env: mmc/fat/ext4: make sure that the MMC sub-system is initialized before using it

When booting from a non-MMC device, the MMC sub-system may not be initialized when the environment is first accessed.
We need to make sure that the MMC sub-system is ready in even a non-MMC boot case.

Therefore, initialize mmc during .init() of environment.

---
 env/ext4.c | 9 +++++++++
 env/fat.c  | 9 +++++++++
 env/mmc.c  | 8 ++++++++
 3 files changed, 26 insertions(+)
env/ext4.c +9 -0
index 9cdf28e..ba93e5b 100644
@@ -123,9 +123,18 @@ err_env_relocate:
 	return -EIO;
 }
 
+static int env_ext4_init(void)
+{
+	if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))
+		mmc_initialize(NULL);
+
+	return 0;
+}
+
 U_BOOT_ENV_LOCATION(ext4) = {
 	.location	= ENVL_EXT4,
 	ENV_NAME("EXT4")
 	.load		= env_ext4_load,
 	.save		= env_save_ptr(env_ext4_save),
+	.init		= env_ext4_init,
 };
env/fat.c +9 -0
index ec49c39..9f147ee 100644
@@ -112,6 +112,14 @@ err_env_relocate:
 }
 #endif /* LOADENV */
 
+static int env_fat_init(void)
+{
+	if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))
+		mmc_initialize(NULL);
+
+	return 0;
+}
+
 U_BOOT_ENV_LOCATION(fat) = {
 	.location	= ENVL_FAT,
 	ENV_NAME("FAT")
@@ -121,4 +129,5 @@ U_BOOT_ENV_LOCATION(fat) = {
 #ifdef CMD_SAVEENV
 	.save		= env_save_ptr(env_fat_save),
 #endif
+	.init		= env_fat_init,
 };
env/mmc.c +8 -0
index ed7bcf1..714a073 100644
@@ -365,6 +365,13 @@ err:
 }
 #endif /* CONFIG_ENV_OFFSET_REDUND */
 
+static int env_mmc_init(void)
+{
+	mmc_initialize(NULL);
+
+	return 0;
+}
+
 U_BOOT_ENV_LOCATION(mmc) = {
 	.location	= ENVL_MMC,
 	ENV_NAME("MMC")
@@ -372,4 +379,5 @@ U_BOOT_ENV_LOCATION(mmc) = {
 #ifndef CONFIG_SPL_BUILD
 	.save		= env_save_ptr(env_mmc_save),
 #endif
+	.init		= env_mmc_init,
 };
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 env: mmc/fat/ext4: make sure that the MMC sub-system is initialized before using it

Quoted 81 lines · On Fri, 2 Feb 2018 15:17:55 +0530 Faiz Abbas <[email protected]> wrote:

When booting from a non-MMC device, the MMC sub-system may not be initialized when the environment is first accessed.
We need to make sure that the MMC sub-system is ready in even a non-MMC boot case.

Therefore, initialize mmc during .init() of environment.

---
 env/ext4.c | 9 +++++++++
 env/fat.c  | 9 +++++++++
 env/mmc.c  | 8 ++++++++
 3 files changed, 26 insertions(+)
env/ext4.c +9 -0
index 9cdf28e..ba93e5b 100644
@@ -123,9 +123,18 @@ err_env_relocate:
 	return -EIO;
 }
 
+static int env_ext4_init(void)
+{
+	if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))
+		mmc_initialize(NULL);
+
+	return 0;
+}
+
 U_BOOT_ENV_LOCATION(ext4) = {
 	.location	= ENVL_EXT4,
 	ENV_NAME("EXT4")
 	.load		= env_ext4_load,
 	.save		= env_save_ptr(env_ext4_save),
+	.init		= env_ext4_init,
 };
env/fat.c +9 -0
index ec49c39..9f147ee 100644
@@ -112,6 +112,14 @@ err_env_relocate:
 }
 #endif /* LOADENV */
 
+static int env_fat_init(void)
+{
+	if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))
+		mmc_initialize(NULL);
+
+	return 0;
+}
+
 U_BOOT_ENV_LOCATION(fat) = {
 	.location	= ENVL_FAT,
 	ENV_NAME("FAT")
@@ -121,4 +129,5 @@ U_BOOT_ENV_LOCATION(fat) = {
 #ifdef CMD_SAVEENV
 	.save		= env_save_ptr(env_fat_save),
 #endif
+	.init		= env_fat_init,
 };
env/mmc.c +7 -0
index ed7bcf1..714a073 100644
@@ -365,6 +365,13 @@ err:
 }
 #endif /* CONFIG_ENV_OFFSET_REDUND */
 
+static int env_mmc_init(void)
+{
+	mmc_initialize(NULL);
+
+	return 0;
+}
+
 U_BOOT_ENV_LOCATION(mmc) = {
 	.location	= ENVL_MMC,
 	ENV_NAME("MMC")

env/mmc.c U_BOOT_ENV_LOCATION(mmc) = { · line 383

Quoted 5 lines
env/mmc.c +1 -0
@@ -372,4 +379,5 @@ U_BOOT_ENV_LOCATION(mmc) = {
 #ifndef CONFIG_SPL_BUILD
 	.save		= env_save_ptr(env_mmc_save),
 #endif
+	.init		= env_mmc_init,
 };

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180204/028ed066/attachment.sig>

#2 lore raw

PATCH 1/1 env: mmc/fat/ext4: make sure that the MMC sub-system is initialized before using it

In reply to Faiz Abbas
Quoted 19 lines · Faiz Abbas

When booting from a non-MMC device, the MMC sub-system may not be initialized when the environment is first accessed.
We need to make sure that the MMC sub-system is ready in even a non-MMC boot case.

Therefore, initialize mmc during .init() of environment.

---
 env/ext4.c | 9 +++++++++
 env/fat.c  | 9 +++++++++
 env/mmc.c  | 8 ++++++++
 3 files changed, 26 insertions(+)
env/ext4.c +0 -0
index 9cdf28e..ba93e5b 100644

env/ext4.c err_env_relocate: · line 128

Quoted 6 lines
env/ext4.c +3 -0
@@ -123,9 +123,18 @@ err_env_relocate:
        return -EIO;
 }
 
+static int env_ext4_init(void)
+{
+       if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))

Shouldn't that be CONFIG_ENV_EXT4_INTERFACE ?

Signature · 1 line
Alex Kiernan
author
#3 lore raw

PATCH 1/1 env: mmc/fat/ext4: make sure that the MMC sub-system is initialized before using it

Hi,

Quoted 23 lines · Alex Kiernan
Quoted 22 lines · Faiz Abbas

When booting from a non-MMC device, the MMC sub-system may not be initialized when the environment is first accessed.
We need to make sure that the MMC sub-system is ready in even a non-MMC boot case.

Therefore, initialize mmc during .init() of environment.

---
 env/ext4.c | 9 +++++++++
 env/fat.c  | 9 +++++++++
 env/mmc.c  | 8 ++++++++
 3 files changed, 26 insertions(+)
env/ext4.c +0 -0
index 9cdf28e..ba93e5b 100644
@@ -123,9 +123,18 @@ err_env_relocate:
        return -EIO;
 }
 
Quoted 5 lines

env/ext4.c err_env_relocate: · line 128

Quoted 3 lines
env/ext4.c +3 -0
+static int env_ext4_init(void)
+{
+       if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc"))

Shouldn't that be CONFIG_ENV_EXT4_INTERFACE ?

Yes. Will fix in v2.

Thanks,
Faiz

#4 lore raw

PATCH 1/1 env: mmc/fat/ext4: make sure that the MMC sub-system is initialized before using it

In reply to Faiz Abbas

Dear Faiz Abbas,

Quoted 6 lines · In message <[email protected]> you wrote:

When booting from a non-MMC device, the MMC sub-system may not be initialized when the environment is first accessed.
We need to make sure that the MMC sub-system is ready in even a non-MMC boot case.

Therefore, initialize mmc during .init() of environment.

Do I understand correctly that you will always initialize the MMC sub-system if it is a candidate for reading the environment, even when the environment is read from elsewhere?

In this case I hereby NAK this patch.

U-Boot shall always use lazy initialization and never ever initialize hardware which it does not really use - see especially item 2 at [1].

[1] http://www.denx.de/wiki/U-Boot/DesignPrinciples

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The management question ... is not _whether_ to build a pilot  system
and  throw  it away. You _will_ do that. The only question is whether
to plan in advance to build a throwaway, or to promise to deliver the
throwaway to customers.       - Fred Brooks, "The Mythical Man Month"
author
#5 lore raw

PATCH 1/1 env: mmc/fat/ext4: make sure that the MMC sub-system is initialized before using it

Hi Wolfgang,

Quoted 8 lines · Wolfgang Denk

Dear Faiz Abbas,

Quoted 5 lines · In message <[email protected]> you wrote:

When booting from a non-MMC device, the MMC sub-system may not be initialized when the environment is first accessed.
We need to make sure that the MMC sub-system is ready in even a non-MMC boot case.

Quoted 5 lines
Quoted 1 line

Therefore, initialize mmc during .init() of environment.

Do I understand correctly that you will always initialize the MMC sub-system if it is a candidate for reading the environment, even when the environment is read from elsewhere?

I didn't realize that U-boot was supporting multiple environment candidates now. Will try to find another place to initialize mmc.

Thanks,
Faiz