diff mbox series

mtd: allow multiple -(name) parts on cmdline.

Message ID 20181105133752.27480-1-daniel@dd-wrt.com
State Changes Requested
Headers show
Series mtd: allow multiple -(name) parts on cmdline. | expand

Commit Message

Daniel Danzberger Nov. 5, 2018, 1:37 p.m. UTC
This allows to specify multiple -(name) SIZE_REMAINING partitions on the
commandline parser.

Example:
mtdparts=physmap-flash.0:256k(uboot),128k(params),-(firmware),1966080(kernel),-(rootfs)

Having a "firmaware" partition makes it easier to flash/erase firmware on embedded decvices.
Many platforms have such a partition already defined in their platform or device tree code.

This patch makes it possible to define such partitions
on the cmdline as well.

Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
---
 drivers/mtd/cmdlinepart.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Comments

Boris Brezillon Nov. 5, 2018, 2:39 p.m. UTC | #1
+Rafal for the subpartition stuff

Hi Daniel,

On Mon,  5 Nov 2018 14:37:52 +0100
Daniel Danzberger <daniel@dd-wrt.com> wrote:

> This allows to specify multiple -(name) SIZE_REMAINING partitions on the
> commandline parser.
> 
> Example:
> mtdparts=physmap-flash.0:256k(uboot),128k(params),-(firmware),1966080(kernel),-(rootfs)

Now that Rafal introduced sub-partitioning support I'd prefer to go for
this solution. If I take your example, that would give something like:

mtdparts=physmap-flash.0:256k(uboot),128k(params),-(firmware);firmware:1966080(kernel),-(rootfs)

I'm not entirely sure, but I think all you'd have to do to support that
is add "cmdline" to the default_subpartition_type[] array [1] (or
simply use default_partition_type since default_subpartition_type and
default_partition_type would be the same after this change).

Regards,

Boris

[1]https://elixir.bootlin.com/linux/latest/source/drivers/mtd/mtdpart.c#L800
diff mbox series

Patch

diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index 3ea44cff9b75..b011e661f8a8 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -167,10 +167,6 @@  static struct mtd_partition * newpart(char *s,
 
 	/* test if more partitions are following */
 	if (*s == ',') {
-		if (size == SIZE_REMAINING) {
-			pr_err("no partitions allowed after a fill-up partition\n");
-			return ERR_PTR(-EINVAL);
-		}
 		/* more partitions follow, parse them */
 		parts = newpart(s + 1, &s, num_parts, this_part + 1,
 				&extra_mem, extra_mem_size);
@@ -335,20 +331,28 @@  static int parse_cmdline_partitions(struct mtd_info *master,
 		return 0;
 
 	for (i = 0, offset = 0; i < part->num_parts; i++) {
+		int move_offset;
+
 		if (part->parts[i].offset == OFFSET_CONTINUOUS)
 			part->parts[i].offset = offset;
 		else
 			offset = part->parts[i].offset;
 
-		if (part->parts[i].size == SIZE_REMAINING)
+		if (part->parts[i].size == SIZE_REMAINING) {
 			part->parts[i].size = master->size - offset;
+			move_offset = 0;
+		} else {
+			move_offset = 1;
+		}
 
 		if (offset + part->parts[i].size > master->size) {
 			pr_warn("%s: partitioning exceeds flash size, truncating\n",
 				part->mtd_id);
 			part->parts[i].size = master->size - offset;
 		}
-		offset += part->parts[i].size;
+
+		if (move_offset)
+			offset += part->parts[i].size;
 
 		if (part->parts[i].size == 0) {
 			pr_warn("%s: skipping zero sized partition\n",