Skip to contentSkip to conversation

mtd: sharpslpart partition parser

PATCH Superseded Andrea Adami 2 participants 9 messages Apr 22, 2017 – May 25, 2017

Subsystems (2)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v2 cover mtd: sharpslpart partition parser

This patchset introduces a simple partition parser for the Sharp SL Series PXA handhelds. More details in the commit text.

I have set in cc the ARM PXA maintainers because this is the MTD part of a planned wider patchset cleaning the Zaurus board files.

Changelog:
v1 initial import of 2.4 sources [1]
v2 refactor applying many suggested fixes [2]

[1] https://github.com/LinuxPDA/Sharp_FTL_2.4.20
[2] https://github.com/LinuxPDA/linux/commits/sharpslpart_v2

Andrea Adami (3):
mtd: sharpsl: add sharpslpart MTD partition parser
mtd: nand: sharpsl.c: prefer sharpslpart MTD partition parser
mtd: nand: tmio_nand.c: prefer sharpslpart MTD partition parser

 drivers/mtd/Kconfig          |   8 ++
 drivers/mtd/Makefile         |   2 +
 drivers/mtd/nand/sharpsl.c   |   4 +-
 drivers/mtd/nand/tmio_nand.c |   4 +-
 drivers/mtd/sharpsl_ftl.c    | 219 +++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/sharpsl_ftl.h    |  34 +++++++
 drivers/mtd/sharpslpart.c    | 132 ++++++++++++++++++++++++++
 7 files changed, 401 insertions(+), 2 deletions(-)
 create mode 100644 drivers/mtd/sharpsl_ftl.c
 create mode 100644 drivers/mtd/sharpsl_ftl.h
 create mode 100644 drivers/mtd/sharpslpart.c
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/3 mtd: nand: sharpsl.c: prefer sharpslpart MTD partition parser

This is the specific parser for Sharp SL Series (Zaurus).

---
 drivers/mtd/nand/sharpsl.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/nand/sharpsl.c +3 -1
index 064ca17..2d1ba0e 100644
@@ -108,6 +108,8 @@ static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, const u_char * dat,
 /*
  * Main initialization routine
  */
+static const char * const probes[] = { "sharpslpart", NULL };
+
 static int sharpsl_nand_probe(struct platform_device *pdev)
 {
 	struct nand_chip *this;
@@ -183,7 +185,7 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
 	/* Register the partitions */
 	mtd->name = "sharpsl-nand";
 
-	err = mtd_device_parse_register(mtd, NULL, NULL,
+	err = mtd_device_parse_register(mtd, probes, NULL,
 					data->partitions, data->nr_partitions);
 	if (err)
 		goto err_add;
Signature · 1 line
2.7.4
#3 lore raw

PATCH v2 3/3 mtd: nand: tmio_nand.c: prefer sharpslpart MTD partition parser

In reply to Andrea Adami

This is the specific parser for Sharp SL Series (Zaurus)

---
 drivers/mtd/nand/tmio_nand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/nand/tmio_nand.c +3 -1
index fc5e773..f3612ac 100644
@@ -357,6 +357,8 @@ static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio)
 		cell->disable(dev);
 }
 
