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)
88 * JFFS2/CRAMFS support
93 #include <jffs2/jffs2.h>
94 #include <linux/list.h>
95 #include <linux/ctype.h>
96 #include <cramfs/cramfs_fs.h>
98 #if defined(CONFIG_CMD_NAND)
99 #ifdef CONFIG_NAND_LEGACY
100 #include <linux/mtd/nand_legacy.h>
101 #else /* !CONFIG_NAND_LEGACY */
102 #include <linux/mtd/nand.h>
104 #endif /* !CONFIG_NAND_LEGACY */
107 #if defined(CONFIG_CMD_ONENAND)
108 #include <linux/mtd/mtd.h>
109 #include <linux/mtd/onenand.h>
110 #include <onenand_uboot.h>
113 /* enable/disable debugging messages */
114 #define DEBUG_MTDPARTS
115 #undef DEBUG_MTDPARTS
117 #ifdef DEBUG_MTDPARTS
118 # define DEBUGF(fmt, args...) printf(fmt ,##args)
120 # define DEBUGF(fmt, args...)
123 /* special size referring to all the remaining space in a partition */
124 #define SIZE_REMAINING 0xFFFFFFFF
126 /* special offset value, it is used when not provided by user
128 * this value is used temporarily during parsing, later such offests
129 * are recalculated */
130 #define OFFSET_NOT_SPECIFIED 0xFFFFFFFF
132 /* minimum partition size */
133 #define MIN_PART_SIZE 4096
135 /* this flag needs to be set in part_info struct mask_flags
136 * field for read-only partitions */
137 #define MTD_WRITEABLE_CMD 1
139 /* default values for mtdids and mtdparts variables */
140 #if defined(MTDIDS_DEFAULT)
141 static const char *const mtdids_default = MTDIDS_DEFAULT;
143 #warning "MTDIDS_DEFAULT not defined!"
144 static const char *const mtdids_default = NULL;
147 #if defined(MTDPARTS_DEFAULT)
148 static const char *const mtdparts_default = MTDPARTS_DEFAULT;
150 #warning "MTDPARTS_DEFAULT not defined!"
151 static const char *const mtdparts_default = NULL;
154 /* copies of last seen 'mtdids', 'mtdparts' and 'partition' env variables */
155 #define MTDIDS_MAXLEN 128
156 #define MTDPARTS_MAXLEN 512
157 #define PARTITION_MAXLEN 16
158 static char last_ids[MTDIDS_MAXLEN];
159 static char last_parts[MTDPARTS_MAXLEN];
160 static char last_partition[PARTITION_MAXLEN];
162 /* low level jffs2 cache cleaning routine */
163 extern void jffs2_free_cache(struct part_info *part);
165 /* mtdids mapping list, filled by parse_ids() */
166 struct list_head mtdids;
168 /* device/partition list, parse_cmdline() parses into here */
169 struct list_head devices;
171 /* current active device and partition number */
172 static struct mtd_device *current_dev = NULL;
173 static u8 current_partnum = 0;
175 static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num);
177 /* command line only routines */
178 static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len);
179 static int device_del(struct mtd_device *dev);
182 * Parses a string into a number. The number stored at ptr is
183 * potentially suffixed with K (for kilobytes, or 1024 bytes),
184 * M (for megabytes, or 1048576 bytes), or G (for gigabytes, or
185 * 1073741824). If the number is suffixed with K, M, or G, then
186 * the return value is the number multiplied by one kilobyte, one
187 * megabyte, or one gigabyte, respectively.
189 * @param ptr where parse begins
190 * @param retptr output pointer to next char after parse completes (output)
191 * @return resulting unsigned int
193 static unsigned long memsize_parse (const char *const ptr, const char **retptr)
195 unsigned long ret = simple_strtoul(ptr, (char **)retptr, 0);
216 * Format string describing supplied size. This routine does the opposite job
217 * to memsize_parse(). Size in bytes is converted to string and if possible
218 * shortened by using k (kilobytes), m (megabytes) or g (gigabytes) suffix.
220 * Note, that this routine does not check for buffer overflow, it's the caller
221 * who must assure enough space.
223 * @param buf output buffer
224 * @param size size to be converted to string
226 static void memsize_format(char *buf, u32 size)
228 #define SIZE_GB ((u32)1024*1024*1024)
229 #define SIZE_MB ((u32)1024*1024)
230 #define SIZE_KB ((u32)1024)
232 if ((size % SIZE_GB) == 0)
233 sprintf(buf, "%ug", size/SIZE_GB);
234 else if ((size % SIZE_MB) == 0)
235 sprintf(buf, "%um", size/SIZE_MB);
236 else if (size % SIZE_KB == 0)
237 sprintf(buf, "%uk", size/SIZE_KB);
239 sprintf(buf, "%u", size);
243 * This routine does global indexing of all partitions. Resulting index for
244 * current partition is saved in 'mtddevnum'. Current partition name in
247 static void index_partitions(void)
251 struct part_info *part;
252 struct list_head *dentry;
253 struct mtd_device *dev;
255 DEBUGF("--- index partitions ---\n");
259 list_for_each(dentry, &devices) {
260 dev = list_entry(dentry, struct mtd_device, link);
261 if (dev == current_dev) {
262 mtddevnum += current_partnum;
263 sprintf(buf, "%d", mtddevnum);
264 setenv("mtddevnum", buf);
267 mtddevnum += dev->num_parts;
270 part = mtd_part_info(current_dev, current_partnum);
271 setenv("mtddevname", part->name);
273 DEBUGF("=> mtddevnum %d,\n=> mtddevname %s\n", mtddevnum, part->name);
275 setenv("mtddevnum", NULL);
276 setenv("mtddevname", NULL);
278 DEBUGF("=> mtddevnum NULL\n=> mtddevname NULL\n");
283 * Save current device and partition in environment variable 'partition'.
285 static void current_save(void)
289 DEBUGF("--- current_save ---\n");
292 sprintf(buf, "%s%d,%d", MTD_DEV_TYPE(current_dev->id->type),
293 current_dev->id->num, current_partnum);
295 setenv("partition", buf);
296 strncpy(last_partition, buf, 16);
298 DEBUGF("=> partition %s\n", buf);
300 setenv("partition", NULL);
301 last_partition[0] = '\0';
303 DEBUGF("=> partition NULL\n");
309 * Performs sanity check for supplied NOR flash partition. Table of existing
310 * NOR flash devices is searched and partition device is located. Alignment
311 * with the granularity of NOR flash sectors is verified.
313 * @param id of the parent device
314 * @param part partition to validate
315 * @return 0 if partition is valid, 1 otherwise
317 static int part_validate_nor(struct mtdids *id, struct part_info *part)
319 #if defined(CONFIG_CMD_FLASH)
320 /* info for FLASH chips */
321 extern flash_info_t flash_info[];
324 u32 end_offset, sector_size = 0;
327 flash = &flash_info[id->num];
329 /* size of last sector */
330 part->sector_size = flash->size -
331 (flash->start[flash->sector_count-1] - flash->start[0]);
334 for (i = 0; i < flash->sector_count; i++) {
335 if ((flash->start[i] - flash->start[0]) == part->offset) {
340 if (offset_aligned == 0) {
341 printf("%s%d: partition (%s) start offset alignment incorrect\n",
342 MTD_DEV_TYPE(id->type), id->num, part->name);
346 end_offset = part->offset + part->size;
348 for (i = 0; i < flash->sector_count; i++) {
350 sector_size = flash->start[i] - flash->start[i-1];
351 if (part->sector_size < sector_size)
352 part->sector_size = sector_size;
354 if ((flash->start[i] - flash->start[0]) == end_offset)
358 if (offset_aligned || flash->size == end_offset)
361 printf("%s%d: partition (%s) size alignment incorrect\n",
362 MTD_DEV_TYPE(id->type), id->num, part->name);
368 * Performs sanity check for supplied NAND flash partition. Table of existing
369 * NAND flash devices is searched and partition device is located. Alignment
370 * with the granularity of nand erasesize is verified.
372 * @param id of the parent device
373 * @param part partition to validate
374 * @return 0 if partition is valid, 1 otherwise
376 static int part_validate_nand(struct mtdids *id, struct part_info *part)
378 #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
379 /* info for NAND chips */
382 nand = &nand_info[id->num];
384 part->sector_size = nand->erasesize;
386 if ((unsigned long)(part->offset) % nand->erasesize) {
387 printf("%s%d: partition (%s) start offset alignment incorrect\n",
388 MTD_DEV_TYPE(id->type), id->num, part->name);
392 if (part->size % nand->erasesize) {
393 printf("%s%d: partition (%s) size alignment incorrect\n",
394 MTD_DEV_TYPE(id->type), id->num, part->name);
405 * Performs sanity check for supplied OneNAND flash partition.
406 * Table of existing OneNAND flash devices is searched and partition device
407 * is located. Alignment with the granularity of nand erasesize is verified.
409 * @param id of the parent device
410 * @param part partition to validate
411 * @return 0 if partition is valid, 1 otherwise
413 static int part_validate_onenand(struct mtdids *id, struct part_info *part)
415 #if defined(CONFIG_CMD_ONENAND)
416 /* info for OneNAND chips */
417 struct mtd_info *mtd;
421 part->sector_size = mtd->erasesize;
423 if ((unsigned long)(part->offset) % mtd->erasesize) {
424 printf("%s%d: partition (%s) start offset"
425 "alignment incorrect\n",
426 MTD_DEV_TYPE(id->type), id->num, part->name);
430 if (part->size % mtd->erasesize) {
431 printf("%s%d: partition (%s) size alignment incorrect\n",
432 MTD_DEV_TYPE(id->type), id->num, part->name);
444 * Performs sanity check for supplied partition. Offset and size are verified
445 * to be within valid range. Partition type is checked and either
446 * parts_validate_nor() or parts_validate_nand() is called with the argument
449 * @param id of the parent device
450 * @param part partition to validate
451 * @return 0 if partition is valid, 1 otherwise
453 static int part_validate(struct mtdids *id, struct part_info *part)
455 if (part->size == SIZE_REMAINING)
456 part->size = id->size - part->offset;
458 if (part->offset > id->size) {
459 printf("%s: offset %08x beyond flash size %08x\n",
460 id->mtd_id, part->offset, id->size);
464 if ((part->offset + part->size) <= part->offset) {
465 printf("%s%d: partition (%s) size too big\n",
466 MTD_DEV_TYPE(id->type), id->num, part->name);
470 if (part->offset + part->size > id->size) {
471 printf("%s: partitioning exceeds flash size\n", id->mtd_id);
475 if (id->type == MTD_DEV_TYPE_NAND)
476 return part_validate_nand(id, part);
477 else if (id->type == MTD_DEV_TYPE_NOR)
478 return part_validate_nor(id, part);
479 else if (id->type == MTD_DEV_TYPE_ONENAND)
480 return part_validate_onenand(id, part);
482 DEBUGF("part_validate: invalid dev type\n");
488 * Delete selected partition from the partion list of the specified device.
490 * @param dev device to delete partition from
491 * @param part partition to delete
492 * @return 0 on success, 1 otherwise
494 static int part_del(struct mtd_device *dev, struct part_info *part)
496 u8 current_save_needed = 0;
498 /* if there is only one partition, remove whole device */
499 if (dev->num_parts == 1)
500 return device_del(dev);
502 /* otherwise just delete this partition */
504 if (dev == current_dev) {
505 /* we are modyfing partitions for the current device,
507 struct part_info *curr_pi;
508 curr_pi = mtd_part_info(current_dev, current_partnum);
511 if (curr_pi == part) {
512 printf("current partition deleted, resetting current to 0\n");
514 } else if (part->offset <= curr_pi->offset) {
517 current_save_needed = 1;
521 #ifdef CONFIG_NAND_LEGACY
522 jffs2_free_cache(part);
524 list_del(&part->link);
528 if (current_save_needed > 0)
537 * Delete all partitions from parts head list, free memory.
539 * @param head list of partitions to delete
541 static void part_delall(struct list_head *head)
543 struct list_head *entry, *n;
544 struct part_info *part_tmp;
546 /* clean tmp_list and free allocated memory */
547 list_for_each_safe(entry, n, head) {
548 part_tmp = list_entry(entry, struct part_info, link);
550 #ifdef CONFIG_NAND_LEGACY
551 jffs2_free_cache(part_tmp);
559 * Add new partition to the supplied partition list. Make sure partitions are
560 * sorted by offset in ascending order.
562 * @param head list this partition is to be added to
563 * @param new partition to be added
565 static int part_sort_add(struct mtd_device *dev, struct part_info *part)
567 struct list_head *entry;
568 struct part_info *new_pi, *curr_pi;
570 /* link partition to parrent dev */
573 if (list_empty(&dev->parts)) {
574 DEBUGF("part_sort_add: list empty\n");
575 list_add(&part->link, &dev->parts);
581 new_pi = list_entry(&part->link, struct part_info, link);
583 /* get current partition info if we are updating current device */
585 if (dev == current_dev)
586 curr_pi = mtd_part_info(current_dev, current_partnum);
588 list_for_each(entry, &dev->parts) {
589 struct part_info *pi;
591 pi = list_entry(entry, struct part_info, link);
593 /* be compliant with kernel cmdline, allow only one partition at offset zero */
594 if ((new_pi->offset == pi->offset) && (pi->offset == 0)) {
595 printf("cannot add second partition at offset 0\n");
599 if (new_pi->offset <= pi->offset) {
600 list_add_tail(&part->link, entry);
603 if (curr_pi && (pi->offset <= curr_pi->offset)) {
604 /* we are modyfing partitions for the current
605 * device, update current */
615 list_add_tail(&part->link, &dev->parts);
622 * Add provided partition to the partition list of a given device.
624 * @param dev device to which partition is added
625 * @param part partition to be added
626 * @return 0 on success, 1 otherwise
628 static int part_add(struct mtd_device *dev, struct part_info *part)
630 /* verify alignment and size */
631 if (part_validate(dev->id, part) != 0)
634 /* partition is ok, add it to the list */
635 if (part_sort_add(dev, part) != 0)
642 * Parse one partition definition, allocate memory and return pointer to this
643 * location in retpart.
645 * @param partdef pointer to the partition definition string i.e. <part-def>
646 * @param ret output pointer to next char after parse completes (output)
647 * @param retpart pointer to the allocated partition (output)
648 * @return 0 on success, 1 otherwise
650 static int part_parse(const char *const partdef, const char **ret, struct part_info **retpart)
652 struct part_info *part;
654 unsigned long offset;
657 unsigned int mask_flags;
664 /* fetch the partition size */
666 /* assign all remaining space to this partition */
667 DEBUGF("'-': remaining size assigned\n");
668 size = SIZE_REMAINING;
671 size = memsize_parse(p, &p);
672 if (size < MIN_PART_SIZE) {
673 printf("partition size too small (%lx)\n", size);
678 /* check for offset */
679 offset = OFFSET_NOT_SPECIFIED;
682 offset = memsize_parse(p, &p);
685 /* now look for the name */
688 if ((p = strchr(name, ')')) == NULL) {
689 printf("no closing ) found in partition name\n");
692 name_len = p - name + 1;
693 if ((name_len - 1) == 0) {
694 printf("empty partition name\n");
699 /* 0x00000000@0x00000000 */
704 /* test for options */
706 if (strncmp(p, "ro", 2) == 0) {
707 mask_flags |= MTD_WRITEABLE_CMD;
711 /* check for next partition definition */
713 if (size == SIZE_REMAINING) {
715 printf("no partitions allowed after a fill-up partition\n");
719 } else if ((*p == ';') || (*p == '\0')) {
722 printf("unexpected character '%c' at the end of partition\n", *p);
727 /* allocate memory */
728 part = (struct part_info *)malloc(sizeof(struct part_info) + name_len);
730 printf("out of memory\n");
733 memset(part, 0, sizeof(struct part_info) + name_len);
735 part->offset = offset;
736 part->mask_flags = mask_flags;
737 part->name = (char *)(part + 1);
740 /* copy user provided name */
741 strncpy(part->name, name, name_len - 1);
744 /* auto generated name in form of size@offset */
745 sprintf(part->name, "0x%08lx@0x%08lx", size, offset);
749 part->name[name_len - 1] = '\0';
750 INIT_LIST_HEAD(&part->link);
752 DEBUGF("+ partition: name %-22s size 0x%08x offset 0x%08x mask flags %d\n",
753 part->name, part->size,
754 part->offset, part->mask_flags);
761 * Check device number to be within valid range for given device type.
763 * @param dev device to validate
764 * @return 0 if device is valid, 1 otherwise
766 int mtd_device_validate(u8 type, u8 num, u32 *size)
768 if (type == MTD_DEV_TYPE_NOR) {
769 #if defined(CONFIG_CMD_FLASH)
770 if (num < CONFIG_SYS_MAX_FLASH_BANKS) {
771 extern flash_info_t flash_info[];
772 *size = flash_info[num].size;
777 printf("no such FLASH device: %s%d (valid range 0 ... %d\n",
778 MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_FLASH_BANKS - 1);
780 printf("support for FLASH devices not present\n");
782 } else if (type == MTD_DEV_TYPE_NAND) {
783 #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
784 if (num < CONFIG_SYS_MAX_NAND_DEVICE) {
785 #ifndef CONFIG_NAND_LEGACY
786 *size = nand_info[num].size;
788 extern struct nand_chip nand_dev_desc[CONFIG_SYS_MAX_NAND_DEVICE];
789 *size = nand_dev_desc[num].totlen;
794 printf("no such NAND device: %s%d (valid range 0 ... %d)\n",
795 MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_NAND_DEVICE - 1);
797 printf("support for NAND devices not present\n");
799 } else if (type == MTD_DEV_TYPE_ONENAND) {
800 #if defined(CONFIG_CMD_ONENAND)
801 *size = onenand_mtd.size;
804 printf("support for OneNAND devices not present\n");
807 printf("Unknown defice type %d\n", type);
813 * Delete all mtd devices from a supplied devices list, free memory allocated for
814 * each device and delete all device partitions.
816 * @return 0 on success, 1 otherwise
818 static int device_delall(struct list_head *head)
820 struct list_head *entry, *n;
821 struct mtd_device *dev_tmp;
823 /* clean devices list */
824 list_for_each_safe(entry, n, head) {
825 dev_tmp = list_entry(entry, struct mtd_device, link);
827 part_delall(&dev_tmp->parts);
830 INIT_LIST_HEAD(&devices);
836 * If provided device exists it's partitions are deleted, device is removed
837 * from device list and device memory is freed.
839 * @param dev device to be deleted
840 * @return 0 on success, 1 otherwise
842 static int device_del(struct mtd_device *dev)
844 part_delall(&dev->parts);
845 list_del(&dev->link);
848 if (dev == current_dev) {
849 /* we just deleted current device */
850 if (list_empty(&devices)) {
853 /* reset first partition from first dev from the
854 * devices list as current */
855 current_dev = list_entry(devices.next, struct mtd_device, link);
867 * Search global device list and return pointer to the device of type and num
870 * @param type device type
871 * @param num device number
872 * @return NULL if requested device does not exist
874 static struct mtd_device* device_find(u8 type, u8 num)
876 struct list_head *entry;
877 struct mtd_device *dev_tmp;
879 list_for_each(entry, &devices) {
880 dev_tmp = list_entry(entry, struct mtd_device, link);
882 if ((dev_tmp->id->type == type) && (dev_tmp->id->num == num))
890 * Add specified device to the global device list.
892 * @param dev device to be added
894 static void device_add(struct mtd_device *dev)
896 u8 current_save_needed = 0;
898 if (list_empty(&devices)) {
901 current_save_needed = 1;
904 list_add_tail(&dev->link, &devices);
906 if (current_save_needed > 0)
913 * Parse device type, name and mtd-id. If syntax is ok allocate memory and
914 * return pointer to the device structure.
916 * @param mtd_dev pointer to the device definition string i.e. <mtd-dev>
917 * @param ret output pointer to next char after parse completes (output)
918 * @param retdev pointer to the allocated device (output)
919 * @return 0 on success, 1 otherwise
921 static int device_parse(const char *const mtd_dev, const char **ret, struct mtd_device **retdev)
923 struct mtd_device *dev;
924 struct part_info *part;
927 unsigned int mtd_id_len;
928 const char *p, *pend;
930 struct list_head *entry, *n;
939 DEBUGF("===device_parse===\n");
943 if (!(p = strchr(mtd_id, ':'))) {
944 printf("no <mtd-id> identifier\n");
947 mtd_id_len = p - mtd_id + 1;
950 /* verify if we have a valid device specified */
951 if ((id = id_find_by_mtd_id(mtd_id, mtd_id_len - 1)) == NULL) {
952 printf("invalid mtd device '%.*s'\n", mtd_id_len - 1, mtd_id);
956 DEBUGF("dev type = %d (%s), dev num = %d, mtd-id = %s\n",
957 id->type, MTD_DEV_TYPE(id->type),
958 id->num, id->mtd_id);
959 pend = strchr(p, ';');
960 DEBUGF("parsing partitions %.*s\n", (pend ? pend - p : strlen(p)), p);
963 /* parse partitions */
967 if ((dev = device_find(id->type, id->num)) != NULL) {
968 /* if device already exists start at the end of the last partition */
969 part = list_entry(dev->parts.prev, struct part_info, link);
970 offset = part->offset + part->size;
973 while (p && (*p != '\0') && (*p != ';')) {
975 if ((part_parse(p, &p, &part) != 0) || (!part))
978 /* calculate offset when not specified */
979 if (part->offset == OFFSET_NOT_SPECIFIED)
980 part->offset = offset;
982 offset = part->offset;
984 /* verify alignment and size */
985 if (part_validate(id, part) != 0)
988 offset += part->size;
990 /* partition is ok, add it to the list */
991 list_add_tail(&part->link, &tmp_list);
996 part_delall(&tmp_list);
1000 if (num_parts == 0) {
1001 printf("no partitions for device %s%d (%s)\n",
1002 MTD_DEV_TYPE(id->type), id->num, id->mtd_id);
1006 DEBUGF("\ntotal partitions: %d\n", num_parts);
1008 /* check for next device presence */
1012 } else if (*p == '\0') {
1015 printf("unexpected character '%c' at the end of device\n", *p);
1021 /* allocate memory for mtd_device structure */
1022 if ((dev = (struct mtd_device *)malloc(sizeof(struct mtd_device))) == NULL) {
1023 printf("out of memory\n");
1026 memset(dev, 0, sizeof(struct mtd_device));
1028 dev->num_parts = 0; /* part_sort_add increments num_parts */
1029 INIT_LIST_HEAD(&dev->parts);
1030 INIT_LIST_HEAD(&dev->link);
1032 /* move partitions from tmp_list to dev->parts */
1033 list_for_each_safe(entry, n, &tmp_list) {
1034 part = list_entry(entry, struct part_info, link);
1036 if (part_sort_add(dev, part) != 0) {
1049 * Initialize global device list.
1051 * @return 0 on success, 1 otherwise
1053 static int mtd_devices_init(void)
1055 last_parts[0] = '\0';
1059 return device_delall(&devices);
1063 * Search global mtdids list and find id of requested type and number.
1065 * @return pointer to the id if it exists, NULL otherwise
1067 static struct mtdids* id_find(u8 type, u8 num)
1069 struct list_head *entry;
1072 list_for_each(entry, &mtdids) {
1073 id = list_entry(entry, struct mtdids, link);
1075 if ((id->type == type) && (id->num == num))
1083 * Search global mtdids list and find id of a requested mtd_id.
1085 * Note: first argument is not null terminated.
1087 * @param mtd_id string containing requested mtd_id
1088 * @param mtd_id_len length of supplied mtd_id
1089 * @return pointer to the id if it exists, NULL otherwise
1091 static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len)
1093 struct list_head *entry;
1096 DEBUGF("--- id_find_by_mtd_id: '%.*s' (len = %d)\n",
1097 mtd_id_len, mtd_id, mtd_id_len);
1099 list_for_each(entry, &mtdids) {
1100 id = list_entry(entry, struct mtdids, link);
1102 DEBUGF("entry: '%s' (len = %d)\n",
1103 id->mtd_id, strlen(id->mtd_id));
1105 if (mtd_id_len != strlen(id->mtd_id))
1107 if (strncmp(id->mtd_id, mtd_id, mtd_id_len) == 0)
1115 * Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>,
1116 * return device type and number.
1118 * @param id string describing device id
1119 * @param ret_id output pointer to next char after parse completes (output)
1120 * @param dev_type parsed device type (output)
1121 * @param dev_num parsed device number (output)
1122 * @return 0 on success, 1 otherwise
1124 int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num)
1129 if (strncmp(p, "nand", 4) == 0) {
1130 *dev_type = MTD_DEV_TYPE_NAND;
1132 } else if (strncmp(p, "nor", 3) == 0) {
1133 *dev_type = MTD_DEV_TYPE_NOR;
1135 } else if (strncmp(p, "onenand", 7) == 0) {
1136 *dev_type = MTD_DEV_TYPE_ONENAND;
1139 printf("incorrect device type in %s\n", id);
1144 printf("incorrect device number in %s\n", id);
1148 *dev_num = simple_strtoul(p, (char **)&p, 0);
1155 * Process all devices and generate corresponding mtdparts string describing
1156 * all partitions on all devices.
1158 * @param buf output buffer holding generated mtdparts string (output)
1159 * @param buflen buffer size
1160 * @return 0 on success, 1 otherwise
1162 static int generate_mtdparts(char *buf, u32 buflen)
1164 struct list_head *pentry, *dentry;
1165 struct mtd_device *dev;
1166 struct part_info *part, *prev_part;
1169 u32 size, offset, len, part_cnt;
1170 u32 maxlen = buflen - 1;
1172 DEBUGF("--- generate_mtdparts ---\n");
1174 if (list_empty(&devices)) {
1179 sprintf(p, "mtdparts=");
1182 list_for_each(dentry, &devices) {
1183 dev = list_entry(dentry, struct mtd_device, link);
1186 len = strlen(dev->id->mtd_id) + 1;
1189 memcpy(p, dev->id->mtd_id, len - 1);
1194 /* format partitions */
1197 list_for_each(pentry, &dev->parts) {
1198 part = list_entry(pentry, struct part_info, link);
1200 offset = part->offset;
1203 /* partition size */
1204 memsize_format(tmpbuf, size);
1205 len = strlen(tmpbuf);
1208 memcpy(p, tmpbuf, len);
1213 /* add offset only when there is a gap between
1215 if ((!prev_part && (offset != 0)) ||
1216 (prev_part && ((prev_part->offset + prev_part->size) != part->offset))) {
1218 memsize_format(tmpbuf, offset);
1219 len = strlen(tmpbuf) + 1;
1223 memcpy(p, tmpbuf, len - 1);
1228 /* copy name only if user supplied */
1229 if(!part->auto_name) {
1230 len = strlen(part->name) + 2;
1235 memcpy(p, part->name, len - 2);
1242 if (part->mask_flags && MTD_WRITEABLE_CMD) {
1251 /* print ',' separator if there are other partitions
1253 if (dev->num_parts > part_cnt) {
1261 /* print ';' separator if there are other devices following */
1262 if (dentry->next != &devices) {
1270 /* we still have at least one char left, as we decremented maxlen at
1277 last_parts[0] = '\0';
1282 * Call generate_mtdparts to process all devices and generate corresponding
1283 * mtdparts string, save it in mtdparts environment variable.
1285 * @param buf output buffer holding generated mtdparts string (output)
1286 * @param buflen buffer size
1287 * @return 0 on success, 1 otherwise
1289 static int generate_mtdparts_save(char *buf, u32 buflen)
1293 ret = generate_mtdparts(buf, buflen);
1295 if ((buf[0] != '\0') && (ret == 0))
1296 setenv("mtdparts", buf);
1298 setenv("mtdparts", NULL);
1304 * Format and print out a partition list for each device from global device
1307 static void list_partitions(void)
1309 struct list_head *dentry, *pentry;
1310 struct part_info *part;
1311 struct mtd_device *dev;
1314 DEBUGF("\n---list_partitions---\n");
1315 list_for_each(dentry, &devices) {
1316 dev = list_entry(dentry, struct mtd_device, link);
1317 printf("\ndevice %s%d <%s>, # parts = %d\n",
1318 MTD_DEV_TYPE(dev->id->type), dev->id->num,
1319 dev->id->mtd_id, dev->num_parts);
1320 printf(" #: name\t\t\tsize\t\toffset\t\tmask_flags\n");
1322 /* list partitions for given device */
1324 list_for_each(pentry, &dev->parts) {
1325 part = list_entry(pentry, struct part_info, link);
1326 printf("%2d: %-20s0x%08x\t0x%08x\t%d\n",
1327 part_num, part->name, part->size,
1328 part->offset, part->mask_flags);
1333 if (list_empty(&devices))
1334 printf("no partitions defined\n");
1336 /* current_dev is not NULL only when we have non empty device list */
1338 part = mtd_part_info(current_dev, current_partnum);
1340 printf("\nactive partition: %s%d,%d - (%s) 0x%08x @ 0x%08x\n",
1341 MTD_DEV_TYPE(current_dev->id->type),
1342 current_dev->id->num, current_partnum,
1343 part->name, part->size, part->offset);
1345 printf("could not get current partition info\n\n");
1349 printf("\ndefaults:\n");
1350 printf("mtdids : %s\n", mtdids_default);
1351 printf("mtdparts: %s\n", mtdparts_default);
1355 * Given partition identifier in form of <dev_type><dev_num>,<part_num> find
1356 * corresponding device and verify partition number.
1358 * @param id string describing device and partition or partition name
1359 * @param dev pointer to the requested device (output)
1360 * @param part_num verified partition number (output)
1361 * @param part pointer to requested partition (output)
1362 * @return 0 on success, 1 otherwise
1364 int find_dev_and_part(const char *id, struct mtd_device **dev,
1365 u8 *part_num, struct part_info **part)
1367 struct list_head *dentry, *pentry;
1368 u8 type, dnum, pnum;
1371 DEBUGF("--- find_dev_and_part ---\nid = %s\n", id);
1373 list_for_each(dentry, &devices) {
1375 *dev = list_entry(dentry, struct mtd_device, link);
1376 list_for_each(pentry, &(*dev)->parts) {
1377 *part = list_entry(pentry, struct part_info, link);
1378 if (strcmp((*part)->name, id) == 0)
1389 if (mtd_id_parse(p, &p, &type, &dnum) != 0)
1392 if ((*p++ != ',') || (*p == '\0')) {
1393 printf("no partition number specified\n");
1396 pnum = simple_strtoul(p, (char **)&p, 0);
1398 printf("unexpected trailing character '%c'\n", *p);
1402 if ((*dev = device_find(type, dnum)) == NULL) {
1403 printf("no such device %s%d\n", MTD_DEV_TYPE(type), dnum);
1407 if ((*part = mtd_part_info(*dev, pnum)) == NULL) {
1408 printf("no such partition\n");
1419 * Find and delete partition. For partition id format see find_dev_and_part().
1421 * @param id string describing device and partition
1422 * @return 0 on success, 1 otherwise
1424 static int delete_partition(const char *id)
1427 struct mtd_device *dev;
1428 struct part_info *part;
1430 if (find_dev_and_part(id, &dev, &pnum, &part) == 0) {
1432 DEBUGF("delete_partition: device = %s%d, partition %d = (%s) 0x%08lx@0x%08lx\n",
1433 MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum,
1434 part->name, part->size, part->offset);
1436 if (part_del(dev, part) != 0)
1439 if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
1440 printf("generated mtdparts too long, reseting to null\n");
1446 printf("partition %s not found\n", id);
1451 * Accept character string describing mtd partitions and call device_parse()
1452 * for each entry. Add created devices to the global devices list.
1454 * @param mtdparts string specifing mtd partitions
1455 * @return 0 on success, 1 otherwise
1457 static int parse_mtdparts(const char *const mtdparts)
1459 const char *p = mtdparts;
1460 struct mtd_device *dev;
1463 DEBUGF("\n---parse_mtdparts---\nmtdparts = %s\n\n", p);
1465 /* delete all devices and partitions */
1466 if (mtd_devices_init() != 0) {
1467 printf("could not initialise device list\n");
1471 /* re-read 'mtdparts' variable, mtd_devices_init may be updating env */
1472 p = getenv("mtdparts");
1474 if (strncmp(p, "mtdparts=", 9) != 0) {
1475 printf("mtdparts variable doesn't start with 'mtdparts='\n");
1480 while (p && (*p != '\0')) {
1482 if ((device_parse(p, &p, &dev) != 0) || (!dev))
1485 DEBUGF("+ device: %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
1486 dev->id->num, dev->id->mtd_id);
1488 /* check if parsed device is already on the list */
1489 if (device_find(dev->id->type, dev->id->num) != NULL) {
1490 printf("device %s%d redefined, please correct mtdparts variable\n",
1491 MTD_DEV_TYPE(dev->id->type), dev->id->num);
1495 list_add_tail(&dev->link, &devices);
1499 device_delall(&devices);
1507 * Parse provided string describing mtdids mapping (see file header for mtdids
1508 * variable format). Allocate memory for each entry and add all found entries
1509 * to the global mtdids list.
1511 * @param ids mapping string
1512 * @return 0 on success, 1 otherwise
1514 static int parse_mtdids(const char *const ids)
1516 const char *p = ids;
1520 struct list_head *entry, *n;
1521 struct mtdids *id_tmp;
1526 DEBUGF("\n---parse_mtdids---\nmtdids = %s\n\n", ids);
1528 /* clean global mtdids list */
1529 list_for_each_safe(entry, n, &mtdids) {
1530 id_tmp = list_entry(entry, struct mtdids, link);
1531 DEBUGF("mtdids del: %d %d\n", id_tmp->type, id_tmp->num);
1536 INIT_LIST_HEAD(&mtdids);
1538 while(p && (*p != '\0')) {
1541 /* parse 'nor'|'nand'|'onenand'<dev-num> */
1542 if (mtd_id_parse(p, &p, &type, &num) != 0)
1546 printf("mtdids: incorrect <dev-num>\n");
1551 /* check if requested device exists */
1552 if (mtd_device_validate(type, num, &size) != 0)
1555 /* locate <mtd-id> */
1557 if ((p = strchr(mtd_id, ',')) != NULL) {
1558 mtd_id_len = p - mtd_id + 1;
1561 mtd_id_len = strlen(mtd_id) + 1;
1563 if (mtd_id_len == 0) {
1564 printf("mtdids: no <mtd-id> identifier\n");
1568 /* check if this id is already on the list */
1569 int double_entry = 0;
1570 list_for_each(entry, &mtdids) {
1571 id_tmp = list_entry(entry, struct mtdids, link);
1572 if ((id_tmp->type == type) && (id_tmp->num == num)) {
1578 printf("device id %s%d redefined, please correct mtdids variable\n",
1579 MTD_DEV_TYPE(type), num);
1583 /* allocate mtdids structure */
1584 if (!(id = (struct mtdids *)malloc(sizeof(struct mtdids) + mtd_id_len))) {
1585 printf("out of memory\n");
1588 memset(id, 0, sizeof(struct mtdids) + mtd_id_len);
1592 id->mtd_id = (char *)(id + 1);
1593 strncpy(id->mtd_id, mtd_id, mtd_id_len - 1);
1594 id->mtd_id[mtd_id_len - 1] = '\0';
1595 INIT_LIST_HEAD(&id->link);
1597 DEBUGF("+ id %s%d\t%16d bytes\t%s\n",
1598 MTD_DEV_TYPE(id->type), id->num,
1599 id->size, id->mtd_id);
1601 list_add_tail(&id->link, &mtdids);
1605 /* clean mtdids list and free allocated memory */
1606 list_for_each_safe(entry, n, &mtdids) {
1607 id_tmp = list_entry(entry, struct mtdids, link);
1618 * Parse and initialize global mtdids mapping and create global
1619 * device/partition list.
1621 * @return 0 on success, 1 otherwise
1623 int mtdparts_init(void)
1625 static int initialized = 0;
1626 const char *ids, *parts;
1627 const char *current_partition;
1629 char tmp_ep[PARTITION_MAXLEN];
1631 DEBUGF("\n---mtdparts_init---\n");
1633 INIT_LIST_HEAD(&mtdids);
1634 INIT_LIST_HEAD(&devices);
1635 memset(last_ids, 0, MTDIDS_MAXLEN);
1636 memset(last_parts, 0, MTDPARTS_MAXLEN);
1637 memset(last_partition, 0, PARTITION_MAXLEN);
1642 ids = getenv("mtdids");
1643 parts = getenv("mtdparts");
1644 current_partition = getenv("partition");
1646 /* save it for later parsing, cannot rely on current partition pointer
1647 * as 'partition' variable may be updated during init */
1649 if (current_partition)
1650 strncpy(tmp_ep, current_partition, PARTITION_MAXLEN);
1652 DEBUGF("last_ids : %s\n", last_ids);
1653 DEBUGF("env_ids : %s\n", ids);
1654 DEBUGF("last_parts: %s\n", last_parts);
1655 DEBUGF("env_parts : %s\n\n", parts);
1657 DEBUGF("last_partition : %s\n", last_partition);
1658 DEBUGF("env_partition : %s\n", current_partition);
1660 /* if mtdids varible is empty try to use defaults */
1662 if (mtdids_default) {
1663 DEBUGF("mtdids variable not defined, using default\n");
1664 ids = mtdids_default;
1665 setenv("mtdids", (char *)ids);
1667 printf("mtdids not defined, no default present\n");
1671 if (strlen(ids) > MTDIDS_MAXLEN - 1) {
1672 printf("mtdids too long (> %d)\n", MTDIDS_MAXLEN);
1676 /* do no try to use defaults when mtdparts variable is not defined,
1677 * just check the length */
1679 printf("mtdparts variable not set, see 'help mtdparts'\n");
1681 if (parts && (strlen(parts) > MTDPARTS_MAXLEN - 1)) {
1682 printf("mtdparts too long (> %d)\n", MTDPARTS_MAXLEN);
1686 /* check if we have already parsed those mtdids */
1687 if ((last_ids[0] != '\0') && (strcmp(last_ids, ids) == 0)) {
1692 if (parse_mtdids(ids) != 0) {
1697 /* ok it's good, save new ids */
1698 strncpy(last_ids, ids, MTDIDS_MAXLEN);
1701 /* parse partitions if either mtdparts or mtdids were updated */
1702 if (parts && ((last_parts[0] == '\0') || ((strcmp(last_parts, parts) != 0)) || ids_changed)) {
1703 if (parse_mtdparts(parts) != 0)
1706 if (list_empty(&devices)) {
1707 printf("mtdparts_init: no valid partitions\n");
1711 /* ok it's good, save new parts */
1712 strncpy(last_parts, parts, MTDPARTS_MAXLEN);
1714 /* reset first partition from first dev from the list as current */
1715 current_dev = list_entry(devices.next, struct mtd_device, link);
1716 current_partnum = 0;
1719 DEBUGF("mtdparts_init: current_dev = %s%d, current_partnum = %d\n",
1720 MTD_DEV_TYPE(current_dev->id->type),
1721 current_dev->id->num, current_partnum);
1724 /* mtdparts variable was reset to NULL, delete all devices/partitions */
1725 if (!parts && (last_parts[0] != '\0'))
1726 return mtd_devices_init();
1728 /* do not process current partition if mtdparts variable is null */
1732 /* is current partition set in environment? if so, use it */
1733 if ((tmp_ep[0] != '\0') && (strcmp(tmp_ep, last_partition) != 0)) {
1734 struct part_info *p;
1735 struct mtd_device *cdev;
1738 DEBUGF("--- getting current partition: %s\n", tmp_ep);
1740 if (find_dev_and_part(tmp_ep, &cdev, &pnum, &p) == 0) {
1742 current_partnum = pnum;
1745 } else if (getenv("partition") == NULL) {
1746 DEBUGF("no partition variable set, setting...\n");
1754 * Return pointer to the partition of a requested number from a requested
1757 * @param dev device that is to be searched for a partition
1758 * @param part_num requested partition number
1759 * @return pointer to the part_info, NULL otherwise
1761 static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num)
1763 struct list_head *entry;
1764 struct part_info *part;
1770 DEBUGF("\n--- mtd_part_info: partition number %d for device %s%d (%s)\n",
1771 part_num, MTD_DEV_TYPE(dev->id->type),
1772 dev->id->num, dev->id->mtd_id);
1774 if (part_num >= dev->num_parts) {
1775 printf("invalid partition number %d for device %s%d (%s)\n",
1776 part_num, MTD_DEV_TYPE(dev->id->type),
1777 dev->id->num, dev->id->mtd_id);
1781 /* locate partition number, return it */
1783 list_for_each(entry, &dev->parts) {
1784 part = list_entry(entry, struct part_info, link);
1786 if (part_num == num++) {
1794 /***************************************************/
1795 /* U-boot commands */
1796 /***************************************************/
1797 /* command line only */
1799 * Routine implementing u-boot chpart command. Sets new current partition based
1800 * on the user supplied partition id. For partition id format see find_dev_and_part().
1802 * @param cmdtp command internal data
1803 * @param flag command flag
1804 * @param argc number of arguments supplied to the command
1805 * @param argv arguments list
1806 * @return 0 on success, 1 otherwise
1808 int do_chpart(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1810 /* command line only */
1811 struct mtd_device *dev;
1812 struct part_info *part;
1815 if (mtdparts_init() !=0)
1819 printf("no partition id specified\n");
1823 if (find_dev_and_part(argv[1], &dev, &pnum, &part) != 0)
1827 current_partnum = pnum;
1830 printf("partition changed to %s%d,%d\n",
1831 MTD_DEV_TYPE(dev->id->type), dev->id->num, pnum);
1837 * Routine implementing u-boot mtdparts command. Initialize/update default global
1838 * partition list and process user partition request (list, add, del).
1840 * @param cmdtp command internal data
1841 * @param flag command flag
1842 * @param argc number of arguments supplied to the command
1843 * @param argv arguments list
1844 * @return 0 on success, 1 otherwise
1846 int do_mtdparts(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1849 if (strcmp(argv[1], "default") == 0) {
1850 setenv("mtdids", (char *)mtdids_default);
1851 setenv("mtdparts", (char *)mtdparts_default);
1852 setenv("partition", NULL);
1856 } else if (strcmp(argv[1], "delall") == 0) {
1857 /* this may be the first run, initialize lists if needed */
1860 setenv("mtdparts", NULL);
1862 /* mtd_devices_init() calls current_save() */
1863 return mtd_devices_init();
1867 /* make sure we are in sync with env variables */
1868 if (mtdparts_init() != 0)
1876 /* mtdparts add <mtd-dev> <size>[@<offset>] <name> [ro] */
1877 if (((argc == 5) || (argc == 6)) && (strcmp(argv[1], "add") == 0)) {
1878 #define PART_ADD_DESC_MAXLEN 64
1879 char tmpbuf[PART_ADD_DESC_MAXLEN];
1881 struct mtd_device *dev;
1882 struct mtd_device *dev_tmp;
1884 struct part_info *p;
1886 if (mtd_id_parse(argv[2], NULL, &type, &num) != 0)
1889 if ((id = id_find(type, num)) == NULL) {
1890 printf("no such device %s defined in mtdids variable\n", argv[2]);
1894 len = strlen(id->mtd_id) + 1; /* 'mtd_id:' */
1895 len += strlen(argv[3]); /* size@offset */
1896 len += strlen(argv[4]) + 2; /* '(' name ')' */
1897 if (argv[5] && (strlen(argv[5]) == 2))
1898 len += 2; /* 'ro' */
1900 if (len >= PART_ADD_DESC_MAXLEN) {
1901 printf("too long partition description\n");
1904 sprintf(tmpbuf, "%s:%s(%s)%s",
1905 id->mtd_id, argv[3], argv[4], argv[5] ? argv[5] : "");
1906 DEBUGF("add tmpbuf: %s\n", tmpbuf);
1908 if ((device_parse(tmpbuf, NULL, &dev) != 0) || (!dev))
1911 DEBUGF("+ %s\t%d\t%s\n", MTD_DEV_TYPE(dev->id->type),
1912 dev->id->num, dev->id->mtd_id);
1914 if ((dev_tmp = device_find(dev->id->type, dev->id->num)) == NULL) {
1917 /* merge new partition with existing ones*/
1918 p = list_entry(dev->parts.next, struct part_info, link);
1919 if (part_add(dev_tmp, p) != 0) {
1925 if (generate_mtdparts_save(last_parts, MTDPARTS_MAXLEN) != 0) {
1926 printf("generated mtdparts too long, reseting to null\n");
1933 /* mtdparts del part-id */
1934 if ((argc == 3) && (strcmp(argv[1], "del") == 0)) {
1935 DEBUGF("del: part-id = %s\n", argv[2]);
1937 return delete_partition(argv[2]);
1944 /***************************************************/
1946 chpart, 2, 0, do_chpart,
1947 "change active partition",
1949 " - change active partition (e.g. part-id = nand0,1)\n"
1953 mtdparts, 6, 0, do_mtdparts,
1954 "define flash/nand partitions",
1956 " - list partition table\n"
1958 " - delete all partitions\n"
1959 "mtdparts del part-id\n"
1960 " - delete partition (e.g. part-id = nand0,1)\n"
1961 "mtdparts add <mtd-dev> <size>[@<offset>] [<name>] [ro]\n"
1962 " - add partition\n"
1963 "mtdparts default\n"
1964 " - reset partition table to defaults\n\n"
1966 "this command uses three environment variables:\n\n"
1967 "'partition' - keeps current partition identifier\n\n"
1968 "partition := <part-id>\n"
1969 "<part-id> := <dev-id>,part_num\n\n"
1970 "'mtdids' - linux kernel mtd device id <-> u-boot device id mapping\n\n"
1971 "mtdids=<idmap>[,<idmap>,...]\n\n"
1972 "<idmap> := <dev-id>=<mtd-id>\n"
1973 "<dev-id> := 'nand'|'nor'|'onenand'<dev-num>\n"
1974 "<dev-num> := mtd device number, 0...\n"
1975 "<mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)\n\n"
1976 "'mtdparts' - partition list\n\n"
1977 "mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]\n\n"
1978 "<mtd-def> := <mtd-id>:<part-def>[,<part-def>...]\n"
1979 "<mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)\n"
1980 "<part-def> := <size>[@<offset>][<name>][<ro-flag>]\n"
1981 "<size> := standard linux memsize OR '-' to denote all remaining space\n"
1982 "<offset> := partition start offset within the device\n"
1983 "<name> := '(' NAME ')'\n"
1984 "<ro-flag> := when set to 'ro' makes partition read-only (not used, passed to kernel)\n"
1986 /***************************************************/