Skip to contentSkip to conversation

udev problem (and fix) for /dev/mtdblock*

DISCUSSION David Brownell 3 participants 11 messages Mar 18, 2009 – Mar 24, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Marco suggested this goes "the upstream list" but didn't forward it or say what that list is... udev still goes to the hotplug list?

---------- Forwarded Message ----------

Subject: udev problem (and fix) for lenny/armel
Date: Thursday 20 November 2008
From: David Brownell <[email protected]>
To: [email protected]

Hi,

I have a machine running Debian and it's been getting nasty boot messages like:

...
Synthesizing the initial hotplug events...done.
Waiting for /dev to be fully populated...uncorrectable error : <3>end_request: I/O error, dev mtdblock0, sector 0 Buffer I/O error on device mtdblock0, logical block 0
uncorrectable error : <3>end_request: I/O error, dev mtdblock0, sector 8
Buffer I/O error on device mtdblock0, logical block 1
end_request: I/O error, dev mtdblock0, sector 16
Buffer I/O error on device mtdblock0, logical block 2
end_request: I/O error, dev mtdblock0, sector 24
Buffer I/O error on device mtdblock0, logical block 3
uncorrectable error : <3>end_request: I/O error, dev mtdblock0, sector 0
Buffer I/O error on device mtdblock0, logical block 0
done.
Setting parameters of disc: (none).
...

Where /dev/mtdblock0 is something of a special NAND partition, used by the mask ROM on the ARM to get a second stage loader, which is then loaded from /dev/mtdblock1 etc. The messages about "uncorrectable error" are from the kernel, since that first partition uses a different ECC scheme than the rest of the flash.

What's happening is that it's trying to read partition data from the MTD devices ... which is inappropriate, they don't use internal partition data. And the mtdblock0 read fails, because of the ECC differences, producing messages ... ones that should never have appeared, since it shouldn't have been trying to read partition data.

The boot is easily cleaned up by a patch to a udev rules
file: /etc/udev/rules.d/60-persistent-storage.rules is already skipping a bunch of devices, it just needs to add the "mtd*" devices to what should be skipped:

KERNEL="ram*|loop*|fd*|mtd*|nbd*|gnbd*|dm-*|md*", GOTO="persistent_storage_end"

It'd be good to see this bug fixed before lenny goes final...

- Dave

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

#1 lore raw
Quoted 33 lines · David Brownell

I have a machine running Debian and it's been getting nasty boot messages like:

 ...
 Synthesizing the initial hotplug events...done.
 Waiting for /dev to be fully populated...uncorrectable error : <3>end_request: I/O error, dev mtdblock0, sector 0 Buffer I/O error on device mtdblock0, logical block 0
 uncorrectable error : <3>end_request: I/O error, dev mtdblock0, sector 8
 Buffer I/O error on device mtdblock0, logical block 1
 end_request: I/O error, dev mtdblock0, sector 16
 Buffer I/O error on device mtdblock0, logical block 2
 end_request: I/O error, dev mtdblock0, sector 24
 Buffer I/O error on device mtdblock0, logical block 3
 uncorrectable error : <3>end_request: I/O error, dev mtdblock0, sector 0
 Buffer I/O error on device mtdblock0, logical block 0
 done.
 Setting parameters of disc: (none).
 ...

Where /dev/mtdblock0 is something of a special NAND partition, used by the mask ROM on the ARM to get a second stage loader, which is then loaded from /dev/mtdblock1 etc.  The messages about "uncorrectable error" are from the kernel, since that first partition uses a different ECC scheme than the rest of the flash.

What's happening is that it's trying to read partition data from the MTD devices ... which is inappropriate, they don't use internal partition data.  And the mtdblock0 read fails, because of the ECC differences, producing messages ... ones that should never have appeared, since it shouldn't have been trying to read partition data.

Quoted 8 lines

