Mercurial > flash_v2
comparison packages/redboot/current/src/flash.c @ 210:d2c90368aeef
Merge from eCos master repository on 2002-05-23-21:39:14-BST
| author | jlarmour |
|---|---|
| date | Thu, 23 May 2002 22:59:51 +0000 |
| parents | e0c0827131d1 |
| children | 96e3418e1f5b |
comparison
equal
deleted
inserted
replaced
| 209:19edcb2e78cc | 210:d2c90368aeef |
|---|---|
| 32 // | 32 // |
| 33 // This exception does not invalidate any other reasons why a work based on | 33 // This exception does not invalidate any other reasons why a work based on |
| 34 // this file might be covered by the GNU General Public License. | 34 // this file might be covered by the GNU General Public License. |
| 35 // | 35 // |
| 36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. | 36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
| 37 // at http://sources.redhat.com/ecos/ecos-license | 37 // at http://sources.redhat.com/ecos/ecos-license/ |
| 38 // ------------------------------------------- | 38 // ------------------------------------------- |
| 39 //####ECOSGPLCOPYRIGHTEND#### | 39 //####ECOSGPLCOPYRIGHTEND#### |
| 40 //========================================================================== | 40 //========================================================================== |
| 41 //#####DESCRIPTIONBEGIN#### | 41 //#####DESCRIPTIONBEGIN#### |
| 42 // | 42 // |
| 593 bool length_set = false; | 593 bool length_set = false; |
| 594 bool img_size_set = false; | 594 bool img_size_set = false; |
| 595 bool no_copy = false; | 595 bool no_copy = false; |
| 596 void *err_addr; | 596 void *err_addr; |
| 597 struct fis_image_desc *img = NULL; | 597 struct fis_image_desc *img = NULL; |
| 598 bool slot_found, defaults_assumed; | 598 bool defaults_assumed; |
| 599 struct option_info opts[7]; | 599 struct option_info opts[7]; |
| 600 bool prog_ok = true; | 600 bool prog_ok = true; |
| 601 | 601 |
| 602 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, | 602 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM, |
| 603 (void **)&mem_addr, (bool *)&mem_addr_set, "memory base address"); | 603 (void **)&mem_addr, (bool *)&mem_addr_set, "memory base address"); |
| 634 } | 634 } |
| 635 if (!mem_addr_set && (load_address >= (CYG_ADDRESS)ram_start) && | 635 if (!mem_addr_set && (load_address >= (CYG_ADDRESS)ram_start) && |
| 636 (load_address_end) < (CYG_ADDRESS)ram_end) { | 636 (load_address_end) < (CYG_ADDRESS)ram_end) { |
| 637 mem_addr = load_address; | 637 mem_addr = load_address; |
| 638 mem_addr_set = true; | 638 mem_addr_set = true; |
| 639 defaults_assumed = true; | |
| 639 // Get entry address from loader, unless overridden | 640 // Get entry address from loader, unless overridden |
| 640 if (!entry_addr_set) | 641 if (!entry_addr_set) |
| 641 entry_addr = entry_address; | 642 entry_addr = entry_address; |
| 642 if (!length_set) { | 643 if (!length_set) { |
| 643 length = load_address_end - load_address; | 644 length = load_address_end - load_address; |
| 644 length_set = true; | 645 length_set = true; |
| 645 diag_printf("No memory address or length set.\n"); | |
| 646 if (!verify_action("Inferring base %p, length 0x%x", mem_addr, length)) | |
| 647 return; | |
| 648 } else if (defaults_assumed && !img_size_set) { | 646 } else if (defaults_assumed && !img_size_set) { |
| 649 /* We got length from the FIS table, so the size of the | 647 /* We got length from the FIS table, so the size of the |
| 650 actual loaded image becomes img_size */ | 648 actual loaded image becomes img_size */ |
| 651 img_size = load_address_end - load_address; | 649 img_size = load_address_end - load_address; |
| 652 img_size_set = true; | 650 img_size_set = true; |
| 653 diag_printf("No memory address set.\n"); | |
| 654 if (!verify_action("Inferring base %p, length 0x%x, image size 0x%x, entry %p\n", | |
| 655 mem_addr, length, img_size, entry_addr)) | |
| 656 return; | |
| 657 } | 651 } |
| 658 } | 652 } |
| 659 // Get the remaining fall-back values from the fis | 653 // Get the remaining fall-back values from the fis |
| 660 if (img) { | 654 if (img) { |
| 661 if (!exec_addr_set) { | 655 if (!exec_addr_set) { |
| 711 if (!flash_addr_set && !fis_find_free(&flash_addr, length)) { | 705 if (!flash_addr_set && !fis_find_free(&flash_addr, length)) { |
| 712 diag_printf("Can't locate %lx(%ld) bytes free in FLASH\n", length, length); | 706 diag_printf("Can't locate %lx(%ld) bytes free in FLASH\n", length, length); |
| 713 return; | 707 return; |
| 714 } | 708 } |
| 715 } | 709 } |
| 716 // Find a slot in the directory for this entry | 710 // First, see if the image by this name has agreable properties |
| 717 // First, see if an image by this name is already present | |
| 718 slot_found = false; | |
| 719 img = fis_lookup(name, NULL); | |
| 720 if (img) { | 711 if (img) { |
| 721 if (flash_addr_set && (img->flash_base != flash_addr)) { | 712 if (flash_addr_set && (img->flash_base != flash_addr)) { |
| 722 diag_printf("Image found, but FLASH address incorrect\n"); | 713 diag_printf("Image found, but flash address (%p)\n" |
| 714 " is incorrect (present image location %p)\n", | |
| 715 flash_addr, img->flash_base); | |
| 716 | |
| 723 return; | 717 return; |
| 724 } | 718 } |
| 725 if (img->size != length) { | 719 if (img->size != length) { |
| 726 diag_printf("Image found, but LENGTH is incorrect (0x%lx != 0x%lx)\n", img->size, length); | 720 diag_printf("Image found, but length (0x%lx, necessitating image size 0x%lx)\n" |
| 721 " is incorrect (present image size 0x%lx)\n", | |
| 722 img_size, length, img->size); | |
| 727 return; | 723 return; |
| 728 } | 724 } |
| 729 if (!verify_action("An image named '%s' exists", name)) { | 725 if (!verify_action("An image named '%s' exists", name)) { |
| 730 return; | 726 return; |
| 731 } else { | 727 } else { |
| 732 slot_found = true; | |
| 733 if (defaults_assumed) { | 728 if (defaults_assumed) { |
| 734 if (!verify_action("* CAUTION * about to program '%s'\n at %p..%p from %p", | 729 if (!verify_action("* CAUTION * about to program '%s'\n at %p..%p from %p", |
| 735 name, (void *)flash_addr, (void *)(flash_addr+img_size-1), | 730 name, (void *)flash_addr, (void *)(flash_addr+img_size-1), |
| 736 (void *)mem_addr)) { | 731 (void *)mem_addr)) { |
| 737 return; // The guy gave up | 732 return; // The guy gave up |
| 738 } | 733 } |
| 739 } | 734 } |
| 740 } | 735 } |
| 741 } | 736 } else { |
| 742 // If not found, try and find an empty slot | 737 // If not image by that name, try and find an empty slot |
| 743 if (!slot_found) { | |
| 744 img = (struct fis_image_desc *)fis_work_block; | 738 img = (struct fis_image_desc *)fis_work_block; |
| 745 for (i = 0; i < fisdir_size/sizeof(*img); i++, img++) { | 739 for (i = 0; i < fisdir_size/sizeof(*img); i++, img++) { |
| 746 if (img->name[0] == (unsigned char)0xFF) { | 740 if (img->name[0] == (unsigned char)0xFF) { |
| 747 slot_found = true; | |
| 748 break; | 741 break; |
| 749 } | 742 } |
| 750 } | 743 } |
| 751 } | 744 } |
| 752 if (!no_copy) { | 745 if (!no_copy) { |
| 792 { | 785 { |
| 793 char *name; | 786 char *name; |
| 794 int num_reserved, i, stat; | 787 int num_reserved, i, stat; |
| 795 void *err_addr; | 788 void *err_addr; |
| 796 struct fis_image_desc *img; | 789 struct fis_image_desc *img; |
| 797 bool slot_found; | |
| 798 | 790 |
| 799 if (!scan_opts(argc, argv, 2, 0, 0, (void **)&name, OPTION_ARG_TYPE_STR, "image name")) | 791 if (!scan_opts(argc, argv, 2, 0, 0, (void **)&name, OPTION_ARG_TYPE_STR, "image name")) |
| 800 { | 792 { |
| 801 fis_usage("invalid arguments"); | 793 fis_usage("invalid arguments"); |
| 802 return; | 794 return; |
| 804 #ifdef CYGHWR_REDBOOT_ARM_FLASH_SIB | 796 #ifdef CYGHWR_REDBOOT_ARM_FLASH_SIB |
| 805 // FIXME: this is somewhat half-baked | 797 // FIXME: this is somewhat half-baked |
| 806 arm_fis_delete(name); | 798 arm_fis_delete(name); |
| 807 return; | 799 return; |
| 808 #endif | 800 #endif |
| 809 slot_found = false; | |
| 810 img = (struct fis_image_desc *)fis_work_block; | 801 img = (struct fis_image_desc *)fis_work_block; |
| 811 num_reserved = 0; | 802 num_reserved = 0; |
| 812 #ifdef CYGOPT_REDBOOT_FIS_RESERVED_BASE | 803 #ifdef CYGOPT_REDBOOT_FIS_RESERVED_BASE |
| 813 num_reserved++; | 804 num_reserved++; |
| 814 #endif | 805 #endif |
