Lines Matching +full:partition +full:-

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Read flash partition table from command line
5 * Copyright © 2002 SYSGO Real-Time Solutions GmbH
6 * Copyright © 2002-2010 David Woodhouse <dwmw2@infradead.org>
11 * <mtddef> := <mtd-id>:<partdef>[,<partdef>]
13 * <mtd-id> := unique name used in mapping driver/device (mtd->name)
14 * <size> := standard linux memsize OR "-" to denote all remaining space
31 * 1 NOR Flash, with 1 single writable partition:
32 * edb7312-nor:-
35 * edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
49 #define dbg(x) do { printk("DEBUG-CMDLINE-PART: "); printk x; } while(0)
55 /* special size referring to all the remaining space in a partition */
75 * Parse one partition definition for an MTD. Since there can be many
76 * comma separated partition definitions, this function calls itself
77 * recursively until no more partition definitions are found. Nice side
97 /* fetch the partition size */ in newpart()
98 if (*s == '-') { in newpart()
99 /* assign all remaining space to this partition */ in newpart()
105 pr_err("partition has size 0\n"); in newpart()
106 return ERR_PTR(-EINVAL); in newpart()
110 /* fetch partition name and flags */ in newpart()
111 mask_flags = 0; /* this is going to be a regular partition */ in newpart()
131 pr_err("no closing %c found in partition name\n", delim); in newpart()
132 return ERR_PTR(-EINVAL); in newpart()
134 name_len = p - name; in newpart()
150 /* if lk is found do NOT unlock the MTD partition*/ in newpart()
156 /* if slc is found use emulated SLC mode on this partition*/ in newpart()
165 pr_err("no partitions allowed after a fill-up partition\n"); in newpart()
166 return ERR_PTR(-EINVAL); in newpart()
174 /* this is the last partition: allocate space for all */ in newpart()
183 return ERR_PTR(-ENOMEM); in newpart()
188 * enter this partition (offset will be calculated later if it is in newpart()
202 dbg(("partition %d: name <%s>, offset %llx, size %llx, mask flags %x\n", in newpart()
213 /* return partition table */ in newpart()
240 * make sure that part-names with ":" will not be handled as in mtdpart_setup_real()
241 * part of the mtd-id with an ":" in mtdpart_setup_real()
250 * fetch <mtd-id>. We use strrchr to ignore all ':' that could in mtdpart_setup_real()
252 * as an <mtd-id>/<part-definition> separator. in mtdpart_setup_real()
265 pr_err("no mtd-id\n"); in mtdpart_setup_real()
266 return -EINVAL; in mtdpart_setup_real()
268 mtd_id_len = p - mtd_id; in mtdpart_setup_real()
274 * struct cmdline_mtd_partition and the mtd-id string. in mtdpart_setup_real()
279 0, /* first partition */ in mtdpart_setup_real()
282 sizeof(void*)-1 /*alignment*/); in mtdpart_setup_real()
287 * b) in the middle of the partition spec in mtdpart_setup_real()
298 this_mtd->parts = parts; in mtdpart_setup_real()
299 this_mtd->num_parts = num_parts; in mtdpart_setup_real()
300 this_mtd->mtd_id = (char*)(this_mtd + 1); in mtdpart_setup_real()
301 strscpy(this_mtd->mtd_id, mtd_id, mtd_id_len + 1); in mtdpart_setup_real()
304 this_mtd->next = partitions; in mtdpart_setup_real()
308 this_mtd->mtd_id, this_mtd->num_parts)); in mtdpart_setup_real()
311 /* EOS - we're done */ in mtdpart_setup_real()
317 pr_err("bad character after partition (%c)\n", *s); in mtdpart_setup_real()
318 return -EINVAL; in mtdpart_setup_real()
340 const char *mtd_id = master->name; in parse_cmdline_partitions()
350 * Search for the partition definition matching master->name. in parse_cmdline_partitions()
351 * If master->name is not set, stop at first partition definition. in parse_cmdline_partitions()
353 for (part = partitions; part; part = part->next) { in parse_cmdline_partitions()
354 if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id))) in parse_cmdline_partitions()
361 for (i = 0, offset = 0; i < part->num_parts; i++) { in parse_cmdline_partitions()
362 if (part->parts[i].offset == OFFSET_CONTINUOUS) in parse_cmdline_partitions()
363 part->parts[i].offset = offset; in parse_cmdline_partitions()
365 offset = part->parts[i].offset; in parse_cmdline_partitions()
367 if (part->parts[i].size == SIZE_REMAINING) in parse_cmdline_partitions()
368 part->parts[i].size = master->size - offset; in parse_cmdline_partitions()
370 if (offset + part->parts[i].size > master->size) { in parse_cmdline_partitions()
372 part->mtd_id); in parse_cmdline_partitions()
373 part->parts[i].size = master->size - offset; in parse_cmdline_partitions()
375 offset += part->parts[i].size; in parse_cmdline_partitions()
377 if (part->parts[i].size == 0) { in parse_cmdline_partitions()
378 pr_warn("%s: skipping zero sized partition\n", in parse_cmdline_partitions()
379 part->mtd_id); in parse_cmdline_partitions()
380 part->num_parts--; in parse_cmdline_partitions()
381 memmove(&part->parts[i], &part->parts[i + 1], in parse_cmdline_partitions()
382 sizeof(*part->parts) * (part->num_parts - i)); in parse_cmdline_partitions()
383 i--; in parse_cmdline_partitions()
387 *pparts = kmemdup(part->parts, sizeof(*part->parts) * part->num_parts, in parse_cmdline_partitions()
390 return -ENOMEM; in parse_cmdline_partitions()
392 return part->num_parts; in parse_cmdline_partitions()