The boot is easily cleaned up by a patch to a udev rules
file:  /etc/udev/rules.d/60-persistent-storage.rules is already skipping a bunch of devices, it just needs to add the "mtd*" devices to what should be skipped:

 KERNEL="ram*|loop*|fd*|mtd*|nbd*|gnbd*|dm-*|md*", GOTO="persistent_storage_end"

It'd be good to see this bug fixed before lenny goes final...

Udev, by default, investigates all block devices which are created by the kernel. People use label/uuid and other metadata based stuff, so we should look at them. We can not know in advance which device will not respond properly. I have requests where people ask for more persistent link support for mtd devices, while disabling them would really not make them happier. :)

I don't see how userspace could work around this, and guess the kernel should stop printing errors for stuff it has announced to userspace, but is not usable when we look at it.

Would it help, if we make it easier to disable these rules for specific devices from a custom udev rule?

Thanks,
Kay

#2 lore raw
Quoted 7 lines · Kay Sievers
Quoted 7 lines

The boot is easily cleaned up by a patch to a udev rules
file: /etc/udev/rules.d/60-persistent-storage.rules is already skipping a bunch of devices, it just needs to add the "mtd*" devices to what should be skipped:

KERNEL=="ram*|loop*|fd*|mtd*|nbd*|gnbd*|dm-*|md*", GOTO="persistent_storage_end"

Quoted 9 lines
Quoted 1 line

It'd be good to see this bug fixed before lenny goes final...

Udev, by default, investigates all block devices which are created by the kernel. People use label/uuid and other metadata based stuff, so we should look at them. We can not know in advance which device will not respond properly. I have requests where people ask for more persistent link support for mtd devices, while disabling them would really not make them happier. :)

Indeed, for the Ubuntu ARM port we *rely* on having UUIDs for the MTD partitions. I would be unhappy if mtd devices did not have them.

Scott

Signature · 2 lines
Scott James Remnant
[email protected]
#3 lore raw
In reply to Kay Sievers
Quoted 40 lines · Kay Sievers
Quoted 38 lines · David Brownell

I have a machine running Debian and it's been getting nasty boot messages like:

 ...
 Synthesizing the initial hotplug events...done.
 Waiting for /dev to be fully populated...uncorrectable error : <3>end_request: I/O error, dev mtdblock0, sector 0 Buffer I/O error on device mtdblock0, logical block 0
 uncorrectable error : <3>end_request: I/O error, dev mtdblock0, sector 8
 Buffer I/O error on device mtdblock0, logical block 1
 end_request: I/O error, dev mtdblock0, sector 16
 Buffer I/O error on device mtdblock0, logical block 2
 end_request: I/O error, dev mtdblock0, sector 24
 Buffer I/O error on device mtdblock0, logical block 3
 uncorrectable error : <3>end_request: I/O error, dev mtdblock0, sector 0
 Buffer I/O error on device mtdblock0, logical block 0
 done.
 Setting parameters of disc: (none).
 ...

Where /dev/mtdblock0 is something of a special NAND partition, used by the mask ROM on the ARM to get a second stage loader, which is then loaded from /dev/mtdblock1 etc.  The messages about "uncorrectable error" are from the kernel, since that first partition uses a different ECC scheme than the rest of the flash.

What's happening is that it's trying to read partition data from the MTD devices ... which is inappropriate, they don't use internal partition data.  And the mtdblock0 read fails, because of the ECC differences, producing messages ... ones that should never have appeared, since it shouldn't have been trying to read partition data.

The boot is easily cleaned up by a patch to a udev rules
file:  /etc/udev/rules.d/60-persistent-storage.rules is already skipping a bunch of devices, it just needs to add the "mtd*" devices to what should be skipped:

Quoted 6 lines
Quoted 3 lines

 KERNEL="ram*|loop*|fd*|mtd*|nbd*|gnbd*|dm-*|md*", GOTO="persistent_storage_end"

It'd be good to see this bug fixed before lenny goes final...

Udev, by default, investigates all block devices which are created by the kernel.

