Skip to contentSkip to conversation

Blackfin on-chip NAND Flash Controller driver

PATCH In review Bryan Wu 2 participants 6 messages Sep 4, 2007 – Sep 14, 2007

Subsystems (2)
lore
Share & tools
lore

Bryan Wu

author
#0 lore raw

PATCH 1/1 Blackfin on-chip NAND Flash Controller driver

This is the driver for latest Blackfin on-chip nand flash controller

- use nand_chip and mtd_info common nand driver interface
- provide both PIO and dma operation
- compiled with ezkit bf548 configuration
- use hardware 1-bit ECC
- tested with YAFFS2 and can mount YAFFS2 filesystem as rootfs

ChangeLog from try#1
- use hweight32() instead of count_bits()
- replace bf54x with bf5xx and BF54X with BF5XX
- compare against plat->page_size in 2 cases when enable hardware ECC

---
 drivers/mtd/nand/Kconfig              |   19 +
 drivers/mtd/nand/Makefile             |    1 +
 drivers/mtd/nand/bf5xx_nand.c         |  791 +++++++++++++++++++++++++++++++++
 include/asm-blackfin/mach-bf548/dma.h |    1 +
 include/asm-blackfin/nand.h           |   47 ++
 5 files changed, 859 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/bf5xx_nand.c
 create mode 100644 include/asm-blackfin/nand.h
drivers/mtd/nand/Kconfig +19 -0
index 7992c43..3c88bb8 100644
@@ -131,6 +131,25 @@ config MTD_NAND_AU1550
 	  This enables the driver for the NAND flash controller on the
 	  AMD/Alchemy 1550 SOC.
 
+config MTD_NAND_BF5XX
+	tristate "Blackfin on-chip NAND Flash Controller driver"
+	depends on BF54x && MTD_NAND
+	help
+	  This enables the Blackfin on-chip NAND flash controller
+
+	  No board specific support is done by this driver, each board
+	  must advertise a platform_device for the driver to attach.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called bf5xx-nand.
+
+config MTD_NAND_BF5XX_HWECC
+	bool "BF5XX NAND Hardware ECC"
+	depends on MTD_NAND_BF5XX
+	help
+	  Enable the use of the BF5XX's internal ECC generator when
+	  using NAND.
+
 config MTD_NAND_RTC_FROM4
 	tristate "Renesas Flash ROM 4-slot interface board (FROM_BOARD4)"
 	depends on SH_SOLUTION_ENGINE
drivers/mtd/nand/Makefile +1 -0
index b16d234..e43d8d3 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_MTD_NAND_TOTO)		+= toto.o
 obj-$(CONFIG_MTD_NAND_AUTCPU12)		+= autcpu12.o
 obj-$(CONFIG_MTD_NAND_EDB7312)		+= edb7312.o
 obj-$(CONFIG_MTD_NAND_AU1550)		+= au1550nd.o
+obj-$(CONFIG_MTD_NAND_BF5XX)		+= bf5xx_nand.o
 obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB)	+= ppchameleonevb.o
 obj-$(CONFIG_MTD_NAND_S3C2410)		+= s3c2410.o
 obj-$(CONFIG_MTD_NAND_DISKONCHIP)	+= diskonchip.o
drivers/mtd/nand/bf5xx_nand.c new file +791 -0

791 lines not on this page · raw message

include/asm-blackfin/mach-bf548/dma.h +1 -0
index fcc8b4c..14cb10c 100644
@@ -55,6 +55,7 @@
 #define CH_SPORT3_RX		20
 #define CH_SPORT3_TX		21
 #define CH_SDH			22
+#define CH_NFC			22
 #define CH_SPI2			23
 
 #define CH_MEM_STREAM0_DEST	24
include/asm-blackfin/nand.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.5.2
#1 lore raw
Quoted 8 lines · Bryan Wu

This is the driver for latest Blackfin on-chip nand flash controller

