Changeset 12322
- Timestamp:
- 06/20/09 02:44:04 (4 years ago)
- Location:
- ar5315_microredboot/microredboot/boot/src
- Files:
-
- 3 edited
-
head-ar531x.S (modified) (2 diffs)
-
misc_lzma.c (modified) (3 diffs)
-
ramconfig.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ar5315_microredboot/microredboot/boot/src/head-ar531x.S
r12320 r12322 336 336 .endm 337 337 338 338 339 /* 339 340 * romInitFlash - init flash address space in ar531x flash controller … … 347 348 /* 0x7 == 12.5ns * 8 == 100ns which is typical for flash roms */ 348 349 or t0, FLASHCTL_E | FLASHCTL_AC_8M | FLASHCTL_RBLE | \ 349 FLASHCTL_WP | \350 350 (0x01 << FLASHCTL_IDCY_S) | \ 351 351 (0x07 << FLASHCTL_WST1_S) | \ -
ar5315_microredboot/microredboot/boot/src/misc_lzma.c
r12321 r12322 700 700 #else 701 701 702 703 704 705 typedef unsigned char FLASH_DATA_T; 706 #define FLASH_P2V( _a_ ) ((volatile FLASH_DATA_T *)((unsigned int)((_a_)))) 707 #define FLASH_BLANKVALUE (FLASH_DATA_T)-111 708 #define FLASHWORD(x) ((FLASH_DATA_T)(x)) 709 #define FLASH_POLLING_TIMEOUT (3000000) 710 #define FLASH_READ_ID FLASHWORD( 0x90 ) 711 #define FLASH_WP_STATE FLASHWORD( 0x90 ) 712 #define FLASH_RESET FLASHWORD( 0xF0 ) 713 #define FLASH_PROGRAM FLASHWORD( 0xA0 ) 714 #define FLASH_BLOCK_ERASE FLASHWORD( 0x30 ) 715 #define FLASH_Query FLASHWORD( 0x98 ) // Add by Jason for CFI support 716 717 #define FLASH_DATA FLASHWORD( 0x80 ) // Data complement 718 #define FLASH_BUSY FLASHWORD( 0x40 ) // "Toggle" bit 719 #define FLASH_ERR FLASHWORD( 0x20 ) 720 #define FLASH_SECTOR_ERASE_TIMER FLASHWORD( 0x08 ) 721 722 #define FLASH_UNLOCKED FLASHWORD( 0x00 ) 723 #define FLASH_WP_ADDR (0x12) 724 725 #define FLASH_SETUP_ADDR1 (0x555) 726 #define FLASH_SETUP_ADDR2 (0x2AA) 727 #define FLASH_VENDORID_ADDR (0x0) 728 #define FLASH_DEVICEID_ADDR (0x1) 729 #define FLASH_DEVICEID_ADDR2 (0xe) 730 #define FLASH_DEVICEID_ADDR3 (0xf) 731 //#define FLASH_WP_ADDR (0x12) 732 #define FLASH_SETUP_CODE1 FLASHWORD( 0xAA ) 733 #define FLASH_SETUP_CODE2 FLASHWORD( 0x55 ) 734 #define FLASH_SETUP_ERASE FLASHWORD( 0x80 ) 735 #define FLASH_ERR_OK 0x0 736 #define FLASH_ERR_DRV_TIMEOUT -1 737 738 static void 739 flash_query(void* data) 740 { 741 volatile FLASH_DATA_T *ROM; 742 volatile FLASH_DATA_T *f_s1, *f_s2; 743 FLASH_DATA_T* id = (FLASH_DATA_T*) data; 744 FLASH_DATA_T w; 745 long timeout = 50000; 746 747 ROM = (volatile FLASH_DATA_T*) ((unsigned int)nvramdetect & ~(0x800000-1)); 748 *(FLASH_P2V(ROM)) = FLASH_RESET; 749 750 f_s1 = FLASH_P2V(ROM+FLASH_SETUP_ADDR1); 751 f_s2 = FLASH_P2V(ROM+FLASH_SETUP_ADDR2); 752 753 *f_s1 = FLASH_RESET; 754 w = *(FLASH_P2V(ROM)); 755 756 *f_s1 = FLASH_SETUP_CODE1; 757 *f_s2 = FLASH_SETUP_CODE2; 758 *f_s1 = FLASH_READ_ID; 759 760 id[0] = -1; 761 id[1] = -1; 762 763 // Manufacturers' code 764 id[0] = *(FLASH_P2V(ROM+FLASH_VENDORID_ADDR)); 765 // Part number 766 id[1] = *(FLASH_P2V(ROM+FLASH_DEVICEID_ADDR)); 767 id[2] = *(FLASH_P2V(ROM+FLASH_DEVICEID_ADDR2)); 768 id[3] = *(FLASH_P2V(ROM+FLASH_DEVICEID_ADDR3)); 769 770 771 *(FLASH_P2V(ROM)) = FLASH_RESET; 772 773 // Stall, waiting for flash to return to read mode. 774 while ((--timeout != 0) && (w != *(FLASH_P2V(ROM)))) ; 775 } 776 777 778 #define AR531X_FLASHCTL 0xb8400000 779 #define AR531X_FLASHCTL0 (AR531X_FLASHCTL + 0x00) 780 #define AR531X_FLASHCTL1 (AR531X_FLASHCTL + 0x04) 781 #define AR531X_FLASHCTL2 (AR531X_FLASHCTL + 0x08) 782 #define FLASHCTL_IDCY 0x0000000f /* Idle cycle turn around time */ 783 #define FLASHCTL_IDCY_S 0 784 #define FLASHCTL_WST1 0x000003e0 /* Wait state 1 */ 785 #define FLASHCTL_WST1_S 5 786 #define FLASHCTL_RBLE 0x00000400 /* Read byte lane enable */ 787 #define FLASHCTL_WST2 0x0000f800 /* Wait state 2 */ 788 #define FLASHCTL_WST2_S 11 789 #define FLASHCTL_AC 0x00070000 /* Flash address check (added) */ 790 #define FLASHCTL_AC_S 16 791 #define FLASHCTL_AC_128K 0x00000000 792 #define FLASHCTL_AC_256K 0x00010000 793 #define FLASHCTL_AC_512K 0x00020000 794 #define FLASHCTL_AC_1M 0x00030000 795 #define FLASHCTL_AC_2M 0x00040000 796 #define FLASHCTL_AC_4M 0x00050000 797 #define FLASHCTL_AC_8M 0x00060000 798 #define FLASHCTL_AC_RES 0x00070000 /* 16MB is not supported */ 799 #define FLASHCTL_E 0x00080000 /* Flash bank enable (added) */ 800 #define FLASHCTL_BUSERR 0x01000000 /* Bus transfer error status flag */ 801 #define FLASHCTL_WPERR 0x02000000 /* Write protect error status flag */ 802 #define FLASHCTL_WP 0x04000000 /* Write protect */ 803 #define FLASHCTL_BM 0x08000000 /* Burst mode */ 804 #define FLASHCTL_MW 0x30000000 /* Memory width */ 805 #define FLASHCTL_MWx8 0x00000000 /* Memory width x8 */ 806 #define FLASHCTL_MWx16 0x10000000 /* Memory width x16 */ 807 #define FLASHCTL_MWx32 0x20000000 /* Memory width x32 (not supported) */ 808 #define FLASHCTL_ATNR 0x00000000 /* Access type == no retry */ 809 #define FLASHCTL_ATR 0x80000000 /* Access type == retry every */ 810 #define FLASHCTL_ATR4 0xc0000000 /* Access type == retry every 4 */ 811 702 812 static int flash_erase_nvram(unsigned int flashsize, unsigned int blocksize) 703 813 { … … 708 818 return; 709 819 } 820 unsigned int flash_ctl = sysRegRead(AR531X_FLASHCTL0); 821 822 flash_ctl &= FLASHCTL_MW; 823 824 /* 825 * Configure flash bank 0. 826 * We lie about the prom size here in order to allow it to be multiply 827 * mapped. The heuristics, below, count on that in order to easily 828 * find configuration data. The flash drivers know how big the flash 829 * really is. 830 */ 831 /*flash_ctl = FLASHCTL_E | 832 FLASHCTL_AC_8M | 833 FLASHCTL_RBLE | 834 (0x01 << FLASHCTL_IDCY_S) | 835 (0x07 << FLASHCTL_WST1_S) | 836 (0x07 << FLASHCTL_WST2_S) | 837 flash_ctl; 838 printf("flashctl0 = 0x%08X\n",flash_ctl); 839 840 sysRegWrite(AR531X_FLASHCTL0, flash_ctl); 841 842 flash_ctl = sysRegRead(AR531X_FLASHCTL1); 843 flash_ctl &= ~(FLASHCTL_E | FLASHCTL_AC); 844 sysRegWrite(AR531X_FLASHCTL1, flash_ctl); 845 846 flash_ctl = sysRegRead(AR531X_FLASHCTL2); 847 flash_ctl &= ~(FLASHCTL_E | FLASHCTL_AC); 848 sysRegWrite(AR531X_FLASHCTL2, flash_ctl); 849 */ 850 851 852 853 854 855 856 FLASH_DATA_T id[4]; 857 puts("read id\n"); 858 flash_query(id); 859 printf("FLASH MANID: %X DEVID: %X DEVID2: %X DEVID3: %X\n",id[0],id[1],id[2],id[3]); 860 710 861 printf("erasing nvram at [0x%08X]\n", nvramdetect); 862 863 volatile FLASH_DATA_T* ROM, *BANK; 864 volatile FLASH_DATA_T* b_p = (FLASH_DATA_T*) (nvramdetect); 865 volatile FLASH_DATA_T *b_v; 866 volatile FLASH_DATA_T *f_s0, *f_s1, *f_s2; 867 int timeout = 50000; 868 FLASH_DATA_T state; 869 int len; 870 BANK = ROM = (volatile FLASH_DATA_T*)((unsigned long)nvramdetect & ~(0x800000-1)); 871 f_s0 = FLASH_P2V(BANK); 872 f_s1 = FLASH_P2V(BANK + FLASH_SETUP_ADDR1); 873 f_s2 = FLASH_P2V(BANK + FLASH_SETUP_ADDR2); 874 len = blocksize; 875 int res = FLASH_ERR_OK; 876 877 { 878 #if 0 879 *f_s1 = FLASH_SETUP_CODE1; 880 *f_s2 = FLASH_SETUP_CODE2; 881 *f_s1 = FLASH_WP_STATE; 882 state = *FLASH_P2V(b_p+2); 883 *f_s0 = FLASH_RESET; 884 885 if (FLASH_UNLOCKED != state) 886 { 887 puts("error unprotecting flash\n"); 888 *FLASH_P2V(ROM) = FLASH_RESET; 889 return 0; 890 } 891 #endif 892 b_v = FLASH_P2V(b_p); 893 894 *f_s1 = FLASH_SETUP_CODE1; 895 *f_s2 = FLASH_SETUP_CODE2; 896 *f_s1 = FLASH_SETUP_ERASE; 897 *f_s1 = FLASH_SETUP_CODE1; 898 *f_s2 = FLASH_SETUP_CODE2; 899 *b_v = FLASH_BLOCK_ERASE; 900 timeout = FLASH_POLLING_TIMEOUT; 901 while (1) { 902 state = *b_v; 903 if ((state & FLASH_SECTOR_ERASE_TIMER) 904 == FLASH_SECTOR_ERASE_TIMER) break; 905 udelay(1); 906 if (--timeout == 0) { 907 puts("flash erase timeout\n"); 908 break; 909 } 910 } 911 if (FLASH_ERR_OK == res) { 912 timeout = FLASH_POLLING_TIMEOUT; 913 while (1) { 914 state = *b_v; 915 if (FLASH_BLANKVALUE == state) { 916 break; 917 } 918 udelay(1); 919 if (--timeout == 0) { 920 puts("flash erase timeout while waiting for erase complete\n"); 921 res = FLASH_ERR_DRV_TIMEOUT; 922 break; 923 } 924 } 925 } 926 927 if (FLASH_ERR_OK != res) 928 { 929 *FLASH_P2V(ROM) = FLASH_RESET; 930 return -1; 931 } 932 933 while (len > 0) { 934 b_v = FLASH_P2V(b_p++); 935 if (*b_v != FLASH_BLANKVALUE) { 936 if (FLASH_ERR_OK == res) 937 { 938 puts("erase verify failed\n"); 939 } 940 return 0; 941 } 942 len -= sizeof(*b_p); 943 } 944 945 946 947 948 } 949 950 #if 0 951 711 952 volatile unsigned short *block = (unsigned short *)nvramdetect; 712 953 volatile unsigned short *p555 = … … 751 992 } 752 993 *block = 0xf0; /* Do reset */ 994 995 753 996 puts("erase failed!\n"); 754 997 return -1; 998 #endif 755 999 } 756 1000 -
ar5315_microredboot/microredboot/boot/src/ramconfig.h
r12320 r12322 1 1 #define RAM_SIZE 0x2000000 2 2 #define AR5312 1 3 #define RESETBUTTON 0x 063 #define RESETBUTTON 0x16
Note: See TracChangeset
for help on using the changeset viewer.