Except for the seven exceptions listed above...

I'm just pointing out an eighth one that should be included in that list, as a bugfix: "mtd*". (Or maybe "mtdblock*".)

Quoted 2 lines

People use label/uuid and other metadata based stuff, so we should look at them.

Yes, people are stupid too. Such things are basically meaningless for MTDs. They don't have labels as those tools understand them, and partition data is normally part of board-specific kernel configuration data (or even kernel command line data passed from bootloaders).

And there's MTD-specific metadata, like the OTP bits provided on most modern chips and which MTD technology is used by that device. Not that it's used like disk labels are ... but if "metadata" is going to be your argument, rather than "sort out which disk goes where", you've come up with yet another reason to treat MTD hardware differently than udev does today.

See also:

http://www.linux-mtd.infradead.org/faq/general.html#L_mtd_what
http://www.linux-mtd.infradead.org/faq/general.html#L_mtd_vs_hdd

Plus the "can I use ext2 on an MTD device" section.

Don't be deceived by the need to have a block device to mount JFFS2. Anyone trying to use one of the /dev/mtdblock devices as a general block device is risking system damage. Example, with an MLC NAND operation, don't just randomly update an erase block 1000 times, you will probably kill it forever. And if it's already a bad block ... well, it doesn't handle that well.

Quoted 1 line

I don't see how userspace could work around this,

Well, the obvious fix is the one I described: add the /dev/mtdblock devices to that existing exception list in udev.

A less obvious one would be to teach every tool that udev could possibly point towards MTDs to first check if the device is an MTD, and refuse to use it. Since that set of tools is unbounded, this approach clearly loses.

Another would be to use MTD-specific tools for MTDs. Of course, those tools aren't used to do anything like what that persistent-rules file is doing -- and in fact those tools use the chardev interfaces to MTDs, not the blockdev ones -- so that's equivalent to the original
fix: do nothing for any mtdblock device nodes you find.

Quoted 3 lines

and guess the kernel
should stop printing errors for stuff it has announced to userspace, but is not usable when we look at it.

It's perfectly usable. Not by the tools udev tries to use with it, but by "mount" ... /dev/mtdblock* nodes exist only to support "mount". (And maybe just for JFFS2; UBIFS doesn't need them, and I've not looked at other options.)

Agreed it would be nice to see /dev/mtdblock* vanish, but that wouldn't be a near-term change. JFFS would first need to vanish; I don't know about YAFFS2 (which may never make mainline given UBIFS).

Quoted 2 lines

Would it help, if we make it easier to disable these rules for specific devices from a custom udev rule?

What's needed is to recognize that MTDs are not block devices in any meaningful sense. This is not a "custom" thing -- it's a "standard" thing.

- Dave

Quoted 4 lines

Thanks,
Kay

#4 lore raw
In reply to Kay Sievers
Quoted 11 lines · David Brownell
Quoted 8 lines · Kay Sievers
Quoted 3 lines · David Brownell

 KERNEL="ram*|loop*|fd*|mtd*|nbd*|gnbd*|dm-*|md*", GOTO="persistent_storage_end"

It'd be good to see this bug fixed before lenny goes final...

Udev, by default, investigates all block devices which are created by the kernel.

Except for the seven exceptions listed above...

Loop is no longer there today, ram can also be removed. The others are remote network devices, which are difficult to handle, and can not be identified at creation event time. Floppies do not detect any media changes, and are excluded for that reason. Dm and md have their own rules.

Quoted 5 lines
Quoted 2 lines

People use label/uuid and other metadata based stuff, so we should look at them.

Yes, people are stupid too. Such things are basically meaningless for MTDs.

Maybe, but seems they are used, because mtd currently does not offer any other attributes to identify a device.

Quoted 8 lines

They don't have labels as those
tools understand them, and partition data is normally part of board-specific kernel configuration data (or even kernel command line data passed from bootloaders).

And there's MTD-specific metadata, like the OTP bits provided on most modern chips and which MTD technology is used by that device.

