Skip to contentSkip to conversation

Save environment data to mmc.

PATCH New Terry Lv 3 participants 4 messages Nov 5, 2009 – Nov 6, 2009

lore
Share & tools
lore

Terry Lv

author
#0 lore raw

PATCH 1/1 Save environment data to mmc.

This patch is to save environment data to mmc card. It uses interfaces defined in generic mmc.

---
 common/Makefile       |    1 +
 common/cmd_nvedit.c   |    3 +-
 common/env_mmc.c      |  359 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/environment.h |   18 +++
 lib_arm/board.c       |   10 +-
 lib_ppc/board.c       |   12 +-
 6 files changed, 391 insertions(+), 12 deletions(-)
 create mode 100644 common/env_mmc.c
common/Makefile +1 -0
index a92a75f..e92a2ce 100644
@@ -58,6 +58,7 @@ COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o
 COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o
 COBJS-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o
 COBJS-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o
+COBJS-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o
 COBJS-$(CONFIG_ENV_IS_NOWHERE) += env_nowhere.o
 
 # command
common/cmd_nvedit.c +2 -1
index 9f8d531..9168241 100644
@@ -60,9 +60,10 @@ DECLARE_GLOBAL_DATA_PTR;
     !defined(CONFIG_ENV_IS_IN_NVRAM)	&& \
     !defined(CONFIG_ENV_IS_IN_ONENAND)	&& \
     !defined(CONFIG_ENV_IS_IN_SPI_FLASH)	&& \
+    !defined(CONFIG_ENV_IS_IN_MMC)	&& \
     !defined(CONFIG_ENV_IS_NOWHERE)
 # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
-SPI_FLASH|MG_DISK|NVRAM|NOWHERE}
+SPI_FLASH|MG_DISK|NVRAM|MMC|NOWHERE}
 #endif
 
 #define XMK_STR(x)	#x
common/env_mmc.c new file +359 -0

359 lines not on this page · raw message

include/environment.h +18 -0
index b9924fd..0b72e0b 100644
@@ -94,6 +94,24 @@
 # endif
 #endif /* CONFIG_ENV_IS_IN_MG_DISK */
 
+#if defined(CONFIG_ENV_IS_IN_MMC)
+# ifndef CONFIG_ENV_OFFSET
+#  error "Need to define CONFIG_ENV_OFFSET when using CONFIG_ENV_IS_IN_MMC"
+# endif
+# ifndef CONFIG_ENV_ADDR
+#  define CONFIG_ENV_ADDR	(CONFIG_ENV_OFFSET)
+# endif
+# ifndef CONFIG_ENV_OFFSET
+#  define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR)
+# endif
+# ifdef CONFIG_ENV_OFFSET_REDUND
+#  define CONFIG_SYS_REDUNDAND_ENVIRONMENT
+# endif
+# ifdef CONFIG_ENV_IS_EMBEDDED
+#  define ENV_IS_EMBEDDED	1
+# endif
+#endif /* CONFIG_ENV_IS_IN_MMC */
+
 /* Embedded env is only supported for some flash types */
 #ifdef CONFIG_ENV_IS_EMBEDDED
 # if !defined(CONFIG_ENV_IS_IN_FLASH) && \
lib_arm/board.c +5 -5
index 5e3d7f6..bece7d7 100644
@@ -335,6 +335,11 @@ void start_armboot (void)
 	nand_init();		/* go init the NAND */
 #endif
 
+#ifdef CONFIG_GENERIC_MMC
+        puts ("MMC:   ");
+        mmc_initialize (gd->bd);
+#endif
+
 #if defined(CONFIG_CMD_ONENAND)
 	onenand_init();
 #endif
@@ -416,11 +421,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
lib_ppc/board.c +6 -6
index 765f97a..fac5c29 100644
@@ -776,6 +776,12 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	nand_init();		/* go init the NAND */
 #endif
 
+#ifdef CONFIG_GENERIC_MMC
+        WATCHDOG_RESET ();
+        puts ("MMC:  ");
+        mmc_initialize (bd);
+#endif
+
 	/* relocate environment function pointers etc. */
 	env_relocate ();
 