+static const char * const probes[] = { "sharpslpart", NULL };
+
 static int tmio_probe(struct platform_device *dev)
 {
 	struct tmio_nand_data *data = dev_get_platdata(&dev->dev);
@@ -440,7 +442,7 @@ static int tmio_probe(struct platform_device *dev)
 		goto err_irq;
 
 	/* Register the partitions */
-	retval = mtd_device_parse_register(mtd, NULL, NULL,
+	retval = mtd_device_parse_register(mtd, probes, NULL,
 					   data ? data->partition : NULL,
 					   data ? data->num_partitions : 0);
 	if (!retval)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/3 mtd: sharpsl: add sharpslpart MTD partition parser

In reply to Andrea Adami

The Sharp SL Series (Zaurus) PXA handhelds have 16/64/128M of NAND flash and share the same layout of the first 7M partition, managed by Sharp FTL.

The purpose of this self-contained patch is to add a common parser and remove the hardcoded sizes in the board files (these devices are not yet converted to devicetree).
Users will have benefits because the mtdparts= tag will not be necessary anymore and they will be free to repartition the little sized flash.

The obsolete bootloader can not pass the partitioning info to modern kernels anymore so it has to be read from flash at known logical addresses. (see http://www.h5.dion.ne.jp/~rimemoon/zaurus/memo_006.htm )

In kernel, under arch/arm/mach-pxa we have already 8 machines:
MACH_POODLE, MACH_CORGI, MACH_SHEPERD, MACH_HUSKY, MACH_AKITA, MACH_SPITZ, MACH_BORZOI, MACH_TOSA.
Lost after the 2.4 vendor kernel are MACH_BOXER and MACH_TERRIER.

Almost every model has different factory partitioning: add to this the units can be repartitioned by users with userspace tools (nandlogical) and installers for popular (back then) linux distributions.

The Parameter Area in the first (boot) partition extends from 0x00040000 to 0x0007bfff (176k) and contains two copies of the partition table:
...
0x00060000: Partition Info1 16k
0x00064000: Partition Info2 16k
0x00668000: Model 16k
...

The first 7M partition is managed by the Sharp FTL reserving 5% + 1 blocks for wear-leveling: some blocks are remapped and one layer of translation (logical to physical) is necessary.

There isn't much documentation about this FTL in the 2.4 sources, just the MTD methods for reading and writing using logical addresses and the block management (wear-leveling, use counter).
For the purpose of the MTD parser only the read part of the code was taken.

The NAND drivers that can use this parser are sharpsl.c and tmio_nand.c.

---
 drivers/mtd/Kconfig       |   8 ++
 drivers/mtd/Makefile      |   2 +
 drivers/mtd/sharpsl_ftl.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/sharpsl_ftl.h |  34 +++++++
 drivers/mtd/sharpslpart.c | 132 ++++++++++++++++++++++++++++
 5 files changed, 395 insertions(+)
 create mode 100644 drivers/mtd/sharpsl_ftl.c
 create mode 100644 drivers/mtd/sharpsl_ftl.h
 create mode 100644 drivers/mtd/sharpslpart.c
drivers/mtd/Kconfig +8 -0
index e83a279..5c96127 100644
@@ -155,6 +155,14 @@ config MTD_BCM47XX_PARTS
 	  This provides partitions parser for devices based on BCM47xx
 	  boards.
 
+config MTD_SHARPSL_PARTS
+	tristate "Sharp SL Series NAND flash partition parser"
+	depends on MTD_NAND_SHARPSL || MTD_NAND_TMIO
+	help
+	  This provides the read-only FTL logic necessary to read the partition
+	  table from the NAND flash of Sharp SL Series (Zaurus) and the MTD
+	  partition parser using this code.
+
 comment "User Modules And Translation Layers"
 
 #
drivers/mtd/Makefile +2 -0
index 99bb9a1..89f707b 100644
@@ -13,6 +13,8 @@ obj-$(CONFIG_MTD_AFS_PARTS)	+= afs.o
 obj-$(CONFIG_MTD_AR7_PARTS)	+= ar7part.o
 obj-$(CONFIG_MTD_BCM63XX_PARTS)	+= bcm63xxpart.o
 obj-$(CONFIG_MTD_BCM47XX_PARTS)	+= bcm47xxpart.o
+obj-$(CONFIG_MTD_SHARPSL_PARTS)	+= sharpsl-part.o
+sharpsl-part-objs := sharpsl_ftl.o sharpslpart.o
 
 # 'Users' - code which presents functionality to userspace.
 obj-$(CONFIG_MTD_BLKDEVS)	+= mtd_blkdevs.o
drivers/mtd/sharpsl_ftl.c new file +219 -0

219 lines not on this page · raw message

drivers/mtd/sharpsl_ftl.h new file +34 -0
new file mode 100644
index 0000000..2880cbe
@@ -0,0 +1,34 @@
+/*
+ * Header file for NAND accessing via logical address (SHARP FTL)
+ *
+ * Copyright (C) 2017 Andrea Adami <[email protected]>
+ *
+ * Based on 2.4 sources: linux/include/asm-arm/sharp_nand_logical.h
+ * Copyright (C) 2002  SHARP
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef __SHARPSL_NAND_LOGICAL_H__
+#define __SHARPSL_NAND_LOGICAL_H__
+
+#include <linux/types.h>
+#include <linux/mtd/mtd.h>
+
+int sharpsl_nand_init_logical(struct mtd_info *mtd, u32 partition_size);
+
+void sharpsl_nand_cleanup_logical(void);
+
+int sharpsl_nand_read_laddr(struct mtd_info *mtd, loff_t from, size_t len,
+			    u_char *buf);
+
+#endif
drivers/mtd/sharpslpart.c new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw
In reply to Andrea Adami
Quoted 30 lines · Andrea Adami

This patchset introduces a simple partition parser for the Sharp SL Series PXA handhelds. More details in the commit text.

I have set in cc the ARM PXA maintainers because this is the MTD part of a planned wider patchset cleaning the Zaurus board files.

Changelog:
v1 initial import of 2.4 sources [1]
v2 refactor applying many suggested fixes [2]

[1] https://github.com/LinuxPDA/Sharp_FTL_2.4.20
[2] https://github.com/LinuxPDA/linux/commits/sharpslpart_v2

Andrea Adami (3):
mtd: sharpsl: add sharpslpart MTD partition parser
mtd: nand: sharpsl.c: prefer sharpslpart MTD partition parser
mtd: nand: tmio_nand.c: prefer sharpslpart MTD partition parser

 drivers/mtd/Kconfig          |   8 ++
 drivers/mtd/Makefile         |   2 +
 drivers/mtd/nand/sharpsl.c   |   4 +-
 drivers/mtd/nand/tmio_nand.c |   4 +-
 drivers/mtd/sharpsl_ftl.c    | 219 +++++++++++++++++++++++++++++++++++++++++++
 drivers/mtd/sharpsl_ftl.h    |  34 +++++++
 drivers/mtd/sharpslpart.c    | 132 ++++++++++++++++++++++++++
 7 files changed, 401 insertions(+), 2 deletions(-)
 create mode 100644 drivers/mtd/sharpsl_ftl.c
 create mode 100644 drivers/mtd/sharpsl_ftl.h
 create mode 100644 drivers/mtd/sharpslpart.c
Quoted 3 lines

--
2.7.4

Hello,

I'd be thankful for a second review after the big changes from v1 which was just a proof of concept.
As for the memory management, it totally mimics the other parsers.

The patch has been backported to 4.4 [1] and up to 3.10 [2] with minimal changes to module init/exit:
since linux 4.5 (commit b8f70ba mtd: kill off MTD partition parser boilerplate) we use module_mtd_part_parser().

With this parser we have finally a single linux-as bootloader kernel covering the 4 Zaurus pxa 27x devices (repartitioned or not).

Thanks in advance
Andrea

[1] http://cgit.openembedded.org/meta-handheld/tree/recipes-kernel/linux/linux-handheld-4.4/sharpslpart/0001-mtd-sharpsl-add-sharpslpart-MTD-partition-parser.patch
[2] https://github.com/greguu/linux-3.10.y-c3x00-f2fs-kexec-r0/commit/f087900fbd778cce642a8e24e7351a0d814bb9a7

#4 lore raw

Re: [PATCH v2 3/3] mtd: nand: tmio_nand.c: prefer sharpslpart MTD partition parser

In reply to Andrea Adami
Quoted 12 lines · Andrea Adami

This is the specific parser for Sharp SL Series (Zaurus)

---
 drivers/mtd/nand/tmio_nand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/nand/tmio_nand.c +0 -0
index fc5e773..f3612ac 100644

drivers/mtd/nand/tmio_nand.c static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio) · line 360

Quoted 4 lines
drivers/mtd/nand/tmio_nand.c +1 -0
@@ -357,6 +357,8 @@ static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio)
 		cell->disable(dev);
 }
 
+static const char * const probes[] = { "sharpslpart", NULL };

This breaks anyone who might have used (or might want to use) the ofpart or cmdlinepart parsers. At a minimum, you need to include those in your array here.

But really, I'd rather not add any more parser listings like this in drivers. Parser selection should be determined by the platform, not by the driver. See my last response to Rafal, who is trying to extend support for device-tree based listing of parsers:

http://lists.infradead.org/pipermail/linux-mtd/2017-April/073729.html

He has some more work posted to the mailing list since then; search the archives.

I'll take a look at the parser itself, and maybe we can merge that. But I'm not likely to merge this patch, in any form.

Brian

Quoted 16 lines
drivers/mtd/nand/tmio_nand.c +2 -1
+
 static int tmio_probe(struct platform_device *dev)
 {
 	struct tmio_nand_data *data = dev_get_platdata(&dev->dev);
@@ -440,7 +442,7 @@ static int tmio_probe(struct platform_device *dev)
 		goto err_irq;
 
 	/* Register the partitions */
-	retval = mtd_device_parse_register(mtd, NULL, NULL,
+	retval = mtd_device_parse_register(mtd, probes, NULL,
 					   data ? data->partition : NULL,
 					   data ? data->num_partitions : 0);
 	if (!retval)
Signature · 1 line
2.7.4
#5 lore raw

Re: [PATCH v2 3/3] mtd: nand: tmio_nand.c: prefer sharpslpart MTD partition parser

Quoted 16 lines · Brian Norris
Quoted 15 lines · Andrea Adami

This is the specific parser for Sharp SL Series (Zaurus)

---
 drivers/mtd/nand/tmio_nand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/nand/tmio_nand.c +0 -0
index fc5e773..f3612ac 100644
@@ -357,6 +357,8 @@ static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio)
              cell->disable(dev);
 }
 
Quoted 5 lines

drivers/mtd/nand/tmio_nand.c static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio) · line 360

Quoted 1 line
drivers/mtd/nand/tmio_nand.c +1 -0
+static const char * const probes[] = { "sharpslpart", NULL };

This breaks anyone who might have used (or might want to use) the ofpart or cmdlinepart parsers. At a minimum, you need to include those in your array here.

I have been under the wrong assumption there is cmdlinepart as last option (if compiled) so I have taken a wrong example. Grepping in /mt for probes gives many examples: what if I change it with

static const char * const probes[] = { "sharpslpart", "cmdlinepart", NULL };

ofpart is utopic at the moment: these machines are not yet converted to devicetree and it will take a while.

With this patchset we can move a step forward DT, removing all the static partition definition from spitz.c, tosa.c, corgi.c and poodle.c

I don't dare adding ofpart here: this will be done once Zaurus pxa platform is moved to devicetree.

Quoted 7 lines

But really, I'd rather not add any more parser listings like this in drivers. Parser selection should be determined by the platform, not by the driver. See my last response to Rafal, who is trying to extend support for device-tree based listing of parsers:

http://lists.infradead.org/pipermail/linux-mtd/2017-April/073729.html

Ok then but remember these are obsolete devices and as far as I know these nand drivers are only used on Zaurus devices. No future use I guess.

Quoted 7 lines

He has some more work posted to the mailing list since then; search the archives.

I'll take a look at the parser itself, and maybe we can merge that. But I'm not likely to merge this patch, in any form.

The little parser itself is universal for all Zaurus pxa variants. As said above, please consider we can remove many lines of board code.

Thanks
Andrea

Quoted 18 lines

Brian

Quoted 16 lines
drivers/mtd/nand/tmio_nand.c +2 -2
+
 static int tmio_probe(struct platform_device *dev)
 {
      struct tmio_nand_data *data = dev_get_platdata(&dev->dev);
@@ -440,7 +442,7 @@ static int tmio_probe(struct platform_device *dev)
              goto err_irq;
 
      /* Register the partitions */
-     retval = mtd_device_parse_register(mtd, NULL, NULL,
+     retval = mtd_device_parse_register(mtd, probes, NULL,
                                         data ? data->partition : NULL,
                                         data ? data->num_partitions : 0);
      if (!retval)
--

2.7.4

#6 lore raw

Re: [PATCH v2 3/3] mtd: nand: tmio_nand.c: prefer sharpslpart MTD partition parser

Quoted 30 lines · Andrea Adami
Quoted 16 lines · Brian Norris
Quoted 15 lines · Andrea Adami

This is the specific parser for Sharp SL Series (Zaurus)

---
 drivers/mtd/nand/tmio_nand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/nand/tmio_nand.c +0 -0
index fc5e773..f3612ac 100644
@@ -357,6 +357,8 @@ static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio)
              cell->disable(dev);
 }
 
Quoted 5 lines

drivers/mtd/nand/tmio_nand.c static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio) · line 360

