diff options
Diffstat (limited to 'src/flash/nor/cfi.c')
-rw-r--r-- | src/flash/nor/cfi.c | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/src/flash/nor/cfi.c b/src/flash/nor/cfi.c index c22bcde..3e265dd 100644 --- a/src/flash/nor/cfi.c +++ b/src/flash/nor/cfi.c @@ -131,18 +131,18 @@ static inline uint32_t flash_address(struct flash_bank *bank, int sector, uint32 } } -static int cfi_target_write_memory(struct target *target, target_addr_t addr, +static int cfi_target_write_memory(struct flash_bank *bank, target_addr_t addr, uint32_t size, uint32_t count, const uint8_t *buffer) { - return target_write_memory(target, addr, size, count, buffer); + return target_write_memory(bank->target, addr, size, count, buffer); } -static int cfi_target_read_memory(struct target *target, target_addr_t addr, +static int cfi_target_read_memory(struct flash_bank *bank, target_addr_t addr, uint32_t size, uint32_t count, uint8_t *buffer) { - return target_read_memory(target, addr, size, count, buffer); + return target_read_memory(bank->target, addr, size, count, buffer); } static void cfi_command(struct flash_bank *bank, uint8_t cmd, uint8_t *cmd_buf) @@ -170,7 +170,7 @@ static int cfi_send_command(struct flash_bank *bank, uint8_t cmd, uint32_t addre uint8_t command[CFI_MAX_BUS_WIDTH]; cfi_command(bank, cmd, command); - return cfi_target_write_memory(bank->target, address, bank->bus_width, 1, command); + return cfi_target_write_memory(bank, address, bank->bus_width, 1, command); } /* read unsigned 8-bit value from the bank @@ -179,12 +179,11 @@ static int cfi_send_command(struct flash_bank *bank, uint8_t cmd, uint32_t addre */ static int cfi_query_u8(struct flash_bank *bank, int sector, uint32_t offset, uint8_t *val) { - struct target *target = bank->target; struct cfi_flash_bank *cfi_info = bank->driver_priv; uint8_t data[CFI_MAX_BUS_WIDTH]; int retval; - retval = cfi_target_read_memory(target, flash_address(bank, sector, offset), + retval = cfi_target_read_memory(bank, flash_address(bank, sector, offset), bank->bus_width, 1, data); if (retval != ERROR_OK) return retval; @@ -203,13 +202,12 @@ static int cfi_query_u8(struct flash_bank *bank, int sector, uint32_t offset, ui */ static int cfi_get_u8(struct flash_bank *bank, int sector, uint32_t offset, uint8_t *val) { - struct target *target = bank->target; struct cfi_flash_bank *cfi_info = bank->driver_priv; uint8_t data[CFI_MAX_BUS_WIDTH]; int i; int retval; - retval = cfi_target_read_memory(target, flash_address(bank, sector, offset), + retval = cfi_target_read_memory(bank, flash_address(bank, sector, offset), bank->bus_width, 1, data); if (retval != ERROR_OK) return retval; @@ -231,7 +229,6 @@ static int cfi_get_u8(struct flash_bank *bank, int sector, uint32_t offset, uint static int cfi_query_u16(struct flash_bank *bank, int sector, uint32_t offset, uint16_t *val) { - struct target *target = bank->target; struct cfi_flash_bank *cfi_info = bank->driver_priv; uint8_t data[CFI_MAX_BUS_WIDTH * 2]; int retval; @@ -239,13 +236,13 @@ static int cfi_query_u16(struct flash_bank *bank, int sector, uint32_t offset, u if (cfi_info->x16_as_x8) { uint8_t i; for (i = 0; i < 2; i++) { - retval = cfi_target_read_memory(target, flash_address(bank, sector, offset + i), + retval = cfi_target_read_memory(bank, flash_address(bank, sector, offset + i), bank->bus_width, 1, &data[i * bank->bus_width]); if (retval != ERROR_OK) return retval; } } else { - retval = cfi_target_read_memory(target, flash_address(bank, sector, offset), + retval = cfi_target_read_memory(bank, flash_address(bank, sector, offset), bank->bus_width, 2, data); if (retval != ERROR_OK) return retval; @@ -261,7 +258,6 @@ static int cfi_query_u16(struct flash_bank *bank, int sector, uint32_t offset, u static int cfi_query_u32(struct flash_bank *bank, int sector, uint32_t offset, uint32_t *val) { - struct target *target = bank->target; struct cfi_flash_bank *cfi_info = bank->driver_priv; uint8_t data[CFI_MAX_BUS_WIDTH * 4]; int retval; @@ -269,13 +265,13 @@ static int cfi_query_u32(struct flash_bank *bank, int sector, uint32_t offset, u if (cfi_info->x16_as_x8) { uint8_t i; for (i = 0; i < 4; i++) { - retval = cfi_target_read_memory(target, flash_address(bank, sector, offset + i), + retval = cfi_target_read_memory(bank, flash_address(bank, sector, offset + i), bank->bus_width, 1, &data[i * bank->bus_width]); if (retval != ERROR_OK) return retval; } } else { - retval = cfi_target_read_memory(target, flash_address(bank, sector, offset), + retval = cfi_target_read_memory(bank, flash_address(bank, sector, offset), bank->bus_width, 4, data); if (retval != ERROR_OK) return retval; @@ -2004,14 +2000,13 @@ static int cfi_intel_write_word(struct flash_bank *bank, uint8_t *word, uint32_t { int retval; struct cfi_flash_bank *cfi_info = bank->driver_priv; - struct target *target = bank->target; cfi_intel_clear_status_register(bank); retval = cfi_send_command(bank, 0x40, address); if (retval != ERROR_OK) return retval; - retval = cfi_target_write_memory(target, address, bank->bus_width, 1, word); + retval = cfi_target_write_memory(bank, address, bank->bus_width, 1, word); if (retval != ERROR_OK) return retval; @@ -2038,7 +2033,6 @@ static int cfi_intel_write_words(struct flash_bank *bank, const uint8_t *word, { int retval; struct cfi_flash_bank *cfi_info = bank->driver_priv; - struct target *target = bank->target; /* Calculate buffer size and boundary mask * buffersize is (buffer size per chip) * (number of chips) @@ -2092,7 +2086,7 @@ static int cfi_intel_write_words(struct flash_bank *bank, const uint8_t *word, if (retval != ERROR_OK) return retval; - retval = cfi_target_write_memory(target, address, bank->bus_width, bufferwsize, word); + retval = cfi_target_write_memory(bank, address, bank->bus_width, bufferwsize, word); if (retval != ERROR_OK) return retval; @@ -2123,7 +2117,6 @@ static int cfi_spansion_write_word(struct flash_bank *bank, uint8_t *word, uint3 int retval; struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_spansion_pri_ext *pri_ext = cfi_info->pri_ext; - struct target *target = bank->target; retval = cfi_spansion_unlock_seq(bank); if (retval != ERROR_OK) @@ -2133,7 +2126,7 @@ static int cfi_spansion_write_word(struct flash_bank *bank, uint8_t *word, uint3 if (retval != ERROR_OK) return retval; - retval = cfi_target_write_memory(target, address, bank->bus_width, 1, word); + retval = cfi_target_write_memory(bank, address, bank->bus_width, 1, word); if (retval != ERROR_OK) return retval; @@ -2155,7 +2148,6 @@ static int cfi_spansion_write_words(struct flash_bank *bank, const uint8_t *word { int retval; struct cfi_flash_bank *cfi_info = bank->driver_priv; - struct target *target = bank->target; /* Calculate buffer size and boundary mask * buffersize is (buffer size per chip) * (number of chips) @@ -2195,7 +2187,7 @@ static int cfi_spansion_write_words(struct flash_bank *bank, const uint8_t *word if (retval != ERROR_OK) return retval; - retval = cfi_target_write_memory(target, address, bank->bus_width, bufferwsize, word); + retval = cfi_target_write_memory(bank, address, bank->bus_width, bufferwsize, word); if (retval != ERROR_OK) return retval; @@ -2268,7 +2260,6 @@ static int cfi_write_words(struct flash_bank *bank, const uint8_t *word, static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count) { struct cfi_flash_bank *cfi_info = bank->driver_priv; - struct target *target = bank->target; uint32_t address = bank->base + offset; uint32_t read_p; int align; /* number of unaligned bytes */ @@ -2297,7 +2288,7 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u LOG_INFO("Fixup %d unaligned read head bytes", align); /* read a complete word from flash */ - retval = cfi_target_read_memory(target, read_p, bank->bus_width, 1, current_word); + retval = cfi_target_read_memory(bank, read_p, bank->bus_width, 1, current_word); if (retval != ERROR_OK) return retval; @@ -2310,7 +2301,7 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u align = count / bank->bus_width; if (align) { - retval = cfi_target_read_memory(target, read_p, bank->bus_width, align, buffer); + retval = cfi_target_read_memory(bank, read_p, bank->bus_width, align, buffer); if (retval != ERROR_OK) return retval; @@ -2323,7 +2314,7 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u LOG_INFO("Fixup %" PRIu32 " unaligned read tail bytes", count); /* read a complete word from flash */ - retval = cfi_target_read_memory(target, read_p, bank->bus_width, 1, current_word); + retval = cfi_target_read_memory(bank, read_p, bank->bus_width, 1, current_word); if (retval != ERROR_OK) return retval; @@ -2338,7 +2329,6 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) { struct cfi_flash_bank *cfi_info = bank->driver_priv; - struct target *target = bank->target; uint32_t address = bank->base + offset; /* address of first byte to be programmed */ uint32_t write_p; int align; /* number of unaligned bytes */ @@ -2368,7 +2358,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of LOG_INFO("Fixup %d unaligned head bytes", align); /* read a complete word from flash */ - retval = cfi_target_read_memory(target, write_p, bank->bus_width, 1, current_word); + retval = cfi_target_read_memory(bank, write_p, bank->bus_width, 1, current_word); if (retval != ERROR_OK) return retval; @@ -2488,7 +2478,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of LOG_INFO("Fixup %" PRId32 " unaligned tail bytes", count); /* read a complete word from flash */ - retval = cfi_target_read_memory(target, write_p, bank->bus_width, 1, current_word); + retval = cfi_target_read_memory(bank, write_p, bank->bus_width, 1, current_word); if (retval != ERROR_OK) return retval; @@ -2638,11 +2628,11 @@ static int cfi_probe(struct flash_bank *bank) if (retval != ERROR_OK) return retval; - retval = cfi_target_read_memory(target, flash_address(bank, 0, 0x00), + retval = cfi_target_read_memory(bank, flash_address(bank, 0, 0x00), bank->bus_width, 1, value_buf0); if (retval != ERROR_OK) return retval; - retval = cfi_target_read_memory(target, flash_address(bank, 0, 0x01), + retval = cfi_target_read_memory(bank, flash_address(bank, 0, 0x01), bank->bus_width, 1, value_buf1); if (retval != ERROR_OK) return retval; |