提交 c49dc0b3 编写于 作者: W Wolfgang Denk

Merge branch 'master' of git://git.denx.de/u-boot-cfi-flash

...@@ -2157,6 +2157,11 @@ Configuration Settings: ...@@ -2157,6 +2157,11 @@ Configuration Settings:
This option also enables the building of the cfi_flash driver This option also enables the building of the cfi_flash driver
in the drivers directory in the drivers directory
- CONFIG_FLASH_CFI_MTD
This option enables the building of the cfi_mtd driver
in the drivers directory. The driver exports CFI flash
to the MTD layer.
- CONFIG_SYS_FLASH_USE_BUFFER_WRITE - CONFIG_SYS_FLASH_USE_BUFFER_WRITE
Use buffered writes to flash. Use buffered writes to flash.
......
...@@ -27,6 +27,7 @@ LIB := $(obj)libmtd.a ...@@ -27,6 +27,7 @@ LIB := $(obj)libmtd.a
COBJS-$(CONFIG_HAS_DATAFLASH) += at45.o COBJS-$(CONFIG_HAS_DATAFLASH) += at45.o
COBJS-$(CONFIG_FLASH_CFI_DRIVER) += cfi_flash.o COBJS-$(CONFIG_FLASH_CFI_DRIVER) += cfi_flash.o
COBJS-$(CONFIG_FLASH_CFI_MTD) += cfi_mtd.o
COBJS-$(CONFIG_HAS_DATAFLASH) += dataflash.o COBJS-$(CONFIG_HAS_DATAFLASH) += dataflash.o
COBJS-$(CONFIG_FLASH_CFI_LEGACY) += jedec_flash.o COBJS-$(CONFIG_FLASH_CFI_LEGACY) += jedec_flash.o
COBJS-$(CONFIG_MW_EEPROM) += mw_eeprom.o COBJS-$(CONFIG_MW_EEPROM) += mw_eeprom.o
......
...@@ -158,6 +158,7 @@ typedef union { ...@@ -158,6 +158,7 @@ typedef union {
#define NUM_ERASE_REGIONS 4 /* max. number of erase regions */ #define NUM_ERASE_REGIONS 4 /* max. number of erase regions */
static uint flash_offset_cfi[2] = { FLASH_OFFSET_CFI, FLASH_OFFSET_CFI_ALT }; static uint flash_offset_cfi[2] = { FLASH_OFFSET_CFI, FLASH_OFFSET_CFI_ALT };
static uint flash_verbose = 1;
/* use CONFIG_SYS_MAX_FLASH_BANKS_DETECT if defined */ /* use CONFIG_SYS_MAX_FLASH_BANKS_DETECT if defined */
#ifdef CONFIG_SYS_MAX_FLASH_BANKS_DETECT #ifdef CONFIG_SYS_MAX_FLASH_BANKS_DETECT
...@@ -175,8 +176,6 @@ flash_info_t flash_info[CFI_MAX_FLASH_BANKS]; /* FLASH chips info */ ...@@ -175,8 +176,6 @@ flash_info_t flash_info[CFI_MAX_FLASH_BANKS]; /* FLASH chips info */
#define CONFIG_SYS_FLASH_CFI_WIDTH FLASH_CFI_8BIT #define CONFIG_SYS_FLASH_CFI_WIDTH FLASH_CFI_8BIT
#endif #endif
typedef unsigned long flash_sect_t;
/* CFI standard query structure */ /* CFI standard query structure */
struct cfi_qry { struct cfi_qry {
u8 qry[3]; u8 qry[3];
...@@ -209,38 +208,38 @@ struct cfi_pri_hdr { ...@@ -209,38 +208,38 @@ struct cfi_pri_hdr {
u8 minor_version; u8 minor_version;
} __attribute__((packed)); } __attribute__((packed));
static void flash_write8(u8 value, void *addr) static void __flash_write8(u8 value, void *addr)
{ {
__raw_writeb(value, addr); __raw_writeb(value, addr);
} }
static void flash_write16(u16 value, void *addr) static void __flash_write16(u16 value, void *addr)
{ {
__raw_writew(value, addr); __raw_writew(value, addr);
} }
static void flash_write32(u32 value, void *addr) static void __flash_write32(u32 value, void *addr)
{ {
__raw_writel(value, addr); __raw_writel(value, addr);
} }
static void flash_write64(u64 value, void *addr) static void __flash_write64(u64 value, void *addr)
{ {
/* No architectures currently implement __raw_writeq() */ /* No architectures currently implement __raw_writeq() */
*(volatile u64 *)addr = value; *(volatile u64 *)addr = value;
} }
static u8 flash_read8(void *addr) static u8 __flash_read8(void *addr)
{ {
return __raw_readb(addr); return __raw_readb(addr);
} }
static u16 flash_read16(void *addr) static u16 __flash_read16(void *addr)
{ {
return __raw_readw(addr); return __raw_readw(addr);
} }
static u32 flash_read32(void *addr) static u32 __flash_read32(void *addr)
{ {
return __raw_readl(addr); return __raw_readl(addr);
} }
...@@ -251,7 +250,25 @@ static u64 __flash_read64(void *addr) ...@@ -251,7 +250,25 @@ static u64 __flash_read64(void *addr)
return *(volatile u64 *)addr; 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"))); 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
/*----------------------------------------------------------------------- /*-----------------------------------------------------------------------
*/ */
...@@ -1054,7 +1071,7 @@ int flash_erase (flash_info_t * info, int s_first, int s_last) ...@@ -1054,7 +1071,7 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
if (prot) { if (prot) {
printf ("- Warning: %d protected sectors will not be erased!\n", printf ("- Warning: %d protected sectors will not be erased!\n",
prot); prot);
} else { } else if (flash_verbose) {
putc ('\n'); putc ('\n');
} }
...@@ -1101,11 +1118,14 @@ int flash_erase (flash_info_t * info, int s_first, int s_last) ...@@ -1101,11 +1118,14 @@ int flash_erase (flash_info_t * info, int s_first, int s_last)
if (flash_full_status_check if (flash_full_status_check
(info, sect, info->erase_blk_tout, "erase")) { (info, sect, info->erase_blk_tout, "erase")) {
rcode = 1; rcode = 1;
} else } else if (flash_verbose)
putc ('.'); putc ('.');
} }
} }
if (flash_verbose)
puts (" done\n"); puts (" done\n");
return rcode; return rcode;
} }
...@@ -1217,6 +1237,7 @@ void flash_print_info (flash_info_t * info) ...@@ -1217,6 +1237,7 @@ void flash_print_info (flash_info_t * info)
*/ */
#ifdef CONFIG_FLASH_SHOW_PROGRESS #ifdef CONFIG_FLASH_SHOW_PROGRESS
#define FLASH_SHOW_PROGRESS(scale, dots, digit, dots_sub) \ #define FLASH_SHOW_PROGRESS(scale, dots, digit, dots_sub) \
if (flash_verbose) { \
dots -= dots_sub; \ dots -= dots_sub; \
if ((scale > 0) && (dots <= 0)) { \ if ((scale > 0) && (dots <= 0)) { \
if ((digit % 5) == 0) \ if ((digit % 5) == 0) \
...@@ -1225,6 +1246,7 @@ void flash_print_info (flash_info_t * info) ...@@ -1225,6 +1246,7 @@ void flash_print_info (flash_info_t * info)
putc ('.'); \ putc ('.'); \
digit--; \ digit--; \
dots += scale; \ dots += scale; \
} \
} }
#else #else
#define FLASH_SHOW_PROGRESS(scale, dots, digit, dots_sub) #define FLASH_SHOW_PROGRESS(scale, dots, digit, dots_sub)
...@@ -1942,6 +1964,11 @@ ulong flash_get_size (ulong base, int banknum) ...@@ -1942,6 +1964,11 @@ ulong flash_get_size (ulong base, int banknum)
return (info->size); return (info->size);
} }
void flash_set_verbose(uint v)
{
flash_verbose = v;
}
/*----------------------------------------------------------------------- /*-----------------------------------------------------------------------
*/ */
unsigned long flash_init (void) unsigned long flash_init (void)
...@@ -2060,5 +2087,10 @@ unsigned long flash_init (void) ...@@ -2060,5 +2087,10 @@ unsigned long flash_init (void)
flash_get_info(apl[i].start)); flash_get_info(apl[i].start));
} }
#endif #endif
#ifdef CONFIG_FLASH_CFI_MTD
cfi_mtd_init();
#endif
return (size); return (size);
} }
/*
* (C) Copyright 2008 Semihalf
*
* Written by: Piotr Ziecik <kosmo@semihalf.com>
*
* See file CREDITS for list of people who contributed to this
* project.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*/
#include <common.h>
#include <flash.h>
#include <asm/errno.h>
#include <linux/mtd/mtd.h>
extern flash_info_t flash_info[];
static struct mtd_info cfi_mtd_info[CONFIG_SYS_MAX_FLASH_BANKS];
static int cfi_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
{
flash_info_t *fi = mtd->priv;
size_t a_start = fi->start[0] + instr->addr;
size_t a_end = a_start + instr->len;
int s_first = -1;
int s_last = -1;
int error, sect;
for (sect = 0; sect < fi->sector_count - 1; sect++) {
if (a_start == fi->start[sect])
s_first = sect;
if (a_end == fi->start[sect + 1]) {
s_last = sect;
break;
}
}
if (s_first >= 0 && s_first <= s_last) {
instr->state = MTD_ERASING;
flash_set_verbose(0);
error = flash_erase(fi, s_first, s_last);
flash_set_verbose(1);
if (error) {
instr->state = MTD_ERASE_FAILED;
return -EIO;
}
instr->state = MTD_ERASE_DONE;
mtd_erase_callback(instr);
return 0;
}
return -EINVAL;
}
static int cfi_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf)
{
flash_info_t *fi = mtd->priv;
u_char *f = (u_char*)(fi->start[0]) + from;
memcpy(buf, f, len);
*retlen = len;
return 0;
}
static int cfi_mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t *retlen, const u_char *buf)
{
flash_info_t *fi = mtd->priv;
u_long t = fi->start[0] + to;
int error;
flash_set_verbose(0);
error = write_buff(fi, (u_char*)buf, t, len);
flash_set_verbose(1);
if (!error) {
*retlen = len;
return 0;
}
return -EIO;
}
static void cfi_mtd_sync(struct mtd_info *mtd)
{
/*
* This function should wait until all pending operations
* finish. However this driver is fully synchronous, so
* this function returns immediately
*/
}
static int cfi_mtd_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
{
flash_info_t *fi = mtd->priv;
flash_set_verbose(0);
flash_protect(FLAG_PROTECT_SET, fi->start[0] + ofs,
fi->start[0] + ofs + len - 1, fi);
flash_set_verbose(1);
return 0;
}
static int cfi_mtd_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
{
flash_info_t *fi = mtd->priv;
flash_set_verbose(0);
flash_protect(FLAG_PROTECT_CLEAR, fi->start[0] + ofs,
fi->start[0] + ofs + len - 1, fi);
flash_set_verbose(1);
return 0;
}
static int cfi_mtd_set_erasesize(struct mtd_info *mtd, flash_info_t *fi)
{
int sect_size = 0;
int sect;
for (sect = 0; sect < fi->sector_count; sect++) {
if (!sect_size) {
sect_size = flash_sector_size(fi, sect);
continue;
}
if (sect_size != flash_sector_size(fi, sect)) {
sect_size = 0;
break;
}
}
if (!sect_size) {
puts("cfi-mtd: devices with multiple sector sizes are"
"not supported\n");
return -EINVAL;
}
mtd->erasesize = sect_size;
return 0;
}
int cfi_mtd_init(void)
{
struct mtd_info *mtd;
flash_info_t *fi;
int error, i;
for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
fi = &flash_info[i];
mtd = &cfi_mtd_info[i];
memset(mtd, 0, sizeof(struct mtd_info));
error = cfi_mtd_set_erasesize(mtd, fi);
if (error)
continue;
mtd->name = CFI_MTD_DEV_NAME;
mtd->type = MTD_NORFLASH;
mtd->flags = MTD_CAP_NORFLASH;
mtd->size = fi->size;
mtd->writesize = 1;
mtd->erase = cfi_mtd_erase;
mtd->read = cfi_mtd_read;
mtd->write = cfi_mtd_write;
mtd->sync = cfi_mtd_sync;
mtd->lock = cfi_mtd_lock;
mtd->unlock = cfi_mtd_unlock;
mtd->priv = fi;
if (add_mtd_device(mtd))
return -ENOMEM;
}
return 0;
}
...@@ -58,6 +58,8 @@ typedef struct { ...@@ -58,6 +58,8 @@ typedef struct {
#endif #endif
} flash_info_t; } flash_info_t;
typedef unsigned long flash_sect_t;
/* /*
* Values for the width of the port * Values for the width of the port
*/ */
...@@ -84,6 +86,9 @@ typedef struct { ...@@ -84,6 +86,9 @@ typedef struct {
/* convert between bit value and numeric value */ /* convert between bit value and numeric value */
#define CFI_FLASH_SHIFT_WIDTH 3 #define CFI_FLASH_SHIFT_WIDTH 3
/* cfi-mtd device name */
#define CFI_MTD_DEV_NAME "cfi-mtd"
/* Prototypes */ /* Prototypes */
extern unsigned long flash_init (void); extern unsigned long flash_init (void);
...@@ -92,6 +97,8 @@ extern int flash_erase (flash_info_t *, int, int); ...@@ -92,6 +97,8 @@ extern int flash_erase (flash_info_t *, int, int);
extern int flash_sect_erase (ulong addr_first, ulong addr_last); extern int flash_sect_erase (ulong addr_first, ulong addr_last);
extern int flash_sect_protect (int flag, ulong addr_first, ulong addr_last); extern int flash_sect_protect (int flag, ulong addr_first, ulong addr_last);
extern int flash_sect_roundb (ulong *addr); extern int flash_sect_roundb (ulong *addr);
extern unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect);
extern void flash_set_verbose(uint);
/* common/flash.c */ /* common/flash.c */
extern void flash_protect (int flag, ulong from, ulong to, flash_info_t *info); extern void flash_protect (int flag, ulong from, ulong to, flash_info_t *info);
...@@ -99,6 +106,11 @@ extern int flash_write (char *, ulong, ulong); ...@@ -99,6 +106,11 @@ extern int flash_write (char *, ulong, ulong);
extern flash_info_t *addr2info (ulong); extern flash_info_t *addr2info (ulong);
extern int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt); extern int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt);
/* drivers/mtd/cfi_mtd.c */
#ifdef CONFIG_FLASH_CFI_MTD
extern int cfi_mtd_init(void);
#endif
/* board/?/flash.c */ /* board/?/flash.c */
#if defined(CONFIG_SYS_FLASH_PROTECTION) #if defined(CONFIG_SYS_FLASH_PROTECTION)
extern int flash_real_protect(flash_info_t *info, long sector, int prot); extern int flash_real_protect(flash_info_t *info, long sector, int prot);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册