Skip to contentSkip to conversation

mtdpart: memory accessor interface for MTD layer

PATCH Applied [email protected] 4 participants 5 messages Oct 1, 2010 – Oct 4, 2010 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mtdpart: memory accessor interface for MTD layer

From: Sudhakar Rajashekhara <[email protected]>

Implement a memory accessor interface in the MTD layer which enables the kernel to access flash data.

This patch adds two new members to the mtd_partition structure, a function handler which will be called during setup of the partition and an argument to be passed to this setup function.

Example:
+static struct mtd_partition spi_flash_partitions[] = {
+ [0] = {

+               .name       = "U-Boot",
+               .offset     = 0,
+               .size       = SZ_256K,
+               .mask_flags = MTD_WRITEABLE,
+       },
+       [1] = {
+               .name       = "U-Boot Environment",
+               .offset     = MTDPART_OFS_NXTBLK,
+               .size       = SZ_64K,
+               .mask_flags = MTD_WRITEABLE,
+       },
+       [2] = {
+               .name       = "Linux",
+               .offset     = MTDPART_OFS_NXTBLK,
+               .size       = SZ_7M,
+               .mask_flags = 0,
+       },
+       [3] = {
+               .name       = "MAC Address",
+               .offset     = MTDPART_OFS_NXTBLK,
+               .size       = SZ_64K,
+               .mask_flags = 0,
+               .setup      = davinci_get_mac_addr,
+               .context    = (void *)0,

+ },
+};

The davinci_get_mac_addr function reads the MAC address from offset ZERO of last MTD partition.

---

 drivers/mtd/mtdpart.c          |   40 +++++++++++++++++++++++++++++++
 include/linux/mtd/partitions.h |    3 ++
 2 files changed, 43 insertions(+)
drivers/mtd/mtdpart.c renamed from drivers/mtd/mtdpart.c~mtdpart-memory-accessor-interface-for-mtd-layer +40 -0
diff -puN drivers/mtd/mtdpart.c~mtdpart-memory-accessor-interface-for-mtd-layer drivers/mtd/mtdpart.c
@@ -37,6 +37,7 @@ static LIST_HEAD(mtd_partitions);
 struct mtd_part {
 	struct mtd_info mtd;
 	struct mtd_info *master;
+	struct memory_accessor macc;
 	uint64_t offset;
 	struct list_head list;
 };
@@ -346,6 +347,39 @@ int del_mtd_partitions(struct mtd_info *
 }
 EXPORT_SYMBOL(del_mtd_partitions);
 
+/*
+ * This lets other kernel code access the flash data. For example, it
+ * might hold a board's Ethernet address, or board-specific calibration
+ * data generated on the manufacturing floor.
+ */
+static ssize_t mtd_macc_read(struct memory_accessor *macc, char *buf,
+			off_t offset, size_t count)
+{
+	struct mtd_part *part = container_of(macc, struct mtd_part, macc);
+	ssize_t ret = -EIO;
+	size_t retlen;
+
+	if (part_read((struct mtd_info *)part, offset, count,
+			&retlen, buf) == 0)
+		ret = retlen;
+
+	return ret;
+}
+
+static ssize_t mtd_macc_write(struct memory_accessor *macc, const char *buf,
+			off_t offset, size_t count)
+{
+	struct mtd_part *part = container_of(macc, struct mtd_part, macc);
+	ssize_t ret = -EIO;
+	size_t retlen;
+
+	if (part_write((struct mtd_info *)part, offset, count,
+			&retlen, buf) == 0)
+		ret = retlen;
+
+	return ret;
+}
+
 static struct mtd_part *add_one_partition(struct mtd_info *master,
 		const struct mtd_partition *part, int partno,
 		uint64_t cur_offset)
@@ -383,6 +417,9 @@ static struct mtd_part *add_one_partitio
 	slave->mtd.read = part_read;
 	slave->mtd.write = part_write;
 
+	slave->macc.read = mtd_macc_read;
+	slave->macc.write = mtd_macc_write;
+
 	if (master->panic_write)
 		slave->mtd.panic_write = part_panic_write;
 
