Almost there

itche itche at bridgeport.edu
Thu Sep 15 10:22:53 EDT 2005


Hi all,
Claudio thanks for all your previous help.

I still don't have the device fully functional.
I am attaching a txt file containing the terminal output, and the 
modifications i have made to some of the files involved.
At this point after doing erase /dev/mtd2 the system hangs, however still 
pingable, and boa is respondig to requests. i have managed to narrow down to 
a single line of code (in /drivers/mtdchar.c) where the system stop 
responding (just after calling schedule() ). however i don't know why? my 
guess is that it is something related to the feedback from the nand (status 
register).
thanks in advance for any help.
Isack
-------------- next part --------------
--------------------------------------------------------------------------------------------------------------------------
this is my boot output
uClinux/COLDFIRE(m5272)
COLDFIRE port done by Greg Ungerer, gerg at snapgear.com
Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne
On node 0 totalpages: 1024
zone(0): 0 pages.
zone(1): 1024 pages.
zone(2): 0 pages.
Kernel command line:
Calibrating delay loop... 43.72 BogoMIPS
Memory available: 2236k/4096k RAM, 0k/0k ROM (732k kernel code, 216k data)
kmem_create: Forcing size word alignment - vm_area_struct
kmem_create: Forcing size word alignment - mm_struct
kmem_create: Forcing size word alignment - filp
Dentry cache hash table entries: 512 (order: 0, 4096 bytes)
Inode cache hash table entries: 512 (order: 0, 4096 bytes)
kmem_create: Forcing size word alignment - inode_cache
Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
kmem_create: Forcing size word alignment - bdev_cache
kmem_create: Forcing size word alignment - cdev_cache
kmem_create: Forcing size word alignment - kiobuf
Buffer-cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 1024 (order: 0, 4096 bytes)
POSIX conformance testing by UNIFIX
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
kmem_create: Forcing size word alignment - sock
Initializing RT netlink socket
Starting kswapd
kmem_create: Forcing size word alignment - file_lock_cache
JFFS2 version 2.1. (C) 2001 Red Hat, Inc., designed by Axis Communications AB.
ColdFire internal UART serial driver version 1.00
ttyS0 at 0x10000100 (irq = 73) is a builtin ColdFire UART
ttyS1 at 0x10000140 (irq = 74) is a builtin ColdFire UART
kmem_create: Forcing size word alignment - blkdev_requests
fec.c: Probe number 0 with 0x0000
eth0: FEC ENET Version 0.2, 90:02:22:25:dd:b2
fec: PHY @ 0x0, ID 0x001378e2 -- LXT971
SLIP: version 0.8.4-NET3.019-NEWTTY (dynamic channels, max=256).
CSLIP: code copyright 1989 Regents of the University of California.
Blkmem copyright 1998,1999 D. Jeff Dionne
Blkmem copyright 1998 Kenneth Albanowski
Blkmem 7 disk images:
0: 10D15C-1C155B [VIRTUAL 10D15C-1C155B] (RO)
1: FFE00000-FFE3FFFF [VIRTUAL FFE00000-FFE3FFFF] (RW)
2: FFE00000-FFE07FFF [VIRTUAL FFE00000-FFE07FFF] (RW)
3: FFE08000-FFE3FFFF [VIRTUAL FFE08000-FFE3FFFF] (RW)
4: FFE40000-FFFFFFFF [VIRTUAL FFE40000-FFFFFFFF] (RW)
5: FFF00000-FFFFFFFF [VIRTUAL FFF00000-FFFFFFFF] (RW)
6: FFE00000-FFFFFFFF [VIRTUAL FFE00000-FFFFFFFF] (RW)
RAMDISK driver initialized: 16 RAM disks of 8192K size 1024 blocksize
PPP generic driver version 2.4.2
AMD 8MB OS FLASH: 800000 at ff000000
 Amd/Fujitsu Extended Query Table v1.1 at 0x0040
