[U-Boot] [PATCH] cti_flash.c: use __weak for flash_(read|write){8, 16, 32, 64}

Tom Rini trini at ti.com
Fri Oct 24 22:18:30 CEST 2014


From: Jeroen Hofstee <jeroen at myspectrum.nl>

For various reasons (flash access design, errata work-around) some
platforms need to implement their own flash_read/write functions, so
mark them as __weak.  A follow-up cleanup here would be to remove
CONFIG_CFI_FLASH_USE_WEAK_ACCESSORS if this is always known at
compile-time, as it appears to be.

Signed-off-by: Jeroen Hofstee <jeroen at myspectrum.nl>
Signed-off-by: Tom Rini <trini at ti.com>
---
 drivers/mtd/cfi_flash.c |   45 +++++++++++----------------------------------
 include/mtd/cfi_flash.h |    2 --
 2 files changed, 11 insertions(+), 36 deletions(-)

diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 9b3175d..7639be8 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -24,6 +24,7 @@
 #include <asm/unaligned.h>
 #include <environment.h>
 #include <mtd/cfi_flash.h>
+#include <linux/compiler.h>
 #include <watchdog.h>
 
 /*
@@ -81,14 +82,12 @@ static u16 cfi_flash_config_reg(int i)
 int cfi_flash_num_flash_banks = CONFIG_SYS_MAX_FLASH_BANKS_DETECT;
 #endif
 
-static phys_addr_t __cfi_flash_bank_addr(int i)
+__weak phys_addr_t cfi_flash_bank_addr(int i)
 {
 	return ((phys_addr_t [])CONFIG_SYS_FLASH_BANKS_LIST)[i];
 }
-phys_addr_t cfi_flash_bank_addr(int i)
-	__attribute__((weak, alias("__cfi_flash_bank_addr")));
 
-static unsigned long __cfi_flash_bank_size(int i)
+__weak unsigned long cfi_flash_bank_size(int i)
 {
 #ifdef CONFIG_SYS_FLASH_BANKS_SIZES
 	return ((unsigned long [])CONFIG_SYS_FLASH_BANKS_SIZES)[i];
@@ -96,71 +95,49 @@ static unsigned long __cfi_flash_bank_size(int i)
 	return 0;
 #endif
 }
-unsigned long cfi_flash_bank_size(int i)
-	__attribute__((weak, alias("__cfi_flash_bank_size")));
 
-static void __flash_write8(u8 value, void *addr)
+__weak void flash_write8(u8 value, void *addr)
 {
 	__raw_writeb(value, addr);
 }
 
-static void __flash_write16(u16 value, void *addr)
+__weak void flash_write16(u16 value, void *addr)
 {
 	__raw_writew(value, addr);
 }
 
-static void __flash_write32(u32 value, void *addr)
+__weak void flash_write32(u32 value, void *addr)
 {
 	__raw_writel(value, addr);
 }
 
-static void __flash_write64(u64 value, void *addr)
+__weak void flash_write64(u64 value, void *addr)
 {
 	/* No architectures currently implement __raw_writeq() */
 	*(volatile u64 *)addr = value;
 }
 
-static u8 __flash_read8(void *addr)
+__weak u8 flash_read8(void *addr)
 {
 	return __raw_readb(addr);
 }
 
-static u16 __flash_read16(void *addr)
+__weak u16 flash_read16(void *addr)
 {
 	return __raw_readw(addr);
 }
 
-static u32 __flash_read32(void *addr)
+__weak u32 flash_read32(void *addr)
 {
 	return __raw_readl(addr);
 }
 
-static u64 __flash_read64(void *addr)
+__weak u64 flash_read64(void *addr)
 {
 	/* No architectures currently implement __raw_readq() */
 	return *(volatile u64 *)addr;
 }
 
-#ifdef CONFIG_CFI_FLASH_USE_WEAK_ACCESSORS
-void flash_write8(u8 value, void *addr)__attribute__((weak, alias("__flash_write8")));
-void flash_write16(u16 value, void *addr)__attribute__((weak, alias("__flash_write16")));
-void flash_write32(u32 value, void *addr)__attribute__((weak, alias("__flash_write32")));
-void flash_write64(u64 value, void *addr)__attribute__((weak, alias("__flash_write64")));
-u8 flash_read8(void *addr)__attribute__((weak, alias("__flash_read8")));
-u16 flash_read16(void *addr)__attribute__((weak, alias("__flash_read16")));
-u32 flash_read32(void *addr)__attribute__((weak, alias("__flash_read32")));
-u64 flash_read64(void *addr)__attribute__((weak, alias("__flash_read64")));
-#else
-#define flash_write8	__flash_write8
-#define flash_write16	__flash_write16
-#define flash_write32	__flash_write32
-#define flash_write64	__flash_write64
-#define flash_read8	__flash_read8
-#define flash_read16	__flash_read16
-#define flash_read32	__flash_read32
-#define flash_read64	__flash_read64
-#endif
-
 /*-----------------------------------------------------------------------
  */
 #if defined(CONFIG_ENV_IS_IN_FLASH) || defined(CONFIG_ENV_ADDR_REDUND) || (CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE)
diff --git a/include/mtd/cfi_flash.h b/include/mtd/cfi_flash.h
index 048b477..51385c8 100644
--- a/include/mtd/cfi_flash.h
+++ b/include/mtd/cfi_flash.h
@@ -171,7 +171,6 @@ phys_addr_t cfi_flash_bank_addr(int i);
 unsigned long cfi_flash_bank_size(int i);
 void flash_cmd_reset(flash_info_t *info);
 
-#ifdef CONFIG_CFI_FLASH_USE_WEAK_ACCESSORS
 void flash_write8(u8 value, void *addr);
 void flash_write16(u16 value, void *addr);
 void flash_write32(u32 value, void *addr);
@@ -180,6 +179,5 @@ u8 flash_read8(void *addr);
 u16 flash_read16(void *addr);
 u32 flash_read32(void *addr);
 u64 flash_read64(void *addr);
-#endif
 
 #endif /* __CFI_FLASH_H__ */
-- 
1.7.9.5



More information about the U-Boot mailing list