1 // SPDX-License-Identifier: GPL-2.0+
3 * Simple MTD partitioning layer
5 * Copyright © 2000 Nicolas Pitre <nico@fluxnic.net>
6 * Copyright © 2002 Thomas Gleixner <gleixner@linutronix.de>
7 * Copyright © 2000-2010 David Woodhouse <dwmw2@infradead.org>
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/list.h>
17 #include <linux/kmod.h>
22 #include <linux/errno.h>
23 #include <linux/compat.h>
24 #include <ubi_uboot.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/err.h>
29 #include <linux/sizes.h>
34 static DEFINE_MUTEX(mtd_partitions_mutex);
36 DEFINE_MUTEX(mtd_partitions_mutex);
43 * kstrdup - allocate space for and copy an existing string
44 * @s: the string to duplicate
45 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
47 char *kstrdup(const char *s, gfp_t gfp)
56 buf = kmalloc(len, gfp);
63 #define MTD_SIZE_REMAINING (~0LLU)
64 #define MTD_OFFSET_NOT_SPECIFIED (~0LLU)
67 * mtd_parse_partition - Parse @mtdparts partition definition, fill @partition
68 * with it and update the @mtdparts string pointer.
70 * The partition name is allocated and must be freed by the caller.
72 * This function is widely inspired from part_parse (mtdparts.c).
74 * @mtdparts: String describing the partition with mtdparts command syntax
75 * @partition: MTD partition structure to fill
77 * @return 0 on success, an error otherwise.
79 static int mtd_parse_partition(const char **_mtdparts,
80 struct mtd_partition *partition)
82 const char *mtdparts = *_mtdparts;
83 const char *name = NULL;
87 /* Ensure the partition structure is empty */
88 memset(partition, 0, sizeof(struct mtd_partition));
90 /* Fetch the partition size */
91 if (*mtdparts == '-') {
92 /* Assign all remaining space to this partition */
93 partition->size = MTD_SIZE_REMAINING;
96 partition->size = ustrtoull(mtdparts, (char **)&mtdparts, 0);
97 if (partition->size < SZ_4K) {
98 printf("Minimum partition size 4kiB, %lldB requested\n",
104 /* Check for the offset */
105 partition->offset = MTD_OFFSET_NOT_SPECIFIED;
106 if (*mtdparts == '@') {
108 partition->offset = ustrtoull(mtdparts, (char **)&mtdparts, 0);
111 /* Now look for the name */
112 if (*mtdparts == '(') {
114 mtdparts = strchr(name, ')');
116 printf("No closing ')' found in partition name\n");
119 name_len = mtdparts - name + 1;
120 if ((name_len - 1) == 0) {
121 printf("Empty partition name\n");
126 /* Name will be of the form size@offset */
130 /* Check if the partition is read-only */
131 if (strncmp(mtdparts, "ro", 2) == 0) {
132 partition->mask_flags |= MTD_WRITEABLE;
136 /* Check for a potential next partition definition */
137 if (*mtdparts == ',') {
138 if (partition->size == MTD_SIZE_REMAINING) {
139 printf("No partitions allowed after a fill-up\n");
143 } else if ((*mtdparts == ';') || (*mtdparts == '\0')) {
146 printf("Unexpected character '%c' in mtdparts\n", *mtdparts);
151 * Allocate a buffer for the name and either copy the provided name or
152 * auto-generate it with the form 'size@offset'.
154 buf = malloc(name_len);
159 strncpy(buf, name, name_len - 1);
161 snprintf(buf, name_len, "0x%08llx@0x%08llx",
162 partition->size, partition->offset);
164 buf[name_len - 1] = '\0';
165 partition->name = buf;
167 *_mtdparts = mtdparts;
173 * mtd_parse_partitions - Create a partition array from an mtdparts definition
175 * Stateless function that takes a @parent MTD device, a string @_mtdparts
176 * describing the partitions (with the "mtdparts" command syntax) and creates
177 * the corresponding MTD partition structure array @_parts. Both the name and
178 * the structure partition itself must be freed freed, the caller may use
179 * @mtd_free_parsed_partitions() for this purpose.
181 * @parent: MTD device which contains the partitions
182 * @_mtdparts: Pointer to a string describing the partitions with "mtdparts"
184 * @_parts: Allocated array containing the partitions, must be freed by the
186 * @_nparts: Size of @_parts array.
188 * @return 0 on success, an error otherwise.
190 int mtd_parse_partitions(struct mtd_info *parent, const char **_mtdparts,
191 struct mtd_partition **_parts, int *_nparts)
193 struct mtd_partition partition = {}, *parts;
194 const char *mtdparts = *_mtdparts;
195 int cur_off = 0, cur_sz = 0;
200 /* First, iterate over the partitions until we know their number */
201 while (mtdparts[0] != '\0' && mtdparts[0] != ';') {
202 ret = mtd_parse_partition(&mtdparts, &partition);
206 free((char *)partition.name);
210 /* Allocate an array of partitions to give back to the caller */
211 parts = malloc(sizeof(*parts) * nparts);
213 printf("Not enough space to save partitions meta-data\n");
217 /* Iterate again over each partition to save the data in our array */
218 for (idx = 0; idx < nparts; idx++) {
219 ret = mtd_parse_partition(_mtdparts, &parts[idx]);
223 if (parts[idx].size == MTD_SIZE_REMAINING)
224 parts[idx].size = parent->size - cur_sz;
225 cur_sz += parts[idx].size;
227 sz = parts[idx].size;
228 if (sz < parent->writesize || do_div(sz, parent->writesize)) {
229 printf("Partition size must be a multiple of %d\n",
234 if (parts[idx].offset == MTD_OFFSET_NOT_SPECIFIED)
235 parts[idx].offset = cur_off;
236 cur_off += parts[idx].size;
238 parts[idx].ecclayout = parent->ecclayout;
241 /* Offset by one mtdparts to point to the next device if any */
242 if (*_mtdparts[0] == ';')
252 * mtd_free_parsed_partitions - Free dynamically allocated partitions
254 * Each successful call to @mtd_parse_partitions must be followed by a call to
255 * @mtd_free_parsed_partitions to free any allocated array during the parsing
258 * @parts: Array containing the partitions that will be freed.
259 * @nparts: Size of @parts array.
261 void mtd_free_parsed_partitions(struct mtd_partition *parts,
266 for (i = 0; i < nparts; i++)
267 free((char *)parts[i].name);
273 * MTD methods which simply translate the effective address and pass through
274 * to the _real_ device.
277 static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
278 size_t *retlen, u_char *buf)
280 struct mtd_ecc_stats stats;
283 stats = mtd->parent->ecc_stats;
284 res = mtd->parent->_read(mtd->parent, from + mtd->offset, len,
286 if (unlikely(mtd_is_eccerr(res)))
287 mtd->ecc_stats.failed +=
288 mtd->parent->ecc_stats.failed - stats.failed;
290 mtd->ecc_stats.corrected +=
291 mtd->parent->ecc_stats.corrected - stats.corrected;
296 static int part_point(struct mtd_info *mtd, loff_t from, size_t len,
297 size_t *retlen, void **virt, resource_size_t *phys)
299 return mtd->parent->_point(mtd->parent, from + mtd->offset, len,
303 static int part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
305 return mtd->parent->_unpoint(mtd->parent, from + mtd->offset, len);
309 static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
311 unsigned long offset,
314 offset += mtd->offset;
315 return mtd->parent->_get_unmapped_area(mtd->parent, len, offset, flags);
318 static int part_read_oob(struct mtd_info *mtd, loff_t from,
319 struct mtd_oob_ops *ops)
323 if (from >= mtd->size)
325 if (ops->datbuf && from + ops->len > mtd->size)
329 * If OOB is also requested, make sure that we do not read past the end
335 if (ops->mode == MTD_OPS_AUTO_OOB)
339 pages = mtd_div_by_ws(mtd->size, mtd);
340 pages -= mtd_div_by_ws(from, mtd);
341 if (ops->ooboffs + ops->ooblen > pages * len)
345 res = mtd->parent->_read_oob(mtd->parent, from + mtd->offset, ops);
347 if (mtd_is_bitflip(res))
348 mtd->ecc_stats.corrected++;
349 if (mtd_is_eccerr(res))
350 mtd->ecc_stats.failed++;
355 static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from,
356 size_t len, size_t *retlen, u_char *buf)
358 return mtd->parent->_read_user_prot_reg(mtd->parent, from, len,
362 static int part_get_user_prot_info(struct mtd_info *mtd, size_t len,
363 size_t *retlen, struct otp_info *buf)
365 return mtd->parent->_get_user_prot_info(mtd->parent, len, retlen,
369 static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,
370 size_t len, size_t *retlen, u_char *buf)
372 return mtd->parent->_read_fact_prot_reg(mtd->parent, from, len,
376 static int part_get_fact_prot_info(struct mtd_info *mtd, size_t len,
377 size_t *retlen, struct otp_info *buf)
379 return mtd->parent->_get_fact_prot_info(mtd->parent, len, retlen,
383 static int part_write(struct mtd_info *mtd, loff_t to, size_t len,
384 size_t *retlen, const u_char *buf)
386 return mtd->parent->_write(mtd->parent, to + mtd->offset, len,
390 static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
391 size_t *retlen, const u_char *buf)
393 return mtd->parent->_panic_write(mtd->parent, to + mtd->offset, len,
397 static int part_write_oob(struct mtd_info *mtd, loff_t to,
398 struct mtd_oob_ops *ops)
402 if (ops->datbuf && to + ops->len > mtd->size)
404 return mtd->parent->_write_oob(mtd->parent, to + mtd->offset, ops);
407 static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from,
408 size_t len, size_t *retlen, u_char *buf)
410 return mtd->parent->_write_user_prot_reg(mtd->parent, from, len,
414 static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from,
417 return mtd->parent->_lock_user_prot_reg(mtd->parent, from, len);
421 static int part_writev(struct mtd_info *mtd, const struct kvec *vecs,
422 unsigned long count, loff_t to, size_t *retlen)
424 return mtd->parent->_writev(mtd->parent, vecs, count,
425 to + mtd->offset, retlen);
429 static int part_erase(struct mtd_info *mtd, struct erase_info *instr)
433 instr->addr += mtd->offset;
434 ret = mtd->parent->_erase(mtd->parent, instr);
436 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
437 instr->fail_addr -= mtd->offset;
438 instr->addr -= mtd->offset;
443 void mtd_erase_callback(struct erase_info *instr)
445 if (instr->mtd->_erase == part_erase) {
446 if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN)
447 instr->fail_addr -= instr->mtd->offset;
448 instr->addr -= instr->mtd->offset;
451 instr->callback(instr);
453 EXPORT_SYMBOL_GPL(mtd_erase_callback);
455 static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
457 return mtd->parent->_lock(mtd->parent, ofs + mtd->offset, len);
460 static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
462 return mtd->parent->_unlock(mtd->parent, ofs + mtd->offset, len);
465 static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)
467 return mtd->parent->_is_locked(mtd->parent, ofs + mtd->offset, len);
470 static void part_sync(struct mtd_info *mtd)
472 mtd->parent->_sync(mtd->parent);
476 static int part_suspend(struct mtd_info *mtd)
478 return mtd->parent->_suspend(mtd->parent);
481 static void part_resume(struct mtd_info *mtd)
483 mtd->parent->_resume(mtd->parent);
487 static int part_block_isreserved(struct mtd_info *mtd, loff_t ofs)
490 return mtd->parent->_block_isreserved(mtd->parent, ofs);
493 static int part_block_isbad(struct mtd_info *mtd, loff_t ofs)
496 return mtd->parent->_block_isbad(mtd->parent, ofs);
499 static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
504 res = mtd->parent->_block_markbad(mtd->parent, ofs);
506 mtd->ecc_stats.badblocks++;
510 static inline void free_partition(struct mtd_info *p)
517 * This function unregisters and destroy all slave MTD objects which are
518 * attached to the given master MTD object, recursively.
520 static int do_del_mtd_partitions(struct mtd_info *master)
522 struct mtd_info *slave, *next;
525 list_for_each_entry_safe(slave, next, &master->partitions, node) {
526 if (mtd_has_partitions(slave))
527 del_mtd_partitions(slave);
529 debug("Deleting %s MTD partition\n", slave->name);
530 ret = del_mtd_device(slave);
532 printf("Error when deleting partition \"%s\" (%d)\n",
538 list_del(&slave->node);
539 free_partition(slave);
545 int del_mtd_partitions(struct mtd_info *master)
549 debug("Deleting MTD partitions on \"%s\":\n", master->name);
551 mutex_lock(&mtd_partitions_mutex);
552 ret = do_del_mtd_partitions(master);
553 mutex_unlock(&mtd_partitions_mutex);
558 static struct mtd_info *allocate_partition(struct mtd_info *master,
559 const struct mtd_partition *part,
560 int partno, uint64_t cur_offset)
562 struct mtd_info *slave;
565 /* allocate the partition structure */
566 slave = kzalloc(sizeof(*slave), GFP_KERNEL);
567 name = kstrdup(part->name, GFP_KERNEL);
568 if (!name || !slave) {
569 printk(KERN_ERR"memory allocation error while creating partitions for \"%s\"\n",
573 return ERR_PTR(-ENOMEM);
576 /* set up the MTD object for this partition */
577 slave->type = master->type;
578 slave->flags = master->flags & ~part->mask_flags;
579 slave->size = part->size;
580 slave->writesize = master->writesize;
581 slave->writebufsize = master->writebufsize;
582 slave->oobsize = master->oobsize;
583 slave->oobavail = master->oobavail;
584 slave->subpage_sft = master->subpage_sft;
587 slave->owner = master->owner;
589 slave->backing_dev_info = master->backing_dev_info;
591 /* NOTE: we don't arrange MTDs as a tree; it'd be error-prone
592 * to have the same data be in two different partitions.
594 slave->dev.parent = master->dev.parent;
598 slave->_read = part_read;
600 slave->_write = part_write;
602 if (master->_panic_write)
603 slave->_panic_write = part_panic_write;
606 if (master->_point && master->_unpoint) {
607 slave->_point = part_point;
608 slave->_unpoint = part_unpoint;
612 if (master->_get_unmapped_area)
613 slave->_get_unmapped_area = part_get_unmapped_area;
614 if (master->_read_oob)
615 slave->_read_oob = part_read_oob;
616 if (master->_write_oob)
617 slave->_write_oob = part_write_oob;
618 if (master->_read_user_prot_reg)
619 slave->_read_user_prot_reg = part_read_user_prot_reg;
620 if (master->_read_fact_prot_reg)
621 slave->_read_fact_prot_reg = part_read_fact_prot_reg;
622 if (master->_write_user_prot_reg)
623 slave->_write_user_prot_reg = part_write_user_prot_reg;
624 if (master->_lock_user_prot_reg)
625 slave->_lock_user_prot_reg = part_lock_user_prot_reg;
626 if (master->_get_user_prot_info)
627 slave->_get_user_prot_info = part_get_user_prot_info;
628 if (master->_get_fact_prot_info)
629 slave->_get_fact_prot_info = part_get_fact_prot_info;
631 slave->_sync = part_sync;
633 if (!partno && !master->dev.class && master->_suspend &&
635 slave->_suspend = part_suspend;
636 slave->_resume = part_resume;
639 slave->_writev = part_writev;
642 slave->_lock = part_lock;
644 slave->_unlock = part_unlock;
645 if (master->_is_locked)
646 slave->_is_locked = part_is_locked;
647 if (master->_block_isreserved)
648 slave->_block_isreserved = part_block_isreserved;
649 if (master->_block_isbad)
650 slave->_block_isbad = part_block_isbad;
651 if (master->_block_markbad)
652 slave->_block_markbad = part_block_markbad;
653 slave->_erase = part_erase;
654 slave->parent = master;
655 slave->offset = part->offset;
656 INIT_LIST_HEAD(&slave->partitions);
657 INIT_LIST_HEAD(&slave->node);
659 if (slave->offset == MTDPART_OFS_APPEND)
660 slave->offset = cur_offset;
661 if (slave->offset == MTDPART_OFS_NXTBLK) {
662 slave->offset = cur_offset;
663 if (mtd_mod_by_eb(cur_offset, master) != 0) {
664 /* Round up to next erasesize */
665 slave->offset = (mtd_div_by_eb(cur_offset, master) + 1) * master->erasesize;
666 debug("Moving partition %d: "
667 "0x%012llx -> 0x%012llx\n", partno,
668 (unsigned long long)cur_offset, (unsigned long long)slave->offset);
671 if (slave->offset == MTDPART_OFS_RETAIN) {
672 slave->offset = cur_offset;
673 if (master->size - slave->offset >= slave->size) {
674 slave->size = master->size - slave->offset
677 debug("mtd partition \"%s\" doesn't have enough space: %#llx < %#llx, disabled\n",
678 part->name, master->size - slave->offset,
680 /* register to preserve ordering */
684 if (slave->size == MTDPART_SIZ_FULL)
685 slave->size = master->size - slave->offset;
687 debug("0x%012llx-0x%012llx : \"%s\"\n", (unsigned long long)slave->offset,
688 (unsigned long long)(slave->offset + slave->size), slave->name);
690 /* let's do some sanity checks */
691 if (slave->offset >= master->size) {
692 /* let's register it anyway to preserve ordering */
695 printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
699 if (slave->offset + slave->size > master->size) {
700 slave->size = master->size - slave->offset;
701 printk(KERN_WARNING"mtd: partition \"%s\" extends beyond the end of device \"%s\" -- size truncated to %#llx\n",
702 part->name, master->name, slave->size);
704 if (master->numeraseregions > 1) {
705 /* Deal with variable erase size stuff */
706 int i, max = master->numeraseregions;
707 u64 end = slave->offset + slave->size;
708 struct mtd_erase_region_info *regions = master->eraseregions;
710 /* Find the first erase regions which is part of this
712 for (i = 0; i < max && regions[i].offset <= slave->offset; i++)
714 /* The loop searched for the region _behind_ the first one */
718 /* Pick biggest erasesize */
719 for (; i < max && regions[i].offset < end; i++) {
720 if (slave->erasesize < regions[i].erasesize)
721 slave->erasesize = regions[i].erasesize;
723 WARN_ON(slave->erasesize == 0);
725 /* Single erase size */
726 slave->erasesize = master->erasesize;
729 if ((slave->flags & MTD_WRITEABLE) &&
730 mtd_mod_by_eb(slave->offset, slave)) {
731 /* Doesn't start on a boundary of major erase size */
732 /* FIXME: Let it be writable if it is on a boundary of
733 * _minor_ erase size though */
734 slave->flags &= ~MTD_WRITEABLE;
735 printk(KERN_WARNING"mtd: partition \"%s\" doesn't start on an erase block boundary -- force read-only\n",
738 if ((slave->flags & MTD_WRITEABLE) &&
739 mtd_mod_by_eb(slave->size, slave)) {
740 slave->flags &= ~MTD_WRITEABLE;
741 printk(KERN_WARNING"mtd: partition \"%s\" doesn't end on an erase block -- force read-only\n",
745 slave->ecclayout = master->ecclayout;
746 slave->ecc_step_size = master->ecc_step_size;
747 slave->ecc_strength = master->ecc_strength;
748 slave->bitflip_threshold = master->bitflip_threshold;
750 if (master->_block_isbad) {
753 while (offs < slave->size) {
754 if (mtd_block_isbad(master, offs + slave->offset))
755 slave->ecc_stats.badblocks++;
756 offs += slave->erasesize;
765 int mtd_add_partition(struct mtd_info *master, const char *name,
766 long long offset, long long length)
768 struct mtd_partition part;
769 struct mtd_info *p, *new;
773 /* the direct offset is expected */
774 if (offset == MTDPART_OFS_APPEND ||
775 offset == MTDPART_OFS_NXTBLK)
778 if (length == MTDPART_SIZ_FULL)
779 length = master->size - offset;
786 part.offset = offset;
788 part.ecclayout = NULL;
790 new = allocate_partition(master, &part, -1, offset);
795 end = offset + length;
797 mutex_lock(&mtd_partitions_mutex);
798 list_for_each_entry(p, &master->partitions, node) {
799 if (start >= p->offset &&
800 (start < (p->offset + p->size)))
803 if (end >= p->offset &&
804 (end < (p->offset + p->size)))
808 list_add_tail(&new->node, &master->partitions);
809 mutex_unlock(&mtd_partitions_mutex);
815 mutex_unlock(&mtd_partitions_mutex);
819 EXPORT_SYMBOL_GPL(mtd_add_partition);
821 int mtd_del_partition(struct mtd_info *master, int partno)
823 struct mtd_info *slave, *next;
826 mutex_lock(&mtd_partitions_mutex);
827 list_for_each_entry_safe(slave, next, &master->partitions, node)
828 if (slave->index == partno) {
829 ret = del_mtd_device(slave);
833 list_del(&slave->node);
834 free_partition(slave);
837 mutex_unlock(&mtd_partitions_mutex);
841 EXPORT_SYMBOL_GPL(mtd_del_partition);
845 * This function, given a master MTD object and a partition table, creates
846 * and registers slave MTD objects which are bound to the master according to
847 * the partition definitions.
849 * We don't register the master, or expect the caller to have done so,
850 * for reasons of data integrity.
853 int add_mtd_partitions(struct mtd_info *master,
854 const struct mtd_partition *parts,
857 struct mtd_info *slave;
858 uint64_t cur_offset = 0;
861 debug("Creating %d MTD partitions on \"%s\":\n", nbparts, master->name);
863 for (i = 0; i < nbparts; i++) {
864 slave = allocate_partition(master, parts + i, i, cur_offset);
866 return PTR_ERR(slave);
868 mutex_lock(&mtd_partitions_mutex);
869 list_add_tail(&slave->node, &master->partitions);
870 mutex_unlock(&mtd_partitions_mutex);
872 add_mtd_device(slave);
874 cur_offset = slave->offset + slave->size;
881 static DEFINE_SPINLOCK(part_parser_lock);
882 static LIST_HEAD(part_parsers);
884 static struct mtd_part_parser *get_partition_parser(const char *name)
886 struct mtd_part_parser *p, *ret = NULL;
888 spin_lock(&part_parser_lock);
890 list_for_each_entry(p, &part_parsers, list)
891 if (!strcmp(p->name, name) && try_module_get(p->owner)) {
896 spin_unlock(&part_parser_lock);
901 #define put_partition_parser(p) do { module_put((p)->owner); } while (0)
903 void register_mtd_parser(struct mtd_part_parser *p)
905 spin_lock(&part_parser_lock);
906 list_add(&p->list, &part_parsers);
907 spin_unlock(&part_parser_lock);
909 EXPORT_SYMBOL_GPL(register_mtd_parser);
911 void deregister_mtd_parser(struct mtd_part_parser *p)
913 spin_lock(&part_parser_lock);
915 spin_unlock(&part_parser_lock);
917 EXPORT_SYMBOL_GPL(deregister_mtd_parser);
920 * Do not forget to update 'parse_mtd_partitions()' kerneldoc comment if you
921 * are changing this array!
923 static const char * const default_mtd_part_types[] = {
930 * parse_mtd_partitions - parse MTD partitions
931 * @master: the master partition (describes whole MTD device)
932 * @types: names of partition parsers to try or %NULL
933 * @pparts: array of partitions found is returned here
934 * @data: MTD partition parser-specific data
936 * This function tries to find partition on MTD device @master. It uses MTD
937 * partition parsers, specified in @types. However, if @types is %NULL, then
938 * the default list of parsers is used. The default list contains only the
939 * "cmdlinepart" and "ofpart" parsers ATM.
940 * Note: If there are more then one parser in @types, the kernel only takes the
941 * partitions parsed out by the first parser.
943 * This function may return:
944 * o a negative error code in case of failure
945 * o zero if no partitions were found
946 * o a positive number of found partitions, in which case on exit @pparts will
947 * point to an array containing this number of &struct mtd_info objects.
949 int parse_mtd_partitions(struct mtd_info *master, const char *const *types,
950 struct mtd_partition **pparts,
951 struct mtd_part_parser_data *data)
953 struct mtd_part_parser *parser;
957 types = default_mtd_part_types;
959 for ( ; ret <= 0 && *types; types++) {
960 parser = get_partition_parser(*types);
961 if (!parser && !request_module("%s", *types))
962 parser = get_partition_parser(*types);
965 ret = (*parser->parse_fn)(master, pparts, data);
966 put_partition_parser(parser);
968 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
969 ret, parser->name, master->name);
977 /* Returns the size of the entire flash chip */
978 uint64_t mtd_get_device_size(const struct mtd_info *mtd)
980 if (mtd_is_partition(mtd))
981 return mtd->parent->size;
985 EXPORT_SYMBOL_GPL(mtd_get_device_size);