- use nand_chip and mtd_info common nand driver interface
- provide both PIO and dma operation
- compiled with ezkit bf548 configuration
- use hardware 1-bit ECC
- tested with YAFFS2 and can mount YAFFS2 filesystem as rootfs

Quoted 6 lines

ChangeLog from try#1
- use hweight32() instead of count_bits()
- replace bf54x with bf5xx and BF54X with BF5XX
- compare against plat->page_size in 2 cases when enable hardware ECC

Bryan,

I'd suggest you to test your NAND driver with the following NAND tests:

git://git.infradead.org/~ahunter/nand-tests.git

(http://git.infradead.org/?p=users/ahunter/nand-tests.git;a=summary)

You may want to avoid the torture test, but it is useful to run it with limited amount of erase cycles to make sure your flash/driver survives really high I/O load.For example, we caught occasional DMA transfer problems while running the torture test for few days.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
author
#2 lore raw
Quoted 18 lines · Artem Bityutskiy
Quoted 1 line · Bryan Wu

This is the driver for latest Blackfin on-chip nand flash

controller

Quoted 11 lines

- use nand_chip and mtd_info common nand driver interface
- provide both PIO and dma operation
- compiled with ezkit bf548 configuration
- use hardware 1-bit ECC
- tested with YAFFS2 and can mount YAFFS2 filesystem as rootfs

ChangeLog from try#1
- use hweight32() instead of count_bits()
- replace bf54x with bf5xx and BF54X with BF5XX
- compare against plat->page_size in 2 cases when enable hardware

ECC

Quoted 2 lines
Quoted 9 lines

Bryan,

I'd suggest you to test your NAND driver with the following NAND tests:

git://git.infradead.org/~ahunter/nand-tests.git

(http://git.infradead.org/?p=users/ahunter/nand-tests.git;a=summary)

Thanks Artem, I got the code and did some test on my EZKIT548 with this driver.

Here is the test log, only 2 errors in oobtest. After digging into the mtd-nand driver code, it should be no relation to my bf5xx_nand driver. Maybe somethings wrong in the mtd-nand code. I intend to get some help from you, please see my test log below:

1. boot message:
---
Linux version 2.6.22.6-ADI-2007R2-pre-svn3643 (roc@roc-desktop) (gcc version 4.1.2 (ADI svn)) #38 Mon Sep 10 17:35:51 CST 2007 Hardware Trace Active and Enabled
Blackfin support (C) 2004-2007 Analog Devices, Inc. Compiled for ADSP-BF549 Rev 0.0
Blackfin Linux support by http://blackfin.uclinux.org/
Processor Speed: 525 MHz core clock and 131 Mhz System Clock Board Memory: 64MB
Kernel Managed Memory: 64MB
Memory map:

  text      = 0x00001000-0x00117820
  rodata    = 0x00118000-0x001630dc
  data      = 0x00164000-0x00178000
    stack   = 0x00164000-0x00166000
  init      = 0x00178000-0x002c4c4d
  bss       = 0x002c4c50-0x002d4890

available = 0x002d4890-0x03eff000
DMA Zone = 0x03f00000-0x04000000
Instruction Cache Enabled
Data Cache Enabled (write-through)
Built 1 zonelists. Total pages: 16002
Kernel command line: root=/dev/mtdblock0 rw ip=192.168.0.66:192.168.0.55:192.168.0.1:255.255.255.0:BF548:eth0:off Configuring Blackfin Priority Driven Interrupts
PID hash table entries: 256 (order: 8, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes) Inode-cache hash table entries: 4096 (order: 2, 16384 bytes) Physical pages: 3eff
Memory available: 60968k/64112k RAM, (1331k init code, 1114k kernel code, 63k data, 1024k dma)
Blackfin Scratchpad data SRAM: 4 KB
Blackfin Data A SRAM: 16 KB (15 KB free)
Blackfin Data B SRAM: 16 KB (16 KB free)
Blackfin Instruction SRAM: 48 KB (42 KB free)
Security Framework v1.0.0 initialized
Capability LSM initialized
Mount-cache hash table entries: 512
NET: Registered protocol family 16
Blackfin GPIO Controller
Blackfin DMA Controller
stamp_init(): registering device resources
SCSI subsystem initialized
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes) TCP established hash table entries: 2048 (order: 2, 16384 bytes) TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP reno registered
yaffs Sep 10 2007 15:04:46 Installing.
io scheduler noop registered
io scheduler anticipatory registered (default)
io scheduler cfq registered
Serial: Blackfin serial driver
bfin-uart.1: ttyBF0 at MMIO 0xffc02000 (irq = 48) is a BFIN-UART RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize BF5xx on-chip NAND FLash Controller Driver, Version 1.2 (c) 2007 Analog Devices, Inc.
bf5xx-nand bf5xx-nand.0: page_size=256, data_width=8, wr_dly=3, rd_dly=3 NAND device: Manufacturer ID: 0x20, Chip ID: 0xda (ST Micro NAND 256MiB 3,3V 8-bit)
Creating 2 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x00000000-0x00400000 : "Linux Kernel"
mtd: Giving out device 0 to Linux Kernel 0x00400000-0x10000000 : "File System"
mtd: Giving out device 1 to File System
rtc-bfin rtc-bfin: rtc core: registered rtc-bfin as rtc0
TCP cubic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
rtc-bfin rtc-bfin: setting the system clock to 2004-06-25 05:06:29 (1088139989)
eth0: SMSC911x/921x identified at 0x24000000, IRQ: 175
eth0: SMSC911x MAC Address: 32:3b:f3:01:26:4a
eth0: link down
IP-Config: Complete:

      device=eth0, addr=192.168.0.66, mask=255.255.255.0,
gw=192.168.0.1,
     host=BF548, domain=, nis-domain=(none),
     bootserver=192.168.0.55, rootserver=192.168.0.55, rootpath=

Freeing unused kernel memory: 1331k freed
---

2. oobtest:
root:~> insmod oobtest.ko

=========================================================================================
oobtest: dev = 0
oobtest: oob available per page = 38
oobtest: scanning for bad blocks
oobtest: scanned 0
oobtest: Block 5 is bad
oobtest: Block 27 is bad
oobtest: scanned 32
oobtest: Test 1 of 5
oobtest: erasing
oobtest: erased 0
oobtest: erased 32
oobtest: writing
oobtest: written 0
oobtest: written 32
oobtest: verifying
oobtest: verified 0
oobtest: verified 32
oobtest: Test 2 of 5
oobtest: erasing
oobtest: erased 0
oobtest: erased 32
oobtest: writing
oobtest: written 0
oobtest: written 32
oobtest: verifying
oobtest: verified 0
oobtest: verified 32
oobtest: Test 3 of 5
oobtest: erasing
oobtest: erased 0
oobtest: erased 32
oobtest: writing
oobtest: written 0
oobtest: written 32
oobtest: verifying
oobtest: verified 0
oobtest: verified 32
oobtest: Test 4 of 5
oobtest: erasing
oobtest: erased 0
oobtest: erased 32
oobtest: Attempting to start write past end of oob
oobtest: An error is expected...
nand_write_oob: Attempt to write past end of page
oobtest: Error occurred as expected
oobtest: Attempting to start read past end of oob
oobtest: An error is expected...
nand_read_oob: Attempt to start read outside oob
oobtest: Error occurred as expected
oobtest: Attempting to write past end of device
oobtest: An error is expected...
nand_write_oob: Attempt to write past end of page
oobtest: Error occurred as expected
oobtest: Attempting to read past end of device
oobtest: An error is expected...
oobtest: error: read past end of device
oobtest: Attempting to write past end of device
oobtest: An error is expected...
nand_write_oob: Attempt to write past end of page
oobtest: Error occurred as expected
oobtest: Attempting to read past end of device
oobtest: An error is expected...
oobtest: error: read past end of device
oobtest: Test 5 of 5
oobtest: erasing
oobtest: erased 0
oobtest: erased 32
oobtest: writing
oobtest: written 0
oobtest: written 0
oobtest: written 31
oobtest: verifying
oobtest: verified 0
oobtest: verified 31
oobtest: oobtest finished with 2 errors
=========================================================================================

3. pagetest
root:~> insmod pagetest.ko

=========================================================================================
pagetest: dev = 0
pagetest: scanning for bad blocks
pagetest: scanned 0
pagetest: Block 5 is bad
pagetest: Block 27 is bad
pagetest: scanned 32
pagetest: erasing
pagetest: erased 0
pagetest: erased 32
pagetest: writing
pagetest: written 0
pagetest: written 32
pagetest: verifying
pagetest: verified 0
pagetest: verified 32
pagetest: crosstest
pagetest: reading page at 0x00000000
pagetest: reading page at 0x003ff800
pagetest: reading page at 0x00000000
pagetest: verifying pages read at 0x00000000 match
pagetest: crosstest ok
pagetest: erasecrosstest
pagetest: erasing block 0
pagetest: writing 1st page of block 0
pagetest: reading 1st page of block 0
pagetest: verifying 1st page of block 0
pagetest: erasing block 0
pagetest: writing 1st page of block 0
pagetest: erasing block 31
pagetest: reading 1st page of block 0
pagetest: verifying 1st page of block 0
pagetest: erasecrosstest ok
pagetest: erasetest
pagetest: erasing block 0
pagetest: writing 1st page of block 0
pagetest: erasing block 0
pagetest: reading 1st page of block 0
pagetest: verifying 1st page of block 0 is all 0xff
pagetest: erasetest ok
pagetest: pagetest finished with 0 errors
=========================================================================================

4. subpagetest

root:~> insmod subpagetest.ko

=========================================================================================
subpagetest: dev = 0
sub-page size is: 512
subpagetest: scanning for bad blocks
subpagetest: scanned 0
subpagetest: Block 5 is bad
subpagetest: Block 27 is bad
subpagetest: scanned 32
subpagetest: erasing
subpagetest: erased 0
subpagetest: erased 32
subpagetest: writing
subpagetest: written 0
subpagetest: written 32
subpagetest: verifying
subpagetest: verified 0
subpagetest: verified 32
subpagetest: erasing
subpagetest: erased 0
subpagetest: erased 32
subpagetest: verifying 0xff
subpagetest: verified 0
subpagetest: verified 32
subpagetest: writing
subpagetest: written 0
subpagetest: written 32
subpagetest: verifying
subpagetest: verified 0
subpagetest: verified 32
subpagetest: erasing
subpagetest: erased 0
subpagetest: erased 32
subpagetest: verifying 0xff
subpagetest: verified 0
subpagetest: verified 32
subpagetest: subpagetest finished with 0 errors
=========================================================================================

Quoted 7 lines

You may want to avoid the torture test, but it is useful to run it with
limited amount of erase cycles to make sure your flash/driver survives
really high I/O load.For example, we caught occasional DMA transfer problems while running the torture test for few days.

I plan to do the torture test after this oobtest passed. And this nand_test suites are intended to integrated into our Blackfin uClinux-dist testsuites.

Thanks a lot
Best Regards,
- Bryan Wu

#3 lore raw

Hi,

Quoted 8 lines · Bryan Wu

Here is the test log, only 2 errors in oobtest. After digging into the mtd-nand driver code, it should be no relation to my bf5xx_nand driver. Maybe somethings wrong in the mtd-nand code. I intend to get some help from you, please see my test log below:

oobtest: Attempting to read past end of device
oobtest: An error is expected...
oobtest: error: read past end of device

This means that MTD did not return an error when the test tried to read the last NAND page's OOB. Here is the code:

/* Attempt to write off end of device */

ops.mode      = MTD_OOB_AUTO;
ops.ooblen    = mtd->ecclayout->oobavail + 1;
ops.oobbuf    = writebuf;

printk(PRINT_PREF "Attempting to write past end of device\n"); printk(PRINT_PREF "An error is expected...\n");
err = mtd->write_oob(mtd, mtd->size - mtd->writesize, &ops);

So we read OOB size + 1 byte from the last NAND page and get no error.

This test passes for nandsim, so I'm not sure the problem is in the generic code. On the other hand, it is generic code which should check rages.

Quoted 7 lines

oobtest: Attempting to write past end of device
oobtest: An error is expected...
nand_write_oob: Attempt to write past end of page
oobtest: Error occurred as expected
oobtest: Attempting to read past end of device
oobtest: An error is expected...
oobtest: error: read past end of device

Similar.

Quoted 3 lines

I plan to do the torture test after this oobtest passed. And this nand_test suites are intended to integrated into our Blackfin uClinux-dist testsuites.

We are planning to clean up the tests and submit them for kernel inclusion some day, when we have time.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
author
#4 lore raw
Quoted 16 lines · Artem Bityutskiy

Hi,

Quoted 8 lines · Bryan Wu

Here is the test log, only 2 errors in oobtest. After digging into the mtd-nand driver code, it should be no relation to my bf5xx_nand driver. Maybe somethings wrong in the mtd-nand code. I intend to get some help from you, please see my test log below:

oobtest: Attempting to read past end of device
oobtest: An error is expected...
oobtest: error: read past end of device

This means that MTD did not return an error when the test tried to read the last NAND page's OOB. Here is the code:

/* Attempt to write off end of device */

Quoted 9 lines
ops.mode      = MTD_OOB_AUTO;
ops.ooblen    = mtd->ecclayout->oobavail + 1;
ops.oobbuf    = writebuf;

printk(PRINT_PREF "Attempting to write past end of device\n"); printk(PRINT_PREF "An error is expected...\n");
err = mtd->write_oob(mtd, mtd->size - mtd->writesize, &ops);

So we read OOB size + 1 byte from the last NAND page and get no error.

Yes, it makes sense.

Quoted 3 lines

This test passes for nandsim, so I'm not sure the problem is in the generic code. On the other hand, it is generic code which should check rages.

Actually, I debugged both oobtest.c and drivers/mtd/nand/nand_base.c

in the kernel nand_base.c
mtd->read_oob() --> nand_read_oob() --> nand_do_read_oob() --> chip->ecc.read_oob() --> nand_read_oob_std() --> chip->read_buf() --> bf5xx_nand.c bf5xx_nand_dma_read_buf().

In the calling path, rage check should not be in my driver code bf5xx_nand_dma_read_buf() like other low level nand controller drivers. It is already in nand_do_read_oob() as below:

---

	/* Do not allow reads past end of device */
	if (unlikely(from >= mtd->size ||
		     ops->ooboffs + readlen > ((mtd->size >> chip->page_shift) -
					(from >> chip->page_shift)) * len)) {
		DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: "
			"Attempt read beyond end of device\n");
		return -EINVAL;
	}