If we can provide any other useful data to identify devices, it would be nice, if someone could make that work. Can such attributes somehow be added to sysfs?

MTD currently creates all devices as "virtual", it does not even use the proper parent devices in the kernel, which would at least allow a very simple identification, based on the underlying platform device properties.

I keep an untested and unfinished patch around, I did the last time someone tried to solve the problem of reordered mtd devices with udev rules:
http://git.kernel.org/?p=linux/kernel/git/kay/patches.git;a=blob;f=mtd-parent-dev.patch;hb=HEAD

If we can offer people the information which will be available with this rather simple change, people can probably switch over to that, and we can replace the current one.

Thanks,
Kay

#5 lore raw
In reply to Kay Sievers
Quoted 10 lines · Kay Sievers
Quoted 9 lines · David Brownell

... etc, dating from last fall ...

Quoted 6 lines
Quoted 3 lines

 KERNEL="ram*|loop*|fd*|mtd*|nbd*|gnbd*|dm-*|md*", GOTO="persistent_storage_end"

It'd be good to see this bug fixed before lenny goes final...

Udev, by default, investigates all block devices which are created by the kernel.

Quoted 7 lines
Quoted 1 line

Except for the seven exceptions listed above...

Loop is no longer there today, ram can also be removed. The others are remote network devices, which are difficult to handle, and can not be identified at creation event time. Floppies do not detect any media changes, and are excluded for that reason. Dm and md have their own rules.

All beside the point. That's not "all" block devices; and "mtdblock" should be in that exception list. The problem is that MTDs don't support the model implemented in the rest of that file

Quoted 13 lines
Quoted 5 lines
Quoted 2 lines

People use label/uuid and other metadata based stuff, so we should look at them.

Yes, people are stupid too. Such things are basically meaningless for MTDs.

Maybe, but seems they are used, because mtd currently does not offer any other attributes to identify a device.

Quoted 4 lines

They don't have labels as those
tools understand them, and partition data is normally part of board-specific kernel configuration data (or even kernel command line data passed from bootloaders).

If "they are used", it's by a decided minority of MTDs. Th

Quoted 7 lines
Quoted 3 lines

And there's MTD-specific metadata, like the OTP bits provided on most modern chips and which MTD technology is used by that device.

If we can provide any other useful data to identify devices, it would be nice, if someone could make that work. Can such attributes somehow be added to sysfs?

In some cases, maybe ... thing is that OTP (One Time Programmable) bits vary widely in terms of structure, size, and even presence.

OTP data in lot of the NAND chips I have here exceeds the sysfs 4KB binary file limit; 20KB commonly, 128KB for OneNand. That's enough that some systems would not want to model it as metadata. And the "manufacturer" data (basically, chip-specific IDs) are not always documented such that GPL'd code could access them.

Quoted 4 lines

MTD currently creates all devices as "virtual", it does not even use the proper parent devices in the kernel, which would at least allow a very simple identification, based on the underlying platform device properties.

That would be an entirely separate problem though. ISTR having a similar "WTF is this doing" reaction last time I had to look at MTD core driver model stuff.

Quoted 4 lines

I keep an untested and unfinished patch around, I did the last time someone tried to solve the problem of reordered mtd devices with udev rules:
http://git.kernel.org/?p=linux/kernel/git/kay/patches.git;a=blob;f=mtd-parent-dev.patch;hb=HEAD

Looks plausible ... and I may have actually seen a system where that "problem" matters. (Normally all flash drivers are linked statically, and the system root uses one of them.)

That obviously needs to be split into "core" (mtd block and char dev support) and driver bits; the core bits could go in at any time once they're ready.

FWIW I did a quick test of this on a physmap flash ... didn't work, /sys/devices/virtual/mtd still held everything that was not in /sys/devices/virtual/block/mtdblock*. I think the issue might be lack of mtdpart support.

Quoted 3 lines

