Ticket #109: flashrom_sc520.diff

File flashrom_sc520.diff, 2.7 KB (added by stepan, 5 months ago)

flashrom sc520 autodetection

  • Makefile

    Replace #ifdefs for sc520 systems by run time probing.
    
    Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
    
    
     
    1111INSTALL = /usr/bin/install 
    1212PREFIX  = /usr/local 
    1313#CFLAGS  = -O2 -g -Wall -Werror 
    14 CFLAGS  = -Os -Wall -Werror # -DTS5300 
     14CFLAGS  = -Os -Wall -Werror 
    1515OS_ARCH = $(shell uname) 
    1616ifeq ($(OS_ARCH), SunOS) 
    1717LDFLAGS = -lpci -lz 
  • flashrom.c

     
    119119 
    120120                size = flash->total_size * 1024; 
    121121 
    122 #ifdef TS5300 
    123                 // FIXME: Wrong place for this decision 
    124                 // FIXME: This should be autodetected. It is trivial. 
    125                 flash_baseaddr = 0x9400000; 
    126 #else 
     122 
     123                // FIXME Calculating the flash base address now. This is the 
     124                // wrong place to do this. 
     125 
     126                /* Usually on the x86 architectures (and on other PC-like 
     127                 * platforms like some Alphas or Itanium) the system flash 
     128                 * is mapped right below 4G. 
     129                 * On the AMD Elan SC520 only a small piece of the system flash 
     130                 * is mapped there, but the complete flash is mapped somewhere 
     131                 * below 1G. The position can be determined by the BOOTCS PAR 
     132                 * register 
     133                 */ 
     134 
     135                /* Assume default PC architecture */ 
    127136                flash_baseaddr = (0xffffffff - size + 1); 
    128 #endif 
    129137 
     138                if (pci_dev_find(0x1022, 0x3000) != NULL) { /* Elan SC520 */ 
     139                        int i, bootcs_found = 0; 
     140                        uint32_t parx = 0; 
     141                        void *mmcr; 
     142 
     143                        /* 1. Map MMCR */ 
     144                        mmcr = mmap(0, getpagesize(), PROT_WRITE | PROT_READ, 
     145                                        MAP_SHARED, fd_mem, (off_t)0xFFFEF000); 
     146 
     147                        if (mmcr == MAP_FAILED) { 
     148                                perror("Can't mmap Elan SC520 specific registers using " MEM_DEV); 
     149                                exit(1); 
     150                        } 
     151 
     152                        /* 2. Scan PAR0 (0x88) - PAR15 (0xc4) for  
     153                         *    BOOTCS region (PARx[31:29] = 100b) 
     154                         */ 
     155                        for (i = 0x88; i <= 0xc4; i += 4) { 
     156                                parx = *(volatile uint32_t *)(mmcr + i); 
     157                                if ((parx >> 29) == 4) { 
     158                                        bootcs_found = 1; 
     159                                        break; /* BOOTCS found */ 
     160                                } 
     161                        } 
     162 
     163                        /* 3. PARx[25] = 1b --> flash_baseaddr[29:16] = PARx[13:0] 
     164                         *    PARx[25] = 0b --> flash_baseaddr[29:12] = PARx[17:0] 
     165                         */ 
     166                        if (bootcs_found) { 
     167                                if (parx & (1 << 25)) { 
     168                                        parx &= (1 << 14) - 1; /* Mask [13:0] */ 
     169                                        flash_baseaddr = parx << 16; 
     170                                } else { 
     171                                        parx &= (1 << 18) - 1; /* Mask [17:0] */ 
     172                                        flash_baseaddr = parx << 12; 
     173                                } 
     174                        } else { 
     175                                printf("AMD Elan SC520 detected, but no BOOTCS. Assuming flash at 4G\n"); 
     176                        } 
     177 
     178                        /* 4. Clean up */ 
     179                        munmap (mmcr, getpagesize()); 
     180                } 
     181 
    130182                /* If getpagesize() > size ->  
    131183                 * "Can't mmap memory using /dev/mem: Invalid argument" 
    132184                 * This should never happen as we don't support any flash chips