Commit e1b7296126bc22825950c24343302205228bdb8d

Authored by Wolfgang Denk

Add support for mtddevnum and mtddevname variables (mtdparts command)

[Merge with /home/m8/git/u-boot]

Showing 2 changed files Side-by-side Diff

... ... @@ -2,6 +2,8 @@
2 2 Changes for U-Boot 1.1.4:
3 3 ======================================================================
4 4  
  5 +* Added support for mtddevnum and mtddevname variables (mtdparts command)
  6 +
5 7 * Change default console baud rate for stxxtc board
6 8  
7 9 * Add I2C support to TQM8540 and TQM8560 boards (EEPROM, RTC, LM75-DTT).
... ... @@ -238,6 +238,46 @@
238 238 }
239 239  
240 240 /**
  241 + * This routine does global indexing of all partitions. Resulting index for
  242 + * current partition is saved in 'mtddevnum'. Current partition name in
  243 + * 'mtddevname'.
  244 + */
  245 +static void index_partitions(void)
  246 +{
  247 + char buf[16];
  248 + u16 mtddevnum;
  249 + struct part_info *part;
  250 + struct list_head *dentry;
  251 + struct mtd_device *dev;
  252 +
  253 + DEBUGF("--- index partitions ---\n");
  254 +
  255 + if (current_dev) {
  256 + mtddevnum = 0;
  257 + list_for_each(dentry, &devices) {
  258 + dev = list_entry(dentry, struct mtd_device, link);
  259 + if (dev == current_dev) {
  260 + mtddevnum += current_partnum;
  261 + sprintf(buf, "%d", mtddevnum);
  262 + setenv("mtddevnum", buf);
  263 + break;
  264 + }
  265 + mtddevnum += dev->num_parts;
  266 + }
  267 +
  268 + part = jffs2_part_info(current_dev, current_partnum);
  269 + setenv("mtddevname", part->name);
  270 +
  271 + DEBUGF("=> mtddevnum %d,\n=> mtddevname %s\n", mtddevnum, part->name);
  272 + } else {
  273 + setenv("mtddevnum", NULL);
  274 + setenv("mtddevname", NULL);
  275 +
  276 + DEBUGF("=> mtddevnum NULL\n=> mtddevname NULL\n");
  277 + }
  278 +}
  279 +
  280 +/**
241 281 * Save current device and partition in environment variable 'partition'.
242 282 */
243 283 static void current_save(void)
... ... @@ -260,6 +300,7 @@
260 300  
261 301 DEBUGF("=> partition NULL\n");
262 302 }
  303 + index_partitions();
263 304 }
264 305  
265 306 /**
... ... @@ -398,6 +439,8 @@
398 439 */
399 440 static int part_del(struct mtd_device *dev, struct part_info *part)
400 441 {
  442 + u8 current_save_needed = 0;
  443 +
401 444 /* if there is only one partition, remove whole device */
402 445 if (dev->num_parts == 1)
403 446 return device_del(dev);
404 447  
405 448  
406 449  
407 450  
... ... @@ -414,20 +457,23 @@
414 457 if (curr_pi == part) {
415 458 printf("current partition deleted, resetting current to 0\n");
416 459 current_partnum = 0;
417   - current_save();
418 460 } else if (part->offset <= curr_pi->offset) {
419 461 current_partnum--;
420   - current_save();
421 462 }
  463 + current_save_needed = 1;
422 464 }
423 465 }
424 466  
425   -
426 467 jffs2_free_cache(part);
427 468 list_del(&part->link);
428 469 free(part);
429 470 dev->num_parts--;
430 471  
  472 + if (current_save_needed > 0)
  473 + current_save();
  474 + else
  475 + index_partitions();
  476 +
431 477 return 0;
432 478 }
433 479  
... ... @@ -469,6 +515,8 @@
469 515 if (list_empty(&dev->parts)) {
470 516 DEBUGF("part_sort_add: list empty\n");
471 517 list_add(&part->link, &dev->parts);
  518 + dev->num_parts++;
  519 + index_partitions();
472 520 return 0;
473 521 }
474 522  
475 523  
476 524  
477 525  
478 526  
... ... @@ -492,18 +540,23 @@
492 540  
493 541 if (new_pi->offset <= pi->offset) {
494 542 list_add_tail(&part->link, entry);
  543 + dev->num_parts++;
495 544  
496 545 if (curr_pi && (pi->offset <= curr_pi->offset)) {
497 546 /* we are modyfing partitions for the current
498 547 * device, update current */
499 548 current_partnum++;
500 549 current_save();
  550 + } else {
  551 + index_partitions();
501 552 }
502   -
503 553 return 0;
504 554 }
505 555 }
  556 +
506 557 list_add_tail(&part->link, &dev->parts);
  558 + dev->num_parts++;
  559 + index_partitions();
507 560 return 0;
508 561 }
509 562  
... ... @@ -524,7 +577,6 @@
524 577 if (part_sort_add(dev, part) != 0)
525 578 return 1;
526 579  
527   - dev->num_parts++;
528 580 return 0;
529 581 }
530 582  
531 583  
... ... @@ -735,9 +787,10 @@
735 787 current_partnum = 0;
736 788 }
737 789 current_save();
  790 + return 0;
738 791 }
739 792  
740   -
  793 + index_partitions();
741 794 return 0;
742 795 }
743 796  
744 797  
745 798  
... ... @@ -771,13 +824,20 @@
771 824 */
772 825 static void device_add(struct mtd_device *dev)
773 826 {
  827 + u8 current_save_needed = 0;
  828 +
774 829 if (list_empty(&devices)) {
775 830 current_dev = dev;
776 831 current_partnum = 0;
777   - current_save();
  832 + current_save_needed = 1;
778 833 }
779 834  
780 835 list_add_tail(&dev->link, &devices);
  836 +
  837 + if (current_save_needed > 0)
  838 + current_save();
  839 + else
  840 + index_partitions();
781 841 }
782 842  
783 843 /**
... ... @@ -896,7 +956,7 @@
896 956 }
897 957 memset(dev, 0, sizeof(struct mtd_device));
898 958 dev->id = id;
899   - dev->num_parts = num_parts;
  959 + dev->num_parts = 0; /* part_sort_add increments num_parts */
900 960 INIT_LIST_HEAD(&dev->parts);
901 961 INIT_LIST_HEAD(&dev->link);
902 962  
... ... @@ -1548,7 +1608,7 @@
1548 1608 ids_changed = 1;
1549 1609  
1550 1610 if (parse_mtdids(ids) != 0) {
1551   - device_delall(&devices);
  1611 + devices_init();
1552 1612 return 1;
1553 1613 }
1554 1614