浏览代码

env: factor out the env_get_char_spec() function

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>
Igor Grinberg 13 年之前
父节点
当前提交
bf95df44ff
共有 9 个文件被更改,包括 9 次插入39 次删除
  1. 7 0
      common/env_common.c
  2. 0 5
      common/env_flash.c
  3. 0 5
      common/env_mgdisk.c
  4. 0 5
      common/env_mmc.c
  5. 0 5
      common/env_nand.c
  6. 0 5
      common/env_nowhere.c
  7. 2 4
      common/env_nvram.c
  8. 0 5
      common/env_onenand.c
  9. 0 5
      common/env_sf.c

+ 7 - 0
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 */

+ 0 - 5
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)
 {

+ 0 - 5
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];

+ 0 - 5
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 */

+ 0 - 5
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.

+ 0 - 5
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
  *

+ 2 - 4
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)
 {

+ 0 - 5
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;

+ 0 - 5
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)
 {