2011-05-06 05:42:48     How to add/select NAND device in menu?

Document created by Aaronwu Employee on Aug 27, 2013
Version 1Show Document
  • View in full screen mode

2011-05-06 05:42:48     How to add/select NAND device in menu?

Gilles Ganault (FRANCE)

Message: 100482   

Hello,

 

Using the 2010 source, even when using "root=/dev/mtdblock2 rw" in Uboot, I cannot access the NAND on the BlackfinOne board, so I guess I really must add bfin_nand.c to linux-2.6.x/drivers/mtd/nand/ and edit its Kconfig/Makefile accordingly.

 

Problem is, "make linux_menuconfig" doesn't display the list of NAND devices in "Device Drivers > Memory Technology Device (MTD) support". How can I choose this new NAND device? Is it located elsewhere in the menu?

 

Thank you.

QuoteReplyEditDelete

 

 

2011-05-06 06:10:45     Re: How to add/select NAND device in menu?

Mike Frysinger (UNITED STATES)

Message: 100484   

 

please consult the mtd wiki:

  docs.blackfin.uclinux.org/doku.php?id=linux-kernel:mtd

QuoteReplyEditDelete

 

 

2011-05-06 08:39:22     Re: How to add/select NAND device in menu?

Gilles Ganault (FRANCE)

Message: 100487   

 

Thanks for the link. I was missing a section in linux-2.6.x/drivers/mtd/nand/Kconfig, which was preventing this new option to show up in menuconfig and bfin_nand.c from being included in the image.

 

However, while bfin_nand.c compiles OK with the 2007/2008 toolchains, the 2010 toolchain stops with the following error:

 

==============

 

drivers/mtd/nand/bfin_nand.c: In function "bfin_read_byte":

drivers/mtd/nand/bfin_nand.c:77: error: implicit declaration of function "readb"

drivers/mtd/nand/bfin_nand.c: In function "bfin_read_word":

drivers/mtd/nand/bfin_nand.c:90: error: implicit declaration of function "readw"

drivers/mtd/nand/bfin_nand.c: In function "bfin_write_buf":

drivers/mtd/nand/bfin_nand.c:129: error: implicit declaration of function "writeb"

drivers/mtd/nand/bfin_nand.c: In function "bfin_nand_init":

drivers/mtd/nand/bfin_nand.c:209: error: implicit declaration of function "ioremap"

drivers/mtd/nand/bfin_nand.c:209: warning: assignment makes pointer from integer without a cast

drivers/mtd/nand/bfin_nand.c:240: error: implicit declaration of function "iounmap"

make[6]: *** [drivers/mtd/nand/bfin_nand.o] Error 1

 

==============

Is it a setting I should change in eg. CFLAGS or a deeper issue?

QuoteReplyEditDelete

 

 

2011-05-06 09:13:56     Re: How to add/select NAND device in menu?

Gilles Ganault (FRANCE)

Message: 100488   

 

Found it: I simply added the following line in bfin_nand.c to resume compiling:

 

#include <asm-generic/io.h>

 

However, even though I included  "root=/dev/mtdblock2 rw" in Uboot's bootargs, uClinux still uses the live RAM root filesystem instead of the one in the NAND: After creating a file in the filesystem and rebooting, the file is gone.

 

========== dmesg

 

...

Generic platform RAM MTD, (c) 2004 Simtec Electronics

NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)

Scanning device for bad blocks

Creating 2 MTD partitions on "NAND 256MiB 3,3V 8-bit":

0x000000000000-0x000000800000 : "linux kernel"

0x000000800000-0x000010000000 : "file system"

 

==========  # mount

 

rootfs on / type rootfs (rw)

proc on /proc type proc (rw,relatime)

ramfs on /var/tmp type ramfs (rw,relatime)

sysfs on /sys type sysfs (rw,relatime)

devpts on /dev/pts type devpts (rw,relatime,mode=600)

usbfs on /proc/bus/usb type usbfs (rw,relatime)

 

==========

 

Is there an option in menuconfig to tell Buildroot to compile an image that will fetch the root filesystem from the NAND instead of using initramfs?

QuoteReplyEditDelete

 

 

2011-05-06 09:16:09     Re: How to add/select NAND device in menu?

Mike Frysinger (UNITED STATES)

Message: 100489   

 