@@ -932,12 +938,6 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	scsi_init ();
 #endif
 
-#ifdef CONFIG_GENERIC_MMC
-	WATCHDOG_RESET ();
-	puts ("MMC:  ");
-	mmc_initialize (bd);
-#endif
-
 #if defined(CONFIG_CMD_DOC)
 	WATCHDOG_RESET ();
 	puts ("DOC:   ");
Signature · 1 line
1.6.0.4
#1 lore raw

PATCH 1/1 Save environment data to mmc.

common/Makefile COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o · line 61

Quoted 7 lines · On Thursday 05 November 2009 02:43:33 Terry Lv wrote:
common/Makefile +1 -0
@@ -58,6 +58,7 @@ COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o
 COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o
 COBJS-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o
 COBJS-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o
+COBJS-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o

this list is attempting to stay in order according to the CONFIG name, so you should add this above the NAND ENV entry

common/env_mmc.c line 1

Quoted 4 lines
common/env_mmc.c new file +1 -0
@@ -0,0 +1,359 @@
+#if defined(CONFIG_ENV_IS_IN_MMC) /* Environment is in MMC Flash */

you dont need this line anymore as it's in the Makefile

common/env_mmc.c line 53

Quoted 3 lines
common/env_mmc.c new file +3 -0
+#ifdef CONFIG_INFERNO
+#error CONFIG_INFERNO not supported yet
+#endif

is this really needed ?

common/env_mmc.c line 57

Quoted 1 line
common/env_mmc.c new file +1 -0
+extern int default_environment_size;

this looks like another useless line copy & pasted from whatever file you based this on
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20091105/7cd8ba61/attachment.pgp

#2 lore raw

PATCH 1/1 Save environment data to mmc.

Hi Mike,

I will fix the two issues you pointed. Thanks a lot.

Actually, env_mmc.c is written based on env_nand.c in u-boot 1.3.3.

I have modified it according to the latest changes in environment code. But seems there's still a lot of issue. Sorry for that.

It works well in our project. So I want to add it to u-boot mainline.

Thanks~~

Yours
Terry

-----Original Message-----
From: Mike Frysinger [mailto:vapier at gentoo.org]
Sent: 2009?11?5? 20:10
To: u-boot at lists.denx.de
Cc: Lv Terry-R65388
Subject: Re: [U-Boot] [PATCH] Save environment data to mmc.

common/Makefile COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o · line 61

Quoted 7 lines · On Thursday 05 November 2009 02:43:33 Terry Lv wrote:
common/Makefile +1 -0
@@ -58,6 +58,7 @@ COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o
 COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o
 COBJS-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o
 COBJS-$(CONFIG_ENV_IS_IN_SPI_FLASH) += env_sf.o
+COBJS-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o

this list is attempting to stay in order according to the CONFIG name, so you should add this above the NAND ENV entry

common/env_mmc.c line 1

Quoted 4 lines
common/env_mmc.c new file +1 -0
@@ -0,0 +1,359 @@
+#if defined(CONFIG_ENV_IS_IN_MMC) /* Environment is in MMC Flash */

you dont need this line anymore as it's in the Makefile

common/env_mmc.c line 3

Quoted 2 lines
common/env_mmc.c new file +2 -0
+#ifdef CONFIG_INFERNO
+#error CONFIG_INFERNO not supported yet #endif

is this really needed ?

common/env_mmc.c line 57

Quoted 1 line
common/env_mmc.c new file +1 -0
+extern int default_environment_size;

this looks like another useless line copy & pasted from whatever file you based this on -mike

#3 lore raw

PATCH 1/1 Save environment data to mmc.

In reply to Terry Lv

Dear Terry Lv,

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

This patch is to save environment data to mmc card. It uses interfaces defined in generic mmc.

...

