Commit f8f744a3e8515cae50adefd861e34dab59f9ae6f

Authored by Ladislav Michl
Committed by Tom Rini
1 parent 1c2a262a9d

cmd: mtdparts: use defaults by default

Boards which are defining default mtdparts often need them early
in boot process (to load environment from UBI volume, for example).
This is currently solved by adding mtdparts and mtdids variable
definitions also to default environment. With this change, default
partitions are used by default unless explicitely deleted or
redefined.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>

Showing 1 changed file with 16 additions and 6 deletions Side-by-side Diff

... ... @@ -142,6 +142,8 @@
142 142 struct mtd_device *current_mtd_dev = NULL;
143 143 u8 current_mtd_partnum = 0;
144 144  
  145 +u8 use_defaults;
  146 +
145 147 static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part_num);
146 148  
147 149 /* command line only routines */
... ... @@ -1723,6 +1725,7 @@
1723 1725 memset(last_ids, 0, MTDIDS_MAXLEN);
1724 1726 memset(last_parts, 0, MTDPARTS_MAXLEN);
1725 1727 memset(last_partition, 0, PARTITION_MAXLEN);
  1728 + use_defaults = 1;
1726 1729 initialized = 1;
1727 1730 }
1728 1731  
... ... @@ -1761,10 +1764,16 @@
1761 1764 return 1;
1762 1765 }
1763 1766  
1764   - /* do no try to use defaults when mtdparts variable is not defined,
1765   - * just check the length */
1766   - if (!parts)
1767   - printf("mtdparts variable not set, see 'help mtdparts'\n");
  1767 + /* use defaults when mtdparts variable is not defined
  1768 + * once mtdparts is saved environment, drop use_defaults flag */
  1769 + if (!parts) {
  1770 + if (mtdparts_default && use_defaults) {
  1771 + parts = mtdparts_default;
  1772 + if (setenv("mtdparts", (char *)parts) == 0)
  1773 + use_defaults = 0;
  1774 + } else
  1775 + printf("mtdparts variable not set, see 'help mtdparts'\n");
  1776 + }
1768 1777  
1769 1778 if (parts && (strlen(parts) > MTDPARTS_MAXLEN - 1)) {
1770 1779 printf("mtdparts too long (> %d)\n", MTDPARTS_MAXLEN);
1771 1780  
... ... @@ -1936,9 +1945,10 @@
1936 1945 {
1937 1946 if (argc == 2) {
1938 1947 if (strcmp(argv[1], "default") == 0) {
1939   - setenv("mtdids", (char *)mtdids_default);
1940   - setenv("mtdparts", (char *)mtdparts_default);
  1948 + setenv("mtdids", NULL);
  1949 + setenv("mtdparts", NULL);
1941 1950 setenv("partition", NULL);
  1951 + use_defaults = 1;
1942 1952  
1943 1953 mtdparts_init();
1944 1954 return 0;