This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to compile nand flash support into kernel

I'm trying to get Nand flash support compiled into the kernel for a custom board with an AM1802 processor.  I've followed the wiki page "

GSG: Building Software Components for OMAP-L1/AM1x" and set the following settings in the kernel configuration and recompiled:

NAND

Device Drivers --->

< > MMC/SD/SDIO card support --->

<*> Memory Technology Device (MTD) support --->
[*] MTD partitioning support
[*] Command line partition table parsing
<*> Direct char device access to MTD devices
<*> Common interface to block layer for MTD 'translation layers'
<*> Caching block device access to MTD devices
<*> NAND Device Support --->
<*> Support NAND on DaVinci SoC

However,
after booting this kernel, I don't see a /dev/mtdX device. Are there other step required to actually use the nand flash?


  • David,

    You will probably want to make sure you are passing sane arguments to the kernel which would set up which NAND device to use as well as your block partitions.

    As an example, on my board I have the following:

    mtdparts=davinci_nand.1:128k(ubootenv),6m(bootloaders),72m(kernel),192m(rootfs),12m(storagefs),-(rest) 

    Where,

    davinci_nand = Name of platform device

    .1 = device number

    :128k(ubootenv) = mtdblock 0

    6m(bootloaders) = mtdblock 1

    ...

    etc etc

     

    This should be added to your u-Boot environment and assigned to your "bootargs". There are numerous examples on the web and you could probably grep bootargs under u-Boot include/configs to find other examples.

     

    Hope this helps,

    Andrew

  • What part does the partition definition in /arch/arm/mach-davinci/board-da850-evm.c play in this?  It appears to define each section inside the kernel itself. 

    Here's the particular snippet of code I'm referring to:

    static struct mtd_partition da850_evm_nandflash_partition[] = {
        {
            .name        = "u-boot env",
            .offset        = 0,
            .size        = SZ_128K,
            .mask_flags    = MTD_WRITEABLE,
         },
        {
            .name        = "UBL",
            .offset        = MTDPART_OFS_APPEND,
            .size        = SZ_128K,
            .mask_flags    = MTD_WRITEABLE,
        },
        {
            .name        = "u-boot",
            .offset        = MTDPART_OFS_APPEND,
            .size        = 4 * SZ_128K,
            .mask_flags    = MTD_WRITEABLE,
        },
        {
            .name        = "kernel",
            .offset        = 0x200000,
            .size        = SZ_4M,
            .mask_flags    = 0,
        },
        {
            .name        = "filesystem",
            .offset        = MTDPART_OFS_APPEND,
            .size        = MTDPART_SIZ_FULL,
            .mask_flags    = 0,
        },
    };

    Thanks,

    David

  • David,

    Maybe a better place to start is if you can even see the nand platform device. The structure you posted does in fact get assigned to .parts in a section of the platform data. God only knows if the device is getting registered or not on your platform. It appears that when the nand is probed, it should configure the partitions. However, it is unclear whether or not those pins get configured as NAND or not. It looks like there is some shared nand_nor function that sets up both devices if there is an lcd card detected and you haven't defined 

    CONFIG_MMC_DAVINCI

    or

    CONFIG_MMC_DAVINCI_MODULE

     

    You might want to sprinkle some print statements around in the kernel to see if your hitting the sections of code you think you are. You could also parse your boot output. If you have mtdparts configured properly and your nand is getting probed, you should see it setting up the partitions. 

     

    Another thing to check is that you have all the MTD/NAND specific CONFIG_x values set in your linux config. If you need help determining this, attach your config as a file and I'll take a gander. It might not hurt to list what kernel version you are using as well.

    Andrew

  • I don't have either CONFIG_MMC_DAVINCI or CONFIG_MMC_DAVINCI_MODULE defined.

    I've been looking at the boot messages pretty thoroughly and I haven't seen any mention of mtd or setting up partitions.

    As for the config values, you can see from my original posts the checkmarks I made in menuconfig.  However, I've attached my config file for you to take a look at.

    The kernel version is 2.6.37 and the sdk version is 5.02.00.00.

    Thanks,

    David

    5584.config.txt

  • David,

    Nothing jumps out at me particularly in your config. However, I'm not a guru when it comes to Linux configs. I took a look the console output on my box and it looks like the partition output that I'm speaking of comes from the davinci_nand driver calling "mtd_has_cmdlinepart" and then parsing the partitions using "parse_mtd_partitions".

     

    This is what my console output looks like for that section:

    ONFI flash detected

    ONFI param page 0 valid

    NAND device: Manufacturer ID: 0x2c, Chip ID: 0xdc (Micron MT29F4G08ABADAWP)

    5 cmdlinepart partitions found on MTD device davinci_nand.1

    Creating 5 MTD partitions on "davinci_nand.1":

    0x000000000000-0x000000020000 : "ubootenv"

    0x000000020000-0x000000620000 : "bootloaders"

    0x000000620000-0x000004e20000 : "kernel"

    0x000004e20000-0x000010e20000 : "rootfs"

    0x000010e20000-0x000020000000 : "rest"

    davinci_nand davinci_nand.1: controller rev. 2.5

     

    That being said, I would suggest passing the partitions on the command line anyway. It prevents you from having to update your kernel if you decide to change your flash layout in the future. If you have time, try passing your partitions in the bootargs of u-Boot and see if it gets you any further. It will undoubtedly be a shorter task than trying to determine why the TI supplied board file isn't creating partitions the way you think it should.

    However, If you are a glutton for punishment like I am, you could always put a print statement in "nand_davinci_probe" to see if the kernel is checking for your device.  A quick look through drivers/mtd/nand/davinci_nand.c will help you find the function I'm talking about. I believe it is responsible for calling "add_mtd_partitions" when it detects mtd partitions. 

    Hope this helps,

    Andrew

  • Looking at u-boot, there are three environment variables of particular interest: mtdids, mtdparts, and partition.  Can you look at your environment variables and let me know what they are set to?  The help command isn't totally clear to me, but if I see what yours are set to and compare that to your bootarg above I can probably figure it out.

    Thanks,

    David

  • David,

    Are you talking about the following?

     

    #define MTDIDS_DEFAULT "nand0=davinci_nand.1"

    #define PART_BOOT "512k(bootloader)ro,"

    #define PART_PARAMS "512k(params)ro,"

    #define PART_KERNEL "4m(kernel),"

    #define PART_REST "-(filesystem)"

    #define MTDPARTS_DEFAULT        \

     "mtdparts=davinci_nand.1:" PART_BOOT PART_PARAMS PART_KERNEL PART_REST

     

     

    I don't use these in my u-boot config. Instead I just define the "bootargs" variable in my CONFIG_EXTRA_ENV_SETTINGS. I chose to do this because it allowed me to test different file systems and flash partitions easily by changing my u-Boot environment variables as opposed to updating u-Boot. I'm sure there is a way to override the previously mentioned defines without recompiling but it's just easier in my opinion to change what you are passing to the kernel manually. Below is an example of how I added the arguments in my u-Boot config.

    During development you can just use "setenv" then once you've nailed everything down, pull it into CONFIG_EXTRA_ENV_SETTINGS in your u-boot board config.

     

    setenv example:

    setenv bootargs 'mem=64M console=ttyS0,115200n8 ubi.mtd=3,2048 ubi.mtd=4,2048 root=ubi0:rootfs rootfstype=ubifs mtdparts=davinci_nand.1:128k(ubootenv),                                6m(bootloaders),72m(kernel),192m(rootfs),12m(storagefs),-(rest) noirqdebug'

     

    CONFIG_EXTRA_ENV_SETTINGS example:

     

    #define CONFIG_EXTRA_ENV_SETTINGS \

    bootargs=" \

            "mem=64M " \

            "console=ttyS0,115200n8 " \

            "ubi.mtd=3,2048 " \

            "ubi.mtd=4,2048 " \

            "root=ubi0:rootfs " \

            "rootfstype=ubifs " \

            "mtdparts=davinci_nand.1:128k(ubootenv)," \

                                    "6m(bootloaders)," \

                                    "72m(kernel)," \

                                    "192m(rootfs)," \

                                    "12m(storagefs)," \

                                    "-(rest) " \

            "noirqdebug " \

            "\0" \

     

    Hopefully this answers your question.

     

    Andrew

     

  • No, I'm not talking about the code.  If you go to a u-boot prompt and type "help mtdparts" it tells you to set partition, mtdids, and mtdparts. Each one is an environment variable.

    Thanks,

    David

  • You can find information for those commands on u-Boot's website:

    http://www.denx.de/wiki/view/DULG/UBootCmdGroupFlash#Section_5.9.3.5

    It looks like they will build the properly formatted kernel arguments for you.

    Good luck,

    Andrew