Skip to contentSkip to conversation

env_mmc: Fix crashing bug encountered after enabling ARM relocation

U-Boot Steve Sakoman 5 participants 9 messages Oct 8, 2010 – Oct 10, 2010 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

The crash was occuring in env_relocate because it was being called prior to mmc_initialize. This patch moves the MMC initialization earlier in the init process.

This patch also cleans up the env_relocate_spec code in env_mmc.c

Developed jointly with Stefano Babic

---

arch/arm/lib/board.c +5 -5
index 5f2dfd0..0e2f129 100644
@@ -779,6 +779,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	onenand_init();
 #endif
 
+#ifdef CONFIG_GENERIC_MMC
+       puts ("MMC:   ");
+       mmc_initialize (bd);
+#endif
+
 #ifdef CONFIG_HAS_DATAFLASH
 	AT91F_DataflashInit();
 	dataflash_print_info();
@@ -854,11 +859,6 @@ extern void davinci_eth_set_mac_addr (const u_int8_t *addr);
 	board_late_init ();
 #endif
 
-#ifdef CONFIG_GENERIC_MMC
-	puts ("MMC:   ");
-	mmc_initialize (gd->bd);
-#endif
-
 #ifdef CONFIG_BITBANGMII
 	bb_miiphy_init();
 #endif
common/env_mmc.c +10 -7
index cc288d4..d443ff5 100644
@@ -129,18 +129,21 @@ inline int read_env(struct mmc *mmc, unsigned long size,
 void env_relocate_spec(void)
 {
 #if !defined(ENV_IS_EMBEDDED)
+       char buf[CONFIG_ENV_SIZE];
+
 	struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
 
-	if (init_mmc_for_env(mmc))
+	if (init_mmc_for_env(mmc)) {
+		use_default();
 		return;
+	}
 
-	if (read_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr))
-		return use_default();
-
-	if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
-		return use_default();
+	if (read_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf)) {
+		use_default();
+		return;
+	}
 
-	gd->env_valid = 1;
+	env_import(buf, 1);
 #endif
 }
 
#1 lore raw
Quoted 9 lines

The crash was occuring in env_relocate because it was being called prior to mmc_initialize. This patch moves the MMC initialization earlier in the init process.

This patch also cleans up the env_relocate_spec code in env_mmc.c

Developed jointly with Stefano Babic

Fine; but is a Signed-off-by or Tested-by/Acked-by required from Stefano then?

Also this patch touch ARM and MMC code so can't add to u-boot-ti unless Wolfgang is ok.

Quoted 66 lines

---

arch/arm/lib/board.c +5 -5
index 5f2dfd0..0e2f129 100644
@@ -779,6 +779,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	onenand_init();
 #endif
 
+#ifdef CONFIG_GENERIC_MMC
+       puts ("MMC:   ");
+       mmc_initialize (bd);
+#endif
+
 #ifdef CONFIG_HAS_DATAFLASH
 	AT91F_DataflashInit();
 	dataflash_print_info();
@@ -854,11 +859,6 @@ extern void davinci_eth_set_mac_addr (const u_int8_t
 *addr);
 	board_late_init ();
 #endif
 
-#ifdef CONFIG_GENERIC_MMC
-	puts ("MMC:   ");
-	mmc_initialize (gd->bd);
-#endif
-
 #ifdef CONFIG_BITBANGMII
 	bb_miiphy_init();

#endif

common/env_mmc.c +10 -7
index cc288d4..d443ff5 100644
@@ -129,18 +129,21 @@ inline int read_env(struct mmc *mmc, unsigned long
 size,
 void env_relocate_spec(void)
 {
 #if !defined(ENV_IS_EMBEDDED)
+       char buf[CONFIG_ENV_SIZE];
+
 	struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
 
-	if (init_mmc_for_env(mmc))
+	if (init_mmc_for_env(mmc)) {
+		use_default();
 		return;
+	}
 
-	if (read_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, env_ptr))
-		return use_default();
-
-	if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
-		return use_default();
+	if (read_env(mmc, CONFIG_ENV_SIZE, CONFIG_ENV_OFFSET, buf)) {
+		use_default();
+		return;
+	}
 
-	gd->env_valid = 1;
+	env_import(buf, 1);
 #endif
 }
