Changeset 1112 for trunk/programmer.h


Ignore:
Timestamp:
07/28/10 00:41:39 (22 months ago)
Author:
hailfinger
Message:

Split off programmer.h from flash.h.
Programmer specific functions are of absolutely no interest to any file
except those dealing with programmer specific actions (special SPI
commands and the generic core).

The new header structure is as follows (and yes, improvements are
possible):
flashchips.h flash chip IDs
chipdrivers.h chip-specific read/write/... functions
flash.h common header for all stuff that doesn't fit elsewhere
hwaccess.h hardware access functions
programmer.h programmer specific functions
coreboot_tables.h header from coreboot, internal programmer only
spi.h SPI command definitions

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>
Acked-by: Uwe Hermann <uwe@…>

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/programmer.h

    r1111 r1112  
    2222 */ 
    2323 
    24 #ifndef __FLASH_H__ 
    25 #define __FLASH_H__ 1 
    26  
    27 #include <stdint.h> 
    28 #include <stddef.h> 
    29 #include "hwaccess.h" 
    30 #ifdef _WIN32 
    31 #include <windows.h> 
    32 #undef min 
    33 #undef max 
    34 #endif 
    35  
    36 typedef unsigned long chipaddr; 
     24#ifndef __PROGRAMMER_H__ 
     25#define __PROGRAMMER_H__ 1 
    3726 
    3827enum programmer { 
     
    114103extern const struct programmer_entry programmer_table[]; 
    115104 
    116 int register_shutdown(void (*function) (void *data), void *data); 
    117  
    118105int programmer_init(char *param); 
    119106int programmer_shutdown(void); 
    120 void *programmer_map_flash_region(const char *descr, unsigned long phys_addr, 
    121                                   size_t len); 
    122 void programmer_unmap_flash_region(void *virt_addr, size_t len); 
    123 void chip_writeb(uint8_t val, chipaddr addr); 
    124 void chip_writew(uint16_t val, chipaddr addr); 
    125 void chip_writel(uint32_t val, chipaddr addr); 
    126 void chip_writen(uint8_t *buf, chipaddr addr, size_t len); 
    127 uint8_t chip_readb(const chipaddr addr); 
    128 uint16_t chip_readw(const chipaddr addr); 
    129 uint32_t chip_readl(const chipaddr addr); 
    130 void chip_readn(uint8_t *buf, const chipaddr addr, size_t len); 
    131 void programmer_delay(int usecs); 
    132107 
    133108enum bitbang_spi_master_type { 
     
    147122        int (*get_miso) (void); 
    148123}; 
    149  
    150 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 
    151  
    152 enum chipbustype { 
    153         CHIP_BUSTYPE_NONE       = 0, 
    154         CHIP_BUSTYPE_PARALLEL   = 1 << 0, 
    155         CHIP_BUSTYPE_LPC        = 1 << 1, 
    156         CHIP_BUSTYPE_FWH        = 1 << 2, 
    157         CHIP_BUSTYPE_SPI        = 1 << 3, 
    158         CHIP_BUSTYPE_NONSPI     = CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH, 
    159         CHIP_BUSTYPE_UNKNOWN    = CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI, 
    160 }; 
    161  
    162 /* 
    163  * How many different contiguous runs of erase blocks with one size each do 
    164  * we have for a given erase function? 
    165  */ 
    166 #define NUM_ERASEREGIONS 5 
    167  
    168 /* 
    169  * How many different erase functions do we have per chip? 
    170  */ 
    171 #define NUM_ERASEFUNCTIONS 5 
    172  
    173 #define FEATURE_REGISTERMAP     (1 << 0) 
    174 #define FEATURE_BYTEWRITES      (1 << 1) 
    175 #define FEATURE_LONG_RESET      (0 << 4) 
    176 #define FEATURE_SHORT_RESET     (1 << 4) 
    177 #define FEATURE_EITHER_RESET    FEATURE_LONG_RESET 
    178 #define FEATURE_ADDR_FULL       (0 << 2) 
    179 #define FEATURE_ADDR_MASK       (3 << 2) 
    180 #define FEATURE_ADDR_2AA        (1 << 2) 
    181 #define FEATURE_ADDR_AAA        (2 << 2) 
    182 #define FEATURE_ADDR_SHIFTED    (1 << 5) 
    183  
    184 struct flashchip { 
    185         const char *vendor; 
    186         const char *name; 
    187  
    188         enum chipbustype bustype; 
    189  
    190         /* 
    191          * With 32bit manufacture_id and model_id we can cover IDs up to 
    192          * (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's 
    193          * Identification code. 
    194          */ 
    195         uint32_t manufacture_id; 
    196         uint32_t model_id; 
    197  
    198         int total_size; 
    199         int page_size; 
    200         int feature_bits; 
    201  
    202         /* 
    203          * Indicate if flashrom has been tested with this flash chip and if 
    204          * everything worked correctly. 
    205          */ 
    206         uint32_t tested; 
    207  
    208         int (*probe) (struct flashchip *flash); 
    209  
    210         /* Delay after "enter/exit ID mode" commands in microseconds. */ 
    211         int probe_timing; 
    212  
    213         /* 
    214          * Erase blocks and associated erase function. Any chip erase function 
    215          * is stored as chip-sized virtual block together with said function. 
    216          */ 
    217         struct block_eraser { 
    218                 struct eraseblock{ 
    219                         unsigned int size; /* Eraseblock size */ 
    220                         unsigned int count; /* Number of contiguous blocks with that size */ 
    221                 } eraseblocks[NUM_ERASEREGIONS]; 
    222                 int (*block_erase) (struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen); 
    223         } block_erasers[NUM_ERASEFUNCTIONS]; 
    224  
    225         int (*printlock) (struct flashchip *flash); 
    226         int (*unlock) (struct flashchip *flash); 
    227         int (*write) (struct flashchip *flash, uint8_t *buf); 
    228         int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len); 
    229  
    230         /* Some flash devices have an additional register space. */ 
    231         chipaddr virtual_memory; 
    232         chipaddr virtual_registers; 
    233 }; 
    234  
    235 #define TEST_UNTESTED   0 
    236  
    237 #define TEST_OK_PROBE   (1 << 0) 
    238 #define TEST_OK_READ    (1 << 1) 
    239 #define TEST_OK_ERASE   (1 << 2) 
    240 #define TEST_OK_WRITE   (1 << 3) 
    241 #define TEST_OK_PR      (TEST_OK_PROBE | TEST_OK_READ) 
    242 #define TEST_OK_PRE     (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE) 
    243 #define TEST_OK_PRW     (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_WRITE) 
    244 #define TEST_OK_PREW    (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE | TEST_OK_WRITE) 
    245 #define TEST_OK_MASK    0x0f 
    246  
    247 #define TEST_BAD_PROBE  (1 << 4) 
    248 #define TEST_BAD_READ   (1 << 5) 
    249 #define TEST_BAD_ERASE  (1 << 6) 
    250 #define TEST_BAD_WRITE  (1 << 7) 
    251 #define TEST_BAD_PREW   (TEST_BAD_PROBE | TEST_BAD_READ | TEST_BAD_ERASE | TEST_BAD_WRITE) 
    252 #define TEST_BAD_MASK   0xf0 
    253  
    254 /* Timing used in probe routines. ZERO is -2 to differentiate between an unset 
    255  * field and zero delay. 
    256  *  
    257  * SPI devices will always have zero delay and ignore this field. 
    258  */ 
    259 #define TIMING_FIXME    -1 
    260 /* this is intentionally same value as fixme */ 
    261 #define TIMING_IGNORED  -1 
    262 #define TIMING_ZERO     -2 
    263  
    264 extern struct flashchip flashchips[]; 
    265124 
    266125#if CONFIG_INTERNAL == 1 
     
    320179extern const struct board_info boards_known[]; 
    321180extern const struct board_info laptops_known[]; 
    322  
    323181#endif 
    324182 
     
    330188#if NEED_PCI == 1 
    331189/* pcidev.c */ 
    332  
    333190extern uint32_t io_base_addr; 
    334191extern struct pci_access *pacc; 
     
    346203 
    347204/* print.c */ 
    348 char *flashbuses_to_text(enum chipbustype bustype); 
    349 void print_supported(void); 
    350205#if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT >= 1 
    351206void print_supported_pcidevs(const struct pcidev_status *devs); 
    352207#endif 
    353 void print_supported_wiki(void); 
    354208 
    355209/* board_enable.c */ 
     
    575429 
    576430/* flashrom.c */ 
    577 enum write_granularity { 
    578         write_gran_1bit, 
    579         write_gran_1byte, 
    580         write_gran_256bytes, 
    581 }; 
    582 extern enum chipbustype buses_supported; 
    583431struct decode_sizes { 
    584432        uint32_t parallel; 
     
    590438extern int programmer_may_write; 
    591439extern unsigned long flashbase; 
    592 extern int verbose; 
    593 extern const char * const flashrom_version; 
    594 extern char *chip_to_probe; 
    595 void map_flash_registers(struct flashchip *flash); 
    596 int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len); 
    597 int erase_flash(struct flashchip *flash); 
    598 struct flashchip *probe_flash(struct flashchip *first_flash, int force); 
    599 int read_flash_to_file(struct flashchip *flash, char *filename); 
    600440void check_chip_supported(struct flashchip *flash); 
    601441int check_max_decode(enum chipbustype buses, uint32_t size); 
    602 int min(int a, int b); 
    603 int max(int a, int b); 
    604 char *extract_param(char **haystack, char *needle, char *delim); 
    605442char *extract_programmer_param(char *param_name); 
    606 int check_erased_range(struct flashchip *flash, int start, int len); 
    607 int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message); 
    608 int need_erase(uint8_t *have, uint8_t *want, int len, enum write_granularity gran); 
    609 char *strcat_realloc(char *dest, const char *src); 
    610 void print_version(void); 
    611 void print_banner(void); 
    612 int selfcheck(void); 
    613 int doit(struct flashchip *flash, int force, char *filename, int read_it, int write_it, int erase_it, int verify_it); 
    614  
    615 #define OK 0 
    616 #define NT 1    /* Not tested */ 
    617  
    618 /* Something happened that shouldn't happen, but we can go on */ 
    619 #define ERROR_NONFATAL 0x100 
    620  
    621 /* cli_output.c */ 
    622 /* Let gcc and clang check for correct printf-style format strings. */ 
    623 int print(int type, const char *fmt, ...) __attribute__((format(printf, 2, 3))); 
    624 #define MSG_ERROR       0 
    625 #define MSG_INFO        1 
    626 #define MSG_DEBUG       2 
    627 #define MSG_BARF        3 
    628 #define msg_gerr(...)   print(MSG_ERROR, __VA_ARGS__)   /* general errors */ 
    629 #define msg_perr(...)   print(MSG_ERROR, __VA_ARGS__)   /* programmer errors */ 
    630 #define msg_cerr(...)   print(MSG_ERROR, __VA_ARGS__)   /* chip errors */ 
    631 #define msg_ginfo(...)  print(MSG_INFO, __VA_ARGS__)    /* general info */ 
    632 #define msg_pinfo(...)  print(MSG_INFO, __VA_ARGS__)    /* programmer info */ 
    633 #define msg_cinfo(...)  print(MSG_INFO, __VA_ARGS__)    /* chip info */ 
    634 #define msg_gdbg(...)   print(MSG_DEBUG, __VA_ARGS__)   /* general debug */ 
    635 #define msg_pdbg(...)   print(MSG_DEBUG, __VA_ARGS__)   /* programmer debug */ 
    636 #define msg_cdbg(...)   print(MSG_DEBUG, __VA_ARGS__)   /* chip debug */ 
    637 #define msg_gspew(...)  print(MSG_BARF, __VA_ARGS__)    /* general debug barf  */ 
    638 #define msg_pspew(...)  print(MSG_BARF, __VA_ARGS__)    /* programmer debug barf  */ 
    639 #define msg_cspew(...)  print(MSG_BARF, __VA_ARGS__)    /* chip debug barf  */ 
    640  
    641 /* cli_classic.c */ 
    642 int cli_classic(int argc, char *argv[]); 
    643443 
    644444/* layout.c */ 
    645445int show_id(uint8_t *bios, int size, int force); 
    646 int read_romlayout(char *name); 
    647 int find_romentry(char *name); 
    648 int handle_romentries(uint8_t *buffer, struct flashchip *flash); 
    649446 
    650447/* spi.c */ 
     
    679476}; 
    680477extern const int spi_programmer_count; 
    681 struct spi_command { 
    682         unsigned int writecnt; 
    683         unsigned int readcnt; 
    684         const unsigned char *writearr; 
    685         unsigned char *readarr; 
    686 }; 
    687478struct spi_programmer { 
    688479        int (*command)(unsigned int writecnt, unsigned int readcnt, 
     
    697488extern enum spi_controller spi_controller; 
    698489extern const struct spi_programmer spi_programmer[]; 
    699 int spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    700                 const unsigned char *writearr, unsigned char *readarr); 
    701 int spi_send_multicommand(struct spi_command *cmds); 
    702490int default_spi_send_command(unsigned int writecnt, unsigned int readcnt, 
    703491                             const unsigned char *writearr, unsigned char *readarr); 
    704492int default_spi_send_multicommand(struct spi_command *cmds); 
    705 uint32_t spi_get_valid_read_addr(void); 
    706493 
    707494/* ichspi.c */ 
     
    769556int serialport_read(unsigned char *buf, unsigned int readcnt); 
    770557 
    771 #endif                          /* !__FLASH_H__ */ 
     558#endif                          /* !__PROGRAMMER_H__ */ 
Note: See TracChangeset for help on using the changeset viewer.