Changeset 1474


Ignore:
Timestamp:
12/18/11 16:01:24 (5 months ago)
Author:
hailfinger
Message:

Add struct flashctx * parameter to all functions accessing flash chips.

All programmer access function prototypes except init have been made
static and moved to the respective file.

A few internal functions in flash chip drivers had chipaddr parameters
which are no longer needed.

The lines touched by flashctx changes have been adjusted to 80 columns
except in header files.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>
Acked-by: Michael Karcher <flashrom@…>

Location:
trunk
Files:
42 edited

Legend:

Unmodified
Added
Removed
  • trunk/82802ab.c

    r1473 r1474  
    4848 
    4949        /* Reset to get a clean state */ 
    50         chip_writeb(0xFF, bios); 
     50        chip_writeb(flash, 0xFF, bios); 
    5151        programmer_delay(10); 
    5252 
    5353        /* Enter ID mode */ 
    54         chip_writeb(0x90, bios); 
    55         programmer_delay(10); 
    56  
    57         id1 = chip_readb(bios + (0x00 << shifted)); 
    58         id2 = chip_readb(bios + (0x01 << shifted)); 
     54        chip_writeb(flash, 0x90, bios); 
     55        programmer_delay(10); 
     56 
     57        id1 = chip_readb(flash, bios + (0x00 << shifted)); 
     58        id2 = chip_readb(flash, bios + (0x01 << shifted)); 
    5959 
    6060        /* Leave ID mode */ 
    61         chip_writeb(0xFF, bios); 
     61        chip_writeb(flash, 0xFF, bios); 
    6262 
    6363        programmer_delay(10); 
     
    7272         * flash contents. 
    7373         */ 
    74         flashcontent1 = chip_readb(bios + (0x00 << shifted)); 
    75         flashcontent2 = chip_readb(bios + (0x01 << shifted)); 
     74        flashcontent1 = chip_readb(flash, bios + (0x00 << shifted)); 
     75        flashcontent2 = chip_readb(flash, bios + (0x01 << shifted)); 
    7676 
    7777        if (id1 == flashcontent1) 
     
    9595        chipaddr bios = flash->virtual_memory; 
    9696 
    97         chip_writeb(0x70, bios); 
    98         if ((chip_readb(bios) & 0x80) == 0) {   // it's busy 
    99                 while ((chip_readb(bios) & 0x80) == 0) ; 
    100         } 
    101  
    102         status = chip_readb(bios); 
     97        chip_writeb(flash, 0x70, bios); 
     98        if ((chip_readb(flash, bios) & 0x80) == 0) {    // it's busy 
     99                while ((chip_readb(flash, bios) & 0x80) == 0) ; 
     100        } 
     101 
     102        status = chip_readb(flash, bios); 
    103103 
    104104        /* Reset to get a clean state */ 
    105         chip_writeb(0xFF, bios); 
     105        chip_writeb(flash, 0xFF, bios); 
    106106 
    107107        return status; 
     
    114114 
    115115        for (i = 0; i < flash->total_size * 1024; i+= flash->page_size) 
    116                 chip_writeb(0, flash->virtual_registers + i + 2); 
     116                chip_writeb(flash, 0, flash->virtual_registers + i + 2); 
    117117 
    118118        return 0; 
     
    126126 
    127127        // clear status register 
    128         chip_writeb(0x50, bios + page); 
     128        chip_writeb(flash, 0x50, bios + page); 
    129129 
    130130        // now start it 
    131         chip_writeb(0x20, bios + page); 
    132         chip_writeb(0xd0, bios + page); 
     131        chip_writeb(flash, 0x20, bios + page); 
     132        chip_writeb(flash, 0xd0, bios + page); 
    133133        programmer_delay(10); 
    134134 
     
    142142 
    143143/* chunksize is 1 */ 
    144 int write_82802ab(struct flashctx *flash, uint8_t *src, unsigned int start, unsigned int len) 
     144int write_82802ab(struct flashctx *flash, uint8_t *src, unsigned int start, 
     145                  unsigned int len) 
    145146{ 
    146147        int i; 
     
    149150        for (i = 0; i < len; i++) { 
    150151                /* transfer data from source to destination */ 
    151                 chip_writeb(0x40, dst); 
    152                 chip_writeb(*src++, dst++); 
     152                chip_writeb(flash, 0x40, dst); 
     153                chip_writeb(flash, *src++, dst++); 
    153154                wait_82802ab(flash); 
    154155        } 
     
    165166 
    166167        /* Clear status register */ 
    167         chip_writeb(0x50, bios); 
     168        chip_writeb(flash, 0x50, bios); 
    168169 
    169170        /* Read identifier codes */ 
    170         chip_writeb(0x90, bios); 
     171        chip_writeb(flash, 0x90, bios); 
    171172 
    172173        /* Read master lock-bit */ 
    173         mcfg = chip_readb(bios + 0x3); 
     174        mcfg = chip_readb(flash, bios + 0x3); 
    174175        msg_cdbg("master lock is "); 
    175176        if (mcfg) { 
     
    182183        /* Read block lock-bits */ 
    183184        for (i = 0; i < flash->total_size * 1024; i+= (64 * 1024)) { 
    184                 bcfg = chip_readb(bios + i + 2); // read block lock config 
     185                bcfg = chip_readb(flash, bios + i + 2); // read block lock config 
    185186                msg_cdbg("block lock at %06x is %slocked!\n", i, bcfg ? "" : "un"); 
    186187                if (bcfg) { 
     
    190191 
    191192        /* Reset chip */ 
    192         chip_writeb(0xFF, bios); 
     193        chip_writeb(flash, 0xFF, bios); 
    193194 
    194195        /* Unlock: clear block lock-bits, if needed */ 
    195196        if (can_unlock && need_unlock) { 
    196197                msg_cdbg("Unlock: "); 
    197                 chip_writeb(0x60, bios); 
    198                 chip_writeb(0xD0, bios); 
    199                 chip_writeb(0xFF, bios); 
     198                chip_writeb(flash, 0x60, bios); 
     199                chip_writeb(flash, 0xD0, bios); 
     200                chip_writeb(flash, 0xFF, bios); 
    200201                msg_cdbg("Done!\n"); 
    201202        } 
     
    221222 
    222223        /* Read identifier codes */ 
    223         chip_writeb(0x90, bios); 
     224        chip_writeb(flash, 0x90, bios); 
    224225 
    225226        /* Read master lock-bit */ 
    226         mcfg = chip_readb(bios + 0x3); 
     227        mcfg = chip_readb(flash, bios + 0x3); 
    227228        msg_cdbg("master lock is "); 
    228229        if (mcfg) { 
     
    236237        for (i = 0; i < flash->total_size * 1024; 
    237238             i += (i >= (64 * 1024) ? 64 * 1024 : 8 * 1024)) { 
    238                 bcfg = chip_readb(bios + i + 2); /* read block lock config */ 
     239                bcfg = chip_readb(flash, bios + i + 2); /* read block lock config */ 
    239240                msg_cdbg("block lock at %06x is %slocked!\n", i, 
    240241                         bcfg ? "" : "un"); 
     
    244245 
    245246        /* Reset chip */ 
    246         chip_writeb(0xFF, bios); 
     247        chip_writeb(flash, 0xFF, bios); 
    247248 
    248249        /* Unlock: clear block lock-bits, if needed */ 
    249250        if (can_unlock && need_unlock) { 
    250251                msg_cdbg("Unlock: "); 
    251                 chip_writeb(0x60, bios); 
    252                 chip_writeb(0xD0, bios); 
    253                 chip_writeb(0xFF, bios); 
     252                chip_writeb(flash, 0x60, bios); 
     253                chip_writeb(flash, 0xD0, bios); 
     254                chip_writeb(flash, 0xFF, bios); 
    254255                wait_82802ab(flash); 
    255256                msg_cdbg("Done!\n"); 
  • trunk/a25.c

    r1473 r1474  
    3434        uint8_t status; 
    3535 
    36         status = spi_read_status_register(); 
     36        status = spi_read_status_register(flash); 
    3737        msg_cdbg("Chip status register is %02x\n", status); 
    3838 
     
    5050        uint8_t status; 
    5151 
    52         status = spi_read_status_register(); 
     52        status = spi_read_status_register(flash); 
    5353        msg_cdbg("Chip status register is %02x\n", status); 
    5454 
     
    6565        uint8_t status; 
    6666 
    67         status = spi_read_status_register(); 
     67        status = spi_read_status_register(flash); 
    6868        msg_cdbg("Chip status register is %02x\n", status); 
    6969 
     
    8383        uint8_t status; 
    8484 
    85         status = spi_read_status_register(); 
     85        status = spi_read_status_register(flash); 
    8686        msg_cdbg("Chip status register is %02x\n", status); 
    8787 
  • trunk/at25.c

    r1473 r1474  
    6262        uint8_t status; 
    6363 
    64         status = spi_read_status_register(); 
     64        status = spi_read_status_register(flash); 
    6565        msg_cdbg("Chip status register is %02x\n", status); 
    6666 
     
    8585        uint8_t status; 
    8686 
    87         status = spi_read_status_register(); 
     87        status = spi_read_status_register(flash); 
    8888        msg_cdbg("Chip status register is %02x\n", status); 
    8989 
     
    104104        uint8_t status; 
    105105 
    106         status = spi_read_status_register(); 
     106        status = spi_read_status_register(flash); 
    107107        msg_cdbg("Chip status register is %02x\n", status); 
    108108 
     
    128128        uint8_t status; 
    129129 
    130         status = spi_read_status_register(); 
     130        status = spi_read_status_register(flash); 
    131131        msg_cdbg("Chip status register is %02x\n", status); 
    132132 
     
    152152        uint8_t status; 
    153153 
    154         status = spi_read_status_register(); 
     154        status = spi_read_status_register(flash); 
    155155        msg_cdbg("Chip status register is %02x\n", status); 
    156156 
     
    169169        int result; 
    170170 
    171         status = spi_read_status_register(); 
     171        status = spi_read_status_register(flash); 
    172172        /* If block protection is disabled, stop here. */ 
    173173        if ((status & (3 << 2)) == 0) 
     
    196196                return result; 
    197197        } 
    198         status = spi_read_status_register(); 
     198        status = spi_read_status_register(flash); 
    199199        if ((status & (3 << 2)) != 0) { 
    200200                msg_cerr("Block protection could not be disabled!\n"); 
     
    224224        int result; 
    225225 
    226         status = spi_read_status_register(); 
     226        status = spi_read_status_register(flash); 
    227227        /* If block protection is disabled, stop here. */ 
    228228        if ((status & 0x6c) == 0) 
     
    245245                return result; 
    246246        } 
    247         status = spi_read_status_register(); 
     247        status = spi_read_status_register(flash); 
    248248        if ((status & 0x6c) != 0) { 
    249249                msg_cerr("Block protection could not be disabled!\n"); 
     
    258258        int result; 
    259259 
    260         status = spi_read_status_register(); 
     260        status = spi_read_status_register(flash); 
    261261        /* If block protection is disabled, stop here. */ 
    262262        if ((status & 0x7c) == 0) 
     
    279279                return result; 
    280280        } 
    281         status = spi_read_status_register(); 
     281        status = spi_read_status_register(flash); 
    282282        if ((status & 0x7c) != 0) { 
    283283                msg_cerr("Block protection could not be disabled!\n"); 
  • trunk/atahpt.c

    r1463 r1474  
    4141}; 
    4242 
     43static void atahpt_chip_writeb(const struct flashctx *flash, uint8_t val, 
     44                               chipaddr addr); 
     45static uint8_t atahpt_chip_readb(const struct flashctx *flash, 
     46                                 const chipaddr addr); 
    4347static const struct par_programmer par_programmer_atahpt = { 
    4448                .chip_readb             = atahpt_chip_readb, 
     
    8185} 
    8286 
    83 void atahpt_chip_writeb(uint8_t val, chipaddr addr) 
     87static void atahpt_chip_writeb(const struct flashctx *flash, uint8_t val, 
     88                               chipaddr addr) 
    8489{ 
    8590        OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR); 
     
    8792} 
    8893 
    89 uint8_t atahpt_chip_readb(const chipaddr addr) 
     94static uint8_t atahpt_chip_readb(const struct flashctx *flash, 
     95                                 const chipaddr addr) 
    9096{ 
    9197        OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR); 
  • trunk/bitbang_spi.c

    r1414 r1474  
    6464} 
    6565 
    66 static int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    67                 const unsigned char *writearr, unsigned char *readarr); 
     66static int bitbang_spi_send_command(struct flashctx *flash, 
     67                                    unsigned int writecnt, unsigned int readcnt, 
     68                                    const unsigned char *writearr, 
     69                                    unsigned char *readarr); 
    6870 
    6971static const struct spi_programmer spi_programmer_bitbang = { 
     
    142144} 
    143145 
    144 static int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    145                 const unsigned char *writearr, unsigned char *readarr) 
     146static int bitbang_spi_send_command(struct flashctx *flash, 
     147                                    unsigned int writecnt, unsigned int readcnt, 
     148                                    const unsigned char *writearr, 
     149                                    unsigned char *readarr) 
    146150{ 
    147151        int i; 
  • trunk/buspirate_spi.c

    r1470 r1474  
    8787} 
    8888 
    89 static int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    90                 const unsigned char *writearr, unsigned char *readarr); 
     89static int buspirate_spi_send_command(struct flashctx *flash, 
     90                                      unsigned int writecnt, 
     91                                      unsigned int readcnt, 
     92                                      const unsigned char *writearr, 
     93                                      unsigned char *readarr); 
    9194 
    9295static const struct spi_programmer spi_programmer_buspirate = { 
     
    292295} 
    293296 
    294 static int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    295                 const unsigned char *writearr, unsigned char *readarr) 
     297static int buspirate_spi_send_command(struct flashctx *flash, 
     298                                      unsigned int writecnt, 
     299                                      unsigned int readcnt, 
     300                                      const unsigned char *writearr, 
     301                                      unsigned char *readarr) 
    296302{ 
    297303        static unsigned char *buf = NULL; 
  • trunk/chipdrivers.h

    r1473 r1474  
    3434int probe_spi_res1(struct flashctx *flash); 
    3535int probe_spi_res2(struct flashctx *flash); 
    36 int spi_write_enable(void); 
    37 int spi_write_disable(void); 
     36int spi_write_enable(struct flashctx *flash); 
     37int spi_write_disable(struct flashctx *flash); 
    3838int spi_block_erase_20(struct flashctx *flash, unsigned int addr, unsigned int blocklen); 
    3939int spi_block_erase_52(struct flashctx *flash, unsigned int addr, unsigned int blocklen); 
     
    4545int spi_chip_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); 
    4646int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, int unsigned len); 
    47 uint8_t spi_read_status_register(void); 
     47uint8_t spi_read_status_register(struct flashctx *flash); 
    4848int spi_write_status_register(struct flashctx *flash, int status); 
    4949void spi_prettyprint_status_register_bit(uint8_t status, int bit); 
     
    5252int spi_prettyprint_status_register(struct flashctx *flash); 
    5353int spi_disable_blockprotect(struct flashctx *flash); 
    54 int spi_byte_program(unsigned int addr, uint8_t databyte); 
    55 int spi_nbyte_program(unsigned int addr, uint8_t *bytes, unsigned int len); 
    56 int spi_nbyte_read(unsigned int addr, uint8_t *bytes, unsigned int len); 
     54int spi_byte_program(struct flashctx *flash, unsigned int addr, uint8_t databyte); 
     55int spi_nbyte_program(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len); 
     56int spi_nbyte_read(struct flashctx *flash, unsigned int addr, uint8_t *bytes, unsigned int len); 
    5757int spi_read_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize); 
    5858int spi_write_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize); 
     
    9696/* jedec.c */ 
    9797uint8_t oddparity(uint8_t val); 
    98 void toggle_ready_jedec(chipaddr dst); 
    99 void data_polling_jedec(chipaddr dst, uint8_t data); 
    100 int write_byte_program_jedec(chipaddr bios, uint8_t *src, 
     98void toggle_ready_jedec(struct flashctx *flash, chipaddr dst); 
     99void data_polling_jedec(struct flashctx *flash, chipaddr dst, uint8_t data); 
     100int write_byte_program_jedec(struct flashctx *flash, chipaddr bios, uint8_t *src, 
    101101                             chipaddr dst); 
    102102int probe_jedec(struct flashctx *flash); 
     
    112112int block_erase_chip_m29f400bt(struct flashctx *flash, unsigned int start, unsigned int len); 
    113113int write_m29f400bt(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); 
    114 void protect_m29f400bt(chipaddr bios); 
     114void protect_m29f400bt(struct flashctx *flash, chipaddr bios); 
    115115 
    116116/* pm49fl00x.c */ 
  • trunk/dediprog.c

    r1473 r1474  
    318318} 
    319319 
    320 static int dediprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    321                         const unsigned char *writearr, unsigned char *readarr) 
     320static int dediprog_spi_send_command(struct flashctx *flash, 
     321                                     unsigned int writecnt, 
     322                                     unsigned int readcnt, 
     323                                     const unsigned char *writearr, 
     324                                     unsigned char *readarr) 
    322325{ 
    323326        int ret; 
  • trunk/drkaiser.c

    r1463 r1474  
    4040static uint8_t *drkaiser_bar; 
    4141 
     42static void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val, 
     43                                 chipaddr addr); 
     44static uint8_t drkaiser_chip_readb(const struct flashctx *flash, 
     45                                   const chipaddr addr); 
    4246static const struct par_programmer par_programmer_drkaiser = { 
    4347                .chip_readb             = drkaiser_chip_readb, 
     
    8589} 
    8690 
    87 void drkaiser_chip_writeb(uint8_t val, chipaddr addr) 
     91static void drkaiser_chip_writeb(const struct flashctx *flash, uint8_t val, 
     92                                 chipaddr addr) 
    8893{ 
    8994        pci_mmio_writeb(val, drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK)); 
    9095} 
    9196 
    92 uint8_t drkaiser_chip_readb(const chipaddr addr) 
     97static uint8_t drkaiser_chip_readb(const struct flashctx *flash, 
     98                                   const chipaddr addr) 
    9399{ 
    94100        return pci_mmio_readb(drkaiser_bar + (addr & DRKAISER_MEMMAP_MASK)); 
  • trunk/dummyflasher.c

    r1473 r1474  
    6161static unsigned int spi_write_256_chunksize = 256; 
    6262 
    63 static int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    64                       const unsigned char *writearr, unsigned char *readarr); 
     63static int dummy_spi_send_command(struct flashctx *flash, unsigned int writecnt, 
     64                                  unsigned int readcnt, 
     65                                  const unsigned char *writearr, 
     66                                  unsigned char *readarr); 
    6567static int dummy_spi_write_256(struct flashctx *flash, uint8_t *buf, 
    6668                               unsigned int start, unsigned int len); 
     69static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, 
     70                              chipaddr addr); 
     71static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, 
     72                              chipaddr addr); 
     73static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, 
     74                              chipaddr addr); 
     75static void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf, 
     76                              chipaddr addr, size_t len); 
     77static uint8_t dummy_chip_readb(const struct flashctx *flash, 
     78                                const chipaddr addr); 
     79static uint16_t dummy_chip_readw(const struct flashctx *flash, 
     80                                 const chipaddr addr); 
     81static uint32_t dummy_chip_readl(const struct flashctx *flash, 
     82                                 const chipaddr addr); 
     83static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, 
     84                             const chipaddr addr, size_t len); 
    6785 
    6886static const struct spi_programmer spi_programmer_dummyflasher = { 
     
    264282} 
    265283 
    266 void dummy_chip_writeb(uint8_t val, chipaddr addr) 
     284static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, 
     285                              chipaddr addr) 
    267286{ 
    268287        msg_pspew("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val); 
    269288} 
    270289 
    271 void dummy_chip_writew(uint16_t val, chipaddr addr) 
     290static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, 
     291                              chipaddr addr) 
    272292{ 
    273293        msg_pspew("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val); 
    274294} 
    275295 
    276 void dummy_chip_writel(uint32_t val, chipaddr addr) 
     296static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, 
     297                              chipaddr addr) 
    277298{ 
    278299        msg_pspew("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val); 
    279300} 
    280301 
    281 void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len) 
     302static void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf, 
     303                              chipaddr addr, size_t len) 
    282304{ 
    283305        size_t i; 
     
    291313} 
    292314 
    293 uint8_t dummy_chip_readb(const chipaddr addr) 
     315static uint8_t dummy_chip_readb(const struct flashctx *flash, 
     316                                const chipaddr addr) 
    294317{ 
    295318        msg_pspew("%s:  addr=0x%lx, returning 0xff\n", __func__, addr); 
     
    297320} 
    298321 
    299 uint16_t dummy_chip_readw(const chipaddr addr) 
     322static uint16_t dummy_chip_readw(const struct flashctx *flash, 
     323                                 const chipaddr addr) 
    300324{ 
    301325        msg_pspew("%s:  addr=0x%lx, returning 0xffff\n", __func__, addr); 
     
    303327} 
    304328 
    305 uint32_t dummy_chip_readl(const chipaddr addr) 
     329static uint32_t dummy_chip_readl(const struct flashctx *flash, 
     330                                 const chipaddr addr) 
    306331{ 
    307332        msg_pspew("%s:  addr=0x%lx, returning 0xffffffff\n", __func__, addr); 
     
    309334} 
    310335 
    311 void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len) 
     336static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, 
     337                             const chipaddr addr, size_t len) 
    312338{ 
    313339        msg_pspew("%s:  addr=0x%lx, len=0x%lx, returning array of 0xff\n", 
     
    318344 
    319345#if EMULATE_SPI_CHIP 
    320 static int emulate_spi_chip_response(unsigned int writecnt, unsigned int readcnt, 
    321                       const unsigned char *writearr, unsigned char *readarr) 
     346static int emulate_spi_chip_response(unsigned int writecnt, 
     347                                     unsigned int readcnt, 
     348                                     const unsigned char *writearr, 
     349                                     unsigned char *readarr) 
    322350{ 
    323351        unsigned int offs; 
     
    514542#endif 
    515543 
    516 static int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    517                       const unsigned char *writearr, unsigned char *readarr) 
     544static int dummy_spi_send_command(struct flashctx *flash, unsigned int writecnt, 
     545                                  unsigned int readcnt, 
     546                                  const unsigned char *writearr, 
     547                                  unsigned char *readarr) 
    518548{ 
    519549        int i; 
  • trunk/flash.h

    r1473 r1474  
    4545                                  size_t len); 
    4646void programmer_unmap_flash_region(void *virt_addr, size_t len); 
    47 void chip_writeb(uint8_t val, chipaddr addr); 
    48 void chip_writew(uint16_t val, chipaddr addr); 
    49 void chip_writel(uint32_t val, chipaddr addr); 
    50 void chip_writen(uint8_t *buf, chipaddr addr, size_t len); 
    51 uint8_t chip_readb(const chipaddr addr); 
    52 uint16_t chip_readw(const chipaddr addr); 
    53 uint32_t chip_readl(const chipaddr addr); 
    54 void chip_readn(uint8_t *buf, const chipaddr addr, size_t len); 
    5547void programmer_delay(int usecs); 
    5648 
     
    213205extern const struct flashchip flashchips[]; 
    214206 
     207void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr); 
     208void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr); 
     209void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr); 
     210void chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len); 
     211uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr); 
     212uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr); 
     213uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr); 
     214void chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len); 
     215 
    215216/* print.c */ 
    216217char *flashbuses_to_text(enum chipbustype bustype); 
     
    293294        unsigned char *readarr; 
    294295}; 
    295 int spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    296                 const unsigned char *writearr, unsigned char *readarr); 
    297 int spi_send_multicommand(struct spi_command *cmds); 
    298 uint32_t spi_get_valid_read_addr(void); 
     296int spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); 
     297int spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds); 
     298uint32_t spi_get_valid_read_addr(struct flashctx *flash); 
    299299 
    300300#endif                          /* !__FLASH_H__ */ 
  • trunk/flashrom.c

    r1473 r1474  
    360360} 
    361361 
    362 void chip_writeb(uint8_t val, chipaddr addr) 
    363 { 
    364         par_programmer->chip_writeb(val, addr); 
    365 } 
    366  
    367 void chip_writew(uint16_t val, chipaddr addr) 
    368 { 
    369         par_programmer->chip_writew(val, addr); 
    370 } 
    371  
    372 void chip_writel(uint32_t val, chipaddr addr) 
    373 { 
    374         par_programmer->chip_writel(val, addr); 
    375 } 
    376  
    377 void chip_writen(uint8_t *buf, chipaddr addr, size_t len) 
    378 { 
    379         par_programmer->chip_writen(buf, addr, len); 
    380 } 
    381  
    382 uint8_t chip_readb(const chipaddr addr) 
    383 { 
    384         return par_programmer->chip_readb(addr); 
    385 } 
    386  
    387 uint16_t chip_readw(const chipaddr addr) 
    388 { 
    389         return par_programmer->chip_readw(addr); 
    390 } 
    391  
    392 uint32_t chip_readl(const chipaddr addr) 
    393 { 
    394         return par_programmer->chip_readl(addr); 
    395 } 
    396  
    397 void chip_readn(uint8_t *buf, chipaddr addr, size_t len) 
    398 { 
    399         par_programmer->chip_readn(buf, addr, len); 
     362void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr) 
     363{ 
     364        par_programmer->chip_writeb(flash, val, addr); 
     365} 
     366 
     367void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr) 
     368{ 
     369        par_programmer->chip_writew(flash, val, addr); 
     370} 
     371 
     372void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr) 
     373{ 
     374        par_programmer->chip_writel(flash, val, addr); 
     375} 
     376 
     377void chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, 
     378                 size_t len) 
     379{ 
     380        par_programmer->chip_writen(flash, buf, addr, len); 
     381} 
     382 
     383uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr) 
     384{ 
     385        return par_programmer->chip_readb(flash, addr); 
     386} 
     387 
     388uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr) 
     389{ 
     390        return par_programmer->chip_readw(flash, addr); 
     391} 
     392 
     393uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr) 
     394{ 
     395        return par_programmer->chip_readl(flash, addr); 
     396} 
     397 
     398void chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr, 
     399                size_t len) 
     400{ 
     401        par_programmer->chip_readn(flash, buf, addr, len); 
    400402} 
    401403 
     
    413415} 
    414416 
    415 int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, int unsigned len) 
    416 { 
    417         chip_readn(buf, flash->virtual_memory + start, len); 
     417int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, 
     418                   int unsigned len) 
     419{ 
     420        chip_readn(flash, buf, flash->virtual_memory + start, len); 
    418421 
    419422        return 0; 
     
    536539 
    537540/* start is an offset to the base address of the flash chip */ 
    538 int check_erased_range(struct flashctx *flash, unsigned int start, unsigned int len) 
     541int check_erased_range(struct flashctx *flash, unsigned int start, 
     542                       unsigned int len) 
    539543{ 
    540544        int ret; 
     
    559563 * @return      0 for success, -1 for failure 
    560564 */ 
    561 int verify_range(struct flashctx *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len, 
    562                  const char *message) 
     565int verify_range(struct flashctx *flash, uint8_t *cmpbuf, unsigned int start, 
     566                 unsigned int len, const char *message) 
    563567{ 
    564568        unsigned int i; 
     
    15381542         * after the members copied from struct flashchip. 
    15391543         */ 
    1540         if (sizeof(struct flashchip) != offsetof(struct flashctx, virtual_memory)) { 
     1544        if (sizeof(struct flashchip) != 
     1545            offsetof(struct flashctx, virtual_memory)) { 
    15411546                msg_gerr("struct flashctx broken!\n"); 
    15421547                ret = 1; 
     
    16191624 * function signature. 
    16201625 */ 
    1621 int chip_safety_check(struct flashctx *flash, int force, int read_it, int write_it, int erase_it, int verify_it) 
     1626int chip_safety_check(struct flashctx *flash, int force, int read_it, 
     1627                      int write_it, int erase_it, int verify_it) 
    16221628{ 
    16231629        if (!programmer_may_write && (write_it || erase_it)) { 
     
    16801686 * Besides that, the function itself is a textbook example of abysmal code flow. 
    16811687 */ 
    1682 int doit(struct flashctx *flash, int force, const char *filename, int read_it, int write_it, int erase_it, int verify_it) 
     1688int doit(struct flashctx *flash, int force, const char *filename, int read_it, 
     1689         int write_it, int erase_it, int verify_it) 
    16831690{ 
    16841691        uint8_t *oldcontents; 
  • trunk/ft2232_spi.c

    r1453 r1474  
    145145} 
    146146 
    147 static int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    148                 const unsigned char *writearr, unsigned char *readarr); 
     147static int ft2232_spi_send_command(struct flashctx *flash, 
     148                                   unsigned int writecnt, unsigned int readcnt, 
     149                                   const unsigned char *writearr, 
     150                                   unsigned char *readarr); 
    149151 
    150152static const struct spi_programmer spi_programmer_ft2232 = { 
     
    343345 
    344346/* Returns 0 upon success, a negative number upon errors. */ 
    345 static int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    346                 const unsigned char *writearr, unsigned char *readarr) 
     347static int ft2232_spi_send_command(struct flashctx *flash, 
     348                                   unsigned int writecnt, unsigned int readcnt, 
     349                                   const unsigned char *writearr, 
     350                                   unsigned char *readarr) 
    347351{ 
    348352        struct ftdi_context *ftdic = &ftdic_context; 
  • trunk/gfxnvidia.c

    r1463 r1474  
    6262}; 
    6363 
     64static void gfxnvidia_chip_writeb(const struct flashctx *flash, uint8_t val, 
     65                                  chipaddr addr); 
     66static uint8_t gfxnvidia_chip_readb(const struct flashctx *flash, 
     67                                    const chipaddr addr); 
    6468static const struct par_programmer par_programmer_gfxnvidia = { 
    6569                .chip_readb             = gfxnvidia_chip_readb, 
     
    113117} 
    114118 
    115 void gfxnvidia_chip_writeb(uint8_t val, chipaddr addr) 
     119static void gfxnvidia_chip_writeb(const struct flashctx *flash, uint8_t val, 
     120                                  chipaddr addr) 
    116121{ 
    117122        pci_mmio_writeb(val, nvidia_bar + (addr & GFXNVIDIA_MEMMAP_MASK)); 
    118123} 
    119124 
    120 uint8_t gfxnvidia_chip_readb(const chipaddr addr) 
     125static uint8_t gfxnvidia_chip_readb(const struct flashctx *flash, 
     126                                    const chipaddr addr) 
    121127{ 
    122128        return pci_mmio_readb(nvidia_bar + (addr & GFXNVIDIA_MEMMAP_MASK)); 
  • trunk/ichspi.c

    r1473 r1474  
    229229static int generate_opcodes(OPCODES * op); 
    230230static int program_opcodes(OPCODES *op, int enable_undo); 
    231 static int run_opcode(OPCODE op, uint32_t offset, 
     231static int run_opcode(const struct flashctx *flash, OPCODE op, uint32_t offset, 
    232232                      uint8_t datalength, uint8_t * data); 
    233233 
     
    639639 * may even crash. 
    640640 */ 
    641  static void ich_read_data(uint8_t *data, int len, int reg0_off) 
     641static void ich_read_data(uint8_t *data, int len, int reg0_off) 
    642642 { 
    643643        int i; 
     
    957957} 
    958958 
    959 static int run_opcode(OPCODE op, uint32_t offset, 
     959static int run_opcode(const struct flashctx *flash, OPCODE op, uint32_t offset, 
    960960                      uint8_t datalength, uint8_t * data) 
    961961{ 
     
    984984} 
    985985 
    986 static int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    987                     const unsigned char *writearr, unsigned char *readarr) 
     986static int ich_spi_send_command(struct flashctx *flash, unsigned int writecnt, 
     987                                unsigned int readcnt, 
     988                                const unsigned char *writearr, 
     989                                unsigned char *readarr) 
    988990{ 
    989991        int result; 
     
    10771079        } 
    10781080 
    1079         result = run_opcode(*opcode, addr, count, data); 
     1081        result = run_opcode(flash, *opcode, addr, count, data); 
    10801082        if (result) { 
    10811083                msg_pdbg("Running OPCODE 0x%02x failed ", opcode->opcode); 
     
    11761178} 
    11771179 
    1178 int ich_hwseq_probe(struct flashctx *flash) 
     1180static int ich_hwseq_probe(struct flashctx *flash) 
    11791181{ 
    11801182        uint32_t total_size, boundary; 
     
    12291231} 
    12301232 
    1231 int ich_hwseq_block_erase(struct flashctx *flash, 
    1232                           unsigned int addr, 
    1233                           unsigned int len) 
     1233static int ich_hwseq_block_erase(struct flashctx *flash, unsigned int addr, 
     1234                                 unsigned int len) 
    12341235{ 
    12351236        uint32_t erase_block; 
     
    12791280} 
    12801281 
    1281 int ich_hwseq_read(struct flashctx *flash, uint8_t *buf, unsigned int addr, 
    1282                   unsigned int len) 
     1282static int ich_hwseq_read(struct flashctx *flash, uint8_t *buf, 
     1283                          unsigned int addr, unsigned int len) 
    12831284{ 
    12841285        uint16_t hsfc; 
     
    13171318} 
    13181319 
    1319 int ich_hwseq_write(struct flashctx *flash, uint8_t *buf, unsigned int addr, 
    1320                     unsigned int len) 
     1320static int ich_hwseq_write(struct flashctx *flash, uint8_t *buf, 
     1321                           unsigned int addr, unsigned int len) 
    13211322{ 
    13221323        uint16_t hsfc; 
     
    13561357} 
    13571358 
    1358 static int ich_spi_send_multicommand(struct spi_command *cmds) 
     1359static int ich_spi_send_multicommand(struct flashctx *flash, 
     1360                                     struct spi_command *cmds) 
    13591361{ 
    13601362        int ret = 0; 
     
    14061408                         */ 
    14071409                } 
    1408                 ret = ich_spi_send_command(cmds->writecnt, cmds->readcnt, 
     1410                ret = ich_spi_send_command(flash, cmds->writecnt, cmds->readcnt, 
    14091411                                           cmds->writearr, cmds->readarr); 
    14101412                /* Reset the type of all opcodes to non-atomic. */ 
  • trunk/internal.c

    r1463 r1474  
    128128int laptop_ok = 0; 
    129129 
     130static void internal_chip_writeb(const struct flashctx *flash, uint8_t val, 
     131                                 chipaddr addr); 
     132static void internal_chip_writew(const struct flashctx *flash, uint16_t val, 
     133                                 chipaddr addr); 
     134static void internal_chip_writel(const struct flashctx *flash, uint32_t val, 
     135                                 chipaddr addr); 
     136static uint8_t internal_chip_readb(const struct flashctx *flash, 
     137                                   const chipaddr addr); 
     138static uint16_t internal_chip_readw(const struct flashctx *flash, 
     139                                    const chipaddr addr); 
     140static uint32_t internal_chip_readl(const struct flashctx *flash, 
     141                                    const chipaddr addr); 
     142static void internal_chip_readn(const struct flashctx *flash, uint8_t *buf, 
     143                                const chipaddr addr, size_t len); 
    130144static const struct par_programmer par_programmer_internal = { 
    131145                .chip_readb             = internal_chip_readb, 
     
    325339#endif 
    326340 
    327 void internal_chip_writeb(uint8_t val, chipaddr addr) 
     341static void internal_chip_writeb(const struct flashctx *flash, uint8_t val, 
     342                                 chipaddr addr) 
    328343{ 
    329344        mmio_writeb(val, (void *) addr); 
    330345} 
    331346 
    332 void internal_chip_writew(uint16_t val, chipaddr addr) 
     347static void internal_chip_writew(const struct flashctx *flash, uint16_t val, 
     348                                 chipaddr addr) 
    333349{ 
    334350        mmio_writew(val, (void *) addr); 
    335351} 
    336352 
    337 void internal_chip_writel(uint32_t val, chipaddr addr) 
     353static void internal_chip_writel(const struct flashctx *flash, uint32_t val, 
     354                                 chipaddr addr) 
    338355{ 
    339356        mmio_writel(val, (void *) addr); 
    340357} 
    341358 
    342 uint8_t internal_chip_readb(const chipaddr addr) 
     359static uint8_t internal_chip_readb(const struct flashctx *flash, 
     360                                   const chipaddr addr) 
    343361{ 
    344362        return mmio_readb((void *) addr); 
    345363} 
    346364 
    347 uint16_t internal_chip_readw(const chipaddr addr) 
     365static uint16_t internal_chip_readw(const struct flashctx *flash, 
     366                                    const chipaddr addr) 
    348367{ 
    349368        return mmio_readw((void *) addr); 
    350369} 
    351370 
    352 uint32_t internal_chip_readl(const chipaddr addr) 
     371static uint32_t internal_chip_readl(const struct flashctx *flash, 
     372                                    const chipaddr addr) 
    353373{ 
    354374        return mmio_readl((void *) addr); 
    355375} 
    356376 
    357 void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len) 
     377static void internal_chip_readn(const struct flashctx *flash, uint8_t *buf, 
     378                                const chipaddr addr, size_t len) 
    358379{ 
    359380        memcpy(buf, (void *)addr, len); 
  • trunk/it85spi.c

    r1463 r1474  
    271271} 
    272272 
    273 static int it85xx_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    274                         const unsigned char *writearr, unsigned char *readarr); 
     273static int it85xx_spi_send_command(struct flashctx *flash, 
     274                                   unsigned int writecnt, unsigned int readcnt, 
     275                                   const unsigned char *writearr, 
     276                                   unsigned char *readarr); 
    275277 
    276278static const struct spi_programmer spi_programmer_it85xx = { 
     
    321323 *      data from MISO) 
    322324 */ 
    323 static int it85xx_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    324                         const unsigned char *writearr, unsigned char *readarr) 
     325static int it85xx_spi_send_command(struct flashctx *flash, 
     326                                   unsigned int writecnt, unsigned int readcnt, 
     327                                   const unsigned char *writearr, 
     328                                   unsigned char *readarr) 
    325329{ 
    326330        int i; 
  • trunk/it87spi.c

    r1473 r1474  
    104104} 
    105105 
    106 static int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    107                         const unsigned char *writearr, unsigned char *readarr); 
     106static int it8716f_spi_send_command(struct flashctx *flash, 
     107                                    unsigned int writecnt, unsigned int readcnt, 
     108                                    const unsigned char *writearr, 
     109                                    unsigned char *readarr); 
    108110static int it8716f_spi_chip_read(struct flashctx *flash, uint8_t *buf, 
    109111                                 unsigned int start, unsigned int len); 
     
    248250 * ordering in case 4 and 5 may seem strange. 
    249251 */ 
    250 static int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    251                         const unsigned char *writearr, unsigned char *readarr) 
     252static int it8716f_spi_send_command(struct flashctx *flash, 
     253                                    unsigned int writecnt, unsigned int readcnt, 
     254                                    const unsigned char *writearr, 
     255                                    unsigned char *readarr) 
    252256{ 
    253257        uint8_t busy, writeenc; 
     
    320324        chipaddr bios = flash->virtual_memory; 
    321325 
    322         result = spi_write_enable(); 
     326        result = spi_write_enable(flash); 
    323327        if (result) 
    324328                return result; 
     
    327331        OUTB(((2 + (fast_spi ? 1 : 0)) << 4), it8716f_flashport); 
    328332        for (i = 0; i < flash->page_size; i++) 
    329                 chip_writeb(buf[i], bios + start + i); 
     333                chip_writeb(flash, buf[i], bios + start + i); 
    330334        OUTB(0, it8716f_flashport); 
    331335        /* Wait until the Write-In-Progress bit is cleared. 
    332336         * This usually takes 1-10 ms, so wait in 1 ms steps. 
    333337         */ 
    334         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     338        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    335339                programmer_delay(1000); 
    336340        return 0; 
  • trunk/jedec.c

    r1473 r1474  
    3838} 
    3939 
    40 static void toggle_ready_jedec_common(chipaddr dst, int delay) 
     40static void toggle_ready_jedec_common(const struct flashctx *flash, 
     41                                      chipaddr dst, int delay) 
    4142{ 
    4243        unsigned int i = 0; 
    4344        uint8_t tmp1, tmp2; 
    4445 
    45         tmp1 = chip_readb(dst) & 0x40; 
     46        tmp1 = chip_readb(flash, dst) & 0x40; 
    4647 
    4748        while (i++ < 0xFFFFFFF) { 
    4849                if (delay) 
    4950                        programmer_delay(delay); 
    50                 tmp2 = chip_readb(dst) & 0x40; 
     51                tmp2 = chip_readb(flash, dst) & 0x40; 
    5152                if (tmp1 == tmp2) { 
    5253                        break; 
     
    5859} 
    5960 
    60 void toggle_ready_jedec(chipaddr dst) 
    61 { 
    62         toggle_ready_jedec_common(dst, 0); 
     61void toggle_ready_jedec(const struct flashctx *flash, chipaddr dst) 
     62{ 
     63        toggle_ready_jedec_common(flash, dst, 0); 
    6364} 
    6465 
     
    7071 * toggle_ready_jedec_slow in erase functions. 
    7172 */ 
    72 static void toggle_ready_jedec_slow(chipaddr dst) 
    73 { 
    74         toggle_ready_jedec_common(dst, 8 * 1000); 
    75 } 
    76  
    77 void data_polling_jedec(chipaddr dst, uint8_t data) 
     73static void toggle_ready_jedec_slow(const struct flashctx *flash, chipaddr dst) 
     74{ 
     75        toggle_ready_jedec_common(flash, dst, 8 * 1000); 
     76} 
     77 
     78void data_polling_jedec(const struct flashctx *flash, chipaddr dst, 
     79                        uint8_t data) 
    7880{ 
    7981        unsigned int i = 0; 
     
    8385 
    8486        while (i++ < 0xFFFFFFF) { 
    85                 tmp = chip_readb(dst) & 0x80; 
     87                tmp = chip_readb(flash, dst) & 0x80; 
    8688                if (tmp == data) { 
    8789                        break; 
     
    111113} 
    112114 
    113 static void start_program_jedec_common(struct flashctx *flash, unsigned int mask) 
    114 { 
    115         chipaddr bios = flash->virtual_memory; 
    116         chip_writeb(0xAA, bios + (0x5555 & mask)); 
    117         chip_writeb(0x55, bios + (0x2AAA & mask)); 
    118         chip_writeb(0xA0, bios + (0x5555 & mask)); 
     115static void start_program_jedec_common(struct flashctx *flash, 
     116                                       unsigned int mask) 
     117{ 
     118        chipaddr bios = flash->virtual_memory; 
     119        chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); 
     120        chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); 
     121        chip_writeb(flash, 0xA0, bios + (0x5555 & mask)); 
    119122} 
    120123 
     
    151154        if ((flash->feature_bits & FEATURE_RESET_MASK) == FEATURE_LONG_RESET) 
    152155        { 
    153                 chip_writeb(0xAA, bios + (0x5555 & mask)); 
     156                chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); 
    154157                if (probe_timing_exit) 
    155158                        programmer_delay(10); 
    156                 chip_writeb(0x55, bios + (0x2AAA & mask)); 
     159                chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); 
    157160                if (probe_timing_exit) 
    158161                        programmer_delay(10); 
    159162        } 
    160         chip_writeb(0xF0, bios + (0x5555 & mask)); 
     163        chip_writeb(flash, 0xF0, bios + (0x5555 & mask)); 
    161164        if (probe_timing_exit) 
    162165                programmer_delay(probe_timing_exit); 
    163166 
    164167        /* Issue JEDEC Product ID Entry command */ 
    165         chip_writeb(0xAA, bios + (0x5555 & mask)); 
     168        chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); 
    166169        if (probe_timing_enter) 
    167170                programmer_delay(10); 
    168         chip_writeb(0x55, bios + (0x2AAA & mask)); 
     171        chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); 
    169172        if (probe_timing_enter) 
    170173                programmer_delay(10); 
    171         chip_writeb(0x90, bios + (0x5555 & mask)); 
     174        chip_writeb(flash, 0x90, bios + (0x5555 & mask)); 
    172175        if (probe_timing_enter) 
    173176                programmer_delay(probe_timing_enter); 
    174177 
    175178        /* Read product ID */ 
    176         id1 = chip_readb(bios); 
    177         id2 = chip_readb(bios + 0x01); 
     179        id1 = chip_readb(flash, bios); 
     180        id2 = chip_readb(flash, bios + 0x01); 
    178181        largeid1 = id1; 
    179182        largeid2 = id2; 
     
    182185        if (id1 == 0x7F) { 
    183186                largeid1 <<= 8; 
    184                 id1 = chip_readb(bios + 0x100); 
     187                id1 = chip_readb(flash, bios + 0x100); 
    185188                largeid1 |= id1; 
    186189        } 
    187190        if (id2 == 0x7F) { 
    188191                largeid2 <<= 8; 
    189                 id2 = chip_readb(bios + 0x101); 
     192                id2 = chip_readb(flash, bios + 0x101); 
    190193                largeid2 |= id2; 
    191194        } 
     
    194197        if ((flash->feature_bits & FEATURE_RESET_MASK) == FEATURE_LONG_RESET) 
    195198        { 
    196                 chip_writeb(0xAA, bios + (0x5555 & mask)); 
     199                chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); 
    197200                if (probe_timing_exit) 
    198201                        programmer_delay(10); 
    199                 chip_writeb(0x55, bios + (0x2AAA & mask)); 
     202                chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); 
    200203                if (probe_timing_exit) 
    201204                        programmer_delay(10); 
    202205        } 
    203         chip_writeb(0xF0, bios + (0x5555 & mask)); 
     206        chip_writeb(flash, 0xF0, bios + (0x5555 & mask)); 
    204207        if (probe_timing_exit) 
    205208                programmer_delay(probe_timing_exit); 
     
    210213 
    211214        /* Read the product ID location again. We should now see normal flash contents. */ 
    212         flashcontent1 = chip_readb(bios); 
    213         flashcontent2 = chip_readb(bios + 0x01); 
     215        flashcontent1 = chip_readb(flash, bios); 
     216        flashcontent2 = chip_readb(flash, bios + 0x01); 
    214217 
    215218        /* Check if it is a continuation ID, this should be a while loop. */ 
    216219        if (flashcontent1 == 0x7F) { 
    217220                flashcontent1 <<= 8; 
    218                 flashcontent1 |= chip_readb(bios + 0x100); 
     221                flashcontent1 |= chip_readb(flash, bios + 0x100); 
    219222        } 
    220223        if (flashcontent2 == 0x7F) { 
    221224                flashcontent2 <<= 8; 
    222                 flashcontent2 |= chip_readb(bios + 0x101); 
     225                flashcontent2 |= chip_readb(flash, bios + 0x101); 
    223226        } 
    224227 
     
    239242 
    240243static int erase_sector_jedec_common(struct flashctx *flash, unsigned int page, 
    241                               unsigned int pagesize, unsigned int mask) 
     244                                     unsigned int pagesize, unsigned int mask) 
    242245{ 
    243246        chipaddr bios = flash->virtual_memory; 
     
    247250 
    248251        /*  Issue the Sector Erase command   */ 
    249         chip_writeb(0xAA, bios + (0x5555 & mask)); 
    250         programmer_delay(delay_us); 
    251         chip_writeb(0x55, bios + (0x2AAA & mask)); 
    252         programmer_delay(delay_us); 
    253         chip_writeb(0x80, bios + (0x5555 & mask)); 
    254         programmer_delay(delay_us); 
    255  
    256         chip_writeb(0xAA, bios + (0x5555 & mask)); 
    257         programmer_delay(delay_us); 
    258         chip_writeb(0x55, bios + (0x2AAA & mask)); 
    259         programmer_delay(delay_us); 
    260         chip_writeb(0x30, bios + page); 
     252        chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); 
     253        programmer_delay(delay_us); 
     254        chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); 
     255        programmer_delay(delay_us); 
     256        chip_writeb(flash, 0x80, bios + (0x5555 & mask)); 
     257        programmer_delay(delay_us); 
     258 
     259        chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); 
     260        programmer_delay(delay_us); 
     261        chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); 
     262        programmer_delay(delay_us); 
     263        chip_writeb(flash, 0x30, bios + page); 
    261264        programmer_delay(delay_us); 
    262265 
    263266        /* wait for Toggle bit ready         */ 
    264         toggle_ready_jedec_slow(bios); 
     267        toggle_ready_jedec_slow(flash, bios); 
    265268 
    266269        /* FIXME: Check the status register for errors. */ 
     
    269272 
    270273static int erase_block_jedec_common(struct flashctx *flash, unsigned int block, 
    271                              unsigned int blocksize, unsigned int mask) 
     274                                    unsigned int blocksize, unsigned int mask) 
    272275{ 
    273276        chipaddr bios = flash->virtual_memory; 
     
    277280 
    278281        /*  Issue the Sector Erase command   */ 
    279         chip_writeb(0xAA, bios + (0x5555 & mask)); 
    280         programmer_delay(delay_us); 
    281         chip_writeb(0x55, bios + (0x2AAA & mask)); 
    282         programmer_delay(delay_us); 
    283         chip_writeb(0x80, bios + (0x5555 & mask)); 
    284         programmer_delay(delay_us); 
    285  
    286         chip_writeb(0xAA, bios + (0x5555 & mask)); 
    287         programmer_delay(delay_us); 
    288         chip_writeb(0x55, bios + (0x2AAA & mask)); 
    289         programmer_delay(delay_us); 
    290         chip_writeb(0x50, bios + block); 
     282        chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); 
     283        programmer_delay(delay_us); 
     284        chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); 
     285        programmer_delay(delay_us); 
     286        chip_writeb(flash, 0x80, bios + (0x5555 & mask)); 
     287        programmer_delay(delay_us); 
     288 
     289        chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); 
     290        programmer_delay(delay_us); 
     291        chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); 
     292        programmer_delay(delay_us); 
     293        chip_writeb(flash, 0x50, bios + block); 
    291294        programmer_delay(delay_us); 
    292295 
    293296        /* wait for Toggle bit ready         */ 
    294         toggle_ready_jedec_slow(bios); 
     297        toggle_ready_jedec_slow(flash, bios); 
    295298 
    296299        /* FIXME: Check the status register for errors. */ 
     
    306309 
    307310        /*  Issue the JEDEC Chip Erase command   */ 
    308         chip_writeb(0xAA, bios + (0x5555 & mask)); 
    309         programmer_delay(delay_us); 
    310         chip_writeb(0x55, bios + (0x2AAA & mask)); 
    311         programmer_delay(delay_us); 
    312         chip_writeb(0x80, bios + (0x5555 & mask)); 
    313         programmer_delay(delay_us); 
    314  
    315         chip_writeb(0xAA, bios + (0x5555 & mask)); 
    316         programmer_delay(delay_us); 
    317         chip_writeb(0x55, bios + (0x2AAA & mask)); 
    318         programmer_delay(delay_us); 
    319         chip_writeb(0x10, bios + (0x5555 & mask)); 
    320         programmer_delay(delay_us); 
    321  
    322         toggle_ready_jedec_slow(bios); 
     311        chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); 
     312        programmer_delay(delay_us); 
     313        chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); 
     314        programmer_delay(delay_us); 
     315        chip_writeb(flash, 0x80, bios + (0x5555 & mask)); 
     316        programmer_delay(delay_us); 
     317 
     318        chip_writeb(flash, 0xAA, bios + (0x5555 & mask)); 
     319        programmer_delay(delay_us); 
     320        chip_writeb(flash, 0x55, bios + (0x2AAA & mask)); 
     321        programmer_delay(delay_us); 
     322        chip_writeb(flash, 0x10, bios + (0x5555 & mask)); 
     323        programmer_delay(delay_us); 
     324 
     325        toggle_ready_jedec_slow(flash, bios); 
    323326 
    324327        /* FIXME: Check the status register for errors. */ 
     
    327330 
    328331static int write_byte_program_jedec_common(struct flashctx *flash, uint8_t *src, 
    329                              chipaddr dst, unsigned int mask) 
     332                                           chipaddr dst, unsigned int mask) 
    330333{ 
    331334        int tried = 0, failed = 0; 
     
    342345 
    343346        /* transfer data from source to destination */ 
    344         chip_writeb(*src, dst); 
    345         toggle_ready_jedec(bios); 
    346  
    347         if (chip_readb(dst) != *src && tried++ < MAX_REFLASH_TRIES) { 
     347        chip_writeb(flash, *src, dst); 
     348        toggle_ready_jedec(flash, bios); 
     349 
     350        if (chip_readb(flash, dst) != *src && tried++ < MAX_REFLASH_TRIES) { 
    348351                goto retry; 
    349352        } 
     
    356359 
    357360/* chunksize is 1 */ 
    358 int write_jedec_1(struct flashctx *flash, uint8_t *src, unsigned int start, unsigned int len) 
     361int write_jedec_1(struct flashctx *flash, uint8_t *src, unsigned int start, 
     362                  unsigned int len) 
    359363{ 
    360364        int i, failed = 0; 
     
    377381} 
    378382 
    379 int write_page_write_jedec_common(struct flashctx *flash, uint8_t *src, unsigned int start, unsigned int page_size) 
     383int write_page_write_jedec_common(struct flashctx *flash, uint8_t *src, 
     384                                  unsigned int start, unsigned int page_size) 
    380385{ 
    381386        int i, tried = 0, failed; 
     
    396401                /* If the data is 0xFF, don't program it */ 
    397402                if (*src != 0xFF) 
    398                         chip_writeb(*src, dst); 
     403                        chip_writeb(flash, *src, dst); 
    399404                dst++; 
    400405                src++; 
    401406        } 
    402407 
    403         toggle_ready_jedec(dst - 1); 
     408        toggle_ready_jedec(flash, dst - 1); 
    404409 
    405410        dst = d; 
     
    425430 * Each page is written separately in chunks with a maximum size of chunksize. 
    426431 */ 
    427 int write_jedec(struct flashctx *flash, uint8_t *buf, unsigned int start, int unsigned len) 
     432int write_jedec(struct flashctx *flash, uint8_t *buf, unsigned int start, 
     433                int unsigned len) 
    428434{ 
    429435        unsigned int i, starthere, lenhere; 
     
    481487} 
    482488 
    483 int erase_sector_jedec(struct flashctx *flash, unsigned int page, unsigned int size) 
     489int erase_sector_jedec(struct flashctx *flash, unsigned int page, 
     490                       unsigned int size) 
    484491{ 
    485492        unsigned int mask; 
     
    489496} 
    490497 
    491 int erase_block_jedec(struct flashctx *flash, unsigned int page, unsigned int size) 
     498int erase_block_jedec(struct flashctx *flash, unsigned int page, 
     499                      unsigned int size) 
    492500{ 
    493501        unsigned int mask; 
  • trunk/linux_spi.c

    r1473 r1474  
    3535 
    3636static int linux_spi_shutdown(void *data); 
    37 static int linux_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    38                         const unsigned char *txbuf, unsigned char *rxbuf); 
     37static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt, 
     38                                  unsigned int readcnt, 
     39                                  const unsigned char *txbuf, 
     40                                  unsigned char *rxbuf); 
    3941static int linux_spi_read(struct flashctx *flash, uint8_t *buf, 
    4042                          unsigned int start, unsigned int len); 
     
    108110} 
    109111 
    110 static int linux_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    111                         const unsigned char *txbuf, unsigned char *rxbuf) 
     112static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt, 
     113                                  unsigned int readcnt, 
     114                                  const unsigned char *txbuf, 
     115                                  unsigned char *rxbuf) 
    112116{ 
    113117        struct spi_ioc_transfer msg[2] = { 
     
    135139                          unsigned int start, unsigned int len) 
    136140{ 
    137         return spi_read_chunked(flash, buf, start, len, (unsigned)getpagesize()); 
     141        return spi_read_chunked(flash, buf, start, len, 
     142                                (unsigned int)getpagesize()); 
    138143} 
    139144 
     
    141146                               unsigned int start, unsigned int len) 
    142147{ 
    143         return spi_write_chunked(flash, buf, start, len, ((unsigned)getpagesize()) - 4); 
     148        return spi_write_chunked(flash, buf, start, len, 
     149                                ((unsigned int)getpagesize()) - 4); 
    144150} 
  • trunk/m29f400bt.c

    r1473 r1474  
    2929 
    3030/* chunksize is 1 */ 
    31 int write_m29f400bt(struct flashctx *flash, uint8_t *src, unsigned int start, unsigned int len) 
     31int write_m29f400bt(struct flashctx *flash, uint8_t *src, unsigned int start, 
     32                    unsigned int len) 
    3233{ 
    3334        int i; 
     
    3637 
    3738        for (i = 0; i < len; i++) { 
    38                 chip_writeb(0xAA, bios + 0xAAA); 
    39                 chip_writeb(0x55, bios + 0x555); 
    40                 chip_writeb(0xA0, bios + 0xAAA); 
     39                chip_writeb(flash, 0xAA, bios + 0xAAA); 
     40                chip_writeb(flash, 0x55, bios + 0x555); 
     41                chip_writeb(flash, 0xA0, bios + 0xAAA); 
    4142 
    4243                /* transfer data from source to destination */ 
    43                 chip_writeb(*src, dst); 
    44                 toggle_ready_jedec(dst); 
     44                chip_writeb(flash, *src, dst); 
     45                toggle_ready_jedec(flash, dst); 
    4546#if 0 
    4647                /* We only want to print something in the error case. */ 
    4748                msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n", 
    48                      (dst - bios), chip_readb(dst), *src); 
     49                     (dst - bios), chip_readb(flash, dst), *src); 
    4950#endif 
    5051                dst++; 
     
    6162        uint8_t id1, id2; 
    6263 
    63         chip_writeb(0xAA, bios + 0xAAA); 
    64         chip_writeb(0x55, bios + 0x555); 
    65         chip_writeb(0x90, bios + 0xAAA); 
     64        chip_writeb(flash, 0xAA, bios + 0xAAA); 
     65        chip_writeb(flash, 0x55, bios + 0x555); 
     66        chip_writeb(flash, 0x90, bios + 0xAAA); 
    6667 
    6768        programmer_delay(10); 
    6869 
    69         id1 = chip_readb(bios); 
     70        id1 = chip_readb(flash, bios); 
    7071        /* The data sheet says id2 is at (bios + 0x01) and id2 listed in 
    7172         * flash.h does not match. It should be possible to use JEDEC probe. 
    7273         */ 
    73         id2 = chip_readb(bios + 0x02); 
     74        id2 = chip_readb(flash, bios + 0x02); 
    7475 
    75         chip_writeb(0xAA, bios + 0xAAA); 
    76         chip_writeb(0x55, bios + 0x555); 
    77         chip_writeb(0xF0, bios + 0xAAA); 
     76        chip_writeb(flash, 0xAA, bios + 0xAAA); 
     77        chip_writeb(flash, 0x55, bios + 0x555); 
     78        chip_writeb(flash, 0xF0, bios + 0xAAA); 
    7879 
    7980        programmer_delay(10); 
     
    9192        chipaddr bios = flash->virtual_memory; 
    9293 
    93         chip_writeb(0xAA, bios + 0xAAA); 
    94         chip_writeb(0x55, bios + 0x555); 
    95         chip_writeb(0x80, bios + 0xAAA); 
     94        chip_writeb(flash, 0xAA, bios + 0xAAA); 
     95        chip_writeb(flash, 0x55, bios + 0x555); 
     96        chip_writeb(flash, 0x80, bios + 0xAAA); 
    9697 
    97         chip_writeb(0xAA, bios + 0xAAA); 
    98         chip_writeb(0x55, bios + 0x555); 
    99         chip_writeb(0x10, bios + 0xAAA); 
     98        chip_writeb(flash, 0xAA, bios + 0xAAA); 
     99        chip_writeb(flash, 0x55, bios + 0x555); 
     100        chip_writeb(flash, 0x10, bios + 0xAAA); 
    100101 
    101102        programmer_delay(10); 
    102         toggle_ready_jedec(bios); 
     103        toggle_ready_jedec(flash, bios); 
    103104 
    104105        /* FIXME: Check the status register for errors. */ 
     
    106107} 
    107108 
    108 int block_erase_m29f400bt(struct flashctx *flash, unsigned int start, unsigned int len) 
     109int block_erase_m29f400bt(struct flashctx *flash, unsigned int start, 
     110                          unsigned int len) 
    109111{ 
    110112        chipaddr bios = flash->virtual_memory; 
    111113        chipaddr dst = bios + start; 
    112114 
    113         chip_writeb(0xAA, bios + 0xAAA); 
    114         chip_writeb(0x55, bios + 0x555); 
    115         chip_writeb(0x80, bios + 0xAAA); 
     115        chip_writeb(flash, 0xAA, bios + 0xAAA); 
     116        chip_writeb(flash, 0x55, bios + 0x555); 
     117        chip_writeb(flash, 0x80, bios + 0xAAA); 
    116118 
    117         chip_writeb(0xAA, bios + 0xAAA); 
    118         chip_writeb(0x55, bios + 0x555); 
    119         chip_writeb(0x30, dst); 
     119        chip_writeb(flash, 0xAA, bios + 0xAAA); 
     120        chip_writeb(flash, 0x55, bios + 0x555); 
     121        chip_writeb(flash, 0x30, dst); 
    120122 
    121123        programmer_delay(10); 
    122         toggle_ready_jedec(bios); 
     124        toggle_ready_jedec(flash, bios); 
    123125 
    124126        /* FIXME: Check the status register for errors. */ 
     
    126128} 
    127129 
    128 int block_erase_chip_m29f400bt(struct flashctx *flash, unsigned int address, unsigned int blocklen) 
     130int block_erase_chip_m29f400bt(struct flashctx *flash, unsigned int address, 
     131                               unsigned int blocklen) 
    129132{ 
    130133        if ((address != 0) || (blocklen != flash->total_size * 1024)) { 
  • trunk/nic3com.c

    r1463 r1474  
    5656}; 
    5757 
     58static void nic3com_chip_writeb(const struct flashctx *flash, uint8_t val, 
     59                                chipaddr addr); 
     60static uint8_t nic3com_chip_readb(const struct flashctx *flash, 
     61                                  const chipaddr addr); 
    5862static const struct par_programmer par_programmer_nic3com = { 
    5963                .chip_readb             = nic3com_chip_readb, 
     
    117121} 
    118122 
    119 void nic3com_chip_writeb(uint8_t val, chipaddr addr) 
     123static void nic3com_chip_writeb(const struct flashctx *flash, uint8_t val, 
     124                                chipaddr addr) 
    120125{ 
    121126        OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR); 
     
    123128} 
    124129 
    125 uint8_t nic3com_chip_readb(const chipaddr addr) 
     130static uint8_t nic3com_chip_readb(const struct flashctx *flash, 
     131                                  const chipaddr addr) 
    126132{ 
    127133        OUTL((uint32_t)addr, io_base_addr + BIOS_ROM_ADDR); 
  • trunk/nicintel.c

    r1463 r1474  
    4444#define CSR_FCR 0x0c 
    4545 
     46static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val, 
     47                                 chipaddr addr); 
     48static uint8_t nicintel_chip_readb(const struct flashctx *flash, 
     49                                   const chipaddr addr); 
    4650static const struct par_programmer par_programmer_nicintel = { 
    4751                .chip_readb             = nicintel_chip_readb, 
     
    118122} 
    119123 
    120 void nicintel_chip_writeb(uint8_t val, chipaddr addr) 
     124static void nicintel_chip_writeb(const struct flashctx *flash, uint8_t val, 
     125                                 chipaddr addr) 
    121126{ 
    122127        pci_mmio_writeb(val, nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); 
    123128} 
    124129 
    125 uint8_t nicintel_chip_readb(const chipaddr addr) 
     130static uint8_t nicintel_chip_readb(const struct flashctx *flash, 
     131                                   const chipaddr addr) 
    126132{ 
    127133        return pci_mmio_readb(nicintel_bar + (addr & NICINTEL_MEMMAP_MASK)); 
  • trunk/nicnatsemi.c

    r1463 r1474  
    3636}; 
    3737 
     38static void nicnatsemi_chip_writeb(const struct flashctx *flash, uint8_t val, 
     39                                   chipaddr addr); 
     40static uint8_t nicnatsemi_chip_readb(const struct flashctx *flash, 
     41                                     const chipaddr addr); 
    3842static const struct par_programmer par_programmer_nicnatsemi = { 
    3943                .chip_readb             = nicnatsemi_chip_readb, 
     
    7579} 
    7680 
    77 void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr) 
     81static void nicnatsemi_chip_writeb(const struct flashctx *flash, uint8_t val, 
     82                                   chipaddr addr) 
    7883{ 
    7984        OUTL((uint32_t)addr & 0x0001FFFF, io_base_addr + BOOT_ROM_ADDR); 
     
    8994} 
    9095 
    91 uint8_t nicnatsemi_chip_readb(const chipaddr addr) 
     96static uint8_t nicnatsemi_chip_readb(const struct flashctx *flash, 
     97                                     const chipaddr addr) 
    9298{ 
    9399        OUTL(((uint32_t)addr & 0x0001FFFF), io_base_addr + BOOT_ROM_ADDR); 
  • trunk/nicrealtek.c

    r1463 r1474  
    3737}; 
    3838 
     39static void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val, 
     40                                   chipaddr addr); 
     41static uint8_t nicrealtek_chip_readb(const struct flashctx *flash, 
     42                                     const chipaddr addr); 
    3943static const struct par_programmer par_programmer_nicrealtek = { 
    4044                .chip_readb             = nicrealtek_chip_readb, 
     
    7074} 
    7175 
    72 void nicrealtek_chip_writeb(uint8_t val, chipaddr addr) 
     76static void nicrealtek_chip_writeb(const struct flashctx *flash, uint8_t val, 
     77                                   chipaddr addr) 
    7378{ 
    7479        /* Output addr and data, set WE to 0, set OE to 1, set CS to 0, 
     
    8489} 
    8590 
    86 uint8_t nicrealtek_chip_readb(const chipaddr addr) 
     91static uint8_t nicrealtek_chip_readb(const struct flashctx *flash, 
     92                                     const chipaddr addr) 
    8793{ 
    8894        uint8_t val; 
  • trunk/pm49fl00x.c

    r1473 r1474  
    2323#include "flash.h" 
    2424 
    25 static void write_lockbits_49fl00x(chipaddr bios, unsigned int size, 
    26                             unsigned char bits, unsigned int block_size) 
     25static void write_lockbits_49fl00x(const struct flashctx *flash, 
     26                                   unsigned int size, unsigned char bits, 
     27                                   unsigned int block_size) 
    2728{ 
    2829        unsigned int i, left = size; 
     30        chipaddr bios = flash->virtual_registers; 
    2931 
    3032        for (i = 0; left >= block_size; i++, left -= block_size) { 
     
    3335                        continue; 
    3436 
    35                 chip_writeb(bits, bios + (i * block_size) + 2); 
     37                chip_writeb(flash, bits, bios + (i * block_size) + 2); 
    3638        } 
    3739} 
     
    3941int unlock_49fl00x(struct flashctx *flash) 
    4042{ 
    41         write_lockbits_49fl00x(flash->virtual_registers, flash->total_size * 1024, 0, flash->page_size); 
     43        write_lockbits_49fl00x(flash, flash->total_size * 1024, 0, 
     44                               flash->page_size); 
    4245        return 0; 
    4346} 
     
    4548int lock_49fl00x(struct flashctx *flash) 
    4649{ 
    47         write_lockbits_49fl00x(flash->virtual_registers, flash->total_size * 1024, 1, flash->page_size); 
     50        write_lockbits_49fl00x(flash, flash->total_size * 1024, 1, 
     51                               flash->page_size); 
    4852        return 0; 
    4953} 
  • trunk/programmer.c

    r1463 r1474  
    22 * This file is part of the flashrom project. 
    33 * 
    4  * Copyright (C) 2009,2010 Carl-Daniel Hailfinger 
     4 * Copyright (C) 2009,2010,2011 Carl-Daniel Hailfinger 
    55 * 
    66 * This program is free software; you can redistribute it and/or modify 
     
    5454 
    5555/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */ 
    56 uint8_t noop_chip_readb(const chipaddr addr) 
     56uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr) 
    5757{ 
    5858        return 0xff; 
     
    6060 
    6161/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */ 
    62 void noop_chip_writeb(uint8_t val, chipaddr addr) 
     62void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr) 
    6363{ 
    6464} 
    6565 
    6666/* Little-endian fallback for drivers not supporting 16 bit accesses */ 
    67 void fallback_chip_writew(uint16_t val, chipaddr addr) 
     67void fallback_chip_writew(const struct flashctx *flash, uint16_t val, 
     68                          chipaddr addr) 
    6869{ 
    69         chip_writeb(val & 0xff, addr); 
    70         chip_writeb((val >> 8) & 0xff, addr + 1); 
     70        chip_writeb(flash, val & 0xff, addr); 
     71        chip_writeb(flash, (val >> 8) & 0xff, addr + 1); 
    7172} 
    7273 
    7374/* Little-endian fallback for drivers not supporting 16 bit accesses */ 
    74 uint16_t fallback_chip_readw(const chipaddr addr) 
     75uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr) 
    7576{ 
    7677        uint16_t val; 
    77         val = chip_readb(addr); 
    78         val |= chip_readb(addr + 1) << 8; 
     78        val = chip_readb(flash, addr); 
     79        val |= chip_readb(flash, addr + 1) << 8; 
    7980        return val; 
    8081} 
    8182 
    8283/* Little-endian fallback for drivers not supporting 32 bit accesses */ 
    83 void fallback_chip_writel(uint32_t val, chipaddr addr) 
     84void fallback_chip_writel(const struct flashctx *flash, uint32_t val, 
     85                          chipaddr addr) 
    8486{ 
    85         chip_writew(val & 0xffff, addr); 
    86         chip_writew((val >> 16) & 0xffff, addr + 2); 
     87        chip_writew(flash, val & 0xffff, addr); 
     88        chip_writew(flash, (val >> 16) & 0xffff, addr + 2); 
    8789} 
    8890 
    8991/* Little-endian fallback for drivers not supporting 32 bit accesses */ 
    90 uint32_t fallback_chip_readl(const chipaddr addr) 
     92uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr) 
    9193{ 
    9294        uint32_t val; 
    93         val = chip_readw(addr); 
    94         val |= chip_readw(addr + 2) << 16; 
     95        val = chip_readw(flash, addr); 
     96        val |= chip_readw(flash, addr + 2) << 16; 
    9597        return val; 
    9698} 
    9799 
    98 void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len) 
     100void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, 
     101                          chipaddr addr, size_t len) 
    99102{ 
    100103        size_t i; 
    101104        for (i = 0; i < len; i++) 
    102                 chip_writeb(buf[i], addr + i); 
     105                chip_writeb(flash, buf[i], addr + i); 
    103106        return; 
    104107} 
    105108 
    106 void fallback_chip_readn(uint8_t *buf, chipaddr addr, size_t len) 
     109void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, 
     110                         chipaddr addr, size_t len) 
    107111{ 
    108112        size_t i; 
    109113        for (i = 0; i < len; i++) 
    110                 buf[i] = chip_readb(addr + i); 
     114                buf[i] = chip_readb(flash, addr + i); 
    111115        return; 
    112116} 
  • trunk/programmer.h

    r1473 r1474  
    9494        int (*init) (void); 
    9595 
    96         void * (*map_flash_region) (const char *descr, unsigned long phys_addr, 
    97                                     size_t len); 
     96        void *(*map_flash_region) (const char *descr, unsigned long phys_addr, 
     97                                   size_t len); 
    9898        void (*unmap_flash_region) (void *virt_addr, size_t len); 
    9999 
     
    301301extern enum chipbustype internal_buses_supported; 
    302302int internal_init(void); 
    303 void internal_chip_writeb(uint8_t val, chipaddr addr); 
    304 void internal_chip_writew(uint16_t val, chipaddr addr); 
    305 void internal_chip_writel(uint32_t val, chipaddr addr); 
    306 uint8_t internal_chip_readb(const chipaddr addr); 
    307 uint16_t internal_chip_readw(const chipaddr addr); 
    308 uint32_t internal_chip_readl(const chipaddr addr); 
    309 void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len); 
    310303#endif 
    311304 
     
    342335void rmmio_vall(void *addr); 
    343336 
    344 /* programmer.c */ 
    345 int noop_shutdown(void); 
    346 void *fallback_map(const char *descr, unsigned long phys_addr, size_t len); 
    347 void fallback_unmap(void *virt_addr, size_t len); 
    348 uint8_t noop_chip_readb(const chipaddr addr); 
    349 void noop_chip_writeb(uint8_t val, chipaddr addr); 
    350 void fallback_chip_writew(uint16_t val, chipaddr addr); 
    351 void fallback_chip_writel(uint32_t val, chipaddr addr); 
    352 void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len); 
    353 uint16_t fallback_chip_readw(const chipaddr addr); 
    354 uint32_t fallback_chip_readl(const chipaddr addr); 
    355 void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len); 
    356 struct par_programmer { 
    357         void (*chip_writeb) (uint8_t val, chipaddr addr); 
    358         void (*chip_writew) (uint16_t val, chipaddr addr); 
    359         void (*chip_writel) (uint32_t val, chipaddr addr); 
    360         void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len); 
    361         uint8_t (*chip_readb) (const chipaddr addr); 
    362         uint16_t (*chip_readw) (const chipaddr addr); 
    363         uint32_t (*chip_readl) (const chipaddr addr); 
    364         void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len); 
    365 }; 
    366 extern const struct par_programmer *par_programmer; 
    367 void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses); 
    368  
    369337/* dummyflasher.c */ 
    370338#if CONFIG_DUMMY == 1 
     
    372340void *dummy_map(const char *descr, unsigned long phys_addr, size_t len); 
    373341void dummy_unmap(void *virt_addr, size_t len); 
    374 void dummy_chip_writeb(uint8_t val, chipaddr addr); 
    375 void dummy_chip_writew(uint16_t val, chipaddr addr); 
    376 void dummy_chip_writel(uint32_t val, chipaddr addr); 
    377 void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len); 
    378 uint8_t dummy_chip_readb(const chipaddr addr); 
    379 uint16_t dummy_chip_readw(const chipaddr addr); 
    380 uint32_t dummy_chip_readl(const chipaddr addr); 
    381 void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len); 
    382342#endif 
    383343 
     
    385345#if CONFIG_NIC3COM == 1 
    386346int nic3com_init(void); 
    387 void nic3com_chip_writeb(uint8_t val, chipaddr addr); 
    388 uint8_t nic3com_chip_readb(const chipaddr addr); 
    389347extern const struct pcidev_status nics_3com[]; 
    390348#endif 
     
    393351#if CONFIG_GFXNVIDIA == 1 
    394352int gfxnvidia_init(void); 
    395 void gfxnvidia_chip_writeb(uint8_t val, chipaddr addr); 
    396 uint8_t gfxnvidia_chip_readb(const chipaddr addr); 
    397353extern const struct pcidev_status gfx_nvidia[]; 
    398354#endif 
     
    401357#if CONFIG_DRKAISER == 1 
    402358int drkaiser_init(void); 
    403 void drkaiser_chip_writeb(uint8_t val, chipaddr addr); 
    404 uint8_t drkaiser_chip_readb(const chipaddr addr); 
    405359extern const struct pcidev_status drkaiser_pcidev[]; 
    406360#endif 
     
    409363#if CONFIG_NICREALTEK == 1 
    410364int nicrealtek_init(void); 
    411 void nicrealtek_chip_writeb(uint8_t val, chipaddr addr); 
    412 uint8_t nicrealtek_chip_readb(const chipaddr addr); 
    413365extern const struct pcidev_status nics_realtek[]; 
    414366#endif 
     
    417369#if CONFIG_NICNATSEMI == 1 
    418370int nicnatsemi_init(void); 
    419 void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr); 
    420 uint8_t nicnatsemi_chip_readb(const chipaddr addr); 
    421371extern const struct pcidev_status nics_natsemi[]; 
    422372#endif 
     
    425375#if CONFIG_NICINTEL == 1 
    426376int nicintel_init(void); 
    427 void nicintel_chip_writeb(uint8_t val, chipaddr addr); 
    428 uint8_t nicintel_chip_readb(const chipaddr addr); 
    429377extern const struct pcidev_status nics_intel[]; 
    430378#endif 
     
    445393#if CONFIG_SATAMV == 1 
    446394int satamv_init(void); 
    447 void satamv_chip_writeb(uint8_t val, chipaddr addr); 
    448 uint8_t satamv_chip_readb(const chipaddr addr); 
    449395extern const struct pcidev_status satas_mv[]; 
    450396#endif 
     
    453399#if CONFIG_SATASII == 1 
    454400int satasii_init(void); 
    455 void satasii_chip_writeb(uint8_t val, chipaddr addr); 
    456 uint8_t satasii_chip_readb(const chipaddr addr); 
    457401extern const struct pcidev_status satas_sii[]; 
    458402#endif 
     
    461405#if CONFIG_ATAHPT == 1 
    462406int atahpt_init(void); 
    463 void atahpt_chip_writeb(uint8_t val, chipaddr addr); 
    464 uint8_t atahpt_chip_readb(const chipaddr addr); 
    465407extern const struct pcidev_status ata_hpt[]; 
    466408#endif 
     
    566508        unsigned int max_data_read; 
    567509        unsigned int max_data_write; 
    568         int (*command)(unsigned int writecnt, unsigned int readcnt, 
     510        int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, 
    569511                   const unsigned char *writearr, unsigned char *readarr); 
    570         int (*multicommand)(struct spi_command *cmds); 
     512        int (*multicommand)(struct flashctx *flash, struct spi_command *cmds); 
    571513 
    572514        /* Optimized functions for this programmer */ 
     
    576518 
    577519extern const struct spi_programmer *spi_programmer; 
    578 int default_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
     520int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, 
    579521                             const unsigned char *writearr, unsigned char *readarr); 
    580 int default_spi_send_multicommand(struct spi_command *cmds); 
     522int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds); 
    581523int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); 
    582524int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); 
     
    633575void register_opaque_programmer(const struct opaque_programmer *pgm); 
    634576 
     577/* programmer.c */ 
     578int noop_shutdown(void); 
     579void *fallback_map(const char *descr, unsigned long phys_addr, size_t len); 
     580void fallback_unmap(void *virt_addr, size_t len); 
     581uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr); 
     582void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr); 
     583void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr); 
     584void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr); 
     585void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len); 
     586uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr); 
     587uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr); 
     588void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len); 
     589struct par_programmer { 
     590        void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr); 
     591        void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr); 
     592        void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr); 
     593        void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len); 
     594        uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr); 
     595        uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr); 
     596        uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr); 
     597        void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len); 
     598}; 
     599extern const struct par_programmer *par_programmer; 
     600void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses); 
     601 
    635602/* serprog.c */ 
    636603#if CONFIG_SERPROG == 1 
    637604int serprog_init(void); 
    638 void serprog_chip_writeb(uint8_t val, chipaddr addr); 
    639 uint8_t serprog_chip_readb(const chipaddr addr); 
    640 void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len); 
    641605void serprog_delay(int usecs); 
    642606#endif 
  • trunk/satamv.c

    r1463 r1474  
    4242#define GPIO_PORT_CONTROL               0x104f0 
    4343 
     44static void satamv_chip_writeb(const struct flashctx *flash, uint8_t val, 
     45                               chipaddr addr); 
     46static uint8_t satamv_chip_readb(const struct flashctx *flash, 
     47                                 const chipaddr addr); 
    4448static const struct par_programmer par_programmer_satamv = { 
    4549                .chip_readb             = satamv_chip_readb, 
     
    184188 
    185189/* FIXME: Prefer direct access to BAR2 if BAR2 is active. */ 
    186 void satamv_chip_writeb(uint8_t val, chipaddr addr) 
     190static void satamv_chip_writeb(const struct flashctx *flash, uint8_t val, 
     191                               chipaddr addr) 
    187192{ 
    188193        satamv_indirect_chip_writeb(val, addr); 
     
    190195 
    191196/* FIXME: Prefer direct access to BAR2 if BAR2 is active. */ 
    192 uint8_t satamv_chip_readb(const chipaddr addr) 
     197static uint8_t satamv_chip_readb(const struct flashctx *flash, 
     198                                 const chipaddr addr) 
    193199{ 
    194200        return satamv_indirect_chip_readb(addr); 
  • trunk/satasii.c

    r1463 r1474  
    4343}; 
    4444 
     45static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val, 
     46                                chipaddr addr); 
     47static uint8_t satasii_chip_readb(const struct flashctx *flash, 
     48                                  const chipaddr addr); 
    4549static const struct par_programmer par_programmer_satasii = { 
    4650                .chip_readb             = satasii_chip_readb, 
     
    96100} 
    97101 
    98 void satasii_chip_writeb(uint8_t val, chipaddr addr) 
     102static void satasii_chip_writeb(const struct flashctx *flash, uint8_t val, 
     103                                chipaddr addr) 
    99104{ 
    100105        uint32_t ctrl_reg, data_reg; 
     
    113118} 
    114119 
    115 uint8_t satasii_chip_readb(const chipaddr addr) 
     120static uint8_t satasii_chip_readb(const struct flashctx *flash, 
     121                                  const chipaddr addr) 
    116122{ 
    117123        uint32_t ctrl_reg; 
  • trunk/sb600spi.c

    r1422 r1474  
    8989} 
    9090 
    91 static int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    92                       const unsigned char *writearr, unsigned char *readarr) 
     91static int sb600_spi_send_command(struct flashctx *flash, unsigned int writecnt, 
     92                                  unsigned int readcnt, 
     93                                  const unsigned char *writearr, 
     94                                  unsigned char *readarr) 
    9395{ 
    9496        int count; 
  • trunk/serprog.c

    r1473 r1474  
    300300} 
    301301 
    302 static int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
     302static int serprog_spi_send_command(struct flashctx *flash, 
     303                                    unsigned int writecnt, unsigned int readcnt, 
    303304                                    const unsigned char *writearr, 
    304305                                    unsigned char *readarr); 
     
    315316}; 
    316317 
     318static void serprog_chip_writeb(const struct flashctx *flash, uint8_t val, 
     319                                chipaddr addr); 
     320static uint8_t serprog_chip_readb(const struct flashctx *flash, 
     321                                  const chipaddr addr); 
     322static void serprog_chip_readn(const struct flashctx *flash, uint8_t *buf, 
     323                               const chipaddr addr, size_t len); 
    317324static const struct par_programmer par_programmer_serprog = { 
    318325                .chip_readb             = serprog_chip_readb, 
     
    681688} 
    682689 
    683 void serprog_chip_writeb(uint8_t val, chipaddr addr) 
     690static void serprog_chip_writeb(const struct flashctx *flash, uint8_t val, 
     691                                chipaddr addr) 
    684692{ 
    685693        msg_pspew("%s\n", __func__); 
     
    712720} 
    713721 
    714 uint8_t serprog_chip_readb(const chipaddr addr) 
     722static uint8_t serprog_chip_readb(const struct flashctx *flash, 
     723                                  const chipaddr addr) 
    715724{ 
    716725        unsigned char c; 
     
    758767 
    759768/* The externally called version that makes sure that max_read_n is obeyed. */ 
    760 void serprog_chip_readn(uint8_t * buf, const chipaddr addr, size_t len) 
     769static void serprog_chip_readn(const struct flashctx *flash, uint8_t * buf, 
     770                               const chipaddr addr, size_t len) 
    761771{ 
    762772        size_t lenm = len; 
     
    793803} 
    794804 
    795 static int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    796                              const unsigned char *writearr, 
    797                              unsigned char *readarr) 
     805static int serprog_spi_send_command(struct flashctx *flash, 
     806                                    unsigned int writecnt, unsigned int readcnt, 
     807                                    const unsigned char *writearr, 
     808                                    unsigned char *readarr) 
    798809{ 
    799810        unsigned char *parmbuf; 
     
    823834 * non-contiguous address space (like AT45DB161D). When spi_read_chunked is 
    824835 * fixed this method can be removed. */ 
    825 static int serprog_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 
     836static int serprog_spi_read(struct flashctx *flash, uint8_t *buf, 
     837                            unsigned int start, unsigned int len) 
    826838{ 
    827839        unsigned int i, cur_len; 
     
    830842                int ret; 
    831843                cur_len = min(max_read, (len - i)); 
    832                 ret = spi_nbyte_read(start + i, buf + i, cur_len); 
     844                ret = spi_nbyte_read(flash, start + i, buf + i, cur_len); 
    833845                if (ret) 
    834846                        return ret; 
  • trunk/sharplhf00l04.c

    r1473 r1474  
    2727 */ 
    2828 
    29 int erase_lhf00l04_block(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen) 
     29int erase_lhf00l04_block(struct flashctx *flash, unsigned int blockaddr, 
     30                         unsigned int blocklen) 
    3031{ 
    3132        chipaddr bios = flash->virtual_memory + blockaddr; 
     
    3435 
    3536        // clear status register 
    36         chip_writeb(0x50, bios); 
     37        chip_writeb(flash, 0x50, bios); 
    3738        status = wait_82802ab(flash); 
    3839        print_status_82802ab(status); 
    3940        // clear write protect 
    4041        msg_cspew("write protect is at 0x%lx\n", (wrprotect)); 
    41         msg_cspew("write protect is 0x%x\n", chip_readb(wrprotect)); 
    42         chip_writeb(0, wrprotect); 
    43         msg_cspew("write protect is 0x%x\n", chip_readb(wrprotect)); 
     42        msg_cspew("write protect is 0x%x\n", chip_readb(flash, wrprotect)); 
     43        chip_writeb(flash, 0, wrprotect); 
     44        msg_cspew("write protect is 0x%x\n", chip_readb(flash, wrprotect)); 
    4445 
    4546        // now start it 
    46         chip_writeb(0x20, bios); 
    47         chip_writeb(0xd0, bios); 
     47        chip_writeb(flash, 0x20, bios); 
     48        chip_writeb(flash, 0xd0, bios); 
    4849        programmer_delay(10); 
    4950        // now let's see what the register is 
  • trunk/spi.c

    r1473 r1474  
    4343const struct spi_programmer *spi_programmer = &spi_programmer_none; 
    4444 
    45 int spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    46                 const unsigned char *writearr, unsigned char *readarr) 
     45int spi_send_command(struct flashctx *flash, unsigned int writecnt, 
     46                     unsigned int readcnt, const unsigned char *writearr, 
     47                     unsigned char *readarr) 
    4748{ 
    4849        if (!spi_programmer->command) { 
     
    5354        } 
    5455 
    55         return spi_programmer->command(writecnt, readcnt, 
    56                                                       writearr, readarr); 
    57 } 
    58  
    59 int spi_send_multicommand(struct spi_command *cmds) 
     56        return spi_programmer->command(flash, writecnt, readcnt, writearr, 
     57                                      readarr); 
     58} 
     59 
     60int spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds) 
    6061{ 
    6162        if (!spi_programmer->multicommand) { 
     
    6667        } 
    6768 
    68         return spi_programmer->multicommand(cmds); 
    69 } 
    70  
    71 int default_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    72                              const unsigned char *writearr, unsigned char *readarr) 
     69        return spi_programmer->multicommand(flash, cmds); 
     70} 
     71 
     72int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, 
     73                             unsigned int readcnt, 
     74                             const unsigned char *writearr, 
     75                             unsigned char *readarr) 
    7376{ 
    7477        struct spi_command cmd[] = { 
     
    8588        }}; 
    8689 
    87         return spi_send_multicommand(cmd); 
    88 } 
    89  
    90 int default_spi_send_multicommand(struct spi_command *cmds) 
     90        return spi_send_multicommand(flash, cmd); 
     91} 
     92 
     93int default_spi_send_multicommand(struct flashctx *flash, 
     94                                  struct spi_command *cmds) 
    9195{ 
    9296        int result = 0; 
    9397        for (; (cmds->writecnt || cmds->readcnt) && !result; cmds++) { 
    94                 result = spi_send_command(cmds->writecnt, cmds->readcnt, 
     98                result = spi_send_command(flash, cmds->writecnt, cmds->readcnt, 
    9599                                          cmds->writearr, cmds->readarr); 
    96100        } 
     
    98102} 
    99103 
    100 int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 
     104int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, 
     105                     unsigned int len) 
    101106{ 
    102107        unsigned int max_data = spi_programmer->max_data_read; 
     
    110115} 
    111116 
    112 int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 
     117int default_spi_write_256(struct flashctx *flash, uint8_t *buf, 
     118                          unsigned int start, unsigned int len) 
    113119{ 
    114120        unsigned int max_data = spi_programmer->max_data_write; 
     
    122128} 
    123129 
    124 int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 
     130int spi_chip_read(struct flashctx *flash, uint8_t *buf, unsigned int start, 
     131                  unsigned int len) 
    125132{ 
    126133        unsigned int addrbase = 0; 
     
    136143         * means 0xffffff, the highest unsigned 24bit number. 
    137144         */ 
    138         addrbase = spi_get_valid_read_addr(); 
     145        addrbase = spi_get_valid_read_addr(flash); 
    139146        if (addrbase + flash->total_size * 1024 > (1 << 24)) { 
    140147                msg_perr("Flash chip size exceeds the allowed access window. "); 
     
    161168 */ 
    162169/* real chunksize is up to 256, logical chunksize is 256 */ 
    163 int spi_chip_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 
     170int spi_chip_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, 
     171                       unsigned int len) 
    164172{ 
    165173        if (!spi_programmer->write_256) { 
     
    178186 * This is a programmer limitation. 
    179187 */ 
    180 uint32_t spi_get_valid_read_addr(void) 
     188uint32_t spi_get_valid_read_addr(struct flashctx *flash) 
    181189{ 
    182190        switch (spi_programmer->type) { 
  • trunk/spi25.c

    r1473 r1474  
    3030#include "spi.h" 
    3131 
    32 static int spi_rdid(unsigned char *readarr, int bytes) 
     32static int spi_rdid(struct flashctx *flash, unsigned char *readarr, int bytes) 
    3333{ 
    3434        static const unsigned char cmd[JEDEC_RDID_OUTSIZE] = { JEDEC_RDID }; 
     
    3636        int i; 
    3737 
    38         ret = spi_send_command(sizeof(cmd), bytes, cmd, readarr); 
     38        ret = spi_send_command(flash, sizeof(cmd), bytes, cmd, readarr); 
    3939        if (ret) 
    4040                return ret; 
     
    4646} 
    4747 
    48 static int spi_rems(unsigned char *readarr) 
     48static int spi_rems(struct flashctx *flash, unsigned char *readarr) 
    4949{ 
    5050        unsigned char cmd[JEDEC_REMS_OUTSIZE] = { JEDEC_REMS, 0, 0, 0 }; 
     
    5252        int ret; 
    5353 
    54         ret = spi_send_command(sizeof(cmd), JEDEC_REMS_INSIZE, cmd, readarr); 
     54        ret = spi_send_command(flash, sizeof(cmd), JEDEC_REMS_INSIZE, cmd, 
     55                               readarr); 
    5556        if (ret == SPI_INVALID_ADDRESS) { 
    5657                /* Find the lowest even address allowed for reads. */ 
    57                 readaddr = (spi_get_valid_read_addr() + 1) & ~1; 
     58                readaddr = (spi_get_valid_read_addr(flash) + 1) & ~1; 
    5859                cmd[1] = (readaddr >> 16) & 0xff, 
    5960                cmd[2] = (readaddr >> 8) & 0xff, 
    6061                cmd[3] = (readaddr >> 0) & 0xff, 
    61                 ret = spi_send_command(sizeof(cmd), JEDEC_REMS_INSIZE, cmd, readarr); 
     62                ret = spi_send_command(flash, sizeof(cmd), JEDEC_REMS_INSIZE, 
     63                                       cmd, readarr); 
    6264        } 
    6365        if (ret) 
     
    6769} 
    6870 
    69 static int spi_res(unsigned char *readarr, int bytes) 
     71static int spi_res(struct flashctx *flash, unsigned char *readarr, int bytes) 
    7072{ 
    7173        unsigned char cmd[JEDEC_RES_OUTSIZE] = { JEDEC_RES, 0, 0, 0 }; 
     
    7476        int i; 
    7577 
    76         ret = spi_send_command(sizeof(cmd), bytes, cmd, readarr); 
     78        ret = spi_send_command(flash, sizeof(cmd), bytes, cmd, readarr); 
    7779        if (ret == SPI_INVALID_ADDRESS) { 
    7880                /* Find the lowest even address allowed for reads. */ 
    79                 readaddr = (spi_get_valid_read_addr() + 1) & ~1; 
     81                readaddr = (spi_get_valid_read_addr(flash) + 1) & ~1; 
    8082                cmd[1] = (readaddr >> 16) & 0xff, 
    8183                cmd[2] = (readaddr >> 8) & 0xff, 
    8284                cmd[3] = (readaddr >> 0) & 0xff, 
    83                 ret = spi_send_command(sizeof(cmd), bytes, cmd, readarr); 
     85                ret = spi_send_command(flash, sizeof(cmd), bytes, cmd, readarr); 
    8486        } 
    8587        if (ret) 
     
    9294} 
    9395 
    94 int spi_write_enable(void) 
     96int spi_write_enable(struct flashctx *flash) 
    9597{ 
    9698        static const unsigned char cmd[JEDEC_WREN_OUTSIZE] = { JEDEC_WREN }; 
     
    98100 
    99101        /* Send WREN (Write Enable) */ 
    100         result = spi_send_command(sizeof(cmd), 0, cmd, NULL); 
     102        result = spi_send_command(flash, sizeof(cmd), 0, cmd, NULL); 
    101103 
    102104        if (result) 
     
    106108} 
    107109 
    108 int spi_write_disable(void) 
     110int spi_write_disable(struct flashctx *flash) 
    109111{ 
    110112        static const unsigned char cmd[JEDEC_WRDI_OUTSIZE] = { JEDEC_WRDI }; 
    111113 
    112114        /* Send WRDI (Write Disable) */ 
    113         return spi_send_command(sizeof(cmd), 0, cmd, NULL); 
     115        return spi_send_command(flash, sizeof(cmd), 0, cmd, NULL); 
    114116} 
    115117 
     
    120122        uint32_t id2; 
    121123 
    122         if (spi_rdid(readarr, bytes)) { 
     124        if (spi_rdid(flash, readarr, bytes)) { 
    123125                return 0; 
    124126        } 
     
    200202        uint32_t id1, id2; 
    201203 
    202         if (spi_rems(readarr)) { 
     204        if (spi_rems(flash, readarr)) { 
    203205                return 0; 
    204206        } 
     
    243245         * 0x00 0x00 0x00. In that case, RES is pointless. 
    244246         */ 
    245         if (!spi_rdid(readarr, 3) && memcmp(readarr, allff, 3) && 
     247        if (!spi_rdid(flash, readarr, 3) && memcmp(readarr, allff, 3) && 
    246248            memcmp(readarr, all00, 3)) { 
    247249                msg_cdbg("Ignoring RES in favour of RDID.\n"); 
     
    251253         * 0x00 0x00. In that case, RES is pointless. 
    252254         */ 
    253         if (!spi_rems(readarr) && memcmp(readarr, allff, JEDEC_REMS_INSIZE) && 
     255        if (!spi_rems(flash, readarr) && 
     256            memcmp(readarr, allff, JEDEC_REMS_INSIZE) && 
    254257            memcmp(readarr, all00, JEDEC_REMS_INSIZE)) { 
    255258                msg_cdbg("Ignoring RES in favour of REMS.\n"); 
     
    257260        } 
    258261 
    259         if (spi_res(readarr, 1)) { 
     262        if (spi_res(flash, readarr, 1)) { 
    260263                return 0; 
    261264        } 
     
    280283        uint32_t id1, id2; 
    281284 
    282         if (spi_res(readarr, 2)) { 
     285        if (spi_res(flash, readarr, 2)) { 
    283286                return 0; 
    284287        } 
     
    299302} 
    300303 
    301 uint8_t spi_read_status_register(void) 
     304uint8_t spi_read_status_register(struct flashctx *flash) 
    302305{ 
    303306        static const unsigned char cmd[JEDEC_RDSR_OUTSIZE] = { JEDEC_RDSR }; 
     
    307310 
    308311        /* Read Status Register */ 
    309         ret = spi_send_command(sizeof(cmd), sizeof(readarr), cmd, readarr); 
     312        ret = spi_send_command(flash, sizeof(cmd), sizeof(readarr), cmd, 
     313                               readarr); 
    310314        if (ret) 
    311315                msg_cerr("RDSR failed!\n"); 
     
    415419        uint8_t status; 
    416420 
    417         status = spi_read_status_register(); 
     421        status = spi_read_status_register(flash); 
    418422        msg_cdbg("Chip status register is %02x\n", status); 
    419423        switch (flash->manufacture_id) { 
     
    466470        }}; 
    467471         
    468         result = spi_send_multicommand(cmds); 
     472        result = spi_send_multicommand(flash, cmds); 
    469473        if (result) { 
    470474                msg_cerr("%s failed during command execution\n", 
     
    476480         */ 
    477481        /* FIXME: We assume spi_read_status_register will never fail. */ 
    478         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     482        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    479483                programmer_delay(1000 * 1000); 
    480484        /* FIXME: Check the status register for errors. */ 
     
    503507        }}; 
    504508 
    505         result = spi_send_multicommand(cmds); 
     509        result = spi_send_multicommand(flash, cmds); 
    506510        if (result) { 
    507511                msg_cerr("%s failed during command execution\n", __func__); 
     
    512516         */ 
    513517        /* FIXME: We assume spi_read_status_register will never fail. */ 
    514         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     518        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    515519                programmer_delay(1000 * 1000); 
    516520        /* FIXME: Check the status register for errors. */ 
     
    518522} 
    519523 
    520 int spi_block_erase_52(struct flashctx *flash, unsigned int addr, unsigned int blocklen) 
     524int spi_block_erase_52(struct flashctx *flash, unsigned int addr, 
     525                       unsigned int blocklen) 
    521526{ 
    522527        int result; 
     
    544549        }}; 
    545550 
    546         result = spi_send_multicommand(cmds); 
     551        result = spi_send_multicommand(flash, cmds); 
    547552        if (result) { 
    548553                msg_cerr("%s failed during command execution at address 0x%x\n", 
     
    553558         * This usually takes 100-4000 ms, so wait in 100 ms steps. 
    554559         */ 
    555         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     560        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    556561                programmer_delay(100 * 1000); 
    557562        /* FIXME: Check the status register for errors. */ 
     
    564569 * 4-32k non-uniform for EON 
    565570 */ 
    566 int spi_block_erase_d8(struct flashctx *flash, unsigned int addr, unsigned int blocklen) 
     571int spi_block_erase_d8(struct flashctx *flash, unsigned int addr, 
     572                       unsigned int blocklen) 
    567573{ 
    568574        int result; 
     
    590596        }}; 
    591597 
    592         result = spi_send_multicommand(cmds); 
     598        result = spi_send_multicommand(flash, cmds); 
    593599        if (result) { 
    594600                msg_cerr("%s failed during command execution at address 0x%x\n", 
     
    599605         * This usually takes 100-4000 ms, so wait in 100 ms steps. 
    600606         */ 
    601         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     607        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    602608                programmer_delay(100 * 1000); 
    603609        /* FIXME: Check the status register for errors. */ 
     
    608614 * 4k for PMC 
    609615 */ 
    610 int spi_block_erase_d7(struct flashctx *flash, unsigned int addr, unsigned int blocklen) 
     616int spi_block_erase_d7(struct flashctx *flash, unsigned int addr, 
     617                       unsigned int blocklen) 
    611618{ 
    612619        int result; 
     
    634641        }}; 
    635642 
    636         result = spi_send_multicommand(cmds); 
     643        result = spi_send_multicommand(flash, cmds); 
    637644        if (result) { 
    638645                msg_cerr("%s failed during command execution at address 0x%x\n", 
     
    643650         * This usually takes 100-4000 ms, so wait in 100 ms steps. 
    644651         */ 
    645         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     652        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    646653                programmer_delay(100 * 1000); 
    647654        /* FIXME: Check the status register for errors. */ 
     
    650657 
    651658/* Sector size is usually 4k, though Macronix eliteflash has 64k */ 
    652 int spi_block_erase_20(struct flashctx *flash, unsigned int addr, unsigned int blocklen) 
     659int spi_block_erase_20(struct flashctx *flash, unsigned int addr, 
     660                       unsigned int blocklen) 
    653661{ 
    654662        int result; 
     
    676684        }}; 
    677685 
    678         result = spi_send_multicommand(cmds); 
     686        result = spi_send_multicommand(flash, cmds); 
    679687        if (result) { 
    680688                msg_cerr("%s failed during command execution at address 0x%x\n", 
     
    685693         * This usually takes 15-800 ms, so wait in 10 ms steps. 
    686694         */ 
    687         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     695        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    688696                programmer_delay(10 * 1000); 
    689697        /* FIXME: Check the status register for errors. */ 
     
    691699} 
    692700 
    693 int spi_block_erase_60(struct flashctx *flash, unsigned int addr, unsigned int blocklen) 
     701int spi_block_erase_60(struct flashctx *flash, unsigned int addr, 
     702                       unsigned int blocklen) 
    694703{ 
    695704        if ((addr != 0) || (blocklen != flash->total_size * 1024)) { 
     
    701710} 
    702711 
    703 int spi_block_erase_c7(struct flashctx *flash, unsigned int addr, unsigned int blocklen) 
     712int spi_block_erase_c7(struct flashctx *flash, unsigned int addr, 
     713                       unsigned int blocklen) 
    704714{ 
    705715        if ((addr != 0) || (blocklen != flash->total_size * 1024)) { 
     
    711721} 
    712722 
    713 int spi_write_status_enable(void) 
     723int spi_write_status_enable(struct flashctx *flash) 
    714724{ 
    715725        static const unsigned char cmd[JEDEC_EWSR_OUTSIZE] = { JEDEC_EWSR }; 
     
    717727 
    718728        /* Send EWSR (Enable Write Status Register). */ 
    719         result = spi_send_command(sizeof(cmd), JEDEC_EWSR_INSIZE, cmd, NULL); 
     729        result = spi_send_command(flash, sizeof(cmd), JEDEC_EWSR_INSIZE, cmd, NULL); 
    720730 
    721731        if (result) 
     
    752762        }}; 
    753763 
    754         result = spi_send_multicommand(cmds); 
     764        result = spi_send_multicommand(flash, cmds); 
    755765        if (result) { 
    756766                msg_cerr("%s failed during command execution\n", 
     
    767777         */ 
    768778        programmer_delay(100 * 1000); 
    769         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) { 
     779        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) { 
    770780                if (++i > 490) { 
    771781                        msg_cerr("Error: WIP bit after WRSR never cleared\n"); 
     
    800810        }}; 
    801811 
    802         result = spi_send_multicommand(cmds); 
     812        result = spi_send_multicommand(flash, cmds); 
    803813        if (result) { 
    804814                msg_cerr("%s failed during command execution\n", 
     
    815825         */ 
    816826        programmer_delay(100 * 1000); 
    817         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) { 
     827        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) { 
    818828                if (++i > 490) { 
    819829                        msg_cerr("Error: WIP bit after WRSR never cleared\n"); 
     
    841851} 
    842852 
    843 int spi_byte_program(unsigned int addr, uint8_t databyte) 
     853int spi_byte_program(struct flashctx *flash, unsigned int addr, 
     854                     uint8_t databyte) 
    844855{ 
    845856        int result; 
     
    868879        }}; 
    869880 
    870         result = spi_send_multicommand(cmds); 
     881        result = spi_send_multicommand(flash, cmds); 
    871882        if (result) { 
    872883                msg_cerr("%s failed during command execution at address 0x%x\n", 
     
    876887} 
    877888 
    878 int spi_nbyte_program(unsigned int addr, uint8_t *bytes, unsigned int len) 
     889int spi_nbyte_program(struct flashctx *flash, unsigned int addr, uint8_t *bytes, 
     890                      unsigned int len) 
    879891{ 
    880892        int result; 
     
    915927        memcpy(&cmd[4], bytes, len); 
    916928 
    917         result = spi_send_multicommand(cmds); 
     929        result = spi_send_multicommand(flash, cmds); 
    918930        if (result) { 
    919931                msg_cerr("%s failed during command execution at address 0x%x\n", 
     
    932944        int result; 
    933945 
    934         status = spi_read_status_register(); 
     946        status = spi_read_status_register(flash); 
    935947        /* If block protection is disabled, stop here. */ 
    936948        if ((status & 0x3c) == 0) 
     
    943955                return result; 
    944956        } 
    945         status = spi_read_status_register(); 
     957        status = spi_read_status_register(flash); 
    946958        if ((status & 0x3c) != 0) { 
    947959                msg_cerr("Block protection could not be disabled!\n"); 
     
    951963} 
    952964 
    953 int spi_nbyte_read(unsigned int address, uint8_t *bytes, unsigned int len) 
     965int spi_nbyte_read(struct flashctx *flash, unsigned int address, uint8_t *bytes, 
     966                   unsigned int len) 
    954967{ 
    955968        const unsigned char cmd[JEDEC_READ_OUTSIZE] = { 
     
    961974 
    962975        /* Send Read */ 
    963         return spi_send_command(sizeof(cmd), len, cmd, bytes); 
     976        return spi_send_command(flash, sizeof(cmd), len, cmd, bytes); 
    964977} 
    965978 
     
    969982 * Each page is read separately in chunks with a maximum size of chunksize. 
    970983 */ 
    971 int spi_read_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize) 
     984int spi_read_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, 
     985                     unsigned int len, unsigned int chunksize) 
    972986{ 
    973987        int rc = 0; 
     
    9921006                for (j = 0; j < lenhere; j += chunksize) { 
    9931007                        toread = min(chunksize, lenhere - j); 
    994                         rc = spi_nbyte_read(starthere + j, buf + starthere - start + j, toread); 
     1008                        rc = spi_nbyte_read(flash, starthere + j, buf + starthere - start + j, toread); 
    9951009                        if (rc) 
    9961010                                break; 
     
    10081022 * Each page is written separately in chunks with a maximum size of chunksize. 
    10091023 */ 
    1010 int spi_write_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len, unsigned int chunksize) 
     1024int spi_write_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start, 
     1025                      unsigned int len, unsigned int chunksize) 
    10111026{ 
    10121027        int rc = 0; 
     
    10361051                for (j = 0; j < lenhere; j += chunksize) { 
    10371052                        towrite = min(chunksize, lenhere - j); 
    1038                         rc = spi_nbyte_program(starthere + j, buf + starthere - start + j, towrite); 
     1053                        rc = spi_nbyte_program(flash, starthere + j, buf + starthere - start + j, towrite); 
    10391054                        if (rc) 
    10401055                                break; 
    1041                         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     1056                        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    10421057                                programmer_delay(10); 
    10431058                } 
     
    10561071 */ 
    10571072/* real chunksize is 1, logical chunksize is 1 */ 
    1058 int spi_chip_write_1(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 
     1073int spi_chip_write_1(struct flashctx *flash, uint8_t *buf, unsigned int start, 
     1074                     unsigned int len) 
    10591075{ 
    10601076        unsigned int i; 
     
    10621078 
    10631079        for (i = start; i < start + len; i++) { 
    1064                 result = spi_byte_program(i, buf[i - start]); 
     1080                result = spi_byte_program(flash, i, buf[i - start]); 
    10651081                if (result) 
    10661082                        return 1; 
    1067                 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     1083                while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    10681084                        programmer_delay(10); 
    10691085        } 
     
    10721088} 
    10731089 
    1074 int spi_aai_write(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 
     1090int spi_aai_write(struct flashctx *flash, uint8_t *buf, unsigned int start, 
     1091                  unsigned int len) 
    10751092{ 
    10761093        uint32_t pos = start; 
     
    11501167 
    11511168 
    1152         result = spi_send_multicommand(cmds); 
     1169        result = spi_send_multicommand(flash, cmds); 
    11531170        if (result) { 
    11541171                msg_cerr("%s failed during start command execution\n", 
     
    11591176                return result; 
    11601177        } 
    1161         while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     1178        while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    11621179                programmer_delay(10); 
    11631180 
     
    11691186                cmd[1] = buf[pos++ - start]; 
    11701187                cmd[2] = buf[pos++ - start]; 
    1171                 spi_send_command(JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE, 0, cmd, NULL); 
    1172                 while (spi_read_status_register() & JEDEC_RDSR_BIT_WIP) 
     1188                spi_send_command(flash, JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE, 0, 
     1189                                 cmd, NULL); 
     1190                while (spi_read_status_register(flash) & JEDEC_RDSR_BIT_WIP) 
    11731191                        programmer_delay(10); 
    11741192        } 
     
    11771195         * other non-AAI command. 
    11781196         */ 
    1179         spi_write_disable(); 
     1197        spi_write_disable(flash); 
    11801198 
    11811199        /* Write remaining byte (if any). */ 
  • trunk/sst28sf040.c

    r1473 r1474  
    3535        chipaddr bios = flash->virtual_memory; 
    3636 
    37         chip_readb(bios + 0x1823); 
    38         chip_readb(bios + 0x1820); 
    39         chip_readb(bios + 0x1822); 
    40         chip_readb(bios + 0x0418); 
    41         chip_readb(bios + 0x041B); 
    42         chip_readb(bios + 0x0419); 
    43         chip_readb(bios + 0x040A); 
     37        chip_readb(flash, bios + 0x1823); 
     38        chip_readb(flash, bios + 0x1820); 
     39        chip_readb(flash, bios + 0x1822); 
     40        chip_readb(flash, bios + 0x0418); 
     41        chip_readb(flash, bios + 0x041B); 
     42        chip_readb(flash, bios + 0x0419); 
     43        chip_readb(flash, bios + 0x040A); 
    4444 
    4545        return 0; 
     
    5050        chipaddr bios = flash->virtual_memory; 
    5151 
    52         chip_readb(bios + 0x1823); 
    53         chip_readb(bios + 0x1820); 
    54         chip_readb(bios + 0x1822); 
    55         chip_readb(bios + 0x0418); 
    56         chip_readb(bios + 0x041B); 
    57         chip_readb(bios + 0x0419); 
    58         chip_readb(bios + 0x041A); 
     52        chip_readb(flash, bios + 0x1823); 
     53        chip_readb(flash, bios + 0x1820); 
     54        chip_readb(flash, bios + 0x1822); 
     55        chip_readb(flash, bios + 0x0418); 
     56        chip_readb(flash, bios + 0x041B); 
     57        chip_readb(flash, bios + 0x0419); 
     58        chip_readb(flash, bios + 0x041A); 
    5959 
    6060        return 0; 
    6161} 
    6262 
    63 int erase_sector_28sf040(struct flashctx *flash, unsigned int address, unsigned int sector_size) 
     63int erase_sector_28sf040(struct flashctx *flash, unsigned int address, 
     64                         unsigned int sector_size) 
    6465{ 
    6566        chipaddr bios = flash->virtual_memory; 
    6667 
    6768        /* This command sequence is very similar to erase_block_82802ab. */ 
    68         chip_writeb(AUTO_PG_ERASE1, bios); 
    69         chip_writeb(AUTO_PG_ERASE2, bios + address); 
     69        chip_writeb(flash, AUTO_PG_ERASE1, bios); 
     70        chip_writeb(flash, AUTO_PG_ERASE2, bios + address); 
    7071 
    7172        /* wait for Toggle bit ready */ 
    72         toggle_ready_jedec(bios); 
     73        toggle_ready_jedec(flash, bios); 
    7374 
    7475        /* FIXME: Check the status register for errors. */ 
     
    7778 
    7879/* chunksize is 1 */ 
    79 int write_28sf040(struct flashctx *flash, uint8_t *src, unsigned int start, unsigned int len) 
     80int write_28sf040(struct flashctx *flash, uint8_t *src, unsigned int start, 
     81                  unsigned int len) 
    8082{ 
    8183        int i; 
     
    9193                } 
    9294                /*issue AUTO PROGRAM command */ 
    93                 chip_writeb(AUTO_PGRM, dst); 
    94                 chip_writeb(*src++, dst++); 
     95                chip_writeb(flash, AUTO_PGRM, dst); 
     96                chip_writeb(flash, *src++, dst++); 
    9597 
    9698                /* wait for Toggle bit ready */ 
    97                 toggle_ready_jedec(bios); 
     99                toggle_ready_jedec(flash, bios); 
    98100        } 
    99101 
     
    105107        chipaddr bios = flash->virtual_memory; 
    106108 
    107         chip_writeb(CHIP_ERASE, bios); 
    108         chip_writeb(CHIP_ERASE, bios); 
     109        chip_writeb(flash, CHIP_ERASE, bios); 
     110        chip_writeb(flash, CHIP_ERASE, bios); 
    109111 
    110112        programmer_delay(10); 
    111         toggle_ready_jedec(bios); 
     113        toggle_ready_jedec(flash, bios); 
    112114 
    113115        /* FIXME: Check the status register for errors. */ 
     
    115117} 
    116118 
    117 int erase_chip_28sf040(struct flashctx *flash, unsigned int addr, unsigned int blocklen) 
     119int erase_chip_28sf040(struct flashctx *flash, unsigned int addr, 
     120                       unsigned int blocklen) 
    118121{ 
    119122        if ((addr != 0) || (blocklen != flash->total_size * 1024)) { 
  • trunk/sst49lfxxxc.c

    r1473 r1474  
    2424#include "chipdrivers.h" 
    2525 
    26 static int write_lockbits_block_49lfxxxc(struct flashctx *flash, unsigned long address, unsigned char bits) 
     26static int write_lockbits_block_49lfxxxc(struct flashctx *flash, 
     27                                         unsigned long address, 
     28                                         unsigned char bits) 
    2729{ 
    2830        unsigned long lock = flash->virtual_registers + address + 2; 
    29         msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", lock, chip_readb(lock)); 
    30         chip_writeb(bits, lock); 
     31        msg_cdbg("lockbits at address=0x%08lx is 0x%01x\n", lock, 
     32                 chip_readb(flash, lock)); 
     33        chip_writeb(flash, bits, lock); 
    3134 
    3235        return 0; 
     
    6063} 
    6164 
    62 int erase_sector_49lfxxxc(struct flashctx *flash, unsigned int address, unsigned int sector_size) 
     65int erase_sector_49lfxxxc(struct flashctx *flash, unsigned int address, 
     66                          unsigned int sector_size) 
    6367{ 
    6468        uint8_t status; 
    6569        chipaddr bios = flash->virtual_memory; 
    6670 
    67         chip_writeb(0x30, bios); 
    68         chip_writeb(0xD0, bios + address); 
     71        chip_writeb(flash, 0x30, bios); 
     72        chip_writeb(flash, 0xD0, bios + address); 
    6973 
    7074        status = wait_82802ab(flash); 
  • trunk/sst_fwhub.c

    r1473 r1474  
    3030        uint8_t blockstatus; 
    3131 
    32         blockstatus = chip_readb(registers + offset + 2); 
     32        blockstatus = chip_readb(flash, registers + offset + 2); 
    3333        msg_cdbg("Lock status for 0x%06x (size 0x%06x) is %02x, ", 
    3434                     offset, flash->page_size, blockstatus); 
     
    6060        if (blockstatus) { 
    6161                msg_cdbg("Trying to clear lock for 0x%06x... ", offset); 
    62                 chip_writeb(0, registers + offset + 2); 
     62                chip_writeb(flash, 0, registers + offset + 2); 
    6363 
    6464                blockstatus = check_sst_fwhub_block_lock(flash, offset); 
  • trunk/stm50flw0x0x.c

    r1473 r1474  
    6161                for (j = 0; j < 0x10000; j += 0x1000) { 
    6262                        msg_cdbg("unlocking at 0x%x\n", offset + j); 
    63                         chip_writeb(unlock_sector, wrprotect + offset + j); 
    64                         if (chip_readb(wrprotect + offset + j) != unlock_sector) { 
     63                        chip_writeb(flash, unlock_sector, 
     64                                    wrprotect + offset + j); 
     65                        if (chip_readb(flash, wrprotect + offset + j) != 
     66                            unlock_sector) { 
    6567                                msg_cerr("Cannot unlock sector @ 0x%x\n", 
    6668                                       offset + j); 
     
    7072        } else { 
    7173                msg_cdbg("unlocking at 0x%x\n", offset); 
    72                 chip_writeb(unlock_sector, wrprotect + offset); 
    73                 if (chip_readb(wrprotect + offset) != unlock_sector) { 
     74                chip_writeb(flash, unlock_sector, wrprotect + offset); 
     75                if (chip_readb(flash, wrprotect + offset) != unlock_sector) { 
    7476                        msg_cerr("Cannot unlock sector @ 0x%x\n", offset); 
    7577                        return -1; 
     
    9597 
    9698/* This function is unused. */ 
    97 int erase_sector_stm50flw0x0x(struct flashctx *flash, unsigned int sector, unsigned int sectorsize) 
     99int erase_sector_stm50flw0x0x(struct flashctx *flash, unsigned int sector, 
     100                              unsigned int sectorsize) 
    98101{ 
    99102        chipaddr bios = flash->virtual_memory + sector; 
    100103 
    101104        // clear status register 
    102         chip_writeb(0x50, bios); 
     105        chip_writeb(flash, 0x50, bios); 
    103106        // now start it 
    104         chip_writeb(0x32, bios); 
    105         chip_writeb(0xd0, bios); 
     107        chip_writeb(flash, 0x32, bios); 
     108        chip_writeb(flash, 0xd0, bios); 
    106109        programmer_delay(10); 
    107110 
  • trunk/w29ee011.c

    r1473 r1474  
    3939 
    4040        /* Issue JEDEC Product ID Entry command */ 
    41         chip_writeb(0xAA, bios + 0x5555); 
     41        chip_writeb(flash, 0xAA, bios + 0x5555); 
    4242        programmer_delay(10); 
    43         chip_writeb(0x55, bios + 0x2AAA); 
     43        chip_writeb(flash, 0x55, bios + 0x2AAA); 
    4444        programmer_delay(10); 
    45         chip_writeb(0x80, bios + 0x5555); 
     45        chip_writeb(flash, 0x80, bios + 0x5555); 
    4646        programmer_delay(10); 
    47         chip_writeb(0xAA, bios + 0x5555); 
     47        chip_writeb(flash, 0xAA, bios + 0x5555); 
    4848        programmer_delay(10); 
    49         chip_writeb(0x55, bios + 0x2AAA); 
     49        chip_writeb(flash, 0x55, bios + 0x2AAA); 
    5050        programmer_delay(10); 
    51         chip_writeb(0x60, bios + 0x5555); 
     51        chip_writeb(flash, 0x60, bios + 0x5555); 
    5252        programmer_delay(10); 
    5353 
    5454        /* Read product ID */ 
    55         id1 = chip_readb(bios); 
    56         id2 = chip_readb(bios + 0x01); 
     55        id1 = chip_readb(flash, bios); 
     56        id2 = chip_readb(flash, bios + 0x01); 
    5757 
    5858        /* Issue JEDEC Product ID Exit command */ 
    59         chip_writeb(0xAA, bios + 0x5555); 
     59        chip_writeb(flash, 0xAA, bios + 0x5555); 
    6060        programmer_delay(10); 
    61         chip_writeb(0x55, bios + 0x2AAA); 
     61        chip_writeb(flash, 0x55, bios + 0x2AAA); 
    6262        programmer_delay(10); 
    63         chip_writeb(0xF0, bios + 0x5555); 
     63        chip_writeb(flash, 0xF0, bios + 0x5555); 
    6464        programmer_delay(10); 
    6565 
  • trunk/w39.c

    r1473 r1474  
    2727        uint8_t locking; 
    2828 
    29         locking = chip_readb(wrprotect); 
     29        locking = chip_readb(flash, wrprotect); 
    3030        msg_cdbg("Lock status of block at 0x%08x is ", offset); 
    3131        switch (locking & 0x7) { 
     
    6565        uint8_t locking; 
    6666 
    67         locking = chip_readb(wrprotect); 
     67        locking = chip_readb(flash, wrprotect); 
    6868        /* Read or write lock present? */ 
    6969        if (locking & ((1 << 2) | (1 << 0))) { 
     
    7474                } else { 
    7575                        msg_cdbg("Unlocking block at 0x%08x\n", offset); 
    76                         chip_writeb(0, wrprotect); 
     76                        chip_writeb(flash, 0, wrprotect); 
    7777                } 
    7878        } 
     
    8787 
    8888        /* Product Identification Entry */ 
    89         chip_writeb(0xAA, bios + 0x5555); 
    90         chip_writeb(0x55, bios + 0x2AAA); 
    91         chip_writeb(0x90, bios + 0x5555); 
     89        chip_writeb(flash, 0xAA, bios + 0x5555); 
     90        chip_writeb(flash, 0x55, bios + 0x2AAA); 
     91        chip_writeb(flash, 0x90, bios + 0x5555); 
    9292        programmer_delay(10); 
    9393 
    9494        /* Read something, maybe hardware lock bits */ 
    95         val = chip_readb(bios + offset); 
     95        val = chip_readb(flash, bios + offset); 
    9696 
    9797        /* Product Identification Exit */ 
    98         chip_writeb(0xAA, bios + 0x5555); 
    99         chip_writeb(0x55, bios + 0x2AAA); 
    100         chip_writeb(0xF0, bios + 0x5555); 
     98        chip_writeb(flash, 0xAA, bios + 0x5555); 
     99        chip_writeb(flash, 0x55, bios + 0x2AAA); 
     100        chip_writeb(flash, 0xF0, bios + 0x5555); 
    101101        programmer_delay(10); 
    102102 
     
    161161} 
    162162 
    163 int printlock_w39l040(struct flashctx * flash) 
     163int printlock_w39l040(struct flashctx *flash) 
    164164{ 
    165165        uint8_t lock; 
  • trunk/wbsio_spi.c

    r1473 r1474  
    6161} 
    6262 
    63 static int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    64                       const unsigned char *writearr, unsigned char *readarr); 
    65 static int wbsio_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); 
     63static int wbsio_spi_send_command(struct flashctx *flash, unsigned int writecnt, 
     64                                  unsigned int readcnt, 
     65                                  const unsigned char *writearr, 
     66                                  unsigned char *readarr); 
     67static int wbsio_spi_read(struct flashctx *flash, uint8_t *buf, 
     68                          unsigned int start, unsigned int len); 
    6669 
    6770static const struct spi_programmer spi_programmer_wbsio = { 
     
    111114 * such a big difference? 
    112115 */ 
    113 static int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    114                       const unsigned char *writearr, unsigned char *readarr) 
     116static int wbsio_spi_send_command(struct flashctx *flash, unsigned int writecnt, 
     117                                  unsigned int readcnt, 
     118                                  const unsigned char *writearr, 
     119                                  unsigned char *readarr) 
    115120{ 
    116121        int i; 
     
    195200} 
    196201 
    197 static int wbsio_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) 
     202static int wbsio_spi_read(struct flashctx *flash, uint8_t *buf, 
     203                          unsigned int start, unsigned int len) 
    198204{ 
    199205        return read_memmapped(flash, buf, start, len); 
Note: See TracChangeset for help on using the changeset viewer.