---

maybe this condition testing does not include your case. I am not sure, still busy at other task.

Quoted 8 lines
Quoted 7 lines

oobtest: Attempting to write past end of device
oobtest: An error is expected...
nand_write_oob: Attempt to write past end of page
oobtest: Error occurred as expected
oobtest: Attempting to read past end of device
oobtest: An error is expected...
oobtest: error: read past end of device

Quoted 9 lines

Similar.

Quoted 3 lines

I plan to do the torture test after this oobtest passed. And this nand_test suites are intended to integrated into our Blackfin uClinux-dist testsuites.

We are planning to clean up the tests and submit them for kernel inclusion some day, when we have time.

Good news. Thanks
Best Regards,
- Bryan Wu

author
#5 lore raw

PATCH 1/1 Blackfin on-chip NAND Flash Controller driver

In reply to Bryan Wu

This is the driver for latest Blackfin on-chip nand flash controller

- use nand_chip and mtd_info common nand driver interface
- provide both PIO and dma operation
- compiled with ezkit bf548 configuration
- use hardware 1-bit ECC
- tested with YAFFS2 and can mount YAFFS2 filesystem as rootfs

ChangeLog from try#1
- use hweight32() instead of count_bits()
- replace bf54x with bf5xx and BF54X with BF5XX
- compare against plat->page_size in 2 cases when enable hardware ECC

