Linux-mtd Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/1] mtd/intel-spi: Support cmdline-based partition
@ 2020-03-23 19:58 ron minnich
  2020-03-23 23:19 ` ron minnich
  0 siblings, 1 reply; 32+ messages in thread
From: ron minnich @ 2020-03-23 19:58 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, linux-mtd

The MTD subsystem can support command-line defined partitions
for one or more MTD devices.

The format is:
 * mtdparts=<mtddef>[;<mtddef]
 * <mtddef>  := <mtd-id>:<partdef>[,<partdef>]

The ':' currently separates the id from the partdef.

The mtdparts can define more than one part, in which case
there will be more than one <mtd-id>:<partdef> component.

On Intel spi devices, the name is set to the PCI slot name,
e.g. 0000:00:1f.5.  There are two : in the name alone.
Since strchr is used to find the <mtd-id>,
in this case it will return the wrong
result. Using strrchr is not an option, as there may
be more than one mtddef in the argument.

This change modifies the name attached to the intel spi
device, changing all ':' to '.', e.g. 0000:00:1f.5
becomes 0000.00.1f.5. It also adds command line partition
parsing registration to the intel_spi_probe function.

This change has been tested and works on a modern Intel chipset with
a 64 MiB FLASH part.

Signed-off-by: Ronald G. Minnich <rminnich@google.com>
---
 drivers/mtd/spi-nor/intel-spi-pci.c | 22 ++++++++++++++++++++++
 drivers/mtd/spi-nor/intel-spi.c     |  4 +++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/intel-spi-pci.c
b/drivers/mtd/spi-nor/intel-spi-pci.c
index 81329f680bec..57716e53c219 100644
--- a/drivers/mtd/spi-nor/intel-spi-pci.c
+++ b/drivers/mtd/spi-nor/intel-spi-pci.c
@@ -24,6 +24,23 @@ static const struct intel_spi_boardinfo cnl_info = {
        .type = INTEL_SPI_CNL,
 };

+/*
+ * PCI names use a ':' as a separator, which conflicts
+ * with the mtdparts cmdline parameter. Dup the name and
+ * replace : with .
+ */
+static int fixname(struct pci_dev *pdev) {
+       char *name;
+        name = kstrdup(pci_name(pdev), GFP_KERNEL);
+       if (! name) {
+               return -ENOMEM;
+       }
+       strreplace(name, ':', '.');
+       dev_set_name(&pdev->dev, name);
+       kfree(name);
+       return 0;
+}
+
 static int intel_spi_pci_probe(struct pci_dev *pdev,
                               const struct pci_device_id *id)
 {
@@ -41,6 +58,11 @@ static int intel_spi_pci_probe(struct pci_dev *pdev,
        if (!info)
                return -ENOMEM;

+       if (fixname(pdev)) {
+               kfree(info);
+               return -ENOMEM;
+       }
+
        /* Try to make the chip read/write */
        pci_read_config_dword(pdev, BCR, &bcr);
        if (!(bcr & BCR_WPD)) {
diff --git a/drivers/mtd/spi-nor/intel-spi.c b/drivers/mtd/spi-nor/intel-spi.c
index 61d2a0ad2131..261b10cf5076 100644
--- a/drivers/mtd/spi-nor/intel-spi.c
+++ b/drivers/mtd/spi-nor/intel-spi.c
@@ -894,6 +894,8 @@ static const struct spi_nor_controller_ops
intel_spi_controller_ops = {
        .erase = intel_spi_erase,
 };

+static const char * const part_probes[] = { "cmdlinepart", NULL };
+
 struct intel_spi *intel_spi_probe(struct device *dev,
        struct resource *mem, const struct intel_spi_boardinfo *info)
 {
@@ -941,7 +943,7 @@ struct intel_spi *intel_spi_probe(struct device *dev,
        if (!ispi->writeable || !writeable)
                ispi->nor.mtd.flags &= ~MTD_WRITEABLE;

-       ret = mtd_device_register(&ispi->nor.mtd, &part, 1);
+       ret = mtd_device_parse_register(&ispi->nor.mtd, part_probes,
NULL, &part, 1);
        if (ret)
                return ERR_PTR(ret);

-- 
2.25.1.696.g5e7596f4ac-goog

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, back to index

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23 19:58 [PATCH 1/1] mtd/intel-spi: Support cmdline-based partition ron minnich
2020-03-23 23:19 ` ron minnich
2020-03-25 17:34   ` ron minnich
2020-03-25 17:34     ` ron minnich
2020-03-27 15:48       ` ron minnich
2020-03-27 15:56         ` Mika Westerberg
2020-03-27 16:19           ` Miquel Raynal
2020-03-27 16:48             ` Mika Westerberg
2020-03-27 16:52               ` Miquel Raynal
2020-03-27 17:05                 ` ron minnich
2020-03-27 17:16                   ` Mika Westerberg
2020-03-27 17:39                     ` ron minnich
2020-03-27 23:53                       ` ron minnich
2020-03-30  6:08                         ` Mika Westerberg
2020-03-30  7:27                           ` Miquel Raynal
2020-03-30 15:53                             ` ron minnich
2020-04-01  7:41                               ` Miquel Raynal
2020-04-01 15:42                                 ` ron minnich
2020-04-01 19:49                                   ` ron minnich
2020-04-27  9:16                                 ` Boris Brezillon
2020-04-27  9:49                                   ` Boris Brezillon
2020-04-27 14:41                                     ` Miquel Raynal
2020-04-27 18:48                                       ` ron minnich
2020-04-27 18:50                                         ` ron minnich
2020-04-27 18:56                                           ` Miquel Raynal
2020-04-27 18:59                                             ` ron minnich
2020-04-27 19:21                                             ` Boris Brezillon
2020-04-27 19:31                                               ` ron minnich
2020-04-27 20:31                                     ` ron minnich
2020-04-27 21:20                                       ` Miquel Raynal
2020-03-27 16:53             ` ron minnich
2020-03-27 16:15         ` Miquel Raynal

Linux-mtd Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mtd/0 linux-mtd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mtd linux-mtd/ https://lore.kernel.org/linux-mtd \
		linux-mtd@lists.infradead.org
	public-inbox-index linux-mtd

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-mtd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git