Quoted 9 lines
common/env_mmc.c new file +9 -0
+	if (!crc1_ok && !crc2_ok)
+		gd->env_valid = 0;
+	else if (crc1_ok && !crc2_ok)
+		gd->env_valid = 1;
+	else if (!crc1_ok && crc2_ok)
+		gd->env_valid = 2;
+	else {
+		/* both ok - check serial */
+		if (tmp_env1->flags == 255 && tmp_env2->flags == 0)

common/env_mmc.c line 113

Quoted 10 lines
common/env_mmc.c new file +10 -0
+			gd->env_valid = 2;
+		else if (tmp_env2->flags == 255 && tmp_env1->flags == 0)
+			gd->env_valid = 1;
+		else if (tmp_env1->flags > tmp_env2->flags)
+			gd->env_valid = 1;
+		else if (tmp_env2->flags > tmp_env1->flags)
+			gd->env_valid = 2;
+		else /* flags are equal - almost impossible */
+			gd->env_valid = 1;
+	}

Please check if this logic is really working on MMC - do you really "erase" (i. e. fill with 0xFF bytes) the data blocks when "erasing"?

...

common/env_mmc.c line 148

Quoted 9 lines
common/env_mmc.c new file +9 -0
+	if (!mmc) {
+		puts("No MMC card found\n");
+		return;
+	}
+
+	if (mmc_init(mmc)) {
+		puts("MMC init failed\n");
+		return 1;
+	}

This code repeats a number of times. Make it a (inline?) function?

common/env_mmc.c line 234

Quoted 5 lines
common/env_mmc.c new file +5 -0
+	tmp_env1 = (env_t *)malloc(CONFIG_ENV_SIZE);
+	if (!tmp_env1) {
+		puts("Not enough memory!\n");
+		goto use_default;
+	}

Please print where we are, and how many bytes you attempted to allocate.

common/env_mmc.c line 241

Quoted 4 lines
common/env_mmc.c new file +4 -0
+	if (!tmp_env2) {
+		puts("Not enough memory!\n");
+		goto use_default;
+	}

Ditto . Again - repeated code!

Quoted 13 lines
include/environment.h +7 -0
@@ -94,6 +94,24 @@
 # endif
 #endif /* CONFIG_ENV_IS_IN_MG_DISK */
 
+#if defined(CONFIG_ENV_IS_IN_MMC)
+# ifndef CONFIG_ENV_OFFSET
+#  error "Need to define CONFIG_ENV_OFFSET when using CONFIG_ENV_IS_IN_MMC"
+# endif
+# ifndef CONFIG_ENV_ADDR
+#  define CONFIG_ENV_ADDR	(CONFIG_ENV_OFFSET)
+# endif

include/environment.h line 113

Quoted 10 lines
include/environment.h +10 -0
+# ifndef CONFIG_ENV_OFFSET
+#  define CONFIG_ENV_OFFSET (CONFIG_ENV_ADDR)
+# endif
+# ifdef CONFIG_ENV_OFFSET_REDUND
+#  define CONFIG_SYS_REDUNDAND_ENVIRONMENT
+# endif
+# ifdef CONFIG_ENV_IS_EMBEDDED
+#  define ENV_IS_EMBEDDED	1
+# endif
+#endif /* CONFIG_ENV_IS_IN_MMC */

Does this make sense on MMC?

Would it not be better to define block numbers instead?

include/environment.h line 117

Quoted 4 lines
include/environment.h +4 -0
+#ifdef CONFIG_GENERIC_MMC
+        puts ("MMC:   ");
+        mmc_initialize (gd->bd);
+#endif

Indentation by TABs, please.

Are you sure movin the MMC initialization here has no negative impact on any of the existing boards?

lib_ppc/board.c void board_init_r (gd_t *id, ulong dest_addr) · line 783

Quoted 11 lines
lib_ppc/board.c +5 -0
@@ -776,6 +776,12 @@ void board_init_r (gd_t *id, ulong dest_addr)
 	nand_init();		/* go init the NAND */
 #endif
 
+#ifdef CONFIG_GENERIC_MMC
+        WATCHDOG_RESET ();
+        puts ("MMC:  ");
+        mmc_initialize (bd);
+#endif

Ditto, for both remarks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
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 only way you could make a happy  marriage  is  by  cuttin'  their
heads  off  as  soon  as  they say `I do', yes? You can't make happi-
ness...                           - Terry Pratchett, _Witches Abroad_