no, stop trying to do anything at all with bfin_nand.  that driver is long dead.  use the generic platform NAND driver like the bf537-stamp does.

QuoteReplyEditDelete

 

 

2011-05-09 20:00:42     Re: How to add/select NAND device in menu?

Gilles Ganault (FRANCE)

Message: 100526   

 

Using plat_nand.c as-in instead of bfin_nand.c (since the structure of those two files changed quite a bit between 2008 and 2010)...

 

==================

 

#obj-$(CONFIG_MTD_NAND_BFIN)            += bfin_nand.o

obj-$(CONFIG_MTD_NAND_PLATFORM)         += plat_nand.o

 

==================

 

... I can successfully boot with "root=/dev/mtdblock0 rw", but I get the following error when using "root=/dev/mtdblock2 rw":

 

==================

 

uclinux[mtd]: RAM probe address=0x3700000 size=0x800000

Creating 1 MTD partitions on "RAM":

0x000000000000-0x000000800000 : "ROMfs"

Generic platform RAM MTD, (c) 2004 Simtec Electronics

...

VFS: Cannot open root device "mtdblock2" or unknown-block(0,0)

Please append a correct "root=" boot option; here are the available partitions:

1f00            8192 mtdblock0 (driver?)

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

 

==================

 

FWIW, the NAND currently contains two partitions (0x00000000-0x00800000 : "linux kernel", 0x00800000-0x10000000 : "file system").

 

Do I need to somehow change plat_nand.c so it creates those MTD partitions in addition to the one in RAM? Or do I need to make changes in linux-2.6.x/arch/blackfin/mach-bf533/boards/ip0x.c?

QuoteReplyEditDelete

 

 

2011-05-09 22:33:05     Re: How to add/select NAND device in menu?

Mike Frysinger (UNITED STATES)

Message: 100530   

 

simply building a device driver rarely results in anything useful nowadays.  you almost always have to add relevant resources to your boards file.

QuoteReplyEditDelete

 

 

2011-05-11 07:58:51     Re: How to add/select NAND device in menu?

Gilles Ganault (FRANCE)

Message: 100575   

 

Thanks for the tip.

 

After going through the files in linux-2.6.x/drivers/mtd/nand/ and linux-2.6.x/arch/blackfin/, it seems like, unlike the old bfin_nand.c driver, the new generic NAND driver plat_nand.c only includes code, while resources must be put in a C file under linux-2.6.x/arch/blackfin/.

 

 

So I moved the "mtd_partition partition_info[]" structure from linux-2.6.x/drivers/mtd/nand/bfin_nand.c to

linux-2.6.x/arch/blackfin/mach-bf533/boards/ip0x.c, and copied code (lines 263-360) from linux-2.6.x/arch/blackfin/mach-bf537/boards/stamp.c. Here's my modified ip0x.c.

 

 

However,  a couple of issues pop up:

 

 

1. When compiling, I get this warning: "arch/blackfin/mach-bf533/boards/ip0x.c:353: warning:

"bfin_plat_nand_init" defined but not used". I don't know if that matters.

 

 

2.  More importantly, when booting the image with "root=/dev/mtdblock2 rw", I get those lines in dmesg and the kernel crashes since it can't access the root filesystem in the NAND:

 

 

===================

uclinux[mtd]: RAM probe address=0x3700000 size=0x800000

Creating 1 MTD partitions on "RAM":

0x000000000000-0x000000800000 : "ROMfs"

Generic platform RAM MTD, (c) 2004 Simtec Electronics

nand_get_flash_type: second ID read did not match 10,01 against 62,01

No NAND device found.

...

VFS: Cannot open root device "mtdblock2" or unknown-block(0,0)

Please append a correct "root=" boot option; here are the available partitions:

1f00            8192 mtdblock0 (driver?)

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

===================

 

Does someone know if it's just a matter of changing some settings in ip0x.c, or if the generic NAND driver could require code changes to access the Samsung NAND?

 

dmesg

ip0x.c

QuoteReplyEditDelete

 

 

2011-05-11 10:29:40     Re: How to add/select NAND device in menu?

Mike Frysinger (UNITED STATES)

Message: 100580   

 

please do not use pastebin websites.  they often expire or die and make reviewing history useless.  if you have large output, then attach a file.

 

if gcc is telling you something isnt used, then the code isnt going to be enabled at runtime because gcc removed it.

