diff options
author | Stefan Reinauer <stepan@coresystems.de> | 2007-05-24 08:48:10 +0000 |
---|---|---|
committer | Stefan Reinauer <stepan@coresystems.de> | 2007-05-24 08:48:10 +0000 |
commit | d0f64d83fcf016f32060165027145391f7360eb3 (patch) | |
tree | f0892c97e2f71c31bab955384efebffd8fb1621a | |
parent | 26209c1605e2f7920002cb20fd26ce44877f8c8b (diff) | |
download | flashrom-d0f64d83fcf016f32060165027145391f7360eb3.zip flashrom-d0f64d83fcf016f32060165027145391f7360eb3.tar.gz |
Factor out register mapping code
Corresponding to flashrom svn r113 and coreboot v2 svn r2691.
Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-by: Stefan Reinauer <stepan@coresystems.de>
-rw-r--r-- | 82802ab.c | 20 | ||||
-rw-r--r-- | flash.h | 2 | ||||
-rw-r--r-- | flashrom.c | 17 | ||||
-rw-r--r-- | sharplhf00l04.c | 23 | ||||
-rw-r--r-- | sst49lfxxxc.c | 13 | ||||
-rw-r--r-- | sst_fwhub.c | 12 |
6 files changed, 32 insertions, 55 deletions
@@ -49,7 +49,6 @@ void print_82802ab_status(uint8_t status) int probe_82802ab(struct flashchip *flash) { volatile uint8_t *bios = flash->virtual_memory; - volatile uint8_t *registers; uint8_t id1, id2; #if 0 @@ -75,23 +74,12 @@ int probe_82802ab(struct flashchip *flash) printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2); - if (id1 == flash->manufacture_id && id2 == flash->model_id) { - size_t size = flash->total_size * 1024; + if (id1 != flash->manufacture_id || id2 != flash->model_id) + return 0; - // we need to mmap the write-protect space. - registers = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED, - fd_mem, (off_t) (0 - 0x400000 - size)); - if (registers == MAP_FAILED) { - // it's this part but we can't map it ... - perror("Can't mmap memory using " MEM_DEV); - exit(1); - } + map_flash_registers(flash); - flash->virtual_registers = registers; - return 1; - } - - return 0; + return 1; } uint8_t wait_82802ab(volatile uint8_t *bios) @@ -154,4 +154,6 @@ int chipset_flash_enable(void); /* chipset_enable.c */ extern int fd_mem; +int map_flash_registers(struct flashchip *flash); /* flashrom.c */ + #endif /* !__FLASH_H__ */ @@ -99,6 +99,23 @@ struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device, return NULL; } +int map_flash_registers(struct flashchip *flash) +{ + volatile uint8_t *registers; + size_t size = flash->total_size * 1024; + + registers = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED, + fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1)); + + if (registers == MAP_FAILED) { + perror("Can't mmap registers using " MEM_DEV); + exit(1); + } + flash->virtual_registers = registers; + + return 0; +} + struct flashchip *probe_flash(struct flashchip *flash) { volatile uint8_t *bios; diff --git a/sharplhf00l04.c b/sharplhf00l04.c index a4d086e..1caedd0 100644 --- a/sharplhf00l04.c +++ b/sharplhf00l04.c @@ -48,7 +48,6 @@ void print_lhf00l04_status(uint8_t status) int probe_lhf00l04(struct flashchip *flash) { volatile uint8_t *bios = flash->virtual_memory; - volatile uint8_t *registers; uint8_t id1, id2; #if 0 @@ -75,24 +74,12 @@ int probe_lhf00l04(struct flashchip *flash) printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2); - if (id1 == flash->manufacture_id && id2 == flash->model_id) { - size_t size = flash->total_size * 1024; - // we need to mmap the write-protect space. - registers = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED, - fd_mem, (off_t) (0 - 0x400000 - size)); - if (registers == MAP_FAILED) { - // it's this part but we can't map it ... - perror("Can't mmap memory using " MEM_DEV); - exit(1); - } - - flash->virtual_registers = registers; - printf("bios %p, *bios 0x%x, bios[1] 0x%x\n", bios, *bios, - bios[1]); - return 1; - } + if (id1 != flash->manufacture_id || id2 != flash->model_id) + return 0; + + map_flash_registers(flash); - return 0; + return 1; } uint8_t wait_lhf00l04(volatile uint8_t *bios) diff --git a/sst49lfxxxc.c b/sst49lfxxxc.c index b8f4b84..16f84df 100644 --- a/sst49lfxxxc.c +++ b/sst49lfxxxc.c @@ -133,10 +133,8 @@ static __inline__ int write_sector_49lfxxxc(volatile uint8_t *bios, int probe_49lfxxxc(struct flashchip *flash) { volatile uint8_t *bios = flash->virtual_memory; - volatile uint8_t *registers; uint8_t id1, id2; - size_t size = flash->total_size * 1024; *bios = RESET; @@ -147,17 +145,12 @@ int probe_49lfxxxc(struct flashchip *flash) *bios = RESET; printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2); + if (!(id1 == flash->manufacture_id && id2 == flash->model_id)) return 0; - registers = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED, - fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1)); - if (registers == MAP_FAILED) { - // it's this part but we can't map it ... - perror("Can't mmap memory using " MEM_DEV); - exit(1); - } - flash->virtual_registers = registers; + map_flash_registers(flash); + return 1; } diff --git a/sst_fwhub.c b/sst_fwhub.c index 78589b1..b828cee 100644 --- a/sst_fwhub.c +++ b/sst_fwhub.c @@ -46,21 +46,11 @@ void print_sst_fwhub_status(uint8_t status) /* probe_jedec works fine for probing */ int probe_sst_fwhub(struct flashchip *flash) { - volatile uint8_t *registers; - size_t size = flash->total_size * 1024; - if (probe_jedec(flash) == 0) return 0; - registers = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED, - fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1)); - if (registers == MAP_FAILED) { - // it's this part but we can't map it ... - perror("Can't mmap memory using " MEM_DEV); - exit(1); - } + map_flash_registers(flash); - flash->virtual_registers = registers; return 1; } |