Acked-by
#2 lore raw

Am 09.10.2010 23:49, schrieb Paulraj, Sandeep:

Quoted 11 lines
Quoted 9 lines

The crash was occuring in env_relocate because it was being called prior to mmc_initialize. This patch moves the MMC initialization earlier in the init process.

This patch also cleans up the env_relocate_spec code in env_mmc.c

Developed jointly with Stefano Babic

Fine; but is a Signed-off-by or Tested-by/Acked-by required from Stefano then?

Steve can add my acked-by, as I discussed with him how to fix the issue.

Quoted 2 lines

Also this patch touch ARM and MMC code so can't add to u-boot-ti unless Wolfgang is ok.

Agree. The patch touches both ARM code and common code, and Wolfgang is maintainer for both of them.

Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#3 lore raw
In reply to Steve Sakoman

Hello.

Quoted 16 lines · Steve Sakoman

The crash was occuring in env_relocate because it was being called prior to mmc_initialize. This patch moves the MMC initialization earlier in the init process.

This patch also cleans up the env_relocate_spec code in env_mmc.c

Developed jointly with Stefano Babic

---

arch/arm/lib/board.c +0 -0
index 5f2dfd0..0e2f129 100644

arch/arm/lib/board.c void board_init_r (gd_t *id, ulong dest_addr) · line 784

Quoted 6 lines
arch/arm/lib/board.c +3 -0
@@ -779,6 +779,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
  	onenand_init();
  #endif
 
+#ifdef CONFIG_GENERIC_MMC
+       puts ("MMC:   ");
+       mmc_initialize (bd);