Quoted 1 line
drivers/mtd/nand/tmio_nand.c +1 -0
+static const char * const probes[] = { "sharpslpart", NULL };

This breaks anyone who might have used (or might want to use) the ofpart or cmdlinepart parsers. At a minimum, you need to include those in your array here.

I have been under the wrong assumption there is cmdlinepart as last option (if compiled) so I have taken a wrong example. Grepping in /mt for probes gives many examples: what if I change it with

static const char * const probes[] = { "sharpslpart", "cmdlinepart", NULL };

Quoted 8 lines

ofpart is utopic at the moment: these machines are not yet converted to devicetree and it will take a while.

With this patchset we can move a step forward DT, removing all the static partition definition from spitz.c, tosa.c, corgi.c and poodle.c

I don't dare adding ofpart here: this will be done once Zaurus pxa platform is moved to devicetree.

What's the harm in including ofpart? It will be silently skipped if you don't have a conforming device tree.

Quoted 10 lines
Quoted 6 lines

But really, I'd rather not add any more parser listings like this in drivers. Parser selection should be determined by the platform, not by the driver. See my last response to Rafal, who is trying to extend support for device-tree based listing of parsers:

http://lists.infradead.org/pipermail/linux-mtd/2017-April/073729.html

Ok then but remember these are obsolete devices and as far as I know these nand drivers are only used on Zaurus devices. No future use I guess.

