All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] env: factor out the env_get_char_spec() function
@ 2011-12-26 13:33 Igor Grinberg
  2012-01-05 15:35 ` Wolfgang Denk
  0 siblings, 1 reply; 2+ messages in thread
From: Igor Grinberg @ 2011-12-26 13:33 UTC (permalink / raw)
  To: u-boot

env_get_char_spec() function is duplicated across multiple environment
files.
Remove the duplication by providing a default implementation.
Add "weak" declaration, so the default implementation can be overridden.

Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>
---
 common/env_common.c  |    7 +++++++
 common/env_flash.c   |    5 -----
 common/env_mgdisk.c  |    5 -----
 common/env_mmc.c     |    5 -----
 common/env_nand.c    |    5 -----
 common/env_nowhere.c |    5 -----
 common/env_nvram.c   |    6 ++----
 common/env_onenand.c |    5 -----
 common/env_sf.c      |    5 -----
 9 files changed, 9 insertions(+), 39 deletions(-)

diff --git a/common/env_common.c b/common/env_common.c
index 8a71096..71811c4 100644
--- a/common/env_common.c
+++ b/common/env_common.c
@@ -124,6 +124,13 @@ const uchar default_environment[] = {
 
 struct hsearch_data env_htab;
 
+static uchar __env_get_char_spec(int index)
+{
+	return *((uchar *)(gd->env_addr + index));
+}
+uchar env_get_char_spec(int)
+	__attribute__((weak, alias("__env_get_char_spec")));
+
 static uchar env_get_char_init(int index)
 {
 	/* if crc was bad, use the default environment */
diff --git a/common/env_flash.c b/common/env_flash.c
index a99f850..aa970d4 100644
--- a/common/env_flash.c
+++ b/common/env_flash.c
@@ -73,11 +73,6 @@ static ulong end_addr_new = CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1;
 #endif /* CONFIG_ENV_ADDR_REDUND */
 
 
-uchar env_get_char_spec(int index)
-{
-	return *((uchar *)(gd->env_addr + index));
-}
-
 #ifdef CONFIG_ENV_ADDR_REDUND
 int env_init(void)
 {
diff --git a/common/env_mgdisk.c b/common/env_mgdisk.c
index 5dd92e7..d00e141 100644
--- a/common/env_mgdisk.c
+++ b/common/env_mgdisk.c
@@ -33,11 +33,6 @@ env_t *env_ptr;
 
 DECLARE_GLOBAL_DATA_PTR;
 
-uchar env_get_char_spec(int index)
-{
-	return *((uchar *)(gd->env_addr + index));
-}
-
 void env_relocate_spec(void)
 {
 	char buf[CONFIG_ENV_SIZE];
diff --git a/common/env_mmc.c b/common/env_mmc.c
index 8441c77..0c58ae1 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -54,11 +54,6 @@ static int __mmc_get_env_addr(struct mmc *mmc, u32 *env_addr)
 int mmc_get_env_addr(struct mmc *mmc, u32 *env_addr)
 	__attribute__((weak, alias("__mmc_get_env_addr")));
 
-uchar env_get_char_spec(int index)
-{
-	return *((uchar *)(gd->env_addr + index));
-}
-
 int env_init(void)
 {
 	/* use default */
diff --git a/common/env_nand.c b/common/env_nand.c
index 3cb75c8..e8daec9 100644
--- a/common/env_nand.c
+++ b/common/env_nand.c
@@ -66,11 +66,6 @@ env_t *env_ptr;
 
 DECLARE_GLOBAL_DATA_PTR;
 
-uchar env_get_char_spec(int index)
-{
-	return *((uchar *)(gd->env_addr + index));
-}
-
 /*
  * This is called before nand_init() so we can't read NAND to
  * validate env data.
diff --git a/common/env_nowhere.c b/common/env_nowhere.c
index 8a3ca19..18fcf2c 100644
--- a/common/env_nowhere.c
+++ b/common/env_nowhere.c
@@ -37,11 +37,6 @@ void env_relocate_spec(void)
 {
 }
 
-uchar env_get_char_spec(int index)
-{
-	return *((uchar *)(gd->env_addr + index));
-}
-
 /*
  * Initialize Environment use
  *
diff --git a/common/env_nvram.c b/common/env_nvram.c
index 726eaac..6483db3 100644
--- a/common/env_nvram.c
+++ b/common/env_nvram.c
@@ -59,18 +59,16 @@ env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
 
 char *env_name_spec = "NVRAM";
 
+#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE
 uchar env_get_char_spec(int index)
 {
-#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE
 	uchar c;
 
 	nvram_read(&c, CONFIG_ENV_ADDR + index, 1);
 
 	return c;
-#else
-	return *((uchar *)(gd->env_addr + index));
-#endif
 }
+#endif
 
 void env_relocate_spec(void)
 {
diff --git a/common/env_onenand.c b/common/env_onenand.c
index 0ad2fc7..652665a 100644
--- a/common/env_onenand.c
+++ b/common/env_onenand.c
@@ -44,11 +44,6 @@ char *env_name_spec = "OneNAND";
 
 DECLARE_GLOBAL_DATA_PTR;
 
-uchar env_get_char_spec(int index)
-{
-	return *((uchar *)(gd->env_addr + index));
-}
-
 void env_relocate_spec(void)
 {
 	struct mtd_info *mtd = &onenand_mtd;
diff --git a/common/env_sf.c b/common/env_sf.c
index 592b870..bbd472f 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -59,11 +59,6 @@ char *env_name_spec = "SPI Flash";
 
 static struct spi_flash *env_flash;
 
-uchar env_get_char_spec(int index)
-{
-	return *((uchar *)(gd->env_addr + index));
-}
-
 #if defined(CONFIG_ENV_OFFSET_REDUND)
 int saveenv(void)
 {
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] env: factor out the env_get_char_spec() function
  2011-12-26 13:33 [U-Boot] [PATCH] env: factor out the env_get_char_spec() function Igor Grinberg
@ 2012-01-05 15:35 ` Wolfgang Denk
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Denk @ 2012-01-05 15:35 UTC (permalink / raw)
  To: u-boot

Dear Igor Grinberg,

In message <1324906390-26264-1-git-send-email-grinberg@compulab.co.il> you wrote:
> env_get_char_spec() function is duplicated across multiple environment
> files.
> Remove the duplication by providing a default implementation.
> Add "weak" declaration, so the default implementation can be overridden.
> 
> Signed-off-by: Igor Grinberg <grinberg@compulab.co.il>
> ---
>  common/env_common.c  |    7 +++++++
>  common/env_flash.c   |    5 -----
>  common/env_mgdisk.c  |    5 -----
>  common/env_mmc.c     |    5 -----
>  common/env_nand.c    |    5 -----
>  common/env_nowhere.c |    5 -----
>  common/env_nvram.c   |    6 ++----
>  common/env_onenand.c |    5 -----
>  common/env_sf.c      |    5 -----
>  9 files changed, 9 insertions(+), 39 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

-- 
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
It all seemed, he thought, to be rather a lot of  trouble  to  go  to
just sharpen a razor blade.  - Terry Pratchett, _The Light Fantastic_

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-05 15:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-26 13:33 [U-Boot] [PATCH] env: factor out the env_get_char_spec() function Igor Grinberg
2012-01-05 15:35 ` Wolfgang Denk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.