Skip to contentSkip to conversation

MTD driver

PATCH In review Subrahmanyam 4 participants 6 messages Dec 7, 2004 – Dec 9, 2004 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

Hi,

I need to provide an user interface/GUI wherein when a certain data (string/key) is entered, it should basically store the key in the flash (this basically happens during run time after the target has been identified by the host).

In the target we have a flash in which there is jffs2 file system and also mtd drivers, since i need to store block oriented data, i am looking at the possiblity of using mtd driver and storing data(key) in a particular location in flash. How should i proceed in acheiving the same.

I will be thankful if you can best suggest an approach for acheiving the same.

Thanks,
Subrahmanyam.

#1 lore raw

PATCH 1/1 nand flash through IDE interface

Hi,
I use the ide interface for testing nand flash. I think this driver would be useful for anyone else that does the same. It would save people the time of hacking another board specific driver to work with ide.

Signature · 1 line
William

/*
* drivers/mtd/nand/ide.c
*
* Copyright (C) 2004 William J Beksi <[email protected]> *
* Derived from drivers/mtd/spia.c
* Copyright (C) 2000 Steven J. Hill <[email protected]>
*
* $Id: ide.c,v 1.18 2004/12/07 05:17:46 wjbeksi Exp $
*

 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.

*
* Overview:
* This device driver allows a NAND flash device to be accessed from
* an IDE interface.
*/

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/partitions.h>
#include <asm/io.h>

/*
* IDE MTD structure
*/
static struct mtd_info *ide_mtd = NULL;

/*
* Values specific to the IDE
*/
#define BASEPORT1 0x1F0 /* IDE1 NAND Flash I/O Base Address */
#define BASEPORT2 0x170 /* IDE2 NAND Flash I/O Base Address */

#define IDE_IO_BASE BASEPORT1

/*
* Define partitions for flash device
*/

const static struct mtd_partition partition_info[] = {
    { 
		.name   = "IDE flash partition 1", 
		.offset = 0,  
		.size   = 3*1024*1024 
	},
	{
		.name   = "IDE flash partition 2",
		.offset = 3*1024*1024,
		.size   = 3*1024*1024
	}
};

#define NUM_PARTITIONS 2

/*
* Main initialization routine
*/
int __init ide_init(void)

{
	struct nand_chip *this;

	/* Allocate memory for MTD device structure and private data */
	ide_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
	if (!ide_mtd) {
		printk("Unable to allocate IDE NAND MTD structure.\n");
		return -ENOMEM;
	}

	/* Get pointer to private data */
	this = (struct nand_chip *) (&ide_mtd[1]);

	/* Initialize structures */
	memset((char *) ide_mtd, 0, sizeof(struct mtd_info));
	memset((char *) this, 0, sizeof(struct nand_chip));

	/* Link the private data with the MTD structure */
	ide_mtd->priv = this;

	/* Set address of NAND IO lines */
	this->IO_ADDR_R  = IDE_IO_BASE;
	this->IO_ADDR_W  = IDE_IO_BASE;
	this->dev_ready  = NULL;
	/* 20 us command delay time */
	this->chip_delay = 20;
	/* Set the ECC generator mode */
	this->eccmode = NAND_ECC_SOFT;

	/* Scan to find existance of the device */
	if (nand_scan(ide_mtd, 1)) {
		kfree(ide_mtd);
		return -ENXIO;
	}

	/* Register the partitions */
	add_mtd_partitions(ide_mtd, partition_info, NUM_PARTITIONS);

	/* Return happy */
	return 0;
}

module_init(ide_init);

/*
* Clean up routine
*/
#ifdef MODULE
static void __exit ide_cleanup (void)

{
	/* Release resources, unregister the device */
	nand_release(ide_mtd);	

	/* Free the MTD device structure */
	kfree(ide_mtd);
}

module_exit(ide_cleanup);
#endif

MODULE_LICENSE("GPL");
MODULE_AUTHOR("William J Beksi <[email protected]>"); MODULE_DESCRIPTION("Glue layer for NAND flash through an IDE interface");

#2 lore raw

Re: [PATCH] nand flash through IDE interface

Quoted 4 lines · William J Beksi

Hi,
I use the ide interface for testing nand flash. I think this driver would be useful for anyone else that does the same. It would save people the time of hacking another board specific driver to work with ide.

Interesting.

Which card types can you access with this driver ?

tglx

#3 lore raw

Re: [PATCH] nand flash through IDE interface

Quoted 13 lines · Thomas Gleixner
Quoted 4 lines · William J Beksi

Hi,
I use the ide interface for testing nand flash. I think this driver would be useful for anyone else that does the same. It would save people the time of hacking another board specific driver to work with ide.

Interesting.

Which card types can you access with this driver ?

I've been able to access both Samsung 32MB (K9F5608U0C) and 64MB (K9F1208U0M) cards.
The guys in my hardware department build a small board consisting of a nand flash socket, switch, and ide connector that allows access to the flash from a pc's ide connector.

Signature · 1 line
William
#4 lore raw
In reply to Subrahmanyam
Quoted 11 lines · Subrahmanyam

Hi,

I need to provide an user interface/GUI wherein when a certain data
(string/key) is entered, it should basically store the key in the flash (this basically happens during run time after the target has been identified by the host).

In the target we have a flash in which there is jffs2 file system and also mtd drivers, since i need to store block oriented data, i am looking at the possiblity of using mtd driver and storing data(key) in a particular location in flash. How should i proceed in acheiving the same.

Is there any good reason, why the key cannot be stored on the already available jffs2 filesystem ?

tglx

#5 lore raw

Hi,

you may setup a dedicated partition that gives you access to the particular location in the flash where you whant to place this data. Then you can use normal open() read() write() and seek() functions to access what ever byte in this partition. How to erass a block you can look up in one of the MTD tools. (Only if you are using NAND flash you should not do it like this since bad block handling whould be missing.)
But I aggree with Thomas. Best whould be to put it into a filesystem...

Stephan

Quoted 35 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of Thomas Gleixner
Sent: Mittwoch, 8. Dezember 2004 07:37
To: Subrahmanyam
Cc: [email protected]
Subject: Re: MTD driver

Quoted 5 lines · Subrahmanyam

Hi,

I need to provide an user interface/GUI wherein when a certain data
(string/key) is entered, it should basically store the key in the flash (this basically happens during run time after the target has been

identified

Quoted 6 lines

by the host).

In the target we have a flash in which there is jffs2 file system and also mtd drivers, since i need to store block oriented data, i am looking at the possiblity of using mtd driver and storing data(key) in a particular location in flash. How should i proceed in acheiving the same.

Is there any good reason, why the key cannot be stored on the already available jffs2 filesystem ?

tglx

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/