Lines Matching +full:fixed +full:- +full:partitions

1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
17 #include <linux/mtd/partitions.h>
31 kfree(mtd->name); in free_partition()
40 int wr_alignment = (parent->flags & MTD_NO_ERASE) ? in allocate_partition()
41 master->writesize : master->erasesize; in allocate_partition()
43 parent->part.size : parent->size; in allocate_partition()
51 name = kstrdup(part->name, GFP_KERNEL); in allocate_partition()
53 printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n", in allocate_partition()
54 parent->name); in allocate_partition()
57 return ERR_PTR(-ENOMEM); in allocate_partition()
61 child->type = parent->type; in allocate_partition()
62 child->part.flags = parent->flags & ~part->mask_flags; in allocate_partition()
63 child->part.flags |= part->add_flags; in allocate_partition()
64 child->flags = child->part.flags; in allocate_partition()
65 child->part.size = part->size; in allocate_partition()
66 child->writesize = parent->writesize; in allocate_partition()
67 child->writebufsize = parent->writebufsize; in allocate_partition()
68 child->oobsize = parent->oobsize; in allocate_partition()
69 child->oobavail = parent->oobavail; in allocate_partition()
70 child->subpage_sft = parent->subpage_sft; in allocate_partition()
72 child->name = name; in allocate_partition()
73 child->owner = parent->owner; in allocate_partition()
76 * concern for showing the same data in multiple partitions. in allocate_partition()
81 * distinguish between the parent and its partitions in sysfs. in allocate_partition()
83 child->dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ? in allocate_partition()
84 &parent->dev : parent->dev.parent; in allocate_partition()
85 child->dev.of_node = part->of_node; in allocate_partition()
86 child->parent = parent; in allocate_partition()
87 child->part.offset = part->offset; in allocate_partition()
88 INIT_LIST_HEAD(&child->partitions); in allocate_partition()
90 if (child->part.offset == MTDPART_OFS_APPEND) in allocate_partition()
91 child->part.offset = cur_offset; in allocate_partition()
92 if (child->part.offset == MTDPART_OFS_NXTBLK) { in allocate_partition()
94 child->part.offset = cur_offset; in allocate_partition()
97 child->part.offset += wr_alignment - remainder; in allocate_partition()
99 "0x%012llx -> 0x%012llx\n", partno, in allocate_partition()
101 child->part.offset); in allocate_partition()
104 if (child->part.offset == MTDPART_OFS_RETAIN) { in allocate_partition()
105 child->part.offset = cur_offset; in allocate_partition()
106 if (parent_size - child->part.offset >= child->part.size) { in allocate_partition()
107 child->part.size = parent_size - child->part.offset - in allocate_partition()
108 child->part.size; in allocate_partition()
111 part->name, parent_size - child->part.offset, in allocate_partition()
112 child->part.size); in allocate_partition()
117 if (child->part.size == MTDPART_SIZ_FULL) in allocate_partition()
118 child->part.size = parent_size - child->part.offset; in allocate_partition()
120 printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", in allocate_partition()
121 child->part.offset, child->part.offset + child->part.size, in allocate_partition()
122 child->name); in allocate_partition()
125 if (child->part.offset >= parent_size) { in allocate_partition()
127 child->part.offset = 0; in allocate_partition()
128 child->part.size = 0; in allocate_partition()
130 /* Initialize ->erasesize to make add_mtd_device() happy. */ in allocate_partition()
131 child->erasesize = parent->erasesize; in allocate_partition()
132 printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n", in allocate_partition()
133 part->name); in allocate_partition()
136 if (child->part.offset + child->part.size > parent->size) { in allocate_partition()
137 child->part.size = parent_size - child->part.offset; in allocate_partition()
138 …printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncate… in allocate_partition()
139 part->name, parent->name, child->part.size); in allocate_partition()
142 if (parent->numeraseregions > 1) { in allocate_partition()
144 int i, max = parent->numeraseregions; in allocate_partition()
145 u64 end = child->part.offset + child->part.size; in allocate_partition()
146 struct mtd_erase_region_info *regions = parent->eraseregions; in allocate_partition()
150 for (i = 0; i < max && regions[i].offset <= child->part.offset; in allocate_partition()
155 i--; in allocate_partition()
159 if (child->erasesize < regions[i].erasesize) in allocate_partition()
160 child->erasesize = regions[i].erasesize; in allocate_partition()
162 BUG_ON(child->erasesize == 0); in allocate_partition()
165 child->erasesize = master->erasesize; in allocate_partition()
173 if (!(child->flags & MTD_NO_ERASE)) in allocate_partition()
174 wr_alignment = child->erasesize; in allocate_partition()
178 if ((child->flags & MTD_WRITEABLE) && remainder) { in allocate_partition()
182 child->flags &= ~MTD_WRITEABLE; in allocate_partition()
183 …WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n", in allocate_partition()
184 part->name); in allocate_partition()
187 tmp = mtd_get_master_ofs(child, 0) + child->part.size; in allocate_partition()
189 if ((child->flags & MTD_WRITEABLE) && remainder) { in allocate_partition()
190 child->flags &= ~MTD_WRITEABLE; in allocate_partition()
191 …printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n… in allocate_partition()
192 part->name); in allocate_partition()
195 child->size = child->part.size; in allocate_partition()
196 child->ecc_step_size = parent->ecc_step_size; in allocate_partition()
197 child->ecc_strength = parent->ecc_strength; in allocate_partition()
198 child->bitflip_threshold = parent->bitflip_threshold; in allocate_partition()
200 if (master->_block_isbad) { in allocate_partition()
203 while (offs < child->part.size) { in allocate_partition()
205 child->ecc_stats.bbtblocks++; in allocate_partition()
207 child->ecc_stats.badblocks++; in allocate_partition()
208 offs += child->erasesize; in allocate_partition()
221 return sysfs_emit(buf, "%lld\n", mtd->part.offset); in offset_show()
232 int ret = sysfs_create_files(&new->dev.kobj, mtd_partition_attrs); in mtd_add_partition_attrs()
244 parent->part.size : parent->size; in mtd_add_partition()
252 return -EINVAL; in mtd_add_partition()
255 length = parent_size - offset; in mtd_add_partition()
258 return -EINVAL; in mtd_add_partition()
265 child = allocate_partition(parent, &part, -1, offset); in mtd_add_partition()
269 mutex_lock(&master->master.partitions_lock); in mtd_add_partition()
270 list_add_tail(&child->part.node, &parent->partitions); in mtd_add_partition()
271 mutex_unlock(&master->master.partitions_lock); in mtd_add_partition()
282 mutex_lock(&master->master.partitions_lock); in mtd_add_partition()
283 list_del(&child->part.node); in mtd_add_partition()
284 mutex_unlock(&master->master.partitions_lock); in mtd_add_partition()
293 * __mtd_del_partition - delete MTD partition
297 * This function must be called with the partitions mutex locked.
304 list_for_each_entry_safe(child, next, &mtd->partitions, part.node) { in __mtd_del_partition()
310 sysfs_remove_files(&mtd->dev.kobj, mtd_partition_attrs); in __mtd_del_partition()
316 list_del(&mtd->part.node); in __mtd_del_partition()
332 list_for_each_entry_safe(child, next, &mtd->partitions, part.node) { in __del_mtd_partitions()
336 pr_info("Deleting %s MTD partition\n", child->name); in __del_mtd_partitions()
340 child->name, ret); in __del_mtd_partitions()
345 list_del(&child->part.node); in __del_mtd_partitions()
357 pr_info("Deleting MTD partitions on \"%s\":\n", mtd->name); in del_mtd_partitions()
359 mutex_lock(&master->master.partitions_lock); in del_mtd_partitions()
361 mutex_unlock(&master->master.partitions_lock); in del_mtd_partitions()
369 int ret = -EINVAL; in mtd_del_partition()
371 mutex_lock(&master->master.partitions_lock); in mtd_del_partition()
372 list_for_each_entry(child, &mtd->partitions, part.node) { in mtd_del_partition()
373 if (child->index == partno) { in mtd_del_partition()
378 mutex_unlock(&master->master.partitions_lock); in mtd_del_partition()
401 printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", in add_mtd_partitions()
402 nbparts, parent->name); in add_mtd_partitions()
411 mutex_lock(&master->master.partitions_lock); in add_mtd_partitions()
412 list_add_tail(&child->part.node, &parent->partitions); in add_mtd_partitions()
413 mutex_unlock(&master->master.partitions_lock); in add_mtd_partitions()
417 mutex_lock(&master->master.partitions_lock); in add_mtd_partitions()
418 list_del(&child->part.node); in add_mtd_partitions()
419 mutex_unlock(&master->master.partitions_lock); in add_mtd_partitions()
430 cur_offset = child->part.offset + child->part.size; in add_mtd_partitions()
451 if (!strcmp(p->name, name) && try_module_get(p->owner)) { in mtd_part_parser_get()
463 module_put(p->owner); in mtd_part_parser_put()
478 p->owner = owner; in __register_mtd_parser()
480 if (!p->cleanup) in __register_mtd_parser()
481 p->cleanup = &mtd_part_parser_cleanup_default; in __register_mtd_parser()
484 list_add(&p->list, &part_parsers); in __register_mtd_parser()
494 list_del(&p->list); in deregister_mtd_parser()
522 ret = (*parser->parse_fn)(master, &pparts->parts, data); in mtd_part_do_parse()
523 pr_debug("%s: parser %s: %i\n", master->name, parser->name, ret); in mtd_part_do_parse()
527 pr_notice("%d %s partitions found on MTD device %s\n", ret, in mtd_part_do_parse()
528 parser->name, master->name); in mtd_part_do_parse()
530 pparts->nr_parts = ret; in mtd_part_do_parse()
531 pparts->parser = parser; in mtd_part_do_parse()
537 * mtd_part_get_compatible_parser - find MTD parser by a compatible string
539 * @compat: compatible string describing partitions in a device tree
541 * MTD parsers can specify supported partitions by providing a table of
554 matches = p->of_match_table; in mtd_part_get_compatible_parser()
558 for (; matches->compatible[0]; matches++) { in mtd_part_get_compatible_parser()
559 if (!strcmp(matches->compatible, compat) && in mtd_part_get_compatible_parser()
560 try_module_get(p->owner)) { in mtd_part_get_compatible_parser()
583 const char *fixed = "fixed-partitions"; in mtd_part_of_parse() local
586 dev = &master->dev; in mtd_part_of_parse()
589 dev = master->dev.parent; in mtd_part_of_parse()
595 np = of_get_child_by_name(np, "partitions"); in mtd_part_of_parse()
615 * For backward compatibility we have to try the "fixed-partitions" in mtd_part_of_parse()
616 * parser. It supports old DT format with partitions specified as a in mtd_part_of_parse()
620 parser = mtd_part_parser_get(fixed); in mtd_part_of_parse()
621 if (!parser && !request_module("%s", fixed)) in mtd_part_of_parse()
622 parser = mtd_part_parser_get(fixed); in mtd_part_of_parse()
636 * parse_mtd_partitions - parse and register MTD partitions
640 * @data: MTD partition parser-specific data
642 * This function tries to find & register partitions on MTD device @master. It
647 * partitions parsed out by the first parser.
651 * o number of found partitions otherwise
673 pr_debug("%s: parsing partitions %s\n", master->name, in parse_mtd_partitions()
678 pr_debug("%s: got parser %s\n", master->name, in parse_mtd_partitions()
679 parser ? parser->name : NULL); in parse_mtd_partitions()
686 /* Found partitions! */ in parse_mtd_partitions()
710 parser = parts->parser; in mtd_part_parser_cleanup()
712 if (parser->cleanup) in mtd_part_parser_cleanup()
713 parser->cleanup(parts->parts, parts->nr_parts); in mtd_part_parser_cleanup()
724 return master->size; in mtd_get_device_size()