Changeset 3418

Show
Ignore:
Timestamp:
07/07/08 08:38:51 (3 months ago)
Author:
stuge
Message:

flashrom: Trivial SPI cleanups

While writing a new SPI driver I fixed some things in the SPI code:
All calls to spi_command() had unneccessary #define duplications, and in some
cases the read count define could theoretically become harmful because NULL was
passed for the read buffer. Avoid a crash, should someone change the #defines.

I also noticed that the only caller of spi_page_program() was the it87 driver,
and spi_page_program() could only call back into the it87 driver. Removed the
function for easier-to-follow code and made it8716f_spi_page_program() static.
The ichspi driver's static page functions are already static.

Signed-off-by: Peter Stuge <peter@…>
Acked-by: Peter Stuge <peter@…>

Location:
trunk/util/flashrom
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/util/flashrom/flash.h

    r3416 r3418  
    424424void spi_disable_blockprotect(void); 
    425425void spi_byte_program(int address, uint8_t byte); 
    426 void spi_page_program(int block, uint8_t *buf, uint8_t *bios); 
    427426void spi_nbyte_read(int address, uint8_t *bytes, int len); 
    428427 
     
    448447int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf); 
    449448int it8716f_spi_chip_write(struct flashchip *flash, uint8_t *buf); 
    450 void it8716f_spi_page_program(int block, uint8_t *buf, uint8_t *bios); 
    451449 
    452450/* jedec.c */ 
  • trunk/util/flashrom/it87spi.c

    r3401 r3418  
    193193 
    194194/* Page size is usually 256 bytes */ 
    195 void it8716f_spi_page_program(int block, uint8_t *buf, uint8_t *bios) { 
     195static void it8716f_spi_page_program(int block, uint8_t *buf, uint8_t *bios) { 
    196196        int i; 
    197197 
     
    262262        } else { 
    263263                for (i = 0; i < total_size / 256; i++) { 
    264                         spi_page_program(i, buf, (uint8_t *)flash->virtual_memory); 
    265                 } 
    266         } 
    267         return 0; 
    268 } 
    269  
     264                        it8716f_spi_page_program(i, buf, (uint8_t *)flash->virtual_memory); 
     265                } 
     266        } 
     267        return 0; 
     268} 
     269 
  • trunk/util/flashrom/spi.c

    r3401 r3418  
    5252        const unsigned char cmd[JEDEC_RDID_OUTSIZE] = {JEDEC_RDID}; 
    5353 
    54         if (spi_command(JEDEC_RDID_OUTSIZE, bytes, cmd, readarr)) 
     54        if (spi_command(sizeof(cmd), bytes, cmd, readarr)) 
    5555                return 1; 
    5656        printf_debug("RDID returned %02x %02x %02x.\n", readarr[0], readarr[1], readarr[2]); 
     
    6262        const unsigned char cmd[JEDEC_RES_OUTSIZE] = {JEDEC_RES, 0, 0, 0}; 
    6363 
    64         if (spi_command(JEDEC_RES_OUTSIZE, JEDEC_RES_INSIZE, cmd, readarr)) 
     64        if (spi_command(sizeof(cmd), JEDEC_RES_INSIZE, cmd, readarr)) 
    6565                return 1; 
    6666        printf_debug("RES returned %02x.\n", readarr[0]); 
     
    7373 
    7474        /* Send WREN (Write Enable) */ 
    75         spi_command(JEDEC_WREN_OUTSIZE, JEDEC_WREN_INSIZE, cmd, NULL); 
     75        spi_command(sizeof(cmd), 0, cmd, NULL); 
    7676} 
    7777 
     
    8181 
    8282        /* Send WRDI (Write Disable) */ 
    83         spi_command(JEDEC_WRDI_OUTSIZE, JEDEC_WRDI_INSIZE, cmd, NULL); 
     83        spi_command(sizeof(cmd), 0, cmd, NULL); 
    8484} 
    8585 
     
    183183{ 
    184184        const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = {JEDEC_RDSR}; 
    185         unsigned char readarr[1]; 
     185        unsigned char readarr[JEDEC_RDSR_INSIZE]; 
    186186 
    187187        /* Read Status Register */ 
    188         spi_command(JEDEC_RDSR_OUTSIZE, JEDEC_RDSR_INSIZE, cmd, readarr); 
     188        spi_command(sizeof(cmd), sizeof(readarr), cmd, readarr); 
    189189        return readarr[0]; 
    190190} 
     
    274274        spi_write_enable(); 
    275275        /* Send CE (Chip Erase) */ 
    276         spi_command(JEDEC_CE_C7_OUTSIZE, JEDEC_CE_C7_INSIZE, cmd, NULL); 
     276        spi_command(sizeof(cmd), 0, cmd, NULL); 
    277277        /* Wait until the Write-In-Progress bit is cleared. 
    278278         * This usually takes 1-85 s, so wait in 1 s steps. 
     
    297297        spi_write_enable(); 
    298298        /* Send BE (Block Erase) */ 
    299         spi_command(JEDEC_BE_D8_OUTSIZE, JEDEC_BE_D8_INSIZE, cmd, NULL); 
     299        spi_command(sizeof(cmd), 0, cmd, NULL); 
    300300        /* Wait until the Write-In-Progress bit is cleared. 
    301301         * This usually takes 100-4000 ms, so wait in 100 ms steps. 
     
    316316        spi_write_enable(); 
    317317        /* Send SE (Sector Erase) */ 
    318         spi_command(JEDEC_SE_OUTSIZE, JEDEC_SE_INSIZE, cmd, NULL); 
     318        spi_command(sizeof(cmd), 0, cmd, NULL); 
    319319        /* Wait until the Write-In-Progress bit is cleared. 
    320320         * This usually takes 15-800 ms, so wait in 10 ms steps. 
     
    325325} 
    326326 
    327 void spi_page_program(int block, uint8_t *buf, uint8_t *bios) 
    328 { 
    329         switch (flashbus) { 
    330         case BUS_TYPE_IT87XX_SPI: 
    331                 it8716f_spi_page_program(block, buf, bios); 
    332                 break; 
    333         case BUS_TYPE_ICH7_SPI: 
    334         case BUS_TYPE_ICH9_SPI: 
    335                 printf_debug("%s called, but not implemented for ICH\n", __FUNCTION__); 
    336                 break; 
    337         default: 
    338                 printf_debug("%s called, but no SPI chipset/strapping detected\n", __FUNCTION__); 
    339         } 
    340 } 
    341  
    342327/* 
    343328 * This is according the SST25VF016 datasheet, who knows it is more 
     
    349334 
    350335        /* Send WRSR (Write Status Register) */ 
    351         spi_command(JEDEC_WRSR_OUTSIZE, JEDEC_WRSR_INSIZE, cmd, NULL); 
     336        spi_command(sizeof(cmd), 0, cmd, NULL); 
    352337} 
    353338 
     
    362347 
    363348        /* Send Byte-Program */ 
    364         spi_command(JEDEC_BYTE_PROGRAM_OUTSIZE, JEDEC_BYTE_PROGRAM_INSIZE, cmd, NULL); 
     349        spi_command(sizeof(cmd), 0, cmd, NULL); 
    365350} 
    366351 
     
    387372 
    388373        /* Send Read */ 
    389         spi_command(JEDEC_READ_OUTSIZE, len, cmd, bytes); 
     374        spi_command(sizeof(cmd), len, cmd, bytes); 
    390375} 
    391376 
  • trunk/util/flashrom/spi.h

    r3320 r3418  
    5050#define JEDEC_CE_60_INSIZE      0x00 
    5151 
    52 /* Chip Erase 0xc7 is supported by ST/EON/Macronix chips. */ 
     52/* Chip Erase 0xc7 is supported by SST/ST/EON/Macronix chips. */ 
    5353#define JEDEC_CE_C7             0xc7 
    5454#define JEDEC_CE_C7_OUTSIZE     0x01