number of CFI chips: 1
Creating 2 MTD partitions on "OS Flash - AMD 8MB":
0x00000000-0x00500000 : "OperatingSystem (5MB)"
mtd: Giving out device 0 to OperatingSystem (5MB)
0x00500000-0x00800000 : "FileSystem (3MB)"
mtd: Giving out device 1 to FileSystem (3MB)
NAND device: Manufacture ID: 0xec, Chip ID: 0x75 (Samsung K9F5608UOC)
Creating 3 MTD partitions on "Samsung K9F5608UOC":
0x00000000-0x00100000 : "test1"
mtd: Giving out device 2 to test1
0x00100000-0x00a00000 : "test2"
mtd: Giving out device 3 to test2
0x01000000-0x02000000 : "PBX Voice"
mtd: Giving out device 4 to PBX Voice
init_mtdchar: allocated major number 90.
init_mtdblock: allocated major number 31.
Linux telephony interface: v1.00
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
kmem_create: Forcing size word alignment - ip_dst_cache
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 512 bind 512)
NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
VFS: Mounted root (romfs filesystem) readonly.
Freeing unused kernel memory: 24k freed (0xf4000 - 0xf9000)
Shell invoked to run file: /etc/rc
Command: hostname DigiTalks_PBX
Command: /bin/expand /etc/ramfs.img /dev/ram1
Command: mount -t jffs2 /dev/mtdblock1 /mnt
mtdblock_open
ok
Command: mount -t proc proc /proc
Command: mount -t ext2 /dev/ram1 /var
Command: mkdir /var/tmp
Command: mkdir /var/log
Command: mkdir /var/run
Command: mkdir /var/lock
Command: ifconfeZb127.0.0.1
Command:t�add -net 127.0.0.0hrѵͭ255.0.0.0 lo
ro0]Wcommand or file :+5
                                Command: dhcpcd -p  KX*ѡ�&
config: auto-negotiation on, 100FDX, 100HDX, 10FDX, 10HDX.
[16]
Command: cat /etc/motd



                Welcome to  DigiTalks ClodFire based



        **************       *************       *****           *****
        *              *     *             *      *   *         *   *
        *   ********    *    *  ********    *      *   *       *   *
        *   *      *     *   *  *      *     *      *   *     *   *
        *   *      *     *   *  *      *    *        *   *   *   *
        *   ********    *    *  ********   *          *   * *   *
        *              *     *             *           *        *
        *   ***********      *  ********   *          *   * *   *
        *   *                *  *      *     *       *   *   *   *
        *   *                *  *      *      *     *   *     *   *
        *   *                *  ********     *     *   *       *   *
        *   *                *             *      *   *         *   *
        ****                 *************       *****           *****



Running

          ____ _  _
         /  __| ||_|
    _   _| |  | | _ ____  _   _  _  _
   | | | | |  | || |  _ \| | | |\ \/ /
   | |_| | |__| || | | | | |_| |/    \
   |  ___\____|_||_|_| |_|\____|\_/\_/
   | |
   |_|


PBX Port done by Isack Waserman - DigiTalks (6/2005)

For further information check:
http://www.digitalks.com

Execution Finished, Exiting

Sash command shell (version 1.1.1)
/>

---------------------------------------------------------------------------------------------------------------------------------------------------------------------
this is after running the erase command

/> erase /dev/mtd2
MTD_open
MTD_ioctl - itche
MTD_ioctl - itche
 in non region erase
Erase UnMZ�
                 0x4000,

PerT�Flash Erase of leD�5
                                  16384
at offset _�
 sector is unlocked iKJэ
octl - itche
in case MEMERASE
We are going to NAND.C here
nand_erase: start = 0x00000000, len = 16384
 flash is ready, going into erase state
 WP status check,nand status is:0xc0
 going into while loop for: 0x4000
 IN THE while loop for: 0x4000
 checking nand status,nand status is:0xc0
 block eras  is good - in NAND.C
 in erase status
 out of while loop
 end of function nand erase
We are returning from NAND.C here
ret= 0x00

before if statment

---------------------------------------------------------------------------------------------------------------------------------------------------------------------



-------------------------------------------------------------------------------------------------------------------------
this is in /drivers/mtd/nand/nand.c

static unsigned char NAND_CTRL_MIROR;
/*
 * Macros for low-level register control
 */
#define NAND_CTRL (*(volatile unsigned char *) \
			((struct nand_chip *) mtd->priv)->CTRL_ADDR)

#define nand_select()	NAND_CTRL_MIROR &= ~this->NCE; \
			NAND_CTRL = NAND_CTRL_MIROR; \
			nand_command(mtd, NAND_CMD_RESET, -1, -1); \
			udelay (10);
#define nand_deselect() NAND_CTRL_MIROR |= this->NCE; \
			NAND_CTRL = NAND_CTRL_MIROR;


/*
 * NAND erase a block
 */