If we can offer people the information which will be available with this rather simple change, people can probably switch over to that, and we can replace the current one.

Best to get rid of the currently-broken udev bits first. There's no particular reason MTD couldn't add that other feature though.

- Dave

#6 lore raw
In reply to Kay Sievers
Quoted 11 lines · David Brownell
Quoted 9 lines · Kay Sievers
Quoted 3 lines · David Brownell

And there's MTD-specific metadata, like the OTP bits provided on most modern chips and which MTD technology is used by that device.

If we can provide any other useful data to identify devices, it would be nice, if someone could make that work. Can such attributes somehow be added to sysfs?

Quoted 5 lines

In some cases, maybe ... thing is that OTP (One Time Programmable) bits vary widely in terms of structure, size, and even presence.

OTP data in lot of the NAND chips I have here exceeds the sysfs 4KB binary file limit; 20KB commonly, 128KB for OneNand.

There is no such limit for binary sysfs files. We have many large file there, which map such sizes.

Quoted 8 lines
Quoted 4 lines

MTD currently creates all devices as "virtual", it does not even use the proper parent devices in the kernel, which would at least allow a very simple identification, based on the underlying platform device properties.

That would be an entirely separate problem though.  ISTR having a similar "WTF is this doing" reaction last time I had to look at MTD core driver model stuff.

Yeah, it definitely needs fixing. It's not only the driver core, also all mtd devices share a single block request queue for all devices, which is pretty weird.

Quoted 9 lines
Quoted 4 lines

I keep an untested and unfinished patch around, I did the last time someone tried to solve the problem of reordered mtd devices with udev rules:
  http://git.kernel.org/?p=linux/kernel/git/kay/patches.git;a=blob;f=mtd-parent-dev.patch;hb=HEAD

Looks plausible ... and I may have actually seen a system where that "problem" matters.  (Normally all flash drivers are linked statically, and the system root uses one of them.)

Quoted 8 lines

That obviously needs to be split into "core" (mtd block and char dev support) and driver bits; the core bits could go in at any time once they're ready.

FWIW I did a quick test of this on a physmap flash ... didn't work, /sys/devices/virtual/mtd still held everything that was not in /sys/devices/virtual/block/mtdblock*.  I think the issue might be lack of mtdpart support.

Would be great, if you possibly could find out how to get something like this working, so the mtd devices which are backed by real hardware would no longer show up as virtual, and people have at least a chance to identify them by the properties of the platform devices.

Quoted 5 lines
Quoted 3 lines

If we can offer people the information which will be available with this rather simple change, people can probably switch over to that, and we can replace the current one.

Best to get rid of the currently-broken udev bits first.

Done.

Thanks,
Kay

#8 lore raw
In reply to Kay Sievers
Quoted 5 lines · Kay Sievers
Quoted 2 lines

OTP data in lot of the NAND chips I have here exceeds the sysfs 4KB binary file limit; 20KB commonly, 128KB for OneNand.

There is no such limit for binary sysfs files. We have many large file there, which map such sizes.

Odd, just the other day I created one with actual size of 8KB. But "ls -l" showed 4K. That's clearly a limit... and "cp" was unable to read the whole thing, it stopped at 4K. "dd" could read everything though: dd bs=1k count=8 did it.

Something seems odd with binary sysfs files in general. I've observed something zapping size down to zero after userspace did some oddball reads ... of the "past EOF" variety, ISTR.

#9 lore raw
In reply to Kay Sievers
Quoted 9 lines · David Brownell
Quoted 5 lines · Kay Sievers
Quoted 2 lines

OTP data in lot of the NAND chips I have here exceeds the sysfs 4KB binary file limit; 20KB commonly, 128KB for OneNand.

There is no such limit for binary sysfs files. We have many large file there, which map such sizes.

Odd, just the other day I created one with actual size of 8KB. But "ls -l" showed 4K.

There are larger files:

$ ls -l /sys/devices/pci .../usb1/1-1/descriptors
-r--r--r-- 1 root root 65553 2009-03-23 22:12 ... /usb1/1-1/descriptors
Quoted 3 lines

That's clearly a limit... and "cp" was
unable to read the whole thing, it stopped at 4K.  "dd" could read everything though:  dd bs=1k count=8 did it.

Some larger files seem to work here:

$ ls -l /sys/devices/pci0000:00/0000:00:02.0/rom
-r-------- 1 root root 131072 2009-03-23 22:13 /sys/devices/pci ...
$ cat /sys/devices/pci0000:00/0000:00:02.0/rom | wc -c
65536
$ dd if=/sys/devices/.../rom of=/dev/null bs=1
65536+0 records in
65536+0 records out
65536 bytes (66 kB) copied, 0.103753 s, 632 kB/s
Quoted 3 lines

Something seems odd with binary sysfs files in general. I've observed something zapping size down to zero after userspace did some oddball reads ... of the "past EOF" variety, ISTR.

Hmm, never seen such a thing, but the logic is implemented per-file, so it might be something that should be fixed in the driver that created the file.

Kay

#10 lore raw
In reply to Kay Sievers
Quoted 5 lines · Kay Sievers
Quoted 4 lines · David Brownell
Quoted 3 lines · Kay Sievers
Quoted 2 lines

OTP data in lot of the NAND chips I have here exceeds the sysfs 4KB binary file limit; 20KB commonly, 128KB for OneNand.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

There is no such limit for binary sysfs files. We have many large file there, which map such sizes.

Odd, just the other day I created one with actual size of 8KB. But "ls -l" showed 4K.

There are larger files:

Could be. But still ... I set the size of the attribute to 8K, but "ls" reported only 4K.

Quoted 7 lines
Quoted 3 lines

Something seems odd with binary sysfs files in general. I've observed something zapping size down to zero after userspace did some oddball reads ... of the "past EOF" variety, ISTR.

Hmm, never seen such a thing, but the logic is implemented per-file, so it might be something that should be fixed in the driver that created the file.

All those drivers do is respond to read/write calls, and set the size statically.

I've seen both those failures in multiple drivers, FWIW.

- Dave

#7 lore raw
In reply to Kay Sievers
Quoted 18 lines · Kay Sievers
Quoted 9 lines
Quoted 4 lines

I keep an untested and unfinished patch around, I did the last time someone tried to solve the problem of reordered mtd devices with udev rules:
  http://git.kernel.org/?p=linux/kernel/git/kay/patches.git;a=blob;f=mtd-parent-dev.patch;hb=HEAD

Looks plausible ... and I may have actually seen a system where that "problem" matters.  (Normally all flash drivers are linked statically, and the system root uses one of them.)

Quoted 8 lines

That obviously needs to be split into "core" (mtd block and char dev support) and driver bits; the core bits could go in at any time once they're ready.

FWIW I did a quick test of this on a physmap flash ... didn't work, /sys/devices/virtual/mtd still held everything that was not in /sys/devices/virtual/block/mtdblock*.  I think the issue might be lack of mtdpart support.

Quoted 4 lines

Would be great, if you possibly could find out how to get something like this working, so the mtd devices which are backed by real hardware would no longer show up as virtual, and people have at least a chance to identify them by the properties of the platform devices.

See the appended. I've not split out "core" bits yet, or provided all attributes I expect would eventually appear.

====== CUT HERE
This patch updates driver model support in the MTD framework:

- Each mtd_info now has a device node; MTD drivers should set its parent field to point to the physical device, before setting up partitions.

- Those device nodes always map to /sys/class/mtdX device nodes, which no longer depend on MTD_CHARDEV.

- Those mtdX sysfs nodes have a "starter set" of attributes; it's not yet sufficient to replace /proc/mtd

- Enabling MTD_CHARDEV provides /sys/class/mtdXro/ nodes and the /sys/class/mtd*/dev attributes (for udev, mdev, etc).