ChangeLog from try#2
- passed nand_test suites
- use cpu_relax() instead of busy wait loop
- some coding style issue pointed out by Andrew

---
 drivers/mtd/nand/Kconfig              |   19 +
 drivers/mtd/nand/Makefile             |    1 +
 drivers/mtd/nand/bf5xx_nand.c         |  788 +++++++++++++++++++++++++++++++++
 include/asm-blackfin/mach-bf548/dma.h |    1 +
 include/asm-blackfin/nand.h           |   47 ++
 5 files changed, 856 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/bf5xx_nand.c
 create mode 100644 include/asm-blackfin/nand.h
drivers/mtd/nand/Kconfig +19 -0
index 7992c43..3c88bb8 100644
@@ -131,6 +131,25 @@ config MTD_NAND_AU1550
 	  This enables the driver for the NAND flash controller on the
 	  AMD/Alchemy 1550 SOC.
 
+config MTD_NAND_BF5XX
+	tristate "Blackfin on-chip NAND Flash Controller driver"
+	depends on BF54x && MTD_NAND
+	help
+	  This enables the Blackfin on-chip NAND flash controller
+
+	  No board specific support is done by this driver, each board
+	  must advertise a platform_device for the driver to attach.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called bf5xx-nand.
+
+config MTD_NAND_BF5XX_HWECC
+	bool "BF5XX NAND Hardware ECC"
+	depends on MTD_NAND_BF5XX
+	help
+	  Enable the use of the BF5XX's internal ECC generator when
+	  using NAND.
+
 config MTD_NAND_RTC_FROM4
 	tristate "Renesas Flash ROM 4-slot interface board (FROM_BOARD4)"
 	depends on SH_SOLUTION_ENGINE