@@ -449,6 +486,9 @@ static struct mtd_part *add_one_partitio
 	printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", (unsigned long long)slave->offset,
 		(unsigned long long)(slave->offset + slave->mtd.size), slave->mtd.name);
 
+	if (part->setup)
+		part->setup(&slave->macc, (void *)part->context);
+
 	/* let's do some sanity checks */
 	if (slave->offset >= master->size) {
 		/* let's register it anyway to preserve ordering */
include/linux/mtd/partitions.h renamed from include/linux/mtd/partitions.h~mtdpart-memory-accessor-interface-for-mtd-layer +3 -0
diff -puN include/linux/mtd/partitions.h~mtdpart-memory-accessor-interface-for-mtd-layer include/linux/mtd/partitions.h
@@ -10,6 +10,7 @@
 #define MTD_PARTITIONS_H
 
 #include <linux/types.h>
+#include <linux/memory.h>
 
 
 /*
@@ -40,6 +41,8 @@ struct mtd_partition {
 	uint64_t offset;		/* offset within the master MTD space */
 	uint32_t mask_flags;		/* master MTD flags to mask out for this partition */
 	struct nand_ecclayout *ecclayout;	/* out of band layout for this partition (NAND only)*/
+	void (*setup)(struct memory_accessor *, void *context);
+	void *context;
 };
 
 #define MTDPART_OFS_NXTBLK	(-2)

_

#1 lore raw
Quoted 8 lines · On Fri, 2010-10-01 at 14:16 -0700, [email protected] wrote:

From: Sudhakar Rajashekhara <[email protected]>

Implement a memory accessor interface in the MTD layer which enables the kernel to access flash data.

This patch adds two new members to the mtd_partition structure, a function handler which will be called during setup of the partition and an argument to be passed to this setup function.

This patch does not apply to my l2-mtd-2.6.git tree - many confilicts. Sudhakar, you can refresh your patch against my tree and re-send:

http://git.infradead.org/users/dedekind/l2-mtd-2.6.git

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Битюцкий Артём)
#2 lore raw
Quoted 5 lines · Artem Bityutskiy
Quoted 2 lines

Implement a memory accessor interface in the MTD layer which enables

the

Quoted 2 lines

kernel to access flash data.

Quoted 7 lines
Quoted 1 line

This patch adds two new members to the mtd_partition structure, a

function

Quoted 1 line

handler which will be called during setup of the partition and an

argument

Quoted 1 line

to be passed to this setup function.

This patch does not apply to my l2-mtd-2.6.git tree

Wasn't there going to be a much nicer version of this patch coming anyway?

Signature · 1 line
dwmw2
#3 lore raw

All,

Quoted 8 lines · David Woodhouse
Quoted 7 lines · Artem Bityutskiy
Quoted 2 lines

Implement a memory accessor interface in the MTD layer which enables

the

Quoted 3 lines

kernel to access flash data.

This patch adds two new members to the mtd_partition structure, a

function

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

handler which will be called during setup of the partition and an

argument

Quoted 1 line

to be passed to this setup function.

This patch does not apply to my l2-mtd-2.6.git tree

Wasn't there going to be a much nicer version of this patch coming anyway?

This patch can be dropped. Please see the discussion at [1] regarding this.

[1] http://lists.infradead.org/pipermail/linux-mtd/2010-August/031483.html

Thanks,
Sudhakar

#4 lore raw
In reply to Artem Bityutskiy
Quoted 11 lines · On Sat, 02 Oct 2010 17:09:52 +0300 Artem Bityutskiy <[email protected]> wrote:
Quoted 8 lines · On Fri, 2010-10-01 at 14:16 -0700, [email protected] wrote:

From: Sudhakar Rajashekhara <[email protected]>

Implement a memory accessor interface in the MTD layer which enables the kernel to access flash data.

This patch adds two new members to the mtd_partition structure, a function handler which will be called during setup of the partition and an argument to be passed to this setup function.

This patch does not apply to my l2-mtd-2.6.git tree - many confilicts.

It applies against linux-next.

For heavens sake guys, please fix this.