static int nand_erase (struct mtd_info *mtd, struct erase_info *instr)
{
	int i, page, len, status, pages_per_block;
	struct nand_chip *this = mtd->priv;
	DECLARE_WAITQUEUE(wait, current);

	DEBUG (MTD_DEBUG_LEVEL3,
		"nand_erase: start = 0x%08x, len = %i\n",
		(unsigned int) instr->addr, (unsigned int) instr->len);

	/* Start address must align on block boundary */
	if (instr->addr & (mtd->erasesize - 1)) {
		DEBUG (MTD_DEBUG_LEVEL0,
			"nand_erase: Unaligned address\n");
		return -EINVAL;
	}

	/* Length must align on block boundary */
	if (instr->len & (mtd->erasesize - 1)) {
		DEBUG (MTD_DEBUG_LEVEL0,
			"nand_erase: Length not block aligned\n");
		return -EINVAL;
	}

	/* Do not allow erase past end of device */
	if ((instr->len + instr->addr) > mtd->size) {
		DEBUG (MTD_DEBUG_LEVEL0, 
			"nand_erase: Erase past end of device\n");
		return -EINVAL;
	}

retry:
	/* Grab the lock and see if the device is available */
	spin_lock_bh (&this->chip_lock);

	switch (this->state) {
	case FL_READY:
		DEBUG (MTD_DEBUG_LEVEL3," flash is ready, going into erase state\n");//itche
		this->state = FL_ERASING;
		break;
		
	default:
		set_current_state (TASK_UNINTERRUPTIBLE);
		add_wait_queue (&this->wq, &wait);
		spin_unlock_bh (&this->chip_lock);
		schedule();

		remove_wait_queue (&this->wq, &wait);
		goto retry;
	};

	/* Shift to get first page */
	page = (int) (instr->addr >> this->page_shift);

	/* Calculate pages in each block */
	pages_per_block = mtd->erasesize / mtd->oobblock;
	
	/* Select the NAND device */
	nand_select ();

	/* Check the WP bit */
	nand_command (mtd, NAND_CMD_STATUS, -1, -1);
	DEBUG (MTD_DEBUG_LEVEL3," WP status check,nand status is:0x%02x\n",(readb (this->IO_ADDR)));//itche
	if (!(readb (this->IO_ADDR) & 0x80)) {
		DEBUG (MTD_DEBUG_LEVEL0,
			"nand_erase: Device is write protected!!!\n");
		nand_deselect ();
		this->state = FL_READY;
		spin_unlock_bh (&this->chip_lock);
		return -EIO;
	}

	/* Loop through the pages */
	len = instr->len;
	DEBUG (MTD_DEBUG_LEVEL3," going into while loop for: 0x%02x\n" ,instr->len);
	while (len) {
		/* Send commands to erase a page */
		nand_command(mtd, NAND_CMD_ERASE1, -1, page);
		nand_command(mtd, NAND_CMD_ERASE2, -1, -1);
		DEBUG (MTD_DEBUG_LEVEL3," IN THE while loop for: 0x%02x\n" ,len);
		/*
		 * Wait for program operation to complete. This could
		 * take up to 4000us (4ms) on some devices, so we try
		 * and exit as quickly as possible.
		 */
		status = 0;
		for (i=0 ; i<32 ; i++) {
			/* Delay for 125us */
			udelay (125);

			/* Check the status */
			nand_command (mtd, NAND_CMD_STATUS, -1, -1);
			status = (int) readb (this->IO_ADDR);
			DEBUG (MTD_DEBUG_LEVEL3," checking nand status,nand status is:0x%02x\n",status);//itche
			if (status & 0x40)
				break;
		}

		/* See if block erase succeeded */
		if (status & 0x01) {
			DEBUG (MTD_DEBUG_LEVEL0,
				"nand_erase: " \
				"Failed erase, page 0x%08x\n", page);
			nand_deselect ();
			this->state = FL_READY;
			spin_unlock_bh (&this->chip_lock);
			return -EIO;
		}
		else DEBUG (MTD_DEBUG_LEVEL3," block eras  is good - in NAND.C\n");//itche

		/* Increment page address and decrement length */
		len -= mtd->erasesize;
		page += pages_per_block;

		/* Release the spin lock */
		spin_unlock_bh (&this->chip_lock);

erase_retry:
		/* Check the state and sleep if it changed */
		spin_lock_bh (&this->chip_lock);
		if (this->state == FL_ERASING) {
			DEBUG (MTD_DEBUG_LEVEL3," in erase status \n");//itche
			continue;
		}
		else {
			set_current_state (TASK_UNINTERRUPTIBLE);
			add_wait_queue (&this->wq, &wait);
			spin_unlock_bh (&this->chip_lock);
			schedule();
			remove_wait_queue (&this->wq, &wait);
			DEBUG (MTD_DEBUG_LEVEL3," go back to erase_retry \n");//itche
			goto erase_retry;
		}
	}
	DEBUG (MTD_DEBUG_LEVEL3," out of while loop \n");//itche
	
	spin_unlock_bh (&this->chip_lock);

	/* De-select the NAND device */
	nand_deselect ();
	
	/* Do call back function */
	if (instr->callback)
		instr->callback (instr);

	/* The device is ready */
	spin_lock_bh (&this->chip_lock);
	this->state = FL_READY;
	spin_unlock_bh (&this->chip_lock);
	
	
	DEBUG (MTD_DEBUG_LEVEL3," end of function nand erase \n");
	
	
	/* Return happy */
	return 0;
	
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------


-------------------------------------------------------------------------------------------------
this is in /user/mtd-utils/erase.c

int non_region_erase(int Fd, int start, int count, int unlock)
{
	mtd_info_t meminfo;

	if (ioctl(Fd,MEMGETINFO,&meminfo) == 0)
	{
		erase_info_t erase;

		erase.start = start;
		printf (" in non region erase \n" );// itche

		erase.length = meminfo.erasesize;
		printf("Erase Unit Size\n 0x%lx, \n", meminfo.erasesize);

		for (; count > 0; count--) {
			printf("\nPerforming Flash Erase of length\n %lu \nat offset 0x%lx\n",erase.length, erase.start);
			fflush(stdout); 
			if(unlock != 0)
			{
				//Unlock the sector first.
				printf("\n\rPerforming Flash unlock at offset 0x%lx",erase.start);
				if(ioctl(Fd, MEMUNLOCK, &erase) != 0)
				{
					perror("\nMTD Unlock failure");
					close(Fd);
					return 8;
				}
			}
			else printf(" sector is unlocked - itche \n");//itche
			
			if (ioctl(Fd,MEMERASE,&erase) != 0)
			{      
				perror("\nMTD Erase failure");
				close(Fd);
				return 8;
			}
			else printf(" eraes is good\n");//itche
			
			erase.start += meminfo.erasesize;
			
		}
		printf(" done\n");
	}
	return 0;
}
---------------------------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------------

/*
 * $Id: mtdchar.c,v 1.44 2001/10/02 15:05:11 dwmw2 Exp $
 *
 * Character-device access to raw MTD devices.
 * Pure 2.4 version - compatibility cruft removed to mtdchar-compat.c
 *
 */
 
 This is in ioctl section
 case MEMERASE:
	DEBUG(MTD_DEBUG_LEVEL0, "in case MEMERASE\n");//itche
	{
		struct erase_info *erase=kmalloc(sizeof(struct erase_info),GFP_KERNEL);
		if (!erase)
			ret = -ENOMEM;
		else {
			wait_queue_head_t waitq;
			DECLARE_WAITQUEUE(wait, current);

			init_waitqueue_head(&waitq);

			memset (erase,0,sizeof(struct erase_info));
			if (copy_from_user(&erase->addr, (u_long *)arg,
					   2 * sizeof(u_long))) {
				kfree(erase);
				return -EFAULT;
			}
			erase->mtd = mtd;
			erase->callback = mtd_erase_callback;
			erase->priv = (unsigned long)&waitq;
			
			/*
			  FIXME: Allow INTERRUPTIBLE. Which means
			  not having the wait_queue head on the stack.
			  
			  If the wq_head is on the stack, and we
			  leave because we got interrupted, then the
			  wq_head is no longer there when the
			  callback routine tries to wake us up.
			*/
			DEBUG(MTD_DEBUG_LEVEL0, "We are going to NAND.C here\n");//itche
			ret = mtd->erase(mtd, erase);
			DEBUG(MTD_DEBUG_LEVEL0, "We are returning from NAND.C here\n");//itche
			DEBUG(MTD_DEBUG_LEVEL0, "ret= 0x%02x \n\n",ret);//itche
			if (!ret) {
				set_current_state(TASK_UNINTERRUPTIBLE);
				add_wait_queue(&waitq, &wait);
				DEBUG(MTD_DEBUG_LEVEL0, "before if statment\n");//itche
				if (erase->state != MTD_ERASE_DONE &&
				    erase->state != MTD_ERASE_FAILED)
					schedule();
					
				DEBUG(MTD_DEBUG_LEVEL0, "after if statment\n");//itche	
				DEBUG(MTD_DEBUG_LEVEL0, "erase->state = 0x%02x\n", erase->state);//itche
				remove_wait_queue(&waitq, &wait);
				set_current_state(TASK_RUNNING);

				ret = (erase->state == MTD_ERASE_FAILED)?-EIO:0;
			}
			kfree(erase);
		}
		break;
	} 
-----------------------------------------------------------------------------------------------------------------


More information about the linux-mtd mailing list