drivers/mtd/nand/Makefile +1 -0
index b16d234..e43d8d3 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_MTD_NAND_TOTO)		+= toto.o
 obj-$(CONFIG_MTD_NAND_AUTCPU12)		+= autcpu12.o
 obj-$(CONFIG_MTD_NAND_EDB7312)		+= edb7312.o
 obj-$(CONFIG_MTD_NAND_AU1550)		+= au1550nd.o
+obj-$(CONFIG_MTD_NAND_BF5XX)		+= bf5xx_nand.o
 obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB)	+= ppchameleonevb.o
 obj-$(CONFIG_MTD_NAND_S3C2410)		+= s3c2410.o
 obj-$(CONFIG_MTD_NAND_DISKONCHIP)	+= diskonchip.o
drivers/mtd/nand/bf5xx_nand.c new file +788 -0

788 lines not on this page · raw message

include/asm-blackfin/mach-bf548/dma.h +1 -0
index fcc8b4c..14cb10c 100644
@@ -55,6 +55,7 @@
 #define CH_SPORT3_RX		20
 #define CH_SPORT3_TX		21
 #define CH_SDH			22
+#define CH_NFC			22
 #define CH_SPI2			23
 
 #define CH_MEM_STREAM0_DEST	24
include/asm-blackfin/nand.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.5.2