Yes, but the point is I don't want new examples of a bad pattern. And if you ever do gain device tree support, I would then be "breaking" your device tree if I dropped "sharpslpart" from your probe list.

Quoted 8 lines
Quoted 6 lines

He has some more work posted to the mailing list since then; search the archives.

I'll take a look at the parser itself, and maybe we can merge that. But I'm not likely to merge this patch, in any form.

The little parser itself is universal for all Zaurus pxa variants. As said above, please consider we can remove many lines of board code.

Speaking of board code: since this is all initialized by board files, why can't you put the "platform information" (i.e., the partition parser type(s)) in the platform data? e.g, struct sharpsl_nand_platform_data or struct tmio_nand_data. That'd resolve my concern about hardcoding lists in the driver.

Brian

#7 lore raw

Re: [PATCH v2 3/3] mtd: nand: tmio_nand.c: prefer sharpslpart MTD partition parser

Quoted 67 lines · Brian Norris
Quoted 30 lines · Andrea Adami
Quoted 16 lines · Brian Norris
Quoted 15 lines · Andrea Adami

This is the specific parser for Sharp SL Series (Zaurus)

---
 drivers/mtd/nand/tmio_nand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/nand/tmio_nand.c +0 -0
index fc5e773..f3612ac 100644
@@ -357,6 +357,8 @@ static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio)
              cell->disable(dev);
 }
 