So the sysfs structure is pretty much what you'd expect, except that readonly chardev nodes are a bit quirky.

Based on a partial patch from Kay Sievers.

Sanity tested with NOR (physmap, omap_nor, m25p80), DataFlash, NAND (davinci, omap), OneNand (omap); with and without mtdblock. When the MTD driver has been converted, /sys/devices/virtual/mtd/* nodes are gone.

NOT YET SIGNED-OFF ... needs splitting into core vs drivers, and probably a few more attributes.

---
 drivers/mtd/devices/m25p80.c        |    2 
 drivers/mtd/devices/mtd_dataflash.c |    2 
 drivers/mtd/maps/omap_nor.c         |    2 
 drivers/mtd/maps/physmap.c          |   15 ++--
 drivers/mtd/maps/plat-ram.c         |    1 
 drivers/mtd/mtd_blkdevs.c           |    1 
 drivers/mtd/mtdchar.c               |   46 +------------
 drivers/mtd/mtdcore.c               |  115 ++++++++++++++++++++++++++++++++++
 drivers/mtd/mtdpart.c               |    9 ++
 drivers/mtd/nand/davinci_nand.c     |    2 
 drivers/mtd/nand/mxc_nand.c         |    1 
 drivers/mtd/onenand/omap2.c         |    2 
 include/linux/mtd/mtd.h             |    7 ++
 13 files changed, 156 insertions(+), 49 deletions(-)
drivers/mtd/devices/m25p80.c +2 -0
@@ -678,6 +678,8 @@ static int __devinit m25p_probe(struct s
 		flash->mtd.erasesize = info->sector_size;
 	}
 
+	flash->mtd.dev.parent = &spi->dev;
+
 	dev_info(&spi->dev, "%s (%lld Kbytes)\n", info->name,
 			(long long)flash->mtd.size >> 10);
 
drivers/mtd/devices/mtd_dataflash.c +2 -0
@@ -670,6 +670,8 @@ add_dataflash_otp(struct spi_device *spi
 	device->write = dataflash_write;
 	device->priv = priv;
 
+	device->dev.parent = &spi->dev;
+
 	if (revision >= 'c')
 		otp_tag = otp_setup(device, revision);
 
drivers/mtd/maps/omap_nor.c +2 -0
@@ -115,6 +115,8 @@ static int __init omapflash_probe(struct
 	}
 	info->mtd->owner = THIS_MODULE;
 
+	info->mtd->dev.parent = &pdev->dev;
+
 #ifdef CONFIG_MTD_PARTITIONS
 	err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0);
 	if (err > 0)
drivers/mtd/maps/physmap.c +8 -7
@@ -147,6 +147,7 @@ static int physmap_flash_probe(struct pl
 			devices_found++;
 		}
 		info->mtd[i]->owner = THIS_MODULE;
+		info->mtd[i]->dev.parent = &dev->dev;
 	}
 
 	if (devices_found = 1) {
@@ -171,16 +172,16 @@ static int physmap_flash_probe(struct pl
 #ifdef CONFIG_MTD_PARTITIONS
 	err = parse_mtd_partitions(info->cmtd, part_probe_types,
 				&info->parts, 0);
-	if (err > 0) {
-		add_mtd_partitions(info->cmtd, info->parts, err);
+	if (err > 0)
 		info->nr_parts = err;
-		return 0;
+	else {
+		dev_notice(&dev->dev, "Using static partition information\n");
+		info->nr_parts = physmap_data->nr_parts;
+		info->parts = physmap_data->parts;
 	}
 
-	if (physmap_data->nr_parts) {
-		printk(KERN_NOTICE "Using physmap partition information\n");
-		add_mtd_partitions(info->cmtd, physmap_data->parts,
-				   physmap_data->nr_parts);
+	if (info->nr_parts > 0) {
+		add_mtd_partitions(info->cmtd, info->parts, info->nr_parts);
 		return 0;
 	}
 #endif
drivers/mtd/maps/plat-ram.c +1 -0
@@ -224,6 +224,7 @@ static int platram_probe(struct platform
 	}
 
 	info->mtd->owner = THIS_MODULE;
+	info->mtd->dev.parent = &pdev->dev;
 
 	platram_setrw(info, PLATRAM_RW);
 
drivers/mtd/mtd_blkdevs.c +1 -0
@@ -286,6 +286,7 @@ int add_mtd_blktrans_dev(struct mtd_blkt
 	gd->private_data = new;
 	new->blkcore_priv = gd;
 	gd->queue = tr->blkcore_priv->rq;
+	gd->driverfs_dev = new->mtd->dev.parent;
 
 	if (new->readonly)
 		set_disk_ro(gd, 1);
drivers/mtd/mtdchar.c +5 -41

66 lines not on this page · raw message

drivers/mtd/mtdcore.c +115 -0

145 lines not on this page · raw message

drivers/mtd/mtdpart.c +8 -1
@@ -343,6 +343,11 @@ static struct mtd_part *add_one_partitio
 	slave->mtd.name = part->name;
 	slave->mtd.owner = master->owner;
 
+	/* NOTE:  we don't arrange MTDs as a tree; it'd be error-prone
+	 * to have the same data be in two different partitions.
+	 */
+	slave->mtd.dev.parent = master->dev.parent;
+
 	slave->mtd.read = part_read;
 	slave->mtd.write = part_write;
 
