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)
47 /* special size referring to all the remaining space in a partition */
67 * Parse one partition definition for an MTD. Since there can be many
68 * comma separated partition definitions, this function calls itself
69 * recursively until no more partition definitions are found. Nice side
89 /* fetch the partition size */ in newpart()
90 if (*s == '-') { in newpart()
91 /* assign all remaining space to this partition */ in newpart()
97 pr_err("partition has size 0\n"); in newpart()
98 return ERR_PTR(-EINVAL); in newpart()
102 /* fetch partition name and flags */ in newpart()
103 mask_flags = 0; /* this is going to be a regular partition */ in newpart()
123 pr_err("no closing %c found in partition name\n", delim); in newpart()
124 return ERR_PTR(-EINVAL); in newpart()
126 name_len = p - name; in newpart()
142 /* if lk is found do NOT unlock the MTD partition*/ in newpart()
148 /* if slc is found use emulated SLC mode on this partition*/ in newpart()
157 pr_err("no partitions allowed after a fill-up partition\n"); in newpart()
158 return ERR_PTR(-EINVAL); in newpart()
166 /* this is the last partition: allocate space for all */ in newpart()
175 return ERR_PTR(-ENOMEM); in newpart()
180 * enter this partition (offset will be calculated later if it is in newpart()
194 pr_debug("partition %d: name <%s>, offset %llx, size %llx, mask flags %x\n", in newpart()
205 /* return partition table */ in newpart()
232 * make sure that part-names with ":" will not be handled as in mtdpart_setup_real()
233 * part of the mtd-id with an ":" in mtdpart_setup_real()
242 * fetch <mtd-id>. We use strrchr to ignore all ':' that could in mtdpart_setup_real()
244 * as an <mtd-id>/<part-definition> separator. in mtdpart_setup_real()
257 pr_err("no mtd-id\n"); in mtdpart_setup_real()
258 return -EINVAL; in mtdpart_setup_real()
260 mtd_id_len = p - mtd_id; in mtdpart_setup_real()
266 * struct cmdline_mtd_partition and the mtd-id string. in mtdpart_setup_real()
271 0, /* first partition */ in mtdpart_setup_real()
274 sizeof(void*)-1 /*alignment*/); in mtdpart_setup_real()
279 * b) in the middle of the partition spec in mtdpart_setup_real()
290 this_mtd->parts = parts; in mtdpart_setup_real()
291 this_mtd->num_parts = num_parts; in mtdpart_setup_real()
292 this_mtd->mtd_id = (char*)(this_mtd + 1); in mtdpart_setup_real()
293 strscpy(this_mtd->mtd_id, mtd_id, mtd_id_len + 1); in mtdpart_setup_real()
296 this_mtd->next = partitions; in mtdpart_setup_real()
300 this_mtd->mtd_id, this_mtd->num_parts); in mtdpart_setup_real()
303 /* EOS - we're done */ in mtdpart_setup_real()
309 pr_err("bad character after partition (%c)\n", *s); in mtdpart_setup_real()
310 return -EINVAL; in mtdpart_setup_real()
332 const char *mtd_id = master->name; in parse_cmdline_partitions()
342 * Search for the partition definition matching master->name. in parse_cmdline_partitions()
343 * If master->name is not set, stop at first partition definition. in parse_cmdline_partitions()
345 for (part = partitions; part; part = part->next) { in parse_cmdline_partitions()
346 if ((!mtd_id) || (!strcmp(part->mtd_id, mtd_id))) in parse_cmdline_partitions()
353 for (i = 0, offset = 0; i < part->num_parts; i++) { in parse_cmdline_partitions()
354 if (part->parts[i].offset == OFFSET_CONTINUOUS) in parse_cmdline_partitions()
355 part->parts[i].offset = offset; in parse_cmdline_partitions()
357 offset = part->parts[i].offset; in parse_cmdline_partitions()
359 if (part->parts[i].size == SIZE_REMAINING) in parse_cmdline_partitions()
360 part->parts[i].size = master->size - offset; in parse_cmdline_partitions()
362 if (offset + part->parts[i].size > master->size) { in parse_cmdline_partitions()
364 part->mtd_id); in parse_cmdline_partitions()
365 part->parts[i].size = master->size - offset; in parse_cmdline_partitions()
367 offset += part->parts[i].size; in parse_cmdline_partitions()
369 if (part->parts[i].size == 0) { in parse_cmdline_partitions()
370 pr_warn("%s: skipping zero sized partition\n", in parse_cmdline_partitions()
371 part->mtd_id); in parse_cmdline_partitions()
372 part->num_parts--; in parse_cmdline_partitions()
373 memmove(&part->parts[i], &part->parts[i + 1], in parse_cmdline_partitions()
374 sizeof(*part->parts) * (part->num_parts - i)); in parse_cmdline_partitions()
375 i--; in parse_cmdline_partitions()
379 *pparts = kmemdup(part->parts, sizeof(*part->parts) * part->num_parts, in parse_cmdline_partitions()
382 return -ENOMEM; in parse_cmdline_partitions()
384 return part->num_parts; in parse_cmdline_partitions()