3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
9 * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
12 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
14 * Added support for reading flash partition table from environment.
15 * Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4
18 * $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $
19 * Copyright 2002 SYSGO Real-Time Solutions GmbH
21 * See file CREDITS for list of people who contributed to this
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License as
26 * published by the Free Software Foundation; either version 2 of
27 * the License, or (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
41 * Three environment variables are used by the parsing routines:
43 * 'partition' - keeps current partition identifier
45 * partition := <part-id>
46 * <part-id> := <dev-id>,part_num
49 * 'mtdids' - linux kernel mtd device id <-> u-boot device id mapping
51 * mtdids=<idmap>[,<idmap>,...]
53 * <idmap> := <dev-id>=<mtd-id>
54 * <dev-id> := 'nand'|'nor'|'onenand'<dev-num>
55 * <dev-num> := mtd device number, 0...
56 * <mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)
59 * 'mtdparts' - partition list
61 * mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]
63 * <mtd-def> := <mtd-id>:<part-def>[,<part-def>...]
64 * <mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)
65 * <part-def> := <size>[@<offset>][<name>][<ro-flag>]
66 * <size> := standard linux memsize OR '-' to denote all remaining space
67 * <offset> := partition start offset within the device
68 * <name> := '(' NAME ')'
69 * <ro-flag> := when set to 'ro' makes partition read-only (not used, passed to kernel)
72 * - each <mtd-id> used in mtdparts must albo exist in 'mtddis' mapping
73 * - if the above variables are not set defaults for a given target are used
77 * 1 NOR Flash, with 1 single writable partition:
78 * mtdids=nor0=edb7312-nor
79 * mtdparts=mtdparts=edb7312-nor:-
81 * 1 NOR Flash with 2 partitions, 1 NAND with one
82 * mtdids=nor0=edb7312-nor,nand0=edb7312-nand
83 * mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
90 #include <jffs2/load_kernel.h>
91 #include <linux/list.h>
92 #include <linux/ctype.h>
93 #include <linux/err.h>
94 #include <linux/mtd/mtd.h>
96 #if defined(CONFIG_CMD_NAND)
97 #include <linux/mtd/nand.h>
101 #if defined(CONFIG_CMD_ONENAND)
102 #include <linux/mtd/onenand.h>
103 #include <onenand_uboot.h>
106 /* special size referring to all the remaining space in a partition */
107 #define SIZE_REMAINING 0xFFFFFFFF
109 /* special offset value, it is used when not provided by user
111 * this value is used temporarily during parsing, later such offests
112 * are recalculated */
113 #define OFFSET_NOT_SPECIFIED 0xFFFFFFFF
115 /* minimum partition size */
116 #define MIN_PART_SIZE 4096
118 /* this flag needs to be set in part_info struct mask_flags
119 * field for read-only partitions */
120 #define MTD_WRITEABLE_CMD 1
122 /* default values for mtdids and mtdparts variables */
123 #if defined(MTDIDS_DEFAULT)
124 static const char *const mtdids_default = MTDIDS_DEFAULT;
126 static const char *const mtdids_default = NULL;
129 #if defined(MTDPARTS_DEFAULT)
130 static const char *const mtdparts_default = MTDPARTS_DEFAULT;
132 static const char *const mtdparts_default = NULL;
135 /* copies of last seen 'mtdids', 'mtdparts' and 'partition' env variables */
136 #define MTDIDS_MAXLEN 128
137 #define MTDPARTS_MAXLEN 512
138 #define PARTITION_MAXLEN 16
139 static char last_ids[MTDIDS_MAXLEN];
140 static char last_parts[MTDPARTS_MAXLEN];
141 static char last_partition[PARTITION_MAXLEN];
143 /* low level jffs2 cache cleaning routine */
144 extern void jffs2_free_cache(struct part_info *part);
146 /* mtdids mapping list, filled by parse_ids() */
147 struct list_head mtdids;
149 /* device/partition list, parse_cmdline() parses into here */
150 struct list_head devices;
152 /* current active device and partition number */
153 struct mtd_device *current_mtd_dev = NULL;
154 u8 current_mtd_partnum = 0;
156 static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num);
158 /* command line only routines */
159 static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len);
160 static int device_del(struct mtd_device *dev);
163 * Parses a string into a number. The number stored at ptr is
164 * potentially suffixed with K (for kilobytes, or 1024 bytes),
165 * M (for megabytes, or 1048576 bytes), or G (for gigabytes, or
166 * 1073741824). If the number is suffixed with K, M, or G, then
167 * the return value is the number multiplied by one kilobyte, one
168 * megabyte, or one gigabyte, respectively.
170 * @param ptr where parse begins
171 * @param retptr output pointer to next char after parse completes (output)
172 * @return resulting unsigned int
174 static unsigned long memsize_parse (const char *const ptr, const char **retptr)
176 unsigned long ret = simple_strtoul(ptr, (char **)retptr, 0);
197 * Format string describing supplied size. This routine does the opposite job
198 * to memsize_parse(). Size in bytes is converted to string and if possible
199 * shortened by using k (kilobytes), m (megabytes) or g (gigabytes) suffix.
201 * Note, that this routine does not check for buffer overflow, it's the caller
202 * who must assure enough space.
204 * @param buf output buffer
205 * @param size size to be converted to string
207 static void memsize_format(char *buf, u32 size)
209 #define SIZE_GB ((u32)1024*1024*1024)
210 #define SIZE_MB ((u32)1024*1024)
211 #define SIZE_KB ((u32)1024)
213 if ((size % SIZE_GB) == 0)
214 sprintf(buf, "%ug", size/SIZE_GB);
215 else if ((size % SIZE_MB) == 0)
216 sprintf(buf, "%um", size/SIZE_MB);
217 else if (size % SIZE_KB == 0)
218 sprintf(buf, "%uk", size/SIZE_KB);
220 sprintf(buf, "%u", size);
224 * This routine does global indexing of all partitions. Resulting index for
225 * current partition is saved in 'mtddevnum'. Current partition name in
228 static void index_partitions(void)
232 struct part_info *part;
233 struct list_head *dentry;
234 struct mtd_device *dev;
236 debug("--- index partitions ---\n");
238 if (current_mtd_dev) {
240 list_for_each(dentry, &devices) {
241 dev = list_entry(dentry, struct mtd_device, link);
242 if (dev == current_mtd_dev) {
243 mtddevnum += current_mtd_partnum;
244 sprintf(buf, "%d", mtddevnum);
245 setenv("mtddevnum", buf);
248 mtddevnum += dev->num_parts;
251 part = mtd_part_info(current_mtd_dev, current_mtd_partnum);
252 setenv("mtddevname", part->name);
254 debug("=> mtddevnum %d,\n=> mtddevname %s\n", mtddevnum, part->name);
256 setenv("mtddevnum", NULL);
257 setenv("mtddevname", NULL);
259 debug("=> mtddevnum NULL\n=> mtddevname NULL\n");
264 * Save current device and partition in environment variable 'partition'.
266 static void current_save(void)
270 debug("--- current_save ---\n");
272 if (current_mtd_dev) {
273 sprintf(buf, "%s%d,%d", MTD_DEV_TYPE(current_mtd_dev->id->type),
274 current_mtd_dev->id->num, current_mtd_partnum);
276 setenv("partition", buf);
277 strncpy(last_partition, buf, 16);
279 debug("=> partition %s\n", buf);
281 setenv("partition", NULL);
282 last_partition[0] = '\0';
284 debug("=> partition NULL\n");
291 * Produce a mtd_info given a type and num.
293 * @param type mtd type
294 * @param num mtd number
295 * @param mtd a pointer to an mtd_info instance (output)
296 * @return 0 if device is valid, 1 otherwise
298 static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)
302 sprintf(mtd_dev, "%s%d", MTD_DEV_TYPE(type), num);
303 *mtd = get_mtd_device_nm(mtd_dev);
305 printf("Device %s not found!\n", mtd_dev);
313 * Performs sanity check for supplied flash partition.
314 * Table of existing MTD flash devices is searched and partition device
315 * is located. Alignment with the granularity of nand erasesize is verified.
317 * @param id of the parent device
318 * @param part partition to validate
319 * @return 0 if partition is valid, 1 otherwise
321 static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)
323 struct mtd_info *mtd = NULL;
327 if (get_mtd_info(id->type, id->num, &mtd))
330 part->sector_size = mtd->erasesize;
332 if (!mtd->numeraseregions) {
334 * Only one eraseregion (NAND, OneNAND or uniform NOR),
335 * checking for alignment is easy here
337 if ((unsigned long)part->offset % mtd->erasesize) {
338 printf("%s%d: partition (%s) start offset"
339 "alignment incorrect\n",
340 MTD_DEV_TYPE(id->type), id->num, part->name);
344 if (part->size % mtd->erasesize) {
345 printf("%s%d: partition (%s) size alignment incorrect\n",
346 MTD_DEV_TYPE(id->type), id->num, part->name);
351 * Multiple eraseregions (non-uniform NOR),
352 * checking for alignment is more complex here
355 /* Check start alignment */
356 for (i = 0; i < mtd->numeraseregions; i++) {
357 start = mtd->eraseregions[i].offset;
358 for (j = 0; j < mtd->eraseregions[i].numblocks; j++) {
359 if (part->offset == start)
361 start += mtd->eraseregions[i].erasesize;
365 printf("%s%d: partition (%s) start offset alignment incorrect\n",
366 MTD_DEV_TYPE(id->type), id->num, part->name);
371 /* Check end/size alignment */
372 for (i = 0; i < mtd->numeraseregions; i++) {
373 start = mtd->eraseregions[i].offset;
374 for (j = 0; j < mtd->eraseregions[i].numblocks; j++) {
375 if ((part->offset + part->size) == start)
377 start += mtd->eraseregions[i].erasesize;
380 /* Check last sector alignment */
381 if ((part->offset + part->size) == start)
384 printf("%s%d: partition (%s) size alignment incorrect\n",
385 MTD_DEV_TYPE(id->type), id->num, part->name);
397 * Performs sanity check for supplied partition. Offset and size are verified
398 * to be within valid range. Partition type is checked and either
399 * parts_validate_nor() or parts_validate_nand() is called with the argument
402 * @param id of the parent device
403 * @param part partition to validate
404 * @return 0 if partition is valid, 1 otherwise
406 static int part_validate(struct mtdids *id, struct part_info *part)
408 if (part->size == SIZE_REMAINING)
409 part->size = id->size - part->offset;
411 if (part->offset > id->size) {
412 printf("%s: offset %08x beyond flash size %08x\n",
413 id->mtd_id, part->offset, id->size);
417 if ((part->offset + part->size) <= part->offset) {
418 printf("%s%d: partition (%s) size too big\n",
419 MTD_DEV_TYPE(id->type), id->num, part->name);
423 if (part->offset + part->size > id->size) {
424 printf("%s: partitioning exceeds flash size\n", id->mtd_id);
429 * Now we need to check if the partition starts and ends on
430 * sector (eraseblock) regions
432 return part_validate_eraseblock(id, part);
436 * Delete selected partition from the partion list of the specified device.
438 * @param dev device to delete partition from
439 * @param part partition to delete
440 * @return 0 on success, 1 otherwise
442 static int part_del(struct mtd_device *dev, struct part_info *part)
444 u8 current_save_needed = 0;
446 /* if there is only one partition, remove whole device */
447 if (dev->num_parts == 1)
448 return device_del(dev);
450 /* otherwise just delete this partition */
452 if (dev == current_mtd_dev) {
453 /* we are modyfing partitions for the current device,
455 struct part_info *curr_pi;
456 curr_pi = mtd_part_info(current_mtd_dev, current_mtd_partnum);
459 if (curr_pi == part) {
460 printf("current partition deleted, resetting current to 0\n");
461 current_mtd_partnum = 0;
462 } else if (part->offset <= curr_pi->offset) {
463 current_mtd_partnum--;
465 current_save_needed = 1;
469 list_del(&part->link);
473 if (current_save_needed > 0)
482 * Delete all partitions from parts head list, free memory.
484 * @param head list of partitions to delete
486 static void part_delall(struct list_head *head)
488 struct list_head *entry, *n;
489 struct part_info *part_tmp;
491 /* clean tmp_list and free allocated memory */
492 list_for_each_safe(entry, n, head) {
493 part_tmp = list_entry(entry, struct part_info, link);
501 * Add new partition to the supplied partition list. Make sure partitions are
502 * sorted by offset in ascending order.
504 * @param head list this partition is to be added to
505 * @param new partition to be added
507 static int part_sort_add(struct mtd_device *dev, struct part_info *part)
509 struct list_head *entry;
510 struct part_info *new_pi, *curr_pi;
512 /* link partition to parrent dev */
515 if (list_empty(&dev->parts)) {
516 debug("part_sort_add: list empty\n");
517 list_add(&part->link, &dev->parts);
523 new_pi = list_entry(&part->link, struct part_info, link);
525 /* get current partition info if we are updating current device */
527 if (dev == current_mtd_dev)
528 curr_pi = mtd_part_info(current_mtd_dev, current_mtd_partnum);
530 list_for_each(entry, &dev->parts) {
531 struct part_info *pi;
533 pi = list_entry(entry, struct part_info, link);
535 /* be compliant with kernel cmdline, allow only one partition at offset zero */
536 if ((new_pi->offset == pi->offset) && (pi->offset == 0)) {
537 printf("cannot add second partition at offset 0\n");
541 if (new_pi->offset <= pi->offset) {
542 list_add_tail(&part->link, entry);
545 if (curr_pi && (pi->offset <= curr_pi->offset)) {
546 /* we are modyfing partitions for the current
547 * device, update current */
548 current_mtd_partnum++;
557 list_add_tail(&part->link, &dev->parts);
564 * Add provided partition to the partition list of a given device.
566 * @param dev device to which partition is added
567 * @param part partition to be added
568 * @return 0 on success, 1 otherwise
570 static int part_add(struct mtd_device *dev, struct part_info *part)
572 /* verify alignment and size */
573 if (part_validate(dev->id, part) != 0)
576 /* partition is ok, add it to the list */
577 if (part_sort_add(dev, part) != 0)
584 * Parse one partition definition, allocate memory and return pointer to this
585 * location in retpart.
587 * @param partdef pointer to the partition definition string i.e. <part-def>
588 * @param ret output pointer to next char after parse completes (output)
589 * @param retpart pointer to the allocated partition (output)
590 * @return 0 on success, 1 otherwise
592 static int part_parse(const char *const partdef, const char **ret, struct part_info **retpart)
594 struct part_info *part;
596 unsigned long offset;
599 unsigned int mask_flags;
606 /* fetch the partition size */
608 /* assign all remaining space to this partition */
609 debug("'-': remaining size assigned\n");
610 size = SIZE_REMAINING;
613 size = memsize_parse(p, &p);
614 if (size < MIN_PART_SIZE) {
615 printf("partition size too small (%lx)\n", size);
620 /* check for offset */
621 offset = OFFSET_NOT_SPECIFIED;
624 offset = memsize_parse(p, &p);
627 /* now look for the name */
630 if ((p = strchr(name, ')')) == NULL) {
631 printf("no closing ) found in partition name\n");
634 name_len = p - name + 1;
635 if ((name_len - 1) == 0) {
636 printf("empty partition name\n");
641 /* 0x00000000@0x00000000 */
646 /* test for options */
648 if (strncmp(p, "ro", 2) == 0) {
649 mask_flags |= MTD_WRITEABLE_CMD;
653 /* check for next partition definition */
655 if (size == SIZE_REMAINING) {
657 printf("no partitions allowed after a fill-up partition\n");
661 } else if ((*p == ';') || (*p == '\0')) {
664 printf("unexpected character '%c' at the end of partition\n", *p);
669 /* allocate memory */
670 part = (struct part_info *)malloc(sizeof(struct part_info) + name_len);
672 printf("out of memory\n");
675 memset(part, 0, sizeof(struct part_info) + name_len);
677 part->offset = offset;
678 part->mask_flags = mask_flags;
679 part->name = (char *)(part + 1);
682 /* copy user provided name */
683 strncpy(part->name, name, name_len - 1);
686 /* auto generated name in form of size@offset */
687 sprintf(part->name, "0x%08lx@0x%08lx", size, offset);
691 part->name[name_len - 1] = '\0';
692 INIT_LIST_HEAD(&part->link);
694 debug("+ partition: name %-22s size 0x%08x offset 0x%08x mask flags %d\n",
695 part->name, part->size,
696 part->offset, part->mask_flags);
703 * Check device number to be within valid range for given device type.
705 * @param type mtd type
706 * @param num mtd number
707 * @param size a pointer to the size of the mtd device (output)
708 * @return 0 if device is valid, 1 otherwise
710 int mtd_device_validate(u8 type, u8 num, u32 *size)
712 struct mtd_info *mtd = NULL;
714 if (get_mtd_info(type, num, &mtd))
723 * Delete all mtd devices from a supplied devices list, free memory allocated for
724 * each device and delete all device partitions.
726 * @return 0 on success, 1 otherwise
728 static int device_delall(struct list_head *head)
730 struct list_head *entry, *n;
731 struct mtd_device *dev_tmp;
733 /* clean devices list */
734 list_for_each_safe(entry, n, head) {
735 dev_tmp = list_entry(entry, struct mtd_device, link);
737 part_delall(&dev_tmp->parts);
740 INIT_LIST_HEAD(&devices);
746 * If provided device exists it's partitions are deleted, device is removed
747 * from device list and device memory is freed.
749 * @param dev device to be deleted
750 * @return 0 on success, 1 otherwise
752 static int device_del(struct mtd_device *dev)
754 part_delall(&dev->parts);
755 list_del(&dev->link);
758 if (dev == current_mtd_dev) {
759 /* we just deleted current device */
760 if (list_empty(&devices)) {
761 current_mtd_dev = NULL;
763 /* reset first partition from first dev from the
764 * devices list as current */
765 current_mtd_dev = list_entry(devices.next, struct mtd_device, link);
766 current_mtd_partnum = 0;
777 * Search global device list and return pointer to the device of type and num
780 * @param type device type
781 * @param num device number
782 * @return NULL if requested device does not exist
784 struct mtd_device *device_find(u8 type, u8 num)
786 struct list_head *entry;
787 struct mtd_device *dev_tmp;
789 list_for_each(entry, &devices) {
790 dev_tmp = list_entry(entry, struct mtd_device, link);
792 if ((dev_tmp->id->type == type) && (dev_tmp->id->num == num))
800 * Add specified device to the global device list.
802 * @param dev device to be added
804 static void device_add(struct mtd_device *dev)
806 u8 current_save_needed = 0;
808 if (list_empty(&devices)) {
809 current_mtd_dev = dev;
810 current_mtd_partnum = 0;
811 current_save_needed = 1;
814 list_add_tail(&dev->link, &devices);
816 if (current_save_needed > 0)
823 * Parse device type, name and mtd-id. If syntax is ok allocate memory and
824 * return pointer to the device structure.
826 * @param mtd_dev pointer to the device definition string i.e. <mtd-dev>
827 * @param ret output pointer to next char after parse completes (output)
828 * @param retdev pointer to the allocated device (output)
829 * @return 0 on success, 1 otherwise
831 static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_device **retdev)
833 struct mtd_device *dev;
834 struct part_info *part;
837 unsigned int mtd_id_len;
838 const char *p, *pend;
840 struct list_head *entry, *n;
845 debug("===device_parse===\n");
854 mtd_id = p = mtd_dev;
855 if (!(p = strchr(mtd_id, ':'))) {
856 printf("no <mtd-id> identifier\n");
859 mtd_id_len = p - mtd_id + 1;
862 /* verify if we have a valid device specified */
863 if ((id = id_find_by_mtd_id(mtd_id, mtd_id_len - 1)) == NULL) {
864 printf("invalid mtd device '%.*s'\n", mtd_id_len - 1, mtd_id);
868 debug("dev type = %d (%s), dev num = %d, mtd-id = %s\n",
869 id->type, MTD_DEV_TYPE(id->type),
870 id->num, id->mtd_id);
871 pend = strchr(p, ';');
872 debug("parsing partitions %.*s\n", (pend ? pend - p : strlen(p)), p);
875 /* parse partitions */
879 if ((dev = device_find(id->type, id->num)) != NULL) {
880 /* if device already exists start at the end of the last partition */
881 part = list_entry(dev->parts.prev, struct part_info, link);
882 offset = part->offset + part->size;
885 while (p && (*p != '\0') && (*p != ';')) {
887 if ((part_parse(p, &p, &part) != 0) || (!part))
890 /* calculate offset when not specified */
891 if (part->offset == OFFSET_NOT_SPECIFIED)
892 part->offset = offset;
894 offset = part->offset;
896 /* verify alignment and size */
897 if (part_validate(id, part) != 0)
900 offset += part->size;
902 /* partition is ok, add it to the list */
903 list_add_tail(&part->link, &tmp_list);
908 part_delall(&tmp_list);
912 if (num_parts == 0) {
913 printf("no partitions for device %s%d (%s)\n",
914 MTD_DEV_TYPE(id->type), id->num, id->mtd_id);
918 debug("\ntotal partitions: %d\n", num_parts);
920 /* check for next device presence */
925 } else if (*p == '\0') {
929 printf("unexpected character '%c' at the end of device\n", *p);
936 /* allocate memory for mtd_device structure */
937 if ((dev = (struct mtd_device *)malloc(sizeof(struct mtd_device))) == NULL) {
938 printf("out of memory\n");
941 memset(dev, 0, sizeof(struct mtd_device));
943 dev->num_parts = 0; /* part_sort_add increments num_parts */
944 INIT_LIST_HEAD(&dev->parts);
945 INIT_LIST_HEAD(&dev->link);
947 /* move partitions from tmp_list to dev->parts */
948 list_for_each_safe(entry, n, &tmp_list) {
949 part = list_entry(entry, struct part_info, link);
951 if (part_sort_add(dev, part) != 0) {
964 * Initialize global device list.
966 * @return 0 on success, 1 otherwise
968 static int mtd_devices_init(void)
970 last_parts[0] = '\0';
971 current_mtd_dev = NULL;
974 return device_delall(&devices);
978 * Search global mtdids list and find id of requested type and number.
980 * @return pointer to the id if it exists, NULL otherwise
982 static struct mtdids* id_find(u8 type, u8 num)
984 struct list_head *entry;
987 list_for_each(entry, &mtdids) {
988 id = list_entry(entry, struct mtdids, link);
990 if ((id->type == type) && (id->num == num))
998 * Search global mtdids list and find id of a requested mtd_id.
1000 * Note: first argument is not null terminated.
1002 * @param mtd_id string containing requested mtd_id
1003 * @param mtd_id_len length of supplied mtd_id
1004 * @return pointer to the id if it exists, NULL otherwise
1006 static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len)
1008 struct list_head *entry;
1011 debug("--- id_find_by_mtd_id: '%.*s' (len = %d)\n",
1012 mtd_id_len, mtd_id, mtd_id_len);
1014 list_for_each(entry, &mtdids) {
1015 id = list_entry(entry, struct mtdids, link);
1017 debug("entry: '%s' (len = %d)\n",
1018 id->mtd_id, strlen(id->mtd_id));
1020 if (mtd_id_len != strlen(id->mtd_id))
1022 if (strncmp(id->mtd_id, mtd_id, mtd_id_len) == 0)
1030 * Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>,
1031 * return device type and number.
1033 * @param id string describing device id
1034 * @param ret_id output pointer to next char after parse completes (output)
1035 * @param dev_type parsed device type (output)
1036 * @param dev_num parsed device number (output)
1037 * @return 0 on success, 1 otherwise
1039 int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num)
1044 if (strncmp(p, "nand", 4) == 0) {
1045 *dev_type = MTD_DEV_TYPE_NAND;
1047 } else if (strncmp(p, "nor", 3) == 0) {
1048 *dev_type = MTD_DEV_TYPE_NOR;
1050 } else if (strncmp(p, "onenand", 7) == 0) {
1051 *dev_type = MTD_DEV_TYPE_ONENAND;
1054 printf("incorrect device type in %s\n", id);
1059 printf("incorrect device number in %s\n", id);
1063 *dev_num = simple_strtoul(p, (char **)&p, 0);
1070 * Process all devices and generate corresponding mtdparts string describing
1071 * all partitions on all devices.
1073 * @param buf output buffer holding generated mtdparts string (output)
1074 * @param buflen buffer size
1075 * @return 0 on success, 1 otherwise
1077 static int generate_mtdparts(char *buf, u32 buflen)
1079 struct list_head *pentry, *dentry;
1080 struct mtd_device *dev;
1081 struct part_info *part, *prev_part;
1084 u32 size, offset, len, part_cnt;
1085 u32 maxlen = buflen - 1;
1087 debug("--- generate_mtdparts ---\n");
1089 if (list_empty(&devices)) {
1094 sprintf(p, "mtdparts=");
1097 list_for_each(dentry, &devices) {
1098 dev = list_entry(dentry, struct mtd_device, link);
1101 len = strlen(dev->id->mtd_id) + 1;
1104 memcpy(p, dev->id->mtd_id, len - 1);
1109 /* format partitions */
1112 list_for_each(pentry, &dev->parts) {
1113 part = list_entry(pentry, struct part_info, link);
1115 offset = part->offset;
1118 /* partition size */
1119 memsize_format(tmpbuf, size);
1120 len = strlen(tmpbuf);
1123 memcpy(p, tmpbuf, len);
1128 /* add offset only when there is a gap between
1130 if ((!prev_part && (offset != 0)) ||
1131 (prev_part && ((prev_part->offset + prev_part->size) != part->offset))) {
1133 memsize_format(tmpbuf, offset);
1134 len = strlen(tmpbuf) + 1;
1138 memcpy(p, tmpbuf, len - 1);
1143 /* copy name only if user supplied */
1144 if(!part->auto_name) {
1145 len = strlen(part->name) + 2;
1150 memcpy(p, part->name, len - 2);
1157 if (part->mask_flags && MTD_WRITEABLE_CMD) {
1166 /* print ',' separator if there are other partitions
1168 if (dev->num_parts > part_cnt) {
1176 /* print ';' separator if there are other devices following */
1177 if (dentry->next != &devices) {
1185 /* we still have at least one char left, as we decremented maxlen at
1192 last_parts[0] = '\0';
1197 * Call generate_mtdparts to process all devices and generate corresponding
1198 * mtdparts string, save it in mtdparts environment variable.
1200 * @param buf output buffer holding generated mtdparts string (output)
1201 * @param buflen buffer size
1202 * @return 0 on success, 1 otherwise
1204 static int generate_mtdparts_save(char *buf, u32 buflen)
1208 ret = generate_mtdparts(buf, buflen);
1210 if ((buf[0] != '\0') && (ret == 0))
1211 setenv("mtdparts", buf);
1213 setenv("mtdparts", NULL);
1218 #if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
1220 * Get the net size (w/o bad blocks) of the given partition.
1222 * @param mtd the mtd info
1223 * @param part the partition
1224 * @return the calculated net size of this partition
1226 static uint64_t net_part_size(struct mtd_info *mtd, struct part_info *part)
1228 if (!mtd->block_isbad)
1231 uint64_t i, net_size = 0;
1233 for (i = 0; i < part->size; i += mtd->erasesize) {
1234 if (!mtd->block_isbad(mtd, part->offset + i))
1235 net_size += mtd->erasesize;
1241 static void print_partition_table(void)
1243 struct list_head *dentry, *pentry;
1244 struct part_info *part;
1245 struct mtd_device *dev;
1248 list_for_each(dentry, &devices) {
1249 dev = list_entry(dentry, struct mtd_device, link);
1250 /* list partitions for given device */
1252 #if defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES)
1253 struct mtd_info *mtd;
1255 if (get_mtd_info(dev->id->type, dev->id->num, &mtd))
1258 printf("\ndevice %s%d <%s>, # parts = %d\n",
1259 MTD_DEV_TYPE(dev->id->type), dev->id->num,
1260 dev->id->mtd_id, dev->num_parts);
1261 printf(" #: name\t\tsize\t\tnet size\toffset\t\tmask_flags\n");
1263 list_for_each(pentry, &dev->parts) {
1267 part = list_entry(pentry, struct part_info, link);
1268 net_size = net_part_size(mtd, part);
1269 size_note = part->size == net_size ? " " : " (!)";
1270 printf("%2d: %-20s0x%08x\t0x%08x%s\t0x%08x\t%d\n",
1271 part_num, part->name, part->size,
1272 net_size, size_note, part->offset,
1274 #else /* !defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
1275 printf("\ndevice %s%d <%s>, # parts = %d\n",
1276 MTD_DEV_TYPE(dev->id->type), dev->id->num,
1277 dev->id->mtd_id, dev->num_parts);
1278 printf(" #: name\t\tsize\t\toffset\t\tmask_flags\n");
1280 list_for_each(pentry, &dev->parts) {
1281 part = list_entry(pentry, struct part_info, link);
1282 printf("%2d: %-20s0x%08x\t0x%08x\t%d\n",
1283 part_num, part->name, part->size,
1284 part->offset, part->mask_flags);
1285 #endif /* defined(CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES) */
1290 if (list_empty(&devices))
1291 printf("no partitions defined\n");
1295 * Format and print out a partition list for each device from global device
1298 static void list_partitions(void)
1300 struct part_info *part;
1302 debug("\n---list_partitions---\n");
1303 print_partition_table();
1305 /* current_mtd_dev is not NULL only when we have non empty device list */
1306 if (current_mtd_dev) {
1307 part = mtd_part_info(current_mtd_dev, current_mtd_partnum);
1309 printf("\nactive partition: %s%d,%d - (%s) 0x%08x @ 0x%08x\n",
1310 MTD_DEV_TYPE(current_mtd_dev->id->type),
1311 current_mtd_dev->id->num, current_mtd_partnum,
1312 part->name, part->size, part->offset);
1314 printf("could not get current partition info\n\n");
1318 printf("\ndefaults:\n");
1319 printf("mtdids : %s\n",
1320 mtdids_default ? mtdids_default : "none");
1322 * Using printf() here results in printbuffer overflow
1323 * if default mtdparts string is greater than console
1324 * printbuffer. Use puts() to prevent system crashes.
1327 puts(mtdparts_default ? mtdparts_default : "none");
1332 * Given partition identifier in form of <dev_type><dev_num>,<part_num> find
1333 * corresponding device and verify partition number.
1335 * @param id string describing device and partition or partition name
1336 * @param dev pointer to the requested device (output)
1337 * @param part_num verified partition number (output)
1338 * @param part pointer to requested partition (output)
1339 * @return 0 on success, 1 otherwise
1341 int find_dev_and_part(const char *id, struct mtd_device **dev,
1342 u8 *part_num, struct part_info **part)
1344 struct list_head *dentry, *pentry;
1345 u8 type, dnum, pnum;
1348 debug("--- find_dev_and_part ---\nid = %s\n", id);
1350 list_for_each(dentry, &devices) {
1352 *dev = list_entry(dentry, struct mtd_device, link);
1353 list_for_each(pentry, &(*dev)->parts) {
1354 *part = list_entry(pentry, struct part_info, link);
1355 if (strcmp((*part)->name, id) == 0)
1366 if (mtd_id_parse(p, &p, &type, &dnum) != 0)
1369 if ((*p++ != ',') || (*p == '\0')) {
1370 printf("no partition number specified\n");
1373 pnum = simple_strtoul(p, (char **)&p, 0);
1375 printf("unexpected trailing character '%c'\n", *p);
1379 if ((*dev = device_find(type, dnum)) == NULL) {
1380 printf("no such device %s%d\n", MTD_DEV_TYPE(type), dnum);
1384 if ((*part = mtd_part_info(*dev, pnum)) == NULL) {
1385 printf("no such partition\n");
1396 * Find and delete partition. For partition id format see find_dev_and_part().
1398 * @param id string describing device and partition
1399 * @return 0 on success, 1 otherwise
1401 static int delete_partition(const char *id)
1404 struct mtd_device *dev;
1405 struct part_info *part;
1407 if (find_dev_and_part(id, &dev, &pnum, &part) == 0) {
1409 debug("delete_partition: device = %s%d, partition %d = (%s) 0x%08x@0x%08x\n",
1410 MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum,
1411 part->name, part->size, part->offset);
1413 if (part_del(dev, part) != 0)
1416 if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
1417 printf("generated mtdparts too long, reseting to null\n");
1423 printf("partition %s not found\n", id);
1428 * Accept character string describing mtd partitions and call device_parse()
1429 * for each entry. Add created devices to the global devices list.
1431 * @param mtdparts string specifing mtd partitions
1432 * @return 0 on success, 1 otherwise
1434 static int parse_mtdparts(const char *const mtdparts)
1436 const char *p = mtdparts;
1437 struct mtd_device *dev;
1440 debug("\n---parse_mtdparts---\nmtdparts = %s\n\n", p);
1442 /* delete all devices and partitions */
1443 if (mtd_devices_init() != 0) {
1444 printf("could not initialise device list\n");
1448 /* re-read 'mtdparts' variable, mtd_devices_init may be updating env */
1449 p = getenv("mtdparts");
1451 if (strncmp(p, "mtdparts=", 9) != 0) {
1452 printf("mtdparts variable doesn't start with 'mtdparts='\n");
1457 while (p && (*p != '\0')) {
1459 if ((device_parse(p, &p, &dev) != 0) || (!dev))
1462 debug("+ device: %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
1463 dev->id->num, dev->id->mtd_id);
1465 /* check if parsed device is already on the list */
1466 if (device_find(dev->id->type, dev->id->num) != NULL) {
1467 printf("device %s%d redefined, please correct mtdparts variable\n",
1468 MTD_DEV_TYPE(dev->id->type), dev->id->num);
1472 list_add_tail(&dev->link, &devices);
1476 device_delall(&devices);
1484 * Parse provided string describing mtdids mapping (see file header for mtdids
1485 * variable format). Allocate memory for each entry and add all found entries
1486 * to the global mtdids list.
1488 * @param ids mapping string
1489 * @return 0 on success, 1 otherwise
1491 static int parse_mtdids(const char *const ids)
1493 const char *p = ids;
1497 struct list_head *entry, *n;
1498 struct mtdids *id_tmp;
1503 debug("\n---parse_mtdids---\nmtdids = %s\n\n", ids);
1505 /* clean global mtdids list */
1506 list_for_each_safe(entry, n, &mtdids) {
1507 id_tmp = list_entry(entry, struct mtdids, link);
1508 debug("mtdids del: %d %d\n", id_tmp->type, id_tmp->num);
1513 INIT_LIST_HEAD(&mtdids);
1515 while(p && (*p != '\0')) {
1518 /* parse 'nor'|'nand'|'onenand'<dev-num> */
1519 if (mtd_id_parse(p, &p, &type, &num) != 0)
1523 printf("mtdids: incorrect <dev-num>\n");
1528 /* check if requested device exists */
1529 if (mtd_device_validate(type, num, &size) != 0)
1532 /* locate <mtd-id> */
1534 if ((p = strchr(mtd_id, ',')) != NULL) {
1535 mtd_id_len = p - mtd_id + 1;
1538 mtd_id_len = strlen(mtd_id) + 1;
1540 if (mtd_id_len == 0) {
1541 printf("mtdids: no <mtd-id> identifier\n");
1545 /* check if this id is already on the list */
1546 int double_entry = 0;
1547 list_for_each(entry, &mtdids) {
1548 id_tmp = list_entry(entry, struct mtdids, link);
1549 if ((id_tmp->type == type) && (id_tmp->num == num)) {
1555 printf("device id %s%d redefined, please correct mtdids variable\n",
1556 MTD_DEV_TYPE(type), num);
1560 /* allocate mtdids structure */
1561 if (!(id = (struct mtdids *)malloc(sizeof(struct mtdids) + mtd_id_len))) {
1562 printf("out of memory\n");
1565 memset(id, 0, sizeof(struct mtdids) + mtd_id_len);
1569 id->mtd_id = (char *)(id + 1);
1570 strncpy(id->mtd_id, mtd_id, mtd_id_len - 1);
1571 id->mtd_id[mtd_id_len - 1] = '\0';
1572 INIT_LIST_HEAD(&id->link);
1574 debug("+ id %s%d\t%16d bytes\t%s\n",
1575 MTD_DEV_TYPE(id->type), id->num,
1576 id->size, id->mtd_id);
1578 list_add_tail(&id->link, &mtdids);
1582 /* clean mtdids list and free allocated memory */
1583 list_for_each_safe(entry, n, &mtdids) {
1584 id_tmp = list_entry(entry, struct mtdids, link);
1595 * Parse and initialize global mtdids mapping and create global
1596 * device/partition list.
1598 * @return 0 on success, 1 otherwise
1600 int mtdparts_init(void)
1602 static int initialized = 0;
1603 const char *ids, *parts;
1604 const char *current_partition;
1606 char tmp_ep[PARTITION_MAXLEN];
1608 debug("\n---mtdparts_init---\n");
1610 INIT_LIST_HEAD(&mtdids);
1611 INIT_LIST_HEAD(&devices);
1612 memset(last_ids, 0, MTDIDS_MAXLEN);
1613 memset(last_parts, 0, MTDPARTS_MAXLEN);
1614 memset(last_partition, 0, PARTITION_MAXLEN);
1619 ids = getenv("mtdids");
1620 parts = getenv("mtdparts");
1621 current_partition = getenv("partition");
1623 /* save it for later parsing, cannot rely on current partition pointer
1624 * as 'partition' variable may be updated during init */
1626 if (current_partition)
1627 strncpy(tmp_ep, current_partition, PARTITION_MAXLEN);
1629 debug("last_ids : %s\n", last_ids);
1630 debug("env_ids : %s\n", ids);
1631 debug("last_parts: %s\n", last_parts);
1632 debug("env_parts : %s\n\n", parts);
1634 debug("last_partition : %s\n", last_partition);
1635 debug("env_partition : %s\n", current_partition);
1637 /* if mtdids varible is empty try to use defaults */
1639 if (mtdids_default) {
1640 debug("mtdids variable not defined, using default\n");
1641 ids = mtdids_default;
1642 setenv("mtdids", (char *)ids);
1644 printf("mtdids not defined, no default present\n");
1648 if (strlen(ids) > MTDIDS_MAXLEN - 1) {
1649 printf("mtdids too long (> %d)\n", MTDIDS_MAXLEN);
1653 /* do no try to use defaults when mtdparts variable is not defined,
1654 * just check the length */
1656 printf("mtdparts variable not set, see 'help mtdparts'\n");
1658 if (parts && (strlen(parts) > MTDPARTS_MAXLEN - 1)) {
1659 printf("mtdparts too long (> %d)\n", MTDPARTS_MAXLEN);
1663 /* check if we have already parsed those mtdids */
1664 if ((last_ids[0] != '\0') && (strcmp(last_ids, ids) == 0)) {
1669 if (parse_mtdids(ids) != 0) {
1674 /* ok it's good, save new ids */
1675 strncpy(last_ids, ids, MTDIDS_MAXLEN);
1678 /* parse partitions if either mtdparts or mtdids were updated */
1679 if (parts && ((last_parts[0] == '\0') || ((strcmp(last_parts, parts) != 0)) || ids_changed)) {
1680 if (parse_mtdparts(parts) != 0)
1683 if (list_empty(&devices)) {
1684 printf("mtdparts_init: no valid partitions\n");
1688 /* ok it's good, save new parts */
1689 strncpy(last_parts, parts, MTDPARTS_MAXLEN);
1691 /* reset first partition from first dev from the list as current */
1692 current_mtd_dev = list_entry(devices.next, struct mtd_device, link);
1693 current_mtd_partnum = 0;
1696 debug("mtdparts_init: current_mtd_dev = %s%d, current_mtd_partnum = %d\n",
1697 MTD_DEV_TYPE(current_mtd_dev->id->type),
1698 current_mtd_dev->id->num, current_mtd_partnum);
1701 /* mtdparts variable was reset to NULL, delete all devices/partitions */
1702 if (!parts && (last_parts[0] != '\0'))
1703 return mtd_devices_init();
1705 /* do not process current partition if mtdparts variable is null */
1709 /* is current partition set in environment? if so, use it */
1710 if ((tmp_ep[0] != '\0') && (strcmp(tmp_ep, last_partition) != 0)) {
1711 struct part_info *p;
1712 struct mtd_device *cdev;
1715 debug("--- getting current partition: %s\n", tmp_ep);
1717 if (find_dev_and_part(tmp_ep, &cdev, &pnum, &p) == 0) {
1718 current_mtd_dev = cdev;
1719 current_mtd_partnum = pnum;
1722 } else if (getenv("partition") == NULL) {
1723 debug("no partition variable set, setting...\n");
1731 * Return pointer to the partition of a requested number from a requested
1734 * @param dev device that is to be searched for a partition
1735 * @param part_num requested partition number
1736 * @return pointer to the part_info, NULL otherwise
1738 static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num)
1740 struct list_head *entry;
1741 struct part_info *part;
1747 debug("\n--- mtd_part_info: partition number %d for device %s%d (%s)\n",
1748 part_num, MTD_DEV_TYPE(dev->id->type),
1749 dev->id->num, dev->id->mtd_id);
1751 if (part_num >= dev->num_parts) {
1752 printf("invalid partition number %d for device %s%d (%s)\n",
1753 part_num, MTD_DEV_TYPE(dev->id->type),
1754 dev->id->num, dev->id->mtd_id);
1758 /* locate partition number, return it */
1760 list_for_each(entry, &dev->parts) {
1761 part = list_entry(entry, struct part_info, link);
1763 if (part_num == num++) {
1771 /***************************************************/
1772 /* U-boot commands */
1773 /***************************************************/
1774 /* command line only */
1776 * Routine implementing u-boot chpart command. Sets new current partition based
1777 * on the user supplied partition id. For partition id format see find_dev_and_part().
1779 * @param cmdtp command internal data
1780 * @param flag command flag
1781 * @param argc number of arguments supplied to the command
1782 * @param argv arguments list
1783 * @return 0 on success, 1 otherwise
1785 int do_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1787 /* command line only */
1788 struct mtd_device *dev;
1789 struct part_info *part;
1792 if (mtdparts_init() !=0)
1796 printf("no partition id specified\n");
1800 if (find_dev_and_part(argv[1], &dev, &pnum, &part) != 0)
1803 current_mtd_dev = dev;
1804 current_mtd_partnum = pnum;
1807 printf("partition changed to %s%d,%d\n",
1808 MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum);
1814 * Routine implementing u-boot mtdparts command. Initialize/update default global
1815 * partition list and process user partition request (list, add, del).
1817 * @param cmdtp command internal data
1818 * @param flag command flag
1819 * @param argc number of arguments supplied to the command
1820 * @param argv arguments list
1821 * @return 0 on success, 1 otherwise
1823 int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1826 if (strcmp(argv[1], "default") == 0) {
1827 setenv("mtdids", (char *)mtdids_default);
1828 setenv("mtdparts", (char *)mtdparts_default);
1829 setenv("partition", NULL);
1833 } else if (strcmp(argv[1], "delall") == 0) {
1834 /* this may be the first run, initialize lists if needed */
1837 setenv("mtdparts", NULL);
1839 /* mtd_devices_init() calls current_save() */
1840 return mtd_devices_init();
1844 /* make sure we are in sync with env variables */
1845 if (mtdparts_init() != 0)
1853 /* mtdparts add <mtd-dev> <size>[@<offset>] <name> [ro] */
1854 if (((argc == 5) || (argc == 6)) && (strcmp(argv[1], "add") == 0)) {
1855 #define PART_ADD_DESC_MAXLEN 64
1856 char tmpbuf[PART_ADD_DESC_MAXLEN];
1858 struct mtd_device *dev;
1859 struct mtd_device *dev_tmp;
1861 struct part_info *p;
1863 if (mtd_id_parse(argv[2], NULL, &type, &num) != 0)
1866 if ((id = id_find(type, num)) == NULL) {
1867 printf("no such device %s defined in mtdids variable\n", argv[2]);
1871 len = strlen(id->mtd_id) + 1; /* 'mtd_id:' */
1872 len += strlen(argv[3]); /* size@offset */
1873 len += strlen(argv[4]) + 2; /* '(' name ')' */
1874 if (argv[5] && (strlen(argv[5]) == 2))
1875 len += 2; /* 'ro' */
1877 if (len >= PART_ADD_DESC_MAXLEN) {
1878 printf("too long partition description\n");
1881 sprintf(tmpbuf, "%s:%s(%s)%s",
1882 id->mtd_id, argv[3], argv[4], argv[5] ? argv[5] : "");
1883 debug("add tmpbuf: %s\n", tmpbuf);
1885 if ((device_parse(tmpbuf, NULL, &dev) != 0) || (!dev))
1888 debug("+ %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
1889 dev->id->num, dev->id->mtd_id);
1891 if ((dev_tmp = device_find(dev->id->type, dev->id->num)) == NULL) {
1894 /* merge new partition with existing ones*/
1895 p = list_entry(dev->parts.next, struct part_info, link);
1896 if (part_add(dev_tmp, p) != 0) {
1902 if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
1903 printf("generated mtdparts too long, reseting to null\n");
1910 /* mtdparts del part-id */
1911 if ((argc == 3) && (strcmp(argv[1], "del") == 0)) {
1912 debug("del: part-id = %s\n", argv[2]);
1914 return delete_partition(argv[2]);
1917 return cmd_usage(cmdtp);
1920 /***************************************************/
1922 chpart, 2, 0, do_chpart,
1923 "change active partition",
1925 " - change active partition (e.g. part-id = nand0,1)"
1929 mtdparts, 6, 0, do_mtdparts,
1930 "define flash/nand partitions",
1932 " - list partition table\n"
1934 " - delete all partitions\n"
1935 "mtdparts del part-id\n"
1936 " - delete partition (e.g. part-id = nand0,1)\n"
1937 "mtdparts add <mtd-dev> <size>[@<offset>] [<name>] [ro]\n"
1938 " - add partition\n"
1939 "mtdparts default\n"
1940 " - reset partition table to defaults\n\n"
1942 "this command uses three environment variables:\n\n"
1943 "'partition' - keeps current partition identifier\n\n"
1944 "partition := <part-id>\n"
1945 "<part-id> := <dev-id>,part_num\n\n"
1946 "'mtdids' - linux kernel mtd device id <-> u-boot device id mapping\n\n"
1947 "mtdids=<idmap>[,<idmap>,...]\n\n"
1948 "<idmap> := <dev-id>=<mtd-id>\n"
1949 "<dev-id> := 'nand'|'nor'|'onenand'<dev-num>\n"
1950 "<dev-num> := mtd device number, 0...\n"
1951 "<mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)\n\n"
1952 "'mtdparts' - partition list\n\n"
1953 "mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]\n\n"
1954 "<mtd-def> := <mtd-id>:<part-def>[,<part-def>...]\n"
1955 "<mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)\n"
1956 "<part-def> := <size>[@<offset>][<name>][<ro-flag>]\n"
1957 "<size> := standard linux memsize OR '-' to denote all remaining space\n"
1958 "<offset> := partition start offset within the device\n"
1959 "<name> := '(' NAME ')'\n"
1960 "<ro-flag> := when set to 'ro' makes partition read-only (not used, passed to kernel)"
1962 /***************************************************/