Quoted 5 lines

drivers/mtd/nand/tmio_nand.c static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio) · line 360

Quoted 1 line
drivers/mtd/nand/tmio_nand.c +1 -0
+static const char * const probes[] = { "sharpslpart", NULL };

This breaks anyone who might have used (or might want to use) the ofpart or cmdlinepart parsers. At a minimum, you need to include those in your array here.

I have been under the wrong assumption there is cmdlinepart as last option (if compiled) so I have taken a wrong example. Grepping in /mt for probes gives many examples: what if I change it with

static const char * const probes[] = { "sharpslpart", "cmdlinepart", NULL };

Quoted 8 lines

ofpart is utopic at the moment: these machines are not yet converted to devicetree and it will take a while.

With this patchset we can move a step forward DT, removing all the static partition definition from spitz.c, tosa.c, corgi.c and poodle.c

I don't dare adding ofpart here: this will be done once Zaurus pxa platform is moved to devicetree.

What's the harm in including ofpart? It will be silently skipped if you don't have a conforming device tree.

Quoted 10 lines
Quoted 6 lines

But really, I'd rather not add any more parser listings like this in drivers. Parser selection should be determined by the platform, not by the driver. See my last response to Rafal, who is trying to extend support for device-tree based listing of parsers:

http://lists.infradead.org/pipermail/linux-mtd/2017-April/073729.html

Ok then but remember these are obsolete devices and as far as I know these nand drivers are only used on Zaurus devices. No future use I guess.

Yes, but the point is I don't want new examples of a bad pattern. And if you ever do gain device tree support, I would then be "breaking" your device tree if I dropped "sharpslpart" from your probe list.

Quoted 8 lines
Quoted 6 lines

He has some more work posted to the mailing list since then; search the archives.

I'll take a look at the parser itself, and maybe we can merge that. But I'm not likely to merge this patch, in any form.

The little parser itself is universal for all Zaurus pxa variants. As said above, please consider we can remove many lines of board code.

Quoted 7 lines

Speaking of board code: since this is all initialized by board files, why can't you put the "platform information" (i.e., the partition parser type(s)) in the platform data? e.g, struct sharpsl_nand_platform_data or struct tmio_nand_data. That'd resolve my concern about hardcoding lists in the driver.

Brian

Brian,

I now understand your objections about hardcoding parsers in the drivers. I'll ask the maintainers in case there were any objections: the patch will cross mach-pxa and drivers/mtd.

Thanks again

Andrea