DOC / NFTL problem, and fix
Hi,
I noticed a problem when trying to initialize a DOC device like an ordinary harddisk, i. e. when trying to run a command sequence like this one:
bash# eraseall /dev/mtdchar0
bash# nftl_format /dev/mtdchar0 0x00300000 bash# fdisk /dev/nftla
(create partitions, and write partition table) bash# reboot
Usually the DOC would be unusable after this, with no valid partition table at all. Depending on the timing it would sometimes work - if I add a long delay before the "reboot", it works.
It turns out that some internal data structures of the NFTL driver, which are initialized only at boot-time, become invalid after you run nftl_format.
To fix this issue, we added an IOCTL command to the NFTL driver, which would instruct the driver to re-read appropriate meta-data from the DOC device. Nftl_format was modified to invoke this command to accomplish its operation.
Patch attached.
Wolfgang Denk
Signature · 4 lines
Software Engineering: Embedded and Realtime Systems, Embedded Linux Phone: (+49)-8142-4596-87 Fax: (+49)-8142-4596-88 Email: [email protected] I have made mistakes, but have never made the mistake of claiming I never made one. - James G. Bennet
drivers/mtd/mtdchar.c +9 -0
@@ -442,6 +442,15 @@break ; } +case MEMREVALIDATE : + { +if (revalidate_mtd_device (mtd)) +return -EINVAL ; + + ret =0 ; +break ; + } +default :DEBUG (MTD_DEBUG_LEVEL0 ,"Invalid ioctl %x (MEMGETINFO = %x)\n" , cmd,MEMGETINFO );
drivers/mtd/mtdcore.c +35 -0
@@ -105,6 +105,41 @@ }/** +* revalidate_mtd_device - revalidate an MTD device +* @mtd: pointer to MTD device info structure +* +* Notify each currently active MTD 'user' of device is changed. Returns +* zero on success or 1 on failure, which currently will only happen +* if the requested device does not appear to be present in the list. +*/ + +int revalidate_mtd_device (struct mtd_info *mtd) +{ +struct mtd_notifier *not=mtd_notifiers; +int i; + +down (&mtd_table_mutex); + +for (i=0 ; i <MAX_MTD_DEVICES ; i++) + { +if (mtd_table[i] == mtd) + { +while (not) + { +if (not->revalidate) + (*(not->revalidate))(mtd); + not = not->next; + } +up (&mtd_table_mutex); +return 0 ; + } + } + +up (&mtd_table_mutex); +return 1 ; +} + +/** * register_mtd_user - register a 'user' of MTD devices. * @new: pointer to notifier info structure *
drivers/mtd/nftlcore.c +52 -24
121 lines not on this page · raw message
include/linux/mtd/mtd.h +3 -0
@@ -93,6 +93,7 @@#define MEMUNLOCK _IOW('M', 6, struct erase_info_user)#define MEMGETREGIONCOUNT _IOR('M', 7, int)#define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user) +#define MEMREVALIDATE _IO('M', 9)#ifndef __KERNEL__
@@ -219,6 +220,7 @@extern int add_mtd_device (struct mtd_info *mtd);extern int del_mtd_device (struct mtd_info *mtd); +extern int revalidate_mtd_device (struct mtd_info *mtd);extern struct mtd_info *__get_mtd_device (struct mtd_info *mtd,int num);
@@ -244,6 +246,7 @@struct mtd_notifier {void (*add)(struct mtd_info *mtd);void (*remove)(struct mtd_info *mtd); +void (*revalidate)(struct mtd_info *mtd);struct mtd_notifier *next; };
util/nftl_format.c +8 -0
@@ -333,5 +333,13 @@printf ("MEMWRITEOOB at %lx: %s\n" , (unsigned long )oob.start, sys_errlist[errno]); } +/* Phase 4. Revalidating the device */ +printf ("Phase 4. Revalidating the device\n" ); +if (ioctl (fd,MEMREVALIDATE ,0 )) { +perror ("ioctl(MEMREVALIDATE)" ); +close (fd); +return 1 ; + } +exit (0 ); }