Skip to content

Commit

Permalink
kernel: use add_mtd_partitions() helper when using OpenWrt parsers
Browse files Browse the repository at this point in the history
This helper uses hierarchical partitions layout following the way
upstream parsers work. It's closer to what we should use when mainlining
our solutions. It also doesn't require hacky casting of struct
mtd_partition to the const.

THIS WILL AFFECT KERNEL PRINTING PARTITIONS IN THE LOG

Something like:
[    3.930158] 0x0000004e0000-0x000001fb0000 : "rootfs_data"
will get replaced by:
[    3.907338] Creating 1 MTD partitions on "rootfs":
[    3.912142] 0x00000031d400-0x000001ded400 : "rootfs_data"

It's important to understand that "rootfs_data" in above example is a
*subpartition* of the "rootfs" now. To get absolute addresses (e.g. for
some debugging purposes) one has to add them to the "rootfs", e.g.
[    3.912548] 0x0000001c2c00-0x000001fb0000 : "rootfs"

(0x1c2c00 + 0x31d400 = 0x4e0000)

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  • Loading branch information
Rafał Miłecki committed Dec 3, 2018
1 parent e24983e commit 7e88753
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,36 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>

/*
* Given a pointer to the MTD object in the mtd_part structure, we can retrieve
@@ -751,6 +755,36 @@ int mtd_del_partition(struct mtd_info *m
@@ -751,6 +755,28 @@ int mtd_del_partition(struct mtd_info *m
}
EXPORT_SYMBOL_GPL(mtd_del_partition);

+static int
+run_parsers_by_type(struct mtd_part *slave, enum mtd_parser_type type)
+static int run_parsers_by_type(struct mtd_part *slave,
+ enum mtd_parser_type type)
+{
+ struct mtd_partition *parts;
+ const struct mtd_partition *parts;
+ int nr_parts;
+ int i;
+ int err;
+
+ nr_parts = parse_mtd_partitions_by_type(&slave->mtd, type, (const struct mtd_partition **)&parts,
+ nr_parts = parse_mtd_partitions_by_type(&slave->mtd, type, &parts,
+ NULL);
+ if (nr_parts <= 0)
+ return nr_parts;
+
+ if (WARN_ON(!parts))
+ return 0;
+
+ for (i = 0; i < nr_parts; i++) {
+ /* adjust partition offsets */
+ parts[i].offset += slave->offset;
+
+ mtd_add_partition(slave->parent,
+ parts[i].name,
+ parts[i].offset,
+ parts[i].size);
+ }
+ err = add_mtd_partitions(&slave->mtd, parts, nr_parts);
+
+ kfree(parts);
+
+ return nr_parts;
+ return err ? err : nr_parts;
+}
+
#ifdef CONFIG_MTD_SPLIT_FIRMWARE_NAME
#define SPLIT_FIRMWARE_NAME CONFIG_MTD_SPLIT_FIRMWARE_NAME
#else
@@ -1122,6 +1156,61 @@ void mtd_part_parser_cleanup(struct mtd_
@@ -1122,6 +1148,61 @@ void mtd_part_parser_cleanup(struct mtd_
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>

--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -793,6 +793,7 @@ run_parsers_by_type(struct mtd_part *sla
@@ -785,6 +785,7 @@ static int run_parsers_by_type(struct mt

static void split_firmware(struct mtd_info *master, struct mtd_part *part)
{
+ run_parsers_by_type(part, MTD_PARSER_TYPE_FIRMWARE);
}

static void mtd_partition_split(struct mtd_info *master, struct mtd_part *part)
@@ -802,6 +803,12 @@ static void mtd_partition_split(struct m
@@ -794,6 +795,12 @@ static void mtd_partition_split(struct m
if (rootfs_found)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Signed-off-by: Gabor Juhos <juhosg@openwrt.org>

--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -1235,6 +1235,24 @@ int mtd_is_partition(const struct mtd_in
@@ -1227,6 +1227,24 @@ int mtd_is_partition(const struct mtd_in
}
EXPORT_SYMBOL_GPL(mtd_is_partition);

Expand Down

0 comments on commit 7e88753

Please sign in to comment.