Lines Matching +full:partitions +full:- +full:table +full:- +full:offset

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()
37 WARN_ON(!list_empty(&mtd->part.node)); in release_mtd_partition()
46 int wr_alignment = (parent->flags & MTD_NO_ERASE) ? in allocate_partition()
47 master->writesize : master->erasesize; in allocate_partition()
49 parent->part.size : parent->size; in allocate_partition()
57 name = kstrdup(part->name, GFP_KERNEL); in allocate_partition()
59 printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n", in allocate_partition()
60 parent->name); in allocate_partition()
63 return ERR_PTR(-ENOMEM); in allocate_partition()
67 child->type = parent->type; in allocate_partition()
68 child->part.flags = parent->flags & ~part->mask_flags; in allocate_partition()
69 child->part.flags |= part->add_flags; in allocate_partition()
70 child->flags = child->part.flags; in allocate_partition()
71 child->part.size = part->size; in allocate_partition()
72 child->writesize = parent->writesize; in allocate_partition()
73 child->writebufsize = parent->writebufsize; in allocate_partition()
74 child->oobsize = parent->oobsize; in allocate_partition()
75 child->oobavail = parent->oobavail; in allocate_partition()
76 child->subpage_sft = parent->subpage_sft; in allocate_partition()
78 child->name = name; in allocate_partition()
79 child->owner = parent->owner; in allocate_partition()
82 * concern for showing the same data in multiple partitions. in allocate_partition()
87 * distinguish between the parent and its partitions in sysfs. in allocate_partition()
89 child->dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd_is_partition(parent) ? in allocate_partition()
90 &parent->dev : parent->dev.parent; in allocate_partition()
91 child->dev.of_node = part->of_node; in allocate_partition()
92 child->parent = parent; in allocate_partition()
93 child->part.offset = part->offset; in allocate_partition()
94 INIT_LIST_HEAD(&child->partitions); in allocate_partition()
96 if (child->part.offset == MTDPART_OFS_APPEND) in allocate_partition()
97 child->part.offset = cur_offset; in allocate_partition()
98 if (child->part.offset == MTDPART_OFS_NXTBLK) { in allocate_partition()
100 child->part.offset = cur_offset; in allocate_partition()
103 child->part.offset += wr_alignment - remainder; in allocate_partition()
105 "0x%012llx -> 0x%012llx\n", partno, in allocate_partition()
107 child->part.offset); in allocate_partition()
110 if (child->part.offset == MTDPART_OFS_RETAIN) { in allocate_partition()
111 child->part.offset = cur_offset; in allocate_partition()
112 if (parent_size - child->part.offset >= child->part.size) { in allocate_partition()
113 child->part.size = parent_size - child->part.offset - in allocate_partition()
114 child->part.size; in allocate_partition()
117 part->name, parent_size - child->part.offset, in allocate_partition()
118 child->part.size); in allocate_partition()
123 if (child->part.size == MTDPART_SIZ_FULL) in allocate_partition()
124 child->part.size = parent_size - child->part.offset; in allocate_partition()
126 printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", in allocate_partition()
127 child->part.offset, child->part.offset + child->part.size, in allocate_partition()
128 child->name); in allocate_partition()
131 if (child->part.offset >= parent_size) { in allocate_partition()
133 child->part.offset = 0; in allocate_partition()
134 child->part.size = 0; in allocate_partition()
136 /* Initialize ->erasesize to make add_mtd_device() happy. */ in allocate_partition()
137 child->erasesize = parent->erasesize; in allocate_partition()
138 printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n", in allocate_partition()
139 part->name); in allocate_partition()
142 if (child->part.offset + child->part.size > parent->size) { in allocate_partition()
143 child->part.size = parent_size - child->part.offset; in allocate_partition()
144 …printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncate… in allocate_partition()
145 part->name, parent->name, child->part.size); in allocate_partition()
148 if (parent->numeraseregions > 1) { in allocate_partition()
150 int i, max = parent->numeraseregions; in allocate_partition()
151 u64 end = child->part.offset + child->part.size; in allocate_partition()
152 struct mtd_erase_region_info *regions = parent->eraseregions; in allocate_partition()
156 for (i = 0; i < max && regions[i].offset <= child->part.offset; in allocate_partition()
161 i--; in allocate_partition()
164 for (; i < max && regions[i].offset < end; i++) { in allocate_partition()
165 if (child->erasesize < regions[i].erasesize) in allocate_partition()
166 child->erasesize = regions[i].erasesize; in allocate_partition()
168 BUG_ON(child->erasesize == 0); in allocate_partition()
171 child->erasesize = master->erasesize; in allocate_partition()
179 if (!(child->flags & MTD_NO_ERASE)) in allocate_partition()
180 wr_alignment = child->erasesize; in allocate_partition()
184 if ((child->flags & MTD_WRITEABLE) && remainder) { in allocate_partition()
188 child->flags &= ~MTD_WRITEABLE; in allocate_partition()
189 …WARNING"mtd: partition \"%s\" doesn't start on an erase/write block boundary -- force read-only\n", in allocate_partition()
190 part->name); in allocate_partition()
193 tmp = mtd_get_master_ofs(child, 0) + child->part.size; in allocate_partition()
195 if ((child->flags & MTD_WRITEABLE) && remainder) { in allocate_partition()
196 child->flags &= ~MTD_WRITEABLE; in allocate_partition()
197 …printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase/write block -- force read-only\n… in allocate_partition()
198 part->name); in allocate_partition()
201 child->size = child->part.size; in allocate_partition()
202 child->ecc_step_size = parent->ecc_step_size; in allocate_partition()
203 child->ecc_strength = parent->ecc_strength; in allocate_partition()
204 child->bitflip_threshold = parent->bitflip_threshold; in allocate_partition()
206 if (master->_block_isbad) { in allocate_partition()
209 while (offs < child->part.size) { in allocate_partition()
211 child->ecc_stats.bbtblocks++; in allocate_partition()
213 child->ecc_stats.badblocks++; in allocate_partition()
214 offs += child->erasesize; in allocate_partition()
227 return sysfs_emit(buf, "%lld\n", mtd->part.offset); in offset_show()
229 static DEVICE_ATTR_RO(offset); /* mtd partition offset */
238 int ret = sysfs_create_files(&new->dev.kobj, mtd_partition_attrs); in mtd_add_partition_attrs()
246 long long offset, long long length) in mtd_add_partition() argument
250 parent->part.size : parent->size; in mtd_add_partition()
255 /* the direct offset is expected */ in mtd_add_partition()
256 if (offset == MTDPART_OFS_APPEND || in mtd_add_partition()
257 offset == MTDPART_OFS_NXTBLK) in mtd_add_partition()
258 return -EINVAL; in mtd_add_partition()
261 length = parent_size - offset; in mtd_add_partition()
264 return -EINVAL; in mtd_add_partition()
269 part.offset = offset; in mtd_add_partition()
271 child = allocate_partition(parent, &part, -1, offset); in mtd_add_partition()
275 mutex_lock(&master->master.partitions_lock); in mtd_add_partition()
276 list_add_tail(&child->part.node, &parent->partitions); in mtd_add_partition()
277 mutex_unlock(&master->master.partitions_lock); in mtd_add_partition()
288 mutex_lock(&master->master.partitions_lock); in mtd_add_partition()
289 list_del(&child->part.node); in mtd_add_partition()
290 mutex_unlock(&master->master.partitions_lock); in mtd_add_partition()
299 * __mtd_del_partition - delete MTD partition
303 * This function must be called with the partitions mutex locked.
310 list_for_each_entry_safe(child, next, &mtd->partitions, part.node) { in __mtd_del_partition()
316 sysfs_remove_files(&mtd->dev.kobj, mtd_partition_attrs); in __mtd_del_partition()
318 list_del_init(&mtd->part.node); in __mtd_del_partition()
335 list_for_each_entry_safe(child, next, &mtd->partitions, part.node) { in __del_mtd_partitions()
339 pr_info("Deleting %s MTD partition\n", child->name); in __del_mtd_partitions()
340 list_del_init(&child->part.node); in __del_mtd_partitions()
344 child->name, ret); in __del_mtd_partitions()
358 pr_info("Deleting MTD partitions on \"%s\":\n", mtd->name); in del_mtd_partitions()
360 mutex_lock(&master->master.partitions_lock); in del_mtd_partitions()
362 mutex_unlock(&master->master.partitions_lock); in del_mtd_partitions()
370 int ret = -EINVAL; in mtd_del_partition()
372 mutex_lock(&master->master.partitions_lock); in mtd_del_partition()
373 list_for_each_entry(child, &mtd->partitions, part.node) { in mtd_del_partition()
374 if (child->index == partno) { in mtd_del_partition()
379 mutex_unlock(&master->master.partitions_lock); in mtd_del_partition()
386 * This function, given a parent MTD object and a partition table, creates
402 printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", in add_mtd_partitions()
403 nbparts, parent->name); in add_mtd_partitions()
412 mutex_lock(&master->master.partitions_lock); in add_mtd_partitions()
413 list_add_tail(&child->part.node, &parent->partitions); in add_mtd_partitions()
414 mutex_unlock(&master->master.partitions_lock); in add_mtd_partitions()
418 mutex_lock(&master->master.partitions_lock); in add_mtd_partitions()
419 list_del(&child->part.node); in add_mtd_partitions()
420 mutex_unlock(&master->master.partitions_lock); in add_mtd_partitions()
435 cur_offset = child->part.offset + child->part.size; in add_mtd_partitions()
456 if (!strcmp(p->name, name) && try_module_get(p->owner)) { in mtd_part_parser_get()
468 module_put(p->owner); in mtd_part_parser_put()
483 p->owner = owner; in __register_mtd_parser()
485 if (!p->cleanup) in __register_mtd_parser()
486 p->cleanup = &mtd_part_parser_cleanup_default; in __register_mtd_parser()
489 list_add(&p->list, &part_parsers); in __register_mtd_parser()
499 list_del(&p->list); in deregister_mtd_parser()
527 ret = (*parser->parse_fn)(master, &pparts->parts, data); in mtd_part_do_parse()
528 pr_debug("%s: parser %s: %i\n", master->name, parser->name, ret); in mtd_part_do_parse()
532 pr_notice("%d %s partitions found on MTD device %s\n", ret, in mtd_part_do_parse()
533 parser->name, master->name); in mtd_part_do_parse()
535 pparts->nr_parts = ret; in mtd_part_do_parse()
536 pparts->parser = parser; in mtd_part_do_parse()
542 * mtd_part_get_compatible_parser - find MTD parser by a compatible string
544 * @compat: compatible string describing partitions in a device tree
546 * MTD parsers can specify supported partitions by providing a table of
559 matches = p->of_match_table; in mtd_part_get_compatible_parser()
563 for (; matches->compatible[0]; matches++) { in mtd_part_get_compatible_parser()
564 if (!strcmp(matches->compatible, compat) && in mtd_part_get_compatible_parser()
565 try_module_get(p->owner)) { in mtd_part_get_compatible_parser()
589 const char *fixed = "fixed-partitions"; in mtd_part_of_parse()
592 dev = &master->dev; in mtd_part_of_parse()
595 dev = master->dev.parent; in mtd_part_of_parse()
601 np = of_get_child_by_name(np, "partitions"); in mtd_part_of_parse()
609 if (of_device_is_compatible(child, "nvmem-cells")) in mtd_part_of_parse()
630 * For backward compatibility we have to try the "fixed-partitions" in mtd_part_of_parse()
631 * parser. It supports old DT format with partitions specified as a in mtd_part_of_parse()
651 * parse_mtd_partitions - parse and register MTD partitions
655 * @data: MTD partition parser-specific data
657 * This function tries to find & register partitions on MTD device @master. It
662 * partitions parsed out by the first parser.
666 * o number of found partitions otherwise
688 pr_debug("%s: parsing partitions %s\n", master->name, in parse_mtd_partitions()
693 pr_debug("%s: got parser %s\n", master->name, in parse_mtd_partitions()
694 parser ? parser->name : NULL); in parse_mtd_partitions()
701 /* Found partitions! */ in parse_mtd_partitions()
725 parser = parts->parser; in mtd_part_parser_cleanup()
727 if (parser->cleanup) in mtd_part_parser_cleanup()
728 parser->cleanup(parts->parts, parts->nr_parts); in mtd_part_parser_cleanup()
739 return master->size; in mtd_get_device_size()