diff options
author | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2011-12-14 22:25:15 +0000 |
---|---|---|
committer | Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> | 2011-12-14 22:25:15 +0000 |
commit | 63fd9026f1e82b67a65072fda862ba7af35839e1 (patch) | |
tree | 7d9ffba077715cf9e75c9f4a36d0d7f11a3181f6 /flash.h | |
parent | 83c92e983aaf11fb6f5bafb6744275c50add193c (diff) | |
download | flashrom-63fd9026f1e82b67a65072fda862ba7af35839e1.tar.gz flashrom-63fd9026f1e82b67a65072fda862ba7af35839e1.tar.bz2 flashrom-63fd9026f1e82b67a65072fda862ba7af35839e1.zip |
Use struct flashctx instead of struct flashchip for flash chip access
Struct flashchip is used only for the flashchips array and for
operations which do not access hardware, e.g. printing a list of
supported flash chips.
struct flashctx (flash context) contains all data available in
struct flashchip, but it also contains runtime information like
mapping addresses. struct flashctx is expected to grow additional
members over time, a prime candidate being programmer info.
struct flashctx contains all of struct flashchip with identical
member layout, but struct flashctx has additional members at the end.
The separation between struct flashchip/flashctx shrinks the memory
requirement of the big flashchips array and allows future extension
of flashctx without having to worry about bloat.
Corresponding to flashrom svn r1473.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>
Diffstat (limited to 'flash.h')
-rw-r--r-- | flash.h | 56 |
1 files changed, 40 insertions, 16 deletions
@@ -93,6 +93,8 @@ enum chipbustype { #define FEATURE_WRSR_WREN (1 << 7) #define FEATURE_WRSR_EITHER (FEATURE_WRSR_EWSR | FEATURE_WRSR_WREN) +struct flashctx; + struct flashchip { const char *vendor; const char *name; @@ -119,7 +121,7 @@ struct flashchip { */ uint32_t tested; - int (*probe) (struct flashchip *flash); + int (*probe) (struct flashctx *flash); /* Delay after "enter/exit ID mode" commands in microseconds. * NB: negative values have special meanings, see TIMING_* below. @@ -140,20 +142,42 @@ struct flashchip { } eraseblocks[NUM_ERASEREGIONS]; /* a block_erase function should try to erase one block of size * 'blocklen' at address 'blockaddr' and return 0 on success. */ - int (*block_erase) (struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen); + int (*block_erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen); } block_erasers[NUM_ERASEFUNCTIONS]; - int (*printlock) (struct flashchip *flash); - int (*unlock) (struct flashchip *flash); - int (*write) (struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len); - int (*read) (struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len); - struct { + int (*printlock) (struct flashctx *flash); + int (*unlock) (struct flashctx *flash); + int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); + int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); + struct voltage { uint16_t min; uint16_t max; } voltage; +}; - /* Some flash devices have an additional register space. */ +/* struct flashctx must always contain struct flashchip at the beginning. */ +struct flashctx { + const char *vendor; + const char *name; + enum chipbustype bustype; + uint32_t manufacture_id; + uint32_t model_id; + int total_size; + int page_size; + int feature_bits; + uint32_t tested; + int (*probe) (struct flashctx *flash); + int probe_timing; + struct block_eraser block_erasers[NUM_ERASEFUNCTIONS]; + int (*printlock) (struct flashctx *flash); + int (*unlock) (struct flashctx *flash); + int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); + int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); + struct voltage voltage; + /* struct flashchip ends here. */ + chipaddr virtual_memory; + /* Some flash devices have an additional register space. */ chipaddr virtual_registers; }; @@ -203,23 +227,23 @@ extern enum chipbustype buses_supported; extern int verbose; extern const char flashrom_version[]; extern char *chip_to_probe; -void map_flash_registers(struct flashchip *flash); -int read_memmapped(struct flashchip *flash, uint8_t *buf, unsigned int start, unsigned int len); -int erase_flash(struct flashchip *flash); -int probe_flash(int startchip, struct flashchip *fill_flash, int force); -int read_flash_to_file(struct flashchip *flash, const char *filename); +void map_flash_registers(struct flashctx *flash); +int read_memmapped(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); +int erase_flash(struct flashctx *flash); +int probe_flash(int startchip, struct flashctx *fill_flash, int force); +int read_flash_to_file(struct flashctx *flash, const char *filename); int min(int a, int b); int max(int a, int b); void tolower_string(char *str); char *extract_param(char **haystack, const char *needle, const char *delim); -int verify_range(struct flashchip *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len, const char *message); +int verify_range(struct flashctx *flash, uint8_t *cmpbuf, unsigned int start, unsigned int len, const char *message); int need_erase(uint8_t *have, uint8_t *want, unsigned int len, enum write_granularity gran); char *strcat_realloc(char *dest, const char *src); void print_version(void); void print_banner(void); void list_programmers_linebreak(int startcol, int cols, int paren); int selfcheck(void); -int doit(struct flashchip *flash, int force, const char *filename, int read_it, int write_it, int erase_it, int verify_it); +int doit(struct flashctx *flash, int force, const char *filename, int read_it, int write_it, int erase_it, int verify_it); int read_buf_from_file(unsigned char *buf, unsigned long size, const char *filename); int write_buf_to_file(unsigned char *buf, unsigned long size, const char *filename); @@ -259,7 +283,7 @@ int print(int type, const char *fmt, ...) __attribute__((format(printf, 2, 3))); /* layout.c */ int read_romlayout(char *name); int find_romentry(char *name); -int handle_romentries(struct flashchip *flash, uint8_t *oldcontents, uint8_t *newcontents); +int handle_romentries(struct flashctx *flash, uint8_t *oldcontents, uint8_t *newcontents); /* spi.c */ struct spi_command { |