@@ -493,7 +498,9 @@ out_register:
  * This function, given a master MTD object and a partition table, creates
  * and registers slave MTD objects which are bound to the master according to
  * the partition definitions.
- * (Q: should we register the master MTD object as well?)
+ *
+ * We don't register the master, or expect the caller to have done so,
+ * for reasons of data integrity.
  */
 
 int add_mtd_partitions(struct mtd_info *master,
drivers/mtd/nand/davinci_nand.c +2 -0
@@ -615,6 +615,8 @@ static int __init nand_davinci_probe(str
 	info->mtd.name		= dev_name(&pdev->dev);
 	info->mtd.owner		= THIS_MODULE;
 
+	info->mtd.dev.parent	= &pdev->dev;
+
 	info->chip.IO_ADDR_R	= vaddr;
 	info->chip.IO_ADDR_W	= vaddr;
 	info->chip.chip_delay	= 0;
drivers/mtd/nand/mxc_nand.c +1 -0
@@ -866,6 +866,7 @@ static int __init mxcnd_probe(struct pla
 	mtd = &host->mtd;
 	mtd->priv = this;
 	mtd->owner = THIS_MODULE;
+	mtd->dev.parent = &pdev->dev;
 
 	/* 50 us command delay time */
 	this->chip_delay = 5;
drivers/mtd/onenand/omap2.c +2 -0
@@ -672,6 +672,8 @@ static int __devinit omap2_onenand_probe
 	c->mtd.priv = &c->onenand;
 	c->mtd.owner = THIS_MODULE;
 
+	c->mtd.dev.parent = &pdev->dev;
+
 	if (c->dma_channel >= 0) {
 		struct onenand_chip *this = &c->onenand;
 
include/linux/mtd/mtd.h +7 -0
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/uio.h>
 #include <linux/notifier.h>
+#include <linux/device.h>
 
 #include <linux/mtd/compatmac.h>
 #include <mtd/mtd-abi.h>
@@ -223,6 +224,7 @@ struct mtd_info {
 	void *priv;
 
 	struct module *owner;
+	struct device dev;
 	int usecount;
 
 	/* If the driver is something smart, like UBI, it may need to maintain
@@ -233,6 +235,11 @@ struct mtd_info {
 	void (*put_device) (struct mtd_info *mtd);
 };
 
+static inline struct mtd_info *dev_to_mtd(struct device *dev)
+{
+	return dev ? container_of(dev, struct mtd_info, dev) : NULL;
+}
+
 static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
 {
 	if (mtd->erasesize_shift)