QuoteReplyEditDelete

 

 

2011-05-11 11:59:12     Re: How to add/select NAND device in menu?

Gilles Ganault (FRANCE)

Message: 100588   

 

Sorry about that. I'll use attachements instead, although pastebin has the advantage of highlighting specific lines.

 

When going through ip0x.c, I can't tell which bfin_plat_nand_init() might be ignored by gcc:

 

=============

 

static void bfin_plat_nand_init(void)

{

gpio_request(BFIN_NAND_PLAT_READY, "bfin_nand_plat");

}

#else

static void bfin_plat_nand_init(void) {}

#endif

=============

 

 

But since the kernel creates an MTD partition in RAM, I guess that means the latter?

 

 

 

I have more information about the issue accessing the NAND: Using a trick in the archives, I edited nand_base.c to include calls to printk():

 

=================

 

 

 

static struct nand_flash_dev *nand_get_flash_type()

...

/* Read manufacturer and device IDs */

*maf_id = chip->read_byte(mtd);

dev_id = chip->read_byte(mtd);

printk("*********\n Maf ID %d \n Dev ID %d\n",*maf_id,dev_id);

 

/* Read manufacturer and device IDs */

tmp_manf = chip->read_byte(mtd);

tmp_id = chip->read_byte(mtd);

printk("*********\n Maf ID %d \n Dev ID %d\n",tmp_manf,tmp_id);

=================

 

Here's what dmesg says:

 

=================

 

uclinux[mtd]: RAM probe address=0x3700000 size=0x800000

Creating 1 MTD partitions on "RAM":

0x000000000000-0x000000800000 : "ROMfs"

Generic platform RAM MTD, (c) 2004 Simtec Electronics

*********

Maf ID 16

Dev ID 1

*********

Maf ID 98

Dev ID 21

nand_get_flash_type: second ID read did not match 10,01 against 62,15

No NAND device found.

=================

 

Does someone know what can cause this mismatch?

 

Thank you.

QuoteReplyEditDelete

 

 

2011-05-11 17:34:35     Re: How to add/select NAND device in menu?

Mike Frysinger (UNITED STATES)

Message: 100590   

 

the warning output from gcc told you the exact line number to check

 

if the ready pin isnt correctly declared, then attempting to get further makes no sense

 

you should however verify your async timings arent too fast for the nand flash.  the kernel programs things independently of u-boot.

QuoteReplyEditDelete

 

 

2011-05-17 09:49:54     Re: How to add/select NAND device in menu?

Gilles Ganault (FRANCE)

Message: 100696   

 

Thanks for the tip.

 

Is the ready pin set through the BFIN_NAND_PLAT_READY constant? Where are the async timings set?

 

After more reading and trial/error, I could get uClinux to access the NAND and read its two partitions by

 

    changing CLE/ALE from 4/2 to 2/1, respectively

    in the bfin_plat_nand_resources structure, changing .start from 0x20212000 to 0x20000000.

 

However, while it works OK when booting with "root=/dev/mtdblock0 rw", it crashes when using "root=/dev/mtdblock2 rw".

 

I attached dmesg and the board resources file.

 

 

 

Has someone experienced the same thing and has an  idea what part I should investigate?

 

 

ip0x.c

blackfin.mtdblock2.crash.txt

QuoteReplyEditDelete

 

 

2011-05-17 16:25:27     Re: How to add/select NAND device in menu?

Mike Frysinger (UNITED STATES)

Message: 100706   

 

i dont know what you mean by "constant".  you must have a function assigned to your plat_nand's .dev_ready field.  how exactly your nand flash is hooked up is only known by you.  which means only you know how to read the pin via software.  the bf537-stamp board has a very simple example of using a GPIO.

 

as for the register offsets, those too are really only known by you.  they completely depend on how you've connected the hardware.  i cant tell you what the "correct" values are.

 

async timings are set in the same place they've always been -- the kernel config.

Blackfin Processor Options -> Asynchronous Memory Configuration

 

there isnt a "crash".  the kernel aborted because it couldnt find a rootfs, like it reported:

No filesystem could mount root, tried:  ext2 vfat msdos

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)

 

make sure you set rootfstype= to the right value, and you've enabled the appropriate filesystem in your kernel.  building it as a module wont work.

Outcomes