This would cause checkpatch.pl to complain -- no spaces allowed before (.

WBR, Sergei

#4 lore raw
Quoted 23 lines · Sergei Shtylyov

Hello.

Quoted 19 lines · Steve Sakoman

The crash was occuring in env_relocate because it was being called prior to mmc_initialize. ?This patch moves the MMC initialization earlier in the init process.

This patch also cleans up the env_relocate_spec code in env_mmc.c

Developed jointly with Stefano Babic

---

arch/arm/lib/board.c +0 -0
index 5f2dfd0..0e2f129 100644
@@ -779,6 +779,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
 ? ? ? onenand_init();

? #endif

Quoted 5 lines
Quoted 3 lines

+#ifdef CONFIG_GENERIC_MMC
+ ? ? ? puts ("MMC: ? ");
+ ? ? ? mmc_initialize (bd);

? ?This would cause checkpatch.pl to complain -- no spaces allowed before (.

I will resubmit a V2 with that change as well as Stefano's Signed-off-by

Steve

#5 lore raw

Hello.

Quoted 19 lines · Steve Sakoman
Quoted 19 lines
Quoted 19 lines

The crash was occuring in env_relocate because it was being called prior to mmc_initialize. This patch moves the MMC initialization earlier in the init process.

This patch also cleans up the env_relocate_spec code in env_mmc.c

Developed jointly with Stefano Babic

---

arch/arm/lib/board.c +0 -0
index 5f2dfd0..0e2f129 100644
@@ -779,6 +779,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
       onenand_init();
   #endif
 
Quoted 7 lines
Quoted 5 lines

arch/arm/lib/board.c void board_init_r (gd_t *id, ulong dest_addr) · line 784

Quoted 3 lines
arch/arm/lib/board.c +3 -0
+#ifdef CONFIG_GENERIC_MMC
+       puts ("MMC:   ");
+       mmc_initialize (bd);

This would cause checkpatch.pl to complain -- no spaces allowed before (.

I will resubmit a V2 with that change as well as Stefano's Signed-off-by

You've posted V2 with Stefano's ACK... and this line unchanged. :-)

Quoted 1 line

Steve

WBR, Sergei

#6 lore raw
Quoted 30 lines · Sergei Shtylyov

Hello.

Quoted 25 lines · Steve Sakoman
Quoted 25 lines
Quoted 19 lines

The crash was occuring in env_relocate because it was being called prior to mmc_initialize. ?This patch moves the MMC initialization earlier in the init process.

This patch also cleans up the env_relocate_spec code in env_mmc.c

Developed jointly with Stefano Babic

---

arch/arm/lib/board.c +0 -0
index 5f2dfd0..0e2f129 100644
@@ -779,6 +779,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
 ? ? ? onenand_init();

? #endif

Quoted 3 lines

+#ifdef CONFIG_GENERIC_MMC
+ ? ? ? puts ("MMC: ? ");
+ ? ? ? mmc_initialize (bd);

? ?This would cause checkpatch.pl to complain -- no spaces allowed before (.

Quoted 3 lines
Quoted 1 line

I ?will resubmit a V2 with that change as well as Stefano's Signed-off-by

? You've posted V2 with Stefano's ACK... and this line unchanged. :-)

???

+#ifdef CONFIG_GENERIC_MMC
+ puts("MMC: ");
+ mmc_initialize (bd);
+#endif
+

It looks changed to me!

Steve

#7 lore raw
Quoted 38 lines · Steve Sakoman
Quoted 26 lines
Quoted 25 lines
Quoted 25 lines
Quoted 16 lines

The crash was occuring in env_relocate because it was being called prior to mmc_initialize. This patch moves the MMC initialization earlier in the init process.

This patch also cleans up the env_relocate_spec code in env_mmc.c

Developed jointly with Stefano Babic

---

arch/arm/lib/board.c +0 -0
index 5f2dfd0..0e2f129 100644

arch/arm/lib/board.c void board_init_r (gd_t *id, ulong dest_addr) · line 784

Quoted 6 lines
arch/arm/lib/board.c +3 -0
@@ -779,6 +779,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
       onenand_init();
   #endif
 
+#ifdef CONFIG_GENERIC_MMC
+       puts ("MMC:   ");
+       mmc_initialize (bd);

This would cause checkpatch.pl to complain -- no spaces allowed before
(.

Quoted 3 lines
Quoted 1 line

I will resubmit a V2 with that change as well as Stefano's Signed-off-by

You've posted V2 with Stefano's ACK... and this line unchanged. :-)

???

arch/arm/lib/board.c +5 -0
+#ifdef CONFIG_GENERIC_MMC
+       puts("MMC:   ");
+       mmc_initialize (bd);
+#endif
+
Quoted 1 line

It looks changed to me!

Indeed, I have ovelooked that first line under #ifdef was changed. But not
the second. ;-)

Quoted 1 line

Steve

WBR, Sergei

#8 lore raw
Quoted 43 lines · Sergei Shtylyov
Quoted 40 lines · Steve Sakoman
Quoted 28 lines
Quoted 27 lines
Quoted 27 lines
Quoted 17 lines

The crash was occuring in env_relocate because it was being called prior
to mmc_initialize. This patch moves the MMC initialization earlier in the init process.

This patch also cleans up the env_relocate_spec code in env_mmc.c

Developed jointly with Stefano Babic

---

arch/arm/lib/board.c +0 -0
index 5f2dfd0..0e2f129 100644

arch/arm/lib/board.c void board_init_r (gd_t *id, ulong dest_addr) · line 784

Quoted 6 lines
arch/arm/lib/board.c +3 -0
@@ -779,6 +779,11 @@ void board_init_r (gd_t *id, ulong dest_addr)
      onenand_init();
  #endif
 
+#ifdef CONFIG_GENERIC_MMC
+       puts ("MMC:   ");
+       mmc_initialize (bd);

This would cause checkpatch.pl to complain -- no spaces allowed
before
(.

Quoted 4 lines
Quoted 2 lines

I will resubmit a V2 with that change as well as Stefano's Signed-off-by

You've posted V2 with Stefano's ACK... and this line unchanged. :-)

???

arch/arm/lib/board.c +5 -0
+#ifdef CONFIG_GENERIC_MMC
+       puts("MMC:   ");
+       mmc_initialize (bd);
+#endif
+
Quoted 4 lines
Quoted 1 line

It looks changed to me!

Indeed, I have ovelooked that first line under #ifdef was changed. But not
the second. ;-)

Sigh. You are correct!

I hate these older files that were done when "space before paren" was the rule. You have to be really careful when cutting and pasting, and even then you end up with a source file that is totally inconsistent in spacing unless you go and fix the entire file!

I will submit a v3.

Steve