kernel: backport mtd implementation for "compatible" in "partitions" subnode

This backports upstream support for "compatible" DT property set for the
"partitions" subnode of flash node. It allows specifying how partitions
should be created/parsed. Right now only "fixed-partitions" is
supported.

It should eventually replace our downstream "linux,part-probe" solution.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
This commit is contained in:
Rafał Miłecki 2018-01-11 11:59:39 +01:00
parent ef27f15330
commit bde5e7a632
18 changed files with 386 additions and 56 deletions

View File

@ -0,0 +1,121 @@
From bb2192123ec70470d6ea33f138846b175403a968 Mon Sep 17 00:00:00 2001
From: Brian Norris <computersforpeace@gmail.com>
Date: Thu, 4 Jan 2018 08:05:33 +0100
Subject: [PATCH] mtd: partitions: add of_match_table parser matching
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Partition parsers can now provide an of_match_table to enable
flash<-->parser matching via device tree as documented in the
mtd/partition.txt.
It works by looking for a matching parser for every string in the
"compatibility" property (starting with the most specific one).
This support is currently limited to built-in parsers as it uses
request_module() and friends. This should be sufficient for most cases
though as compiling parsers as modules isn't a common choice.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/mtd/mtdpart.c | 59 ++++++++++++++++++++++++++++++++++++++++++
include/linux/mtd/partitions.h | 1 +
2 files changed, 60 insertions(+)
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -30,6 +30,7 @@
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/err.h>
+#include <linux/of.h>
#include "mtdcore.h"
@@ -894,6 +895,45 @@ static int mtd_part_do_parse(struct mtd_
}
/**
+ * mtd_part_get_compatible_parser - find MTD parser by a compatible string
+ *
+ * @compat: compatible string describing partitions in a device tree
+ *
+ * MTD parsers can specify supported partitions by providing a table of
+ * compatibility strings. This function finds a parser that advertises support
+ * for a passed value of "compatible".
+ */
+static struct mtd_part_parser *mtd_part_get_compatible_parser(const char *compat)
+{
+ struct mtd_part_parser *p, *ret = NULL;
+
+ spin_lock(&part_parser_lock);
+
+ list_for_each_entry(p, &part_parsers, list) {
+ const struct of_device_id *matches;
+
+ matches = p->of_match_table;
+ if (!matches)
+ continue;
+
+ for (; matches->compatible[0]; matches++) {
+ if (!strcmp(matches->compatible, compat) &&
+ try_module_get(p->owner)) {
+ ret = p;
+ break;
+ }
+ }
+
+ if (ret)
+ break;
+ }
+
+ spin_unlock(&part_parser_lock);
+
+ return ret;
+}
+
+/**
* parse_mtd_partitions - parse MTD partitions
* @master: the master partition (describes whole MTD device)
* @types: names of partition parsers to try or %NULL
@@ -919,8 +959,27 @@ int parse_mtd_partitions(struct mtd_info
struct mtd_part_parser_data *data)
{
struct mtd_part_parser *parser;
+ struct device_node *np;
+ struct property *prop;
+ const char *compat;
int ret, err = 0;
+ np = of_get_child_by_name(mtd_get_of_node(master), "partitions");
+ of_property_for_each_string(np, "compatible", prop, compat) {
+ parser = mtd_part_get_compatible_parser(compat);
+ if (!parser)
+ continue;
+ ret = mtd_part_do_parse(parser, master, pparts, data);
+ if (ret > 0) {
+ of_node_put(np);
+ return 0;
+ }
+ mtd_part_parser_put(parser);
+ if (ret < 0 && !err)
+ err = ret;
+ }
+ of_node_put(np);
+
if (!types)
types = default_mtd_part_types;
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -77,6 +77,7 @@ struct mtd_part_parser {
struct list_head list;
struct module *owner;
const char *name;
+ const struct of_device_id *of_match_table;
int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
struct mtd_part_parser_data *);
void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);

View File

@ -0,0 +1,43 @@
From 4ac9222778478a00c7fc9d347b7ed1e0e595120d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
Date: Thu, 4 Jan 2018 08:05:34 +0100
Subject: [PATCH] mtd: ofpart: add of_match_table with "fixed-partitions"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This allows using this parser with any flash driver that takes care of
setting of_node (using mtd_set_of_node helper) correctly. Up to now
support for "fixed-partitions" DT compatibility string was working only
with flash drivers that were specifying "ofpart" (manually or by letting
mtd use the default set of parsers).
This matches existing bindings documentation.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Brian Norris <computersforpeace@gmail.com>
Tested-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/mtd/ofpart.c | 7 +++++++
1 file changed, 7 insertions(+)
--- a/drivers/mtd/ofpart.c
+++ b/drivers/mtd/ofpart.c
@@ -140,9 +140,16 @@ ofpart_none:
return ret;
}
+static const struct of_device_id parse_ofpart_match_table[] = {
+ { .compatible = "fixed-partitions" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, parse_ofpart_match_table);
+
static struct mtd_part_parser ofpart_parser = {
.parse_fn = parse_ofpart_partitions,
.name = "ofpart",
+ .of_match_table = parse_ofpart_match_table,
};
static int parse_ofoldpart_partitions(struct mtd_info *master,

View File

@ -0,0 +1,121 @@
From bb2192123ec70470d6ea33f138846b175403a968 Mon Sep 17 00:00:00 2001
From: Brian Norris <computersforpeace@gmail.com>
Date: Thu, 4 Jan 2018 08:05:33 +0100
Subject: [PATCH] mtd: partitions: add of_match_table parser matching
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Partition parsers can now provide an of_match_table to enable
flash<-->parser matching via device tree as documented in the
mtd/partition.txt.
It works by looking for a matching parser for every string in the
"compatibility" property (starting with the most specific one).
This support is currently limited to built-in parsers as it uses
request_module() and friends. This should be sufficient for most cases
though as compiling parsers as modules isn't a common choice.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/mtd/mtdpart.c | 59 ++++++++++++++++++++++++++++++++++++++++++
include/linux/mtd/partitions.h | 1 +
2 files changed, 60 insertions(+)
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -30,6 +30,7 @@
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/err.h>
+#include <linux/of.h>
#include "mtdcore.h"
@@ -886,6 +887,45 @@ static int mtd_part_do_parse(struct mtd_
}
/**
+ * mtd_part_get_compatible_parser - find MTD parser by a compatible string
+ *
+ * @compat: compatible string describing partitions in a device tree
+ *
+ * MTD parsers can specify supported partitions by providing a table of
+ * compatibility strings. This function finds a parser that advertises support
+ * for a passed value of "compatible".
+ */
+static struct mtd_part_parser *mtd_part_get_compatible_parser(const char *compat)
+{
+ struct mtd_part_parser *p, *ret = NULL;
+
+ spin_lock(&part_parser_lock);
+
+ list_for_each_entry(p, &part_parsers, list) {
+ const struct of_device_id *matches;
+
+ matches = p->of_match_table;
+ if (!matches)
+ continue;
+
+ for (; matches->compatible[0]; matches++) {
+ if (!strcmp(matches->compatible, compat) &&
+ try_module_get(p->owner)) {
+ ret = p;
+ break;
+ }
+ }
+
+ if (ret)
+ break;
+ }
+
+ spin_unlock(&part_parser_lock);
+
+ return ret;
+}
+
+/**
* parse_mtd_partitions - parse MTD partitions
* @master: the master partition (describes whole MTD device)
* @types: names of partition parsers to try or %NULL
@@ -911,8 +951,27 @@ int parse_mtd_partitions(struct mtd_info
struct mtd_part_parser_data *data)
{
struct mtd_part_parser *parser;
+ struct device_node *np;
+ struct property *prop;
+ const char *compat;
int ret, err = 0;
+ np = of_get_child_by_name(mtd_get_of_node(master), "partitions");
+ of_property_for_each_string(np, "compatible", prop, compat) {
+ parser = mtd_part_get_compatible_parser(compat);
+ if (!parser)
+ continue;
+ ret = mtd_part_do_parse(parser, master, pparts, data);
+ if (ret > 0) {
+ of_node_put(np);
+ return 0;
+ }
+ mtd_part_parser_put(parser);
+ if (ret < 0 && !err)
+ err = ret;
+ }
+ of_node_put(np);
+
if (!types)
types = default_mtd_part_types;
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -77,6 +77,7 @@ struct mtd_part_parser {
struct list_head list;
struct module *owner;
const char *name;
+ const struct of_device_id *of_match_table;
int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
struct mtd_part_parser_data *);
void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);

View File

@ -0,0 +1,43 @@
From 4ac9222778478a00c7fc9d347b7ed1e0e595120d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
Date: Thu, 4 Jan 2018 08:05:34 +0100
Subject: [PATCH] mtd: ofpart: add of_match_table with "fixed-partitions"
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This allows using this parser with any flash driver that takes care of
setting of_node (using mtd_set_of_node helper) correctly. Up to now
support for "fixed-partitions" DT compatibility string was working only
with flash drivers that were specifying "ofpart" (manually or by letting
mtd use the default set of parsers).
This matches existing bindings documentation.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Brian Norris <computersforpeace@gmail.com>
Tested-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/mtd/ofpart.c | 7 +++++++
1 file changed, 7 insertions(+)
--- a/drivers/mtd/ofpart.c
+++ b/drivers/mtd/ofpart.c
@@ -140,9 +140,16 @@ ofpart_none:
return ret;
}
+static const struct of_device_id parse_ofpart_match_table[] = {
+ { .compatible = "fixed-partitions" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, parse_ofpart_match_table);
+
static struct mtd_part_parser ofpart_parser = {
.parse_fn = parse_ofpart_partitions,
.name = "ofpart",
+ .of_match_table = parse_ofpart_match_table,
};
static int parse_ofoldpart_partitions(struct mtd_info *master,

View File

@ -102,9 +102,9 @@ Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
#include <linux/mtd/partitions.h>
+#include <linux/of.h>
#include <linux/err.h>
#include <linux/of.h>
#include "mtdcore.h"
@@ -863,6 +864,32 @@ void deregister_mtd_parser(struct mtd_pa
@@ -864,6 +865,32 @@ void deregister_mtd_parser(struct mtd_pa
EXPORT_SYMBOL_GPL(deregister_mtd_parser);
/*
@ -137,9 +137,9 @@ Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
* are changing this array!
*/
@@ -920,6 +947,13 @@ int parse_mtd_partitions(struct mtd_info
{
struct mtd_part_parser *parser;
@@ -963,6 +990,13 @@ int parse_mtd_partitions(struct mtd_info
struct property *prop;
const char *compat;
int ret, err = 0;
+ const char *const *types_of = NULL;
+
@ -149,9 +149,9 @@ Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
+ types = types_of;
+ }
if (!types)
types = default_mtd_part_types;
@@ -945,6 +979,7 @@ int parse_mtd_partitions(struct mtd_info
np = of_get_child_by_name(mtd_get_of_node(master), "partitions");
of_property_for_each_string(np, "compatible", prop, compat) {
@@ -1004,6 +1038,7 @@ int parse_mtd_partitions(struct mtd_info
if (ret < 0 && !err)
err = ret;
}

View File

@ -37,20 +37,21 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
depends on m
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -29,10 +29,12 @@
@@ -29,11 +29,13 @@
#include <linux/kmod.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
+#include <linux/magic.h>
#include <linux/of.h>
#include <linux/err.h>
#include <linux/of.h>
#include "mtdcore.h"
+#include "mtdsplit/mtdsplit.h"
/* Our partition linked list */
static LIST_HEAD(mtd_partitions);
@@ -52,6 +54,8 @@ struct mtd_part {
@@ -53,6 +55,8 @@ struct mtd_part {
struct list_head list;
};
@ -59,7 +60,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
/*
* Given a pointer to the MTD object in the mtd_part structure, we can retrieve
* the pointer to that structure.
@@ -686,6 +690,7 @@ int mtd_add_partition(struct mtd_info *p
@@ -687,6 +691,7 @@ int mtd_add_partition(struct mtd_info *p
mutex_unlock(&mtd_partitions_mutex);
add_mtd_device(&new->mtd);
@ -67,7 +68,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
mtd_add_partition_attrs(new);
@@ -764,6 +769,35 @@ int mtd_del_partition(struct mtd_info *m
@@ -765,6 +770,35 @@ int mtd_del_partition(struct mtd_info *m
}
EXPORT_SYMBOL_GPL(mtd_del_partition);
@ -103,7 +104,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
/*
* 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
@@ -795,6 +829,7 @@ int add_mtd_partitions(struct mtd_info *
@@ -796,6 +830,7 @@ int add_mtd_partitions(struct mtd_info *
mutex_unlock(&mtd_partitions_mutex);
add_mtd_device(&slave->mtd);
@ -113,7 +114,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
mtd_parse_part(slave, parts[i].types);
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -109,5 +109,7 @@ int mtd_add_partition(struct mtd_info *m
@@ -110,5 +110,7 @@ int mtd_add_partition(struct mtd_info *m
long long offset, long long length);
int mtd_del_partition(struct mtd_info *master, int partno);
uint64_t mtd_get_device_size(const struct mtd_info *mtd);

View File

@ -9,7 +9,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -1034,6 +1034,62 @@ void mtd_part_parser_cleanup(struct mtd_
@@ -1093,6 +1093,62 @@ void mtd_part_parser_cleanup(struct mtd_
}
}
@ -90,7 +90,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
struct mtd_part_parser {
struct list_head list;
struct module *owner;
@@ -80,6 +83,7 @@ struct mtd_part_parser {
@@ -81,6 +84,7 @@ struct mtd_part_parser {
int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
struct mtd_part_parser_data *);
void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
@ -98,7 +98,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
};
/* Container for passing around a set of parsed partitions */
@@ -112,4 +116,9 @@ uint64_t mtd_get_device_size(const struc
@@ -113,4 +117,9 @@ uint64_t mtd_get_device_size(const struc
extern void __weak arch_split_mtd_part(struct mtd_info *master,
const char *name, int offset, int size);

View File

@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -769,6 +769,36 @@ int mtd_del_partition(struct mtd_info *m
@@ -770,6 +770,36 @@ int mtd_del_partition(struct mtd_info *m
}
EXPORT_SYMBOL_GPL(mtd_del_partition);
@ -47,7 +47,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
#else
@@ -777,6 +807,7 @@ EXPORT_SYMBOL_GPL(mtd_del_partition);
@@ -778,6 +808,7 @@ EXPORT_SYMBOL_GPL(mtd_del_partition);
static void split_firmware(struct mtd_info *master, struct mtd_part *part)
{
@ -55,7 +55,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
}
void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
@@ -791,6 +822,12 @@ static void mtd_partition_split(struct m
@@ -792,6 +823,12 @@ static void mtd_partition_split(struct m
if (rootfs_found)
return;

View File

@ -11,7 +11,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -799,6 +799,17 @@ run_parsers_by_type(struct mtd_part *sla
@@ -800,6 +800,17 @@ run_parsers_by_type(struct mtd_part *sla
return nr_parts;
}
@ -29,7 +29,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
#else
@@ -1144,6 +1155,24 @@ int mtd_is_partition(const struct mtd_in
@@ -1203,6 +1214,24 @@ int mtd_is_partition(const struct mtd_in
}
EXPORT_SYMBOL_GPL(mtd_is_partition);
@ -83,7 +83,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
if (mtd->writesize_shift)
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -114,6 +114,8 @@ int mtd_is_partition(const struct mtd_in
@@ -115,6 +115,8 @@ int mtd_is_partition(const struct mtd_in
int mtd_add_partition(struct mtd_info *master, const char *name,
long long offset, long long length);
int mtd_del_partition(struct mtd_info *master, int partno);

View File

@ -10,7 +10,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -36,6 +36,8 @@
@@ -37,6 +37,8 @@
#include "mtdcore.h"
#include "mtdsplit/mtdsplit.h"
@ -19,7 +19,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
/* Our partition linked list */
static LIST_HEAD(mtd_partitions);
static DEFINE_MUTEX(mtd_partitions_mutex);
@@ -241,13 +243,61 @@ static int part_erase(struct mtd_info *m
@@ -242,13 +244,61 @@ static int part_erase(struct mtd_info *m
struct mtd_part *part = mtd_to_part(mtd);
int ret;
@ -81,7 +81,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
return ret;
}
@@ -255,6 +305,25 @@ void mtd_erase_callback(struct erase_inf
@@ -256,6 +306,25 @@ void mtd_erase_callback(struct erase_inf
{
if (instr->mtd->_erase == part_erase) {
struct mtd_part *part = mtd_to_part(instr->mtd);
@ -107,7 +107,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
instr->fail_addr -= part->offset;
@@ -598,19 +667,22 @@ static struct mtd_part *allocate_partiti
@@ -599,19 +668,22 @@ static struct mtd_part *allocate_partiti
remainder = do_div(tmp, wr_alignment);
if ((slave->mtd.flags & MTD_WRITEABLE) && remainder) {
/* Doesn't start on a boundary of major erase size */

View File

@ -20,7 +20,7 @@ Signed-off-by: Tim Harvey <tharvey@gateworks.com>
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -343,7 +343,16 @@ static int part_lock(struct mtd_info *mt
@@ -344,7 +344,16 @@ static int part_lock(struct mtd_info *mt
static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{
struct mtd_part *part = mtd_to_part(mtd);

View File

@ -112,9 +112,9 @@ Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
#include <linux/mtd/partitions.h>
+#include <linux/of.h>
#include <linux/err.h>
#include <linux/of.h>
#include "mtdcore.h"
@@ -855,6 +856,42 @@ void deregister_mtd_parser(struct mtd_pa
@@ -856,6 +857,42 @@ void deregister_mtd_parser(struct mtd_pa
EXPORT_SYMBOL_GPL(deregister_mtd_parser);
/*
@ -157,9 +157,9 @@ Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
* Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
* are changing this array!
*/
@@ -912,6 +949,13 @@ int parse_mtd_partitions(struct mtd_info
{
struct mtd_part_parser *parser;
@@ -955,6 +992,13 @@ int parse_mtd_partitions(struct mtd_info
struct property *prop;
const char *compat;
int ret, err = 0;
+ const char *const *types_of = NULL;
+
@ -169,9 +169,9 @@ Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
+ types = types_of;
+ }
if (!types)
types = default_mtd_part_types;
@@ -937,6 +981,7 @@ int parse_mtd_partitions(struct mtd_info
np = of_get_child_by_name(mtd_get_of_node(master), "partitions");
of_property_for_each_string(np, "compatible", prop, compat) {
@@ -996,6 +1040,7 @@ int parse_mtd_partitions(struct mtd_info
if (ret < 0 && !err)
err = ret;
}

View File

@ -37,20 +37,21 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
depends on m
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -29,10 +29,12 @@
@@ -29,11 +29,13 @@
#include <linux/kmod.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
+#include <linux/magic.h>
#include <linux/of.h>
#include <linux/err.h>
#include <linux/of.h>
#include "mtdcore.h"
+#include "mtdsplit/mtdsplit.h"
/* Our partition linked list */
static LIST_HEAD(mtd_partitions);
@@ -52,6 +54,8 @@ struct mtd_part {
@@ -53,6 +55,8 @@ struct mtd_part {
struct list_head list;
};
@ -59,7 +60,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
/*
* Given a pointer to the MTD object in the mtd_part structure, we can retrieve
* the pointer to that structure.
@@ -678,6 +682,7 @@ int mtd_add_partition(struct mtd_info *p
@@ -679,6 +683,7 @@ int mtd_add_partition(struct mtd_info *p
mutex_unlock(&mtd_partitions_mutex);
add_mtd_device(&new->mtd);
@ -67,7 +68,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
mtd_add_partition_attrs(new);
@@ -756,6 +761,35 @@ int mtd_del_partition(struct mtd_info *m
@@ -757,6 +762,35 @@ int mtd_del_partition(struct mtd_info *m
}
EXPORT_SYMBOL_GPL(mtd_del_partition);
@ -103,7 +104,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
/*
* 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
@@ -787,6 +821,7 @@ int add_mtd_partitions(struct mtd_info *
@@ -788,6 +822,7 @@ int add_mtd_partitions(struct mtd_info *
mutex_unlock(&mtd_partitions_mutex);
add_mtd_device(&slave->mtd);
@ -113,7 +114,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
mtd_parse_part(slave, parts[i].types);
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -109,5 +109,7 @@ int mtd_add_partition(struct mtd_info *m
@@ -110,5 +110,7 @@ int mtd_add_partition(struct mtd_info *m
long long offset, long long length);
int mtd_del_partition(struct mtd_info *master, int partno);
uint64_t mtd_get_device_size(const struct mtd_info *mtd);

View File

@ -9,7 +9,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -1036,6 +1036,62 @@ void mtd_part_parser_cleanup(struct mtd_
@@ -1095,6 +1095,62 @@ void mtd_part_parser_cleanup(struct mtd_
}
}
@ -90,7 +90,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
struct mtd_part_parser {
struct list_head list;
struct module *owner;
@@ -80,6 +83,7 @@ struct mtd_part_parser {
@@ -81,6 +84,7 @@ struct mtd_part_parser {
int (*parse_fn)(struct mtd_info *, const struct mtd_partition **,
struct mtd_part_parser_data *);
void (*cleanup)(const struct mtd_partition *pparts, int nr_parts);
@ -98,7 +98,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
};
/* Container for passing around a set of parsed partitions */
@@ -112,4 +116,9 @@ uint64_t mtd_get_device_size(const struc
@@ -113,4 +117,9 @@ uint64_t mtd_get_device_size(const struc
extern void __weak arch_split_mtd_part(struct mtd_info *master,
const char *name, int offset, int size);

View File

@ -10,7 +10,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -761,6 +761,36 @@ int mtd_del_partition(struct mtd_info *m
@@ -762,6 +762,36 @@ int mtd_del_partition(struct mtd_info *m
}
EXPORT_SYMBOL_GPL(mtd_del_partition);
@ -47,7 +47,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
#else
@@ -769,6 +799,7 @@ EXPORT_SYMBOL_GPL(mtd_del_partition);
@@ -770,6 +800,7 @@ EXPORT_SYMBOL_GPL(mtd_del_partition);
static void split_firmware(struct mtd_info *master, struct mtd_part *part)
{
@ -55,7 +55,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
}
void __weak arch_split_mtd_part(struct mtd_info *master, const char *name,
@@ -783,6 +814,12 @@ static void mtd_partition_split(struct m
@@ -784,6 +815,12 @@ static void mtd_partition_split(struct m
if (rootfs_found)
return;

View File

@ -11,7 +11,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -791,6 +791,17 @@ run_parsers_by_type(struct mtd_part *sla
@@ -792,6 +792,17 @@ run_parsers_by_type(struct mtd_part *sla
return nr_parts;
}
@ -29,7 +29,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
#else
@@ -1146,6 +1157,24 @@ int mtd_is_partition(const struct mtd_in
@@ -1205,6 +1216,24 @@ int mtd_is_partition(const struct mtd_in
}
EXPORT_SYMBOL_GPL(mtd_is_partition);
@ -83,7 +83,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
if (mtd->writesize_shift)
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -114,6 +114,8 @@ int mtd_is_partition(const struct mtd_in
@@ -115,6 +115,8 @@ int mtd_is_partition(const struct mtd_in
int mtd_add_partition(struct mtd_info *master, const char *name,
long long offset, long long length);
int mtd_del_partition(struct mtd_info *master, int partno);

View File

@ -10,7 +10,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -36,6 +36,8 @@
@@ -37,6 +37,8 @@
#include "mtdcore.h"
#include "mtdsplit/mtdsplit.h"
@ -19,7 +19,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
/* Our partition linked list */
static LIST_HEAD(mtd_partitions);
static DEFINE_MUTEX(mtd_partitions_mutex);
@@ -241,13 +243,61 @@ static int part_erase(struct mtd_info *m
@@ -242,13 +244,61 @@ static int part_erase(struct mtd_info *m
struct mtd_part *part = mtd_to_part(mtd);
int ret;
@ -81,7 +81,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
return ret;
}
@@ -255,6 +305,25 @@ void mtd_erase_callback(struct erase_inf
@@ -256,6 +306,25 @@ void mtd_erase_callback(struct erase_inf
{
if (instr->mtd->_erase == part_erase) {
struct mtd_part *part = mtd_to_part(instr->mtd);
@ -107,7 +107,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
instr->fail_addr -= part->offset;
@@ -590,19 +659,22 @@ static struct mtd_part *allocate_partiti
@@ -591,19 +660,22 @@ static struct mtd_part *allocate_partiti
remainder = do_div(tmp, wr_alignment);
if ((slave->mtd.flags & MTD_WRITEABLE) && remainder) {
/* Doesn't start on a boundary of major erase size */

View File

@ -20,7 +20,7 @@ Signed-off-by: Tim Harvey <tharvey@gateworks.com>
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -343,7 +343,16 @@ static int part_lock(struct mtd_info *mt
@@ -344,7 +344,16 @@ static int part_lock(struct mtd_info *mt
static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
{
struct mtd_part *